Skip to content

Commit 4e8b5f6

Browse files
authored
Merge pull request #214 from sy-c/master
v2.9.1
2 parents 0c03422 + bcc4573 commit 4e8b5f6

File tree

9 files changed

+92
-31
lines changed

9 files changed

+92
-31
lines changed

doc/releaseNotes.md

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

432432
## v2.9.0 - 23/03/2022
433433
- Added optional database connection to store runtime statistics.
434+
435+
## v2.9.1 - 30/03/2022
436+
- DB improvements: occ.getRole() workaround for source id, logging.
437+
- Added logging of some EOR stats (TF number, etc) as for bookkeeping.
438+
- o2-readout-monitor: indexing by source for correct rates computation.

src/ReadoutDatabase.cxx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
typedef bool my_bool;
1414
#endif
1515

16-
ReadoutDatabase::ReadoutDatabase(const char* cx) {
16+
ReadoutDatabase::ReadoutDatabase(const char* cx, int v, const LogCallback& cb) {
17+
verbose = v;
18+
theLogCallback = cb;
1719

1820
char *db_db=nullptr, *db_user=nullptr, *db_pwd=nullptr, *db_host=nullptr;
1921
char *p=nullptr,*ptr,*lptr;
@@ -77,9 +79,7 @@ ReadoutDatabase::ReadoutDatabase(const char* cx) {
7779
goto open_failed;
7880
}
7981

80-
if (verbose) {
81-
printf("Using DB %s @ %s\n", db_db, db_host);
82-
}
82+
log("Using database " + std::string(db_db) + "@" + std::string(db_host));
8383

8484
// try to connect
8585
if (mysql_real_connect(db,db_host,db_user,db_pwd,db_db,0,nullptr,0)==nullptr) {
@@ -158,9 +158,7 @@ int ReadoutDatabase::query(int maxRetry, const char *inQuery,...) {
158158
return -1;
159159
}
160160

161-
if (verbose) {
162-
printf("Executing query: %s\n", query);
163-
}
161+
log("Executing query: " + std::string(query));
164162

165163
if (maxRetry <= 0) {
166164
maxRetry = 1;
@@ -298,3 +296,13 @@ const char* ReadoutDatabase::getError() {
298296
const char* ReadoutDatabase::getQuery() {
299297
return lastQuery.c_str();
300298
}
299+
300+
void ReadoutDatabase::log(const std::string &msg) {
301+
if (verbose) {
302+
if (theLogCallback!=nullptr) {
303+
theLogCallback(msg);
304+
} else {
305+
printf("%s\n", msg.c_str());
306+
}
307+
}
308+
}

src/ReadoutDatabase.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
#include <stdint.h>
44
#include <vector>
55
#include <string>
6+
#include <functional>
67

78
class ReadoutDatabase {
89
public:
9-
ReadoutDatabase(const char* cx); // create a handle to DB. Connection string in the form user:pwd@host/dbname
10+
// an optional user-provided logging function for all DB-related ops
11+
typedef std::function<void(const std::string &)> LogCallback;
12+
13+
ReadoutDatabase(const char* cx, int verbose = 0, const LogCallback& cb = nullptr); // create a handle to DB. Connection string in the form user:pwd@host/dbname
1014
~ReadoutDatabase();
1115

1216
// admin database structure
@@ -42,6 +46,9 @@ class ReadoutDatabase {
4246
int maxRetry = 20; // number of query retries
4347
int retryTimeout = 50; // retry interval (milliseconds)
4448

49+
LogCallback theLogCallback;
50+
void log(const std::string &log);
51+
4552
std::string lastError = ""; // error string of last query, if any
4653
std::string lastQuery = ""; // last query executed
4754
};

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.9.0"
12+
#define READOUT_VERSION "2.9.1"
1313

src/mainReadout.cxx

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <time.h>
2727
#include <string.h>
2828
#include <sys/mman.h>
29+
#include <inttypes.h>
2930

3031
#include "DataBlock.h"
3132
#include "DataBlockContainer.h"
@@ -124,6 +125,11 @@ static void signalHandler(int signalId)
124125
std::string occRole; // OCC role name
125126
tRunNumber occRunNumber = 0; // OCC run number
126127

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+
127133
class Readout
128134
{
129135

@@ -329,22 +335,6 @@ int Readout::init(int argc, char* argv[])
329335
initLogs.push_back({LogWarningSupport_(3236), "Failed to start Stats publish"});
330336
} //otherwise: disabled
331337

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

356346
// log startup and options
357-
theLog.log(LogInfoSupport_(3001), "Readout " READOUT_VERSION " - process starting, pid %d", getpid());
347+
theLog.log(LogInfoSupport_(3001), "Readout " READOUT_VERSION " - process starting, pid %d for role %s", getpid(), occRole.c_str());
358348
if (cfgVerbose) {
349+
theLog.log(LogInfoDevel, "Build time: %s %s", __DATE__, __TIME__);
359350
theLog.log(LogInfoDevel, "Optional built features enabled:");
360351
#ifdef WITH_READOUTCARD
361352
theLog.log(LogInfoDevel, "READOUTCARD : yes");
@@ -405,12 +396,26 @@ int Readout::init(int argc, char* argv[])
405396
theLog.log(LogInfoDevel, "ZMQ : no");
406397
#endif
407398
}
408-
399+
409400
// report cached logs
410401
for(auto const &l : initLogs) {
411402
theLog.log(l.first, "%s", l.second.c_str());
412403
}
413404

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

@@ -1220,6 +1225,13 @@ int Readout::stop()
12201225
// publish final logbook statistics
12211226
publishLogbookStats();
12221227

1228+
// publish some final counters
1229+
theLog.log(LogInfoDevel_(3003), "Final counters: timeframes = %" PRIu64 " readout = %s recorded = %s",
1230+
gReadoutStats.counters.numberOfSubtimeframes.load(),
1231+
NumberOfBytesToString(gReadoutStats.counters.bytesReadout.load(), "bytes").c_str(),
1232+
NumberOfBytesToString(gReadoutStats.counters.bytesRecorded.load(),"bytes").c_str()
1233+
);
1234+
12231235
theLog.log(LogInfoSupport_(3005), "Readout completed STOP");
12241236
gReadoutStats.counters.state = stringToUint64("ready");
12251237
gReadoutStats.counters.notify++;
@@ -1324,14 +1336,20 @@ class ReadoutOCCStateMachine : public RuntimeControlledObject
13241336
ReadoutOCCStateMachine(std::unique_ptr<Readout> r) : RuntimeControlledObject("Readout Process")
13251337
{
13261338
theReadout = std::move(r);
1327-
occRole = this->getRole();
1339+
// the following does not work: getRole() is empty at this stage - BUG. O2_ROLE is defined.
1340+
// occRole = this->getRole();
13281341
}
13291342

13301343
int executeConfigure(const boost::property_tree::ptree& properties)
13311344
{
13321345
if (theReadout == nullptr) {
13331346
return -1;
13341347
}
1348+
1349+
if (this->getRole() != occRole) {
1350+
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());
1351+
}
1352+
13351353
return theReadout->configure(properties);
13361354
}
13371355

src/readoutAdminDB.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace AliceO2::InfoLogger;
2626
void printUsage()
2727
{
2828
printf("Usage: readoutAdminDB ...\n");
29-
printf(" -c command : action to execute. One of create (create tables), clear (delete tables content), destroy (destroy all tables), test (insert some dummy data)\n");
29+
printf(" -c command : action to execute. One of create (create tables), clear (delete tables content), destroy (destroy all tables), fetch (retrieve content), test (insert some dummy data)\n");
3030
printf(" [-z pathToConfigurationFile] : sets which configuration to use. By default %s\n", cfgDefaultsPath.c_str());
3131
printf(" [-v] : sets verbose mode\n");
3232
printf(" [-h] : print this help\n");

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

src/readoutMonitor.cxx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Common/Configuration.h>
1313
#include <InfoLogger/InfoLogger.hxx>
1414
#include <InfoLogger/InfoLoggerMacros.hxx>
15+
#include <map>
1516
#include <signal.h>
1617
#include <zmq.h>
1718
#include "ReadoutStats.h"
@@ -214,7 +215,9 @@ int main(int argc, const char** argv)
214215
sigaction(SIGINT, &signalSettings, NULL);
215216

216217
theLog.log(LogInfoDevel_(3006), "Entering monitoring loop");
217-
double previousSampleTime = 0;
218+
219+
typedef std::map<std::string, double> MapCountersBySource;
220+
MapCountersBySource latestUpdate; // keep copy of latest counter for each source
218221

219222
// header
220223
if ((!cfgRawBytes)&&(broadcastSocket == nullptr)) {
@@ -244,6 +247,20 @@ int main(int argc, const char** argv)
244247
double t = counters->timestamp.load();
245248
double nRfmq = counters->pagesPendingFairMQreleased.load();
246249
double avgTfmq = 0.0;
250+
251+
std::string k = counters->source;
252+
MapCountersBySource::iterator lb = latestUpdate.lower_bound(k);
253+
double previousSampleTime = 0;
254+
255+
if(lb != latestUpdate.end() && !(latestUpdate.key_comp()(k, lb->first))) {
256+
// source was already sampled
257+
previousSampleTime = lb->second;
258+
lb->second = t;
259+
} else {
260+
// this is first sample for this source
261+
latestUpdate.insert(lb, MapCountersBySource::value_type(k, t));
262+
}
263+
247264
if (previousSampleTime > 0) {
248265
double deltaT = t - previousSampleTime;
249266
nRfmq = nRfmq / deltaT;

src/readoutStatus.tcl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set configSection "readout-monitor"
1212
# defaults
1313
set cfgValue_broadcastPort ""
1414
set cfgValue_broadcastHost ""
15+
set cfgValue_verbose 0
1516

1617
if {[llength $argv] >=2} {
1718
set configFile [lindex $argv 0]
@@ -484,7 +485,10 @@ proc processInput {} {
484485
}
485486

486487
if {[gets $server_fd msg]==-1} {break}
487-
puts "Msg: $msg"
488+
global cfgValue_verbose
489+
if {$cfgValue_verbose} {
490+
puts "Msg: $msg"
491+
}
488492
set lm [split $msg "\t"]
489493
if {[llength $lm]!=11} {break}
490494
updateNode $lm

0 commit comments

Comments
 (0)