Skip to content

Commit cb4e60f

Browse files
authored
Merge pull request #253 from sy-c/master
v2.19.0
2 parents 7e78440 + 9e120a9 commit cb4e60f

10 files changed

+237
-61
lines changed

doc/releaseNotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,8 @@ This file describes the main feature changes for each readout.exe released versi
558558

559559
## v2.18.5 - 17/05/2023
560560
- Fixed bug causing crash in some conditions of buffer empty. Related to same feature (dropIncomplete) as issue fixed in v2.18.3. Different corner case, involving threads, and not always happening.
561+
562+
## v2.19.0 - 01/06/2023
563+
- o2-readout-test-fmq-memory: more options.
564+
- Added protection against unhandled exceptions (e.g. from ReadoutCard).
565+
- Added protection against unexpected state machine transitions (e.g. ECS sending RESET while STARTING).

src/ReadoutEquipmentCruEmulator.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ ReadoutEquipmentCruEmulator::ReadoutEquipmentCruEmulator(ConfigFile& cfg, std::s
138138
payloadDistrib = std::normal_distribution<> (cfgPayloadSize, cfgPayloadSizeStdev * cfgPayloadSize);
139139
}
140140

141-
ReadoutEquipmentCruEmulator::~ReadoutEquipmentCruEmulator() {}
141+
ReadoutEquipmentCruEmulator::~ReadoutEquipmentCruEmulator() {
142+
abortThread();
143+
}
142144

143145
Thread::CallbackResult ReadoutEquipmentCruEmulator::prepareBlocks()
144146
{

src/ReadoutEquipmentDummy.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ ReadoutEquipmentDummy::ReadoutEquipmentDummy(ConfigFile& cfg, std::string cfgEnt
5858
}
5959
}
6060

61-
ReadoutEquipmentDummy::~ReadoutEquipmentDummy() {}
61+
ReadoutEquipmentDummy::~ReadoutEquipmentDummy() {
62+
abortThread();
63+
}
6264

6365
DataBlockContainerReference ReadoutEquipmentDummy::getNextBlock()
6466
{

src/ReadoutEquipmentPlayer.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ ReadoutEquipmentPlayer::ReadoutEquipmentPlayer(ConfigFile& cfg, std::string cfgE
187187

188188
ReadoutEquipmentPlayer::~ReadoutEquipmentPlayer()
189189
{
190+
abortThread();
190191
fpLock.lock();
191192
if (fp != nullptr) {
192193
fclose(fp);

src/ReadoutEquipmentRORC.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile& cfg, std::string name) :
195195
isInitialized = true;
196196
}
197197

198-
ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {}
198+
ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {
199+
abortThread();
200+
}
199201

200202
Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks()
201203
{

src/ReadoutEquipmentZmq.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ ReadoutEquipmentZmq::ReadoutEquipmentZmq(ConfigFile& cfg, std::string cfgEntryPo
193193

194194
ReadoutEquipmentZmq::~ReadoutEquipmentZmq()
195195
{
196+
abortThread();
196197

197198
// stopping snapshot thread
198199
if (snapshotThread != nullptr) {

src/ReadoutVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#define READOUT_VERSION "2.18.5"
12+
#define READOUT_VERSION "2.19.0"
1313

src/mainReadout.cxx

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

src/readoutErrorCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@
5252
{ 3242, "Database error", nullptr},
5353
{ 3243, "Control problem", nullptr},
5454
{ 3244, "Should not happen problem", nullptr},
55+
{ 3245, "Unhandled exception", nullptr},
5556
*/
5657

0 commit comments

Comments
 (0)