From 3bb9db9923c8635ab686d222da8785c252d512b4 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Tue, 7 Feb 2023 17:55:48 +0100 Subject: [PATCH] add try/catch in OnlineBeamMonitor plugin --- DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc | 61 ++++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc b/DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc index 19030aee3e3ec..76758d19a993a 100644 --- a/DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc +++ b/DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc @@ -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 +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("-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 myStringFunctor = [](BSparameters my_param, + 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::globalBeginLuminosityBlock( const LuminosityBlock& iLumi, const EventSetup& iSetup) const { @@ -154,9 +197,12 @@ std::shared_ptr OnlineBeamMonitor::globalBeginLumino auto const& spotDB = *bsHLTHandle; //lastLumiHLT_ = spotDB.lastAnalyzedLumi(); - startTimeStampHLT_ = spotDB.startTime(); - stopTimeStampHLT_ = spotDB.endTime(); - lumiRangeHLT_ = spotDB.lumiRange(); + startTimeStampHLT_ = + try_(std::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error); + stopTimeStampHLT_ = + try_(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error); + lumiRangeHLT_ = + try_(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error); // translate from BeamSpotObjects to reco::BeamSpot BeamSpot::Point apoint(spotDB.x(), spotDB.y(), spotDB.z()); @@ -194,9 +240,12 @@ std::shared_ptr 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::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error); + stopTimeStampLegacy_ = + try_(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error); + lumiRangeLegacy_ = + try_(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error); BeamSpot::CovarianceMatrix matrix; for (int i = 0; i < 7; ++i) {