Skip to content

Commit d562428

Browse files
committed
run number from env / to log
1 parent efbe74a commit d562428

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

doc/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ In all replay modes, ReadoutEquipmentPlayer does not support LZ4 files or files
382382
Readout can cope with input files containing data from multiple CRUs. The data pages will be split and tagged accordingly to the RDH fields (respecting the "1 single link per page" CRU specification).
383383

384384

385+
### Bookkeeping
386+
387+
Readout can store runtime statistics in O2 Bookeeping. See the readout.logbook* configuration variables.
388+
At runtime, the run number is provided by the O2 Control System when executing the START command.
389+
When running from the command line, a run number can be set using the O2_RUN environment variable.
390+
In interactive mode, the value is automatically incremented with successive START/STOP sequences.
391+
392+
385393
### Frequently asked questions
386394

387395
The [howto guide](howto.md) documents some typical use cases and will be extended according to users feedback.

doc/releaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,6 @@ This file describes the main feature changes for each readout.exe released versi
570570
- Added o2-readout-monitor-memory: to view in real time state of data pages.
571571
- Added consistency check of orbit vs timestamp when large gas in TF ids detected.
572572
- Updated configuration parameters documentation.
573+
574+
## next version
575+
- When running from the command line, the environment variable O2_RUN can be used to set the run number. It is set to 0 by default, i.e. undefined run number.

src/mainReadout.cxx

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static void signalHandler(int signalId)
142142

143143
// some globals needed in other components
144144
std::string occRole; // OCC role name
145-
tRunNumber occRunNumber = 0; // OCC run number
145+
tRunNumber occRunNumber = undefinedRunNumber; // OCC run number
146146

