Skip to content

Commit 2f899a2

Browse files
authored
Merge pull request cms-sw#40716 from francescobrivio/alca-fix_runtime_error
Add try/catch in OnlineBeamMonitor plugin to resolve runtime error
2 parents 8e150d4 + 3bb9db9 commit 2f899a2

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

DQM/BeamMonitor/plugins/OnlineBeamMonitor.cc

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,49 @@ void OnlineBeamMonitor::bookHistograms(DQMStore::IBooker& ibooker,
128128
bsChoice_->setAxisTitle("Choice", 2);
129129
}
130130

131+
//----------------------------------------------------------------------------------------------------------------------
132+
// Handle exceptions for the schema evolution of the BeamSpotOnline CondFormat
133+
134+
// Slightly better error handler
135+
static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; }
136+
137+
// Method to catch exceptions
138+
template <typename T, class Except, class Func, class Response>
139+
T try_(Func f, Response r) {
140+
try {
141+
LogDebug("BeamSpotOnlineParameters") << "I have tried" << std::endl;
142+
return f();
143+
} catch (Except& e) {
144+
LogDebug("BeamSpotOnlineParameters") << "I have caught!" << std::endl;
145+
r(e);
146+
return static_cast<T>("-999");
147+
}
148+
}
149+
150+
// Enum the BS string parameters
151+
enum BSparameters {
152+
startTime = 0, // 0 additional std::string parameters
153+
endTime = 1, // 1
154+
lumiRange = 2, // 2
155+
END_OF_TYPES = 3,
156+
};
157+
158+
// Functor
159+
std::function<std::string(BSparameters, BeamSpotOnlineObjects)> myStringFunctor = [](BSparameters my_param,
160+
BeamSpotOnlineObjects m_payload) {
161+
std::string ret("");
162+
switch (my_param) {
163+
case startTime:
164+
return m_payload.startTime();
165+
case endTime:
166+
return m_payload.endTime();
167+
case lumiRange:
168+
return m_payload.lumiRange();
169+
default:
170+
return ret;
171+
}
172+
};
173+
131174
//----------------------------------------------------------------------------------------------------------------------
132175
std::shared_ptr<onlinebeammonitor::NoCache> OnlineBeamMonitor::globalBeginLuminosityBlock(
133176
const LuminosityBlock& iLumi, const EventSetup& iSetup) const {
@@ -154,9 +197,12 @@ std::shared_ptr<onlinebeammonitor::NoCache> OnlineBeamMonitor::globalBeginLumino
154197
auto const& spotDB = *bsHLTHandle;
155198

156199
//lastLumiHLT_ = spotDB.lastAnalyzedLumi();
157-
startTimeStampHLT_ = spotDB.startTime();
158-
stopTimeStampHLT_ = spotDB.endTime();
159-
lumiRangeHLT_ = spotDB.lumiRange();
200+
startTimeStampHLT_ =
201+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error);
202+
stopTimeStampHLT_ =
203+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error);
204+
lumiRangeHLT_ =
205+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error);
160206

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

196242
//lastLumiLegacy_ = spotDB.lastAnalyzedLumi();
197-
startTimeStampLegacy_ = spotDB.startTime();
198-
stopTimeStampLegacy_ = spotDB.endTime();
199-
lumiRangeLegacy_ = spotDB.lumiRange();
243+
startTimeStampLegacy_ =
244+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::startTime, spotDB), print_error);
245+
stopTimeStampLegacy_ =
246+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::endTime, spotDB), print_error);
247+
lumiRangeLegacy_ =
248+
try_<std::string, std::out_of_range>(std::bind(myStringFunctor, BSparameters::lumiRange, spotDB), print_error);
200249

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

0 commit comments

Comments
 (0)