|
38 | 38 | #include "DataBlock.h" |
39 | 39 | #include "DataBlockContainer.h" |
40 | 40 | #include "DataSet.h" |
| 41 | +#include "readoutErrorCodes.h" |
41 | 42 |
|
42 | 43 | #ifdef WITH_ZMQ |
43 | 44 | #include "ZmqServer.hxx" |
@@ -314,59 +315,50 @@ class Readout |
314 | 315 | } |
315 | 316 | return -1; |
316 | 317 | } |
317 | | - int configure(const boost::property_tree::ptree& properties) { |
| 318 | + |
| 319 | + // Wrapper function to catch exception and report fatal errors |
| 320 | + int executeFunction(std::string actionName, std::function<int()> f) { |
| 321 | + // theLog.log(LogDebugDevel, "Calling function for %s",actionName.c_str()); |
| 322 | + int err = -1; |
318 | 323 | try { |
319 | | - return _configure(properties); |
| 324 | + err = f(); |
320 | 325 | } |
321 | 326 | catch (const std::exception& e) { |
322 | 327 | theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
323 | 328 | } |
324 | | - return -1; |
| 329 | + if (err) { |
| 330 | + std::vector<std::string> m; |
| 331 | + theLog.historyGetSummary(m); |
| 332 | + std::string reason = "Readout failed in " + actionName + ". Please check previous messages."; |
| 333 | + if (m.size()) { |
| 334 | + reason += " First error logged was " + m[0]; |
| 335 | + } |
| 336 | + theLog.log(LogFatalOps, "%s", reason.c_str()); |
| 337 | + } |
| 338 | + return err; |
| 339 | + } |
| 340 | + |
| 341 | + int configure(const boost::property_tree::ptree& properties) { |
| 342 | + theLog.historyReset(1); |
| 343 | + return executeFunction("CONFIGURE", std::bind(&Readout::_configure, this, properties)); |
325 | 344 | } |
326 | 345 | int reset() { // as opposed to configure() |
327 | | - try { |
328 | | - return _reset(); |
329 | | - } |
330 | | - catch (const std::exception& e) { |
331 | | - theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
332 | | - } |
333 | | - return -1; |
| 346 | + theLog.historyReset(1); |
| 347 | + return executeFunction("RESET", std::bind(&Readout::_reset, this)); |
334 | 348 | } |
335 | 349 | int start() { |
336 | | - try { |
337 | | - return _start(); |
338 | | - } |
339 | | - catch (const std::exception& e) { |
340 | | - theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
341 | | - } |
342 | | - return -1; |
| 350 | + theLog.historyReset(1); |
| 351 | + return executeFunction("START", std::bind(&Readout::_start, this)); |
343 | 352 | } |
344 | 353 | int stop() { // as opposed to start() |
345 | | - try { |
346 | | - return _stop(); |
347 | | - } |
348 | | - catch (const std::exception& e) { |
349 | | - theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
350 | | - } |
351 | | - return -1; |
| 354 | + theLog.historyReset(1); |
| 355 | + return executeFunction("STOP", std::bind(&Readout::_stop, this)); |
352 | 356 | } |
353 | 357 | int iterateRunning() { |
354 | | - try { |
355 | | - return _iterateRunning(); |
356 | | - } |
357 | | - catch (const std::exception& e) { |
358 | | - theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
359 | | - } |
360 | | - return -1; |
| 358 | + return executeFunction("RUNNING", std::bind(&Readout::_iterateRunning, this)); |
361 | 359 | } |
362 | 360 | int iterateCheck() { |
363 | | - try { |
364 | | - return _iterateCheck(); |
365 | | - } |
366 | | - catch (const std::exception& e) { |
367 | | - theLog.log(LogErrorSupport_(3245), "Exception : %s", e.what()); |
368 | | - } |
369 | | - return -1; |
| 361 | + return executeFunction("CHECK", std::bind(&Readout::_iterateCheck, this)); |
370 | 362 | } |
371 | 363 |
|
372 | 364 | void loopRunning(); // called in state "running" |
@@ -2261,6 +2253,9 @@ int main(int argc, char* argv[]) |
2261 | 2253 | // initialize logging |
2262 | 2254 | theLogContext.setField(InfoLoggerContext::FieldName::Facility, "readout"); |
2263 | 2255 | theLog.setContext(theLogContext); |
| 2256 | + for(const auto &c : readoutErrorCodes) { |
| 2257 | + theLog.registerErrorCodes({ {std::get<0>(c), std::get<1>(c) } }); |
| 2258 | + } |
2264 | 2259 |
|
2265 | 2260 | // create readout instance |
2266 | 2261 | std::unique_ptr<Readout> theReadout = std::make_unique<Readout>(); |
|
0 commit comments