147147
// a general purpose log function for DB
148148
void dbLog(const std::string &msg) {
@@ -228,24 +228,27 @@ class LogbookThread {
228228
// thread loop, 10Hz
229229
while (!shutdownRequest && (logbookHandle != nullptr)) {
230230
if (publishRequest.load() == 1) {
231-
bool isOk = false;
232-
try {
233-
// interface: https://github.com/AliceO2Group/Bookkeeping/tree/main/cxx-client/include/BookkeepingApi
234-
logbookHandle->flp()->updateReadoutCountersByFlpNameAndRunNumber(
235-
occRole, occRunNumber,
236-
(int64_t)gReadoutStats.counters.numberOfSubtimeframes, (int64_t)gReadoutStats.counters.bytesReadout, (int64_t)gReadoutStats.counters.bytesRecorded, (int64_t)gReadoutStats.counters.bytesFairMQ
237-
);
238-
isOk = true;
239-
} catch (const std::exception& ex) {
240-
theLog.log(LogErrorDevel_(3210), "Failed to update logbook: %s", ex.what());
241-
} catch (...) {
242-
theLog.log(LogErrorDevel_(3210), "Failed to update logbook: unknown exception");
243-
}
244-
if (!isOk) {
245-
// closing logbook immediately
246-
logbookHandle = nullptr;
247-
theLog.log(LogErrorSupport_(3210), "Logbook now disabled");
248-
break;
231+
// publishing to logbook makes sense only if a run number defined
232+
if (occRunNumber != undefinedRunNumber) {
233+
bool isOk = false;
234+
try {
235+
// interface: https://github.com/AliceO2Group/Bookkeeping/tree/main/cxx-client/include/BookkeepingApi
236+
logbookHandle->flp()->updateReadoutCountersByFlpNameAndRunNumber(
237+
occRole, occRunNumber,
238+
(int64_t)gReadoutStats.counters.numberOfSubtimeframes, (int64_t)gReadoutStats.counters.bytesReadout, (int64_t)gReadoutStats.counters.bytesRecorded, (int64_t)gReadoutStats.counters.bytesFairMQ
239+
);
240+
isOk = true;
241+
} catch (const std::exception& ex) {
242+
theLog.log(LogErrorDevel_(3210), "Failed to update logbook: %s", ex.what());
243+
} catch (...) {
244+
theLog.log(LogErrorDevel_(3210), "Failed to update logbook: unknown exception");
245+
}
246+
if (!isOk) {
247+
// closing logbook immediately
248+
logbookHandle = nullptr;
249+
theLog.log(LogErrorSupport_(3210), "Logbook now disabled");
250+
break;
251+
}
249252
}
250253
publishRequest = 0;
251254
}
@@ -1357,6 +1360,17 @@ int Readout::_configure(const boost::property_tree::ptree& properties)
13571360

13581361
int Readout::_start()
13591362
{
1363+
// set run number for logs
1364+
theLogContext.setField(InfoLoggerContext::FieldName::Run, std::to_string(occRunNumber)); // this works also for undefinedRunNumber, 0 -> empty field in log API
1365+
theLog.setContext(theLogContext);
1366+
if (occRunNumber != undefinedRunNumber) {
1367+
setenv(envRunNumber, std::to_string(occRunNumber).c_str(), 1);
1368+
theLog.log(LogInfoDevel, "Run number %d", (int)occRunNumber);
1369+
} else {
1370+
unsetenv(envRunNumber);
1371+
theLog.log(LogInfoDevel, "Run number not defined");
1372+
}
1373+
13601374
theLog.resetMessageCount();
13611375
theLog.log(LogInfoSupport_(3005), "Readout executing START");
13621376
gReadoutStats.reset(1);
@@ -1706,6 +1720,9 @@ int Readout::_stop()
17061720

17071721
int Readout::_reset()
17081722
{
1723+
// reset run number for logs
1724+
theLogContext.setField(InfoLoggerContext::FieldName::Run, "");
1725+
theLog.setContext(theLogContext);
17091726

17101727
theLog.log(LogInfoSupport_(3005), "Readout executing RESET");
17111728
gReadoutStats.counters.state = stringToUint64("> reset");
@@ -1914,15 +1931,6 @@ class ReadoutOCCStateMachine : public RuntimeControlledObject
19141931
}
19151932
// set run number
19161933
occRunNumber = this->getRunNumber();
1917-
theLogContext.setField(InfoLoggerContext::FieldName::Run, std::to_string(occRunNumber));
1918-
theLog.setContext(theLogContext);
1919-
if (occRunNumber != 0) {
1920-
setenv(envRunNumber, std::to_string(occRunNumber).c_str(), 1);
1921-
theLog.log(LogInfoDevel, "Run number %d", (int)occRunNumber);
1922-
} else {
1923-
unsetenv(envRunNumber);
1924-
theLog.log(LogInfoDevel, "Run number not defined");
1925-
}
19261934
return theReadout->start();
19271935
}
19281936

@@ -1987,6 +1995,17 @@ class ReadoutOCCStateMachine : public RuntimeControlledObject
19871995
};
19881996
#endif
19891997

1998+
// increment run number based on initial settings from env
1999+
void incrementRunNumber() {
2000+
if (occRunNumber != undefinedRunNumber) {
2001+
occRunNumber++;
2002+
} else {
2003+
if (getenv(envRunNumber) != nullptr) {
2004+
occRunNumber = atoi(getenv(envRunNumber));
2005+
}
2006+
}
2007+
}
2008+
19902009
// the main program loop
19912010
int main(int argc, char* argv[])
19922011
{
@@ -2151,7 +2170,7 @@ int main(int argc, char* argv[])
21512170
}
21522171
} else if (theState == States::Configured) {
21532172
if (theCommand == Commands::Start) {
2154-
occRunNumber++;
2173+
incrementRunNumber();
21552174
err = theReadout->start();
21562175
if (err) {
21572176
newState = States::Error;
@@ -2234,7 +2253,7 @@ int main(int argc, char* argv[])
22342253
return err;
22352254
}
22362255

2237-
int nloop = 1; // number of start/stop loop to execute
2256+
int nloop = 3; // number of start/stop loop to execute
22382257

22392258
auto logTimeGuard = [&](const std::string command, int t) {
22402259
if (t) {
@@ -2262,7 +2281,7 @@ int main(int argc, char* argv[])
22622281

22632282
// loop for testing, single iteration in normal conditions
22642283
for (int i = 0; i < nloop; i++) {
2265-
occRunNumber++;
2284+
incrementRunNumber();
22662285
err = theReadout->start();
22672286
if (err) {
22682287
return err;

src/receiverFMQ.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ int main(int argc, const char** argv)
363363
"STF:\n \
364364
version: %d\n \
365365
timeframeId: %d\n \
366+
runNumber: %d\n \
366367
systemId: %d\n \
367368
feeId: %d\n \
368369
equipmentId: %d\n \
369370
linkId: %d\n\
370371
lastTFMessage: %d\n",
371372
(int)stf->version,
372373
(int)stf->timeframeId,
374+
(int)stf->runNumber,
373375
(int)stf->systemId,
374376
(int)stf->feeId,
375377
(int)stf->equipmentId,

0 commit comments

Comments
 (0)