Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add try/catch in OnlineBeamMonitor plugin to resolve runtime error #40716

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,49 @@ void OnlineBeamMonitor::bookHistograms(DQMStore::IBooker& ibooker,
bsChoice_->setAxisTitle("Choice", 2);
}

//----------------------------------------------------------------------------------------------------------------------
// Handle exceptions for the schema evolution of the BeamSpotOnline CondFormat

// Slightly better error handler
static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; }

// Method to catch exceptions
template <typename T, class Except, class Func, class Response>
T try_(Func f, Response r) {
try {
LogDebug("BeamSpotOnlineParameters") << "I have tried" << std::endl;
return f();
} catch (Except& e) {
LogDebug("BeamSpotOnlineParameters") << "I have caught!" << std::endl;
r(e);
return static_cast<T>("-999");
}
}

// Enum the BS string parameters
enum BSparameters {
startTime = 0, // 0 additional std::string parameters
endTime = 1, // 1
lumiRange = 2, // 2
END_OF_TYPES = 3,
};

// Functor
std::function<std::string(BSparameters, BeamSpotOnlineObjects)> myStringFunctor = [](BSparameters my_param,
francescobrivio marked this conversation as resolved.
Show resolved Hide resolved
BeamSpotOnlineObjects m_payload) {
std::string ret("");
switch (my_param) {
case startTime:
return m_payload.startTime();
case endTime:
return m_payload.endTime();
case lumiRange:
return m_payload.lumiRange();
default:
return ret;
}
};

//----------------------------------------------------------------------------------------------------------------------
std::shared_ptr<onlinebeammonitor::NoCache> OnlineBeamMonitor::globalBeginLuminosityBlock(
const LuminosityBlock& iLumi, const EventSetup& iSetup) const {
Expand All @@ -154,9 +197,12 @@ std::shared_ptr<onlinebeammonitor::NoCache> OnlineBeamMonitor::globalBeginLumino
auto const& spotDB = *bsHLTHandle;

//lastLumiHLT_ = spotDB.lastAnalyzedLumi();
startTimeStampHLT_ = spotDB.startTime();
stopTimeStampHLT_ = spotDB.endTime();
lumiRangeHLT_ = spotDB.lumiRange();
startTimeStampHLT_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error);
stopTimeStampHLT_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error);
lumiRangeHLT_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error);

// translate from BeamSpotObjects to reco::BeamSpot
BeamSpot::Point apoint(spotDB.x(), spotDB.y(), spotDB.z());
Expand Down Expand Up @@ -194,9 +240,12 @@ std::shared_ptr<onlinebeammonitor::NoCache> OnlineBeamMonitor::globalBeginLumino
BeamSpot::Point apoint(spotDB.x(), spotDB.y(), spotDB.z());

//lastLumiLegacy_ = spotDB.lastAnalyzedLumi();
startTimeStampLegacy_ = spotDB.startTime();
stopTimeStampLegacy_ = spotDB.endTime();
lumiRangeLegacy_ = spotDB.lumiRange();
startTimeStampLegacy_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error);
stopTimeStampLegacy_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error);
lumiRangeLegacy_ =
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error);

BeamSpot::CovarianceMatrix matrix;
for (int i = 0; i < 7; ++i) {
Expand Down