@@ -198,13 +198,71 @@ class Readout
198198
199199 public:
200200 ~Readout ();
201- int init (int argc, char * argv[]);
202- int configure (const boost::property_tree::ptree& properties);
203- int reset (); // as opposed to configure()
204- int start ();
205- int stop (); // as opposed to start()
206- int iterateRunning ();
207- int iterateCheck ();
201+
202+ // protected calls catching all exceptions
203+ int init (int argc, char * argv[]) {
204+ try {
205+ return _init (argc, argv);
206+ }
207+ catch (const std::exception& e) {
208+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
209+ }
210+ return -1 ;
211+ }
212+ int configure (const boost::property_tree::ptree& properties) {
213+ try {
214+ return _configure (properties);
215+ }
216+ catch (const std::exception& e) {
217+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
218+ }
219+ return -1 ;
220+ }
221+ int reset () { // as opposed to configure()
222+ try {
223+ return _reset ();
224+ }
225+ catch (const std::exception& e) {
226+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
227+ }
228+ return -1 ;
229+ }
230+ int start () {
231+ try {
232+ return _start ();
233+ }
234+ catch (const std::exception& e) {
235+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
236+ }
237+ return -1 ;
238+ }
239+ int stop () { // as opposed to start()
240+ try {
241+ return _stop ();
242+ }
243+ catch (const std::exception& e) {
244+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
245+ }
246+ return -1 ;
247+ }
248+ int iterateRunning () {
249+ try {
250+ return _iterateRunning ();
251+ }
252+ catch (const std::exception& e) {
253+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
254+ }
255+ return -1 ;
256+ }
257+ int iterateCheck () {
258+ try {
259+ return _iterateCheck ();
260+ }
261+ catch (const std::exception& e) {
262+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
263+ }
264+ return -1 ;
265+ }
208266
209267 void loopRunning (); // called in state "running"
210268
@@ -213,6 +271,14 @@ class Readout
213271 int cfgTimeStop = 0 ; // time at which STOP should be executed in standalone mode
214272
215273 private:
274+ int _init (int argc, char * argv[]);
275+ int _configure (const boost::property_tree::ptree& properties);
276+ int _reset (); // as opposed to configure()
277+ int _start ();
278+ int _stop (); // as opposed to start()
279+ int _iterateRunning ();
280+ int _iterateCheck ();
281+
216282 ConfigFile cfg;
217283 const char * cfgFileURI = " " ;
218284 const char * cfgFileEntryPoint = " " ; // where in the config tree to look for
@@ -330,7 +396,7 @@ void Readout::publishLogbookStats()
330396#endif
331397}
332398
333- int Readout::init (int argc, char * argv[])
399+ int Readout::_init (int argc, char * argv[])
334400{
335401 setThreadName (nullptr );
336402
@@ -577,7 +643,7 @@ int Readout::init(int argc, char* argv[])
577643
578644// #include <boost/property_tree/json_parser.hpp>
579645
580- int Readout::configure (const boost::property_tree::ptree& properties)
646+ int Readout::_configure (const boost::property_tree::ptree& properties)
581647{
582648 theLog.log (LogInfoSupport_ (3005 ), " Readout executing CONFIGURE" );
583649 gReadoutStats .counters .state = stringToUint64 (" > conf" );
@@ -1249,7 +1315,7 @@ int Readout::configure(const boost::property_tree::ptree& properties)
12491315 return 0 ;
12501316}
12511317
1252- int Readout::start ()
1318+ int Readout::_start ()
12531319{
12541320 theLog.resetMessageCount ();
12551321 theLog.log (LogInfoSupport_ (3005 ), " Readout executing START" );
@@ -1359,6 +1425,7 @@ void Readout::loopRunning()
13591425 // ProfilerStart(gperfOutputFile.c_str());
13601426#endif
13611427
1428+ try {
13621429 for (;;) {
13631430 if ((!isRunning) && ((cfgFlushEquipmentTimeout <= 0 ) || (stopTimer.isTimeout ()))) {
13641431 break ;
@@ -1423,6 +1490,10 @@ void Readout::loopRunning()
14231490 usleep (1000 );
14241491 }
14251492 }
1493+ }
1494+ catch (const std::exception& e) {
1495+ theLog.log (LogErrorSupport_ (3245 ), " Exception : %s" , e.what ());
1496+ }
14261497
14271498#ifdef CALLGRIND
14281499 CALLGRIND_STOP_INSTRUMENTATION;
@@ -1437,7 +1508,7 @@ void Readout::loopRunning()
14371508 theLog.log (LogInfoDevel, " Exiting main loop" );
14381509}
14391510
1440- int Readout::iterateCheck ()
1511+ int Readout::_iterateCheck ()
14411512{
14421513 usleep (100000 );
14431514 for (auto && readoutDevice : readoutDevices) {
@@ -1465,7 +1536,7 @@ int Readout::iterateCheck()
14651536 return 0 ;
14661537}
14671538
1468- int Readout::iterateRunning ()
1539+ int Readout::_iterateRunning ()
14691540{
14701541 usleep (100000 );
14711542 // printf("running time: %.2f\n",startTimer.getTime());
@@ -1492,7 +1563,7 @@ int Readout::iterateRunning()
14921563 return 0 ;
14931564}
14941565
1495- int Readout::stop ()
1566+ int Readout::_stop ()
14961567{
14971568
14981569 theLog.log (LogInfoSupport_ (3005 ), " Readout executing STOP" );
@@ -1593,7 +1664,7 @@ int Readout::stop()
15931664 return 0 ;
15941665}
15951666
1596- int Readout::reset ()
1667+ int Readout::_reset ()
15971668{
15981669
15991670 theLog.log (LogInfoSupport_ (3005 ), " Readout executing RESET" );
@@ -1640,6 +1711,10 @@ int Readout::reset()
16401711
16411712 theLog.log (LogInfoDevel, " Releasing readout devices" );
16421713 for (size_t i = 0 , size = readoutDevices.size (); i != size; ++i) {
1714+ if (readoutDevices[i] != nullptr ) {
1715+ // ensure readout equipment threads stopped before releasing resources
1716+ readoutDevices[i]->abortThread ();
1717+ }
16431718 readoutDevices[i] = nullptr ; // effectively deletes the device
16441719 }
16451720 readoutDevices.clear ();
0 commit comments