Skip to content

Commit 1cd3932

Browse files
committed
workaround for occControlInstance->getRole() not working. added db log cb
1 parent e46e0ea commit 1cd3932

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/mainReadout.cxx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ static void signalHandler(int signalId)
125125
std::string occRole; // OCC role name
126126
tRunNumber occRunNumber = 0; // OCC run number
127127

128+
// a general purpose log function for DB
129+
void dbLog(const std::string &msg) {
130+
theLog.log(LogInfoDevel_(3012), "%s", msg.c_str());
131+
}
132+
128133
class Readout
129134
{
130135

@@ -276,7 +281,6 @@ int Readout::init(int argc, char* argv[])
276281
cfgDefaults.getOptionalValue<std::string>(cfgDefaultsEntryPoint + ".statsPublishAddress", cfgStatsPublishAddress, cfgStatsPublishAddress);
277282
cfgDefaults.getOptionalValue<double>(cfgDefaultsEntryPoint + ".statsPublishInterval", cfgStatsPublishInterval, cfgStatsPublishInterval);
278283
cfgDefaults.getOptionalValue<std::string>(cfgDefaultsEntryPoint + ".db", cfgDatabaseCxParams);
279-
cfgDefaults.getOptionalValue<int>(cfgDefaultsEntryPoint + ".dbVerbose", cfgDatabaseVerbose);
280284
}
281285
catch(...) {
282286
//initLogs.push_back({LogWarningSupport_(3100), std::string("Error loading defaults")});
@@ -332,22 +336,6 @@ int Readout::init(int argc, char* argv[])
332336
initLogs.push_back({LogWarningSupport_(3236), "Failed to start Stats publish"});
333337
} //otherwise: disabled
334338

335-
// init database
336-
if (cfgDatabaseCxParams != "") {
337-
#ifdef WITH_DB
338-
try {
339-
dbHandle=std::make_unique<ReadoutDatabase>(cfgDatabaseCxParams.c_str());
340-
if (dbHandle == nullptr) { throw __LINE__; }
341-
dbHandle->verbose = cfgDatabaseVerbose;
342-
initLogs.push_back({LogInfoSupport, "Database connected "});
343-
}
344-
catch(...) {
345-
initLogs.push_back({LogWarningSupport_(3242), "Failed to connect database"});
346-
}
347-
#endif
348-
}
349-
350-
351339
// configure signal handlers for clean exit
352340
struct sigaction signalSettings;
353341
bzero(&signalSettings, sizeof(signalSettings));
@@ -357,8 +345,9 @@ int Readout::init(int argc, char* argv[])
357345
sigaction(SIGINT, &signalSettings, NULL);
358346

359347
// log startup and options
360-
theLog.log(LogInfoSupport_(3001), "Readout " READOUT_VERSION " - process starting, pid %d", getpid());
348+
theLog.log(LogInfoSupport_(3001), "Readout " READOUT_VERSION " - process starting, pid %d for role %s", getpid(), occRole.c_str());
361349
if (cfgVerbose) {
350+
theLog.log(LogInfoDevel, "Build time: %s %s", __DATE__, __TIME__);
362351
theLog.log(LogInfoDevel, "Optional built features enabled:");
363352
#ifdef WITH_READOUTCARD
364353
theLog.log(LogInfoDevel, "READOUTCARD : yes");
@@ -408,12 +397,26 @@ int Readout::init(int argc, char* argv[])
408397
theLog.log(LogInfoDevel, "ZMQ : no");
409398
#endif
410399
}
411-
400+
412401
// report cached logs
413402
for(auto const &l : initLogs) {
414403
theLog.log(l.first, "%s", l.second.c_str());
415404
}
416405

406+
// init database
407+
if (cfgDatabaseCxParams != "") {
408+
#ifdef WITH_DB
409+
try {
410+
dbHandle=std::make_unique<ReadoutDatabase>(cfgDatabaseCxParams.c_str(), cfgVerbose, dbLog);
411+
if (dbHandle == nullptr) { throw __LINE__; }
412+
theLog.log(LogInfoDevel_(3012), "Database connected ");
413+
}
414+
catch(...) {
415+
theLog.log(LogWarningDevel_(3242), "Failed to connect database");
416+
}
417+
#endif
418+
}
419+
417420
return 0;
418421
}
419422

@@ -1334,14 +1337,20 @@ class ReadoutOCCStateMachine : public RuntimeControlledObject
13341337
ReadoutOCCStateMachine(std::unique_ptr<Readout> r) : RuntimeControlledObject("Readout Process")
13351338
{
13361339
theReadout = std::move(r);
1337-
occRole = this->getRole();
1340+
// the following does not work: getRole() is empty at this stage - BUG. O2_ROLE is defined.
1341+
// occRole = this->getRole();
13381342
}
13391343

13401344
int executeConfigure(const boost::property_tree::ptree& properties)
13411345
{
13421346
if (theReadout == nullptr) {
13431347
return -1;
13441348
}
1349+
1350+
if (this->getRole() != occRole) {
1351+
theLog.log(LogWarningDevel_(3243), "OCC role mismatch: getRole()=%s %s=%s occRole=%s", this->getRole().c_str(), OCC_ROLE_ENV, getenv(OCC_ROLE_ENV), occRole.c_str());
1352+
}
1353+
13451354
return theReadout->configure(properties);
13461355
}
13471356

src/readoutErrorCodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{ 3009, "Trace for readout data dump", nullptr},
2727
{ 3010, "Trace for readout hardware operations and status", nullptr},
2828
{ 3011, "Trace for readout data stream content", nullptr},
29+
{ 3012, "Trace for readout database operations", nullptr},
2930
3031
{ 3100, "Configuration problem", nullptr},
3132
{ 3101, "A feature is configured but not supported by this readout build.", nullptr},
@@ -47,5 +48,6 @@
4748
{ 3240, "Readout card problem", nullptr},
4849
{ 3241, "Inconsistent data", nullptr},
4950
{ 3242, "Database error", nullptr},
51+
{ 3243, "Control problem", nullptr},
5052
*/
5153

0 commit comments

Comments
 (0)