99#include < Common/DataBlockContainer.h>
1010#include < Common/MemPool.h>
1111#include < Common/DataSet.h>
12+ #include < Common/Timer.h>
13+ #include < Common/Fifo.h>
14+ #include < Common/Thread.h>
1215
1316#include < atomic>
14- #ifndef __APPLE__
15- #include < malloc.h>
16- #endif
17- #include < boost/format.hpp>
1817#include < chrono>
19- #include < signal.h>
20-
2118#include < memory>
22- #include < stdint.h>
23-
24- #include < Common/Timer.h>
25- #include < Common/Fifo.h>
26- #include < Common/Thread.h>
19+ #include < signal.h>
2720
2821#ifdef WITH_DATASAMPLING
2922#include " DataSampling/InjectorFactory.h"
3023#endif
3124
32-
3325#include " ReadoutEquipment.h"
3426#include " DataBlockAggregator.h"
3527#include " Consumer.h"
3628#include " MemoryBankManager.h"
3729#include " ReadoutUtils.h"
3830
31+
3932// option to add callgrind instrumentation
4033// to use: valgrind --tool=callgrind --instr-atstart=no --dump-instr=yes ./a.out
4134// to display stats: kcachegrind
4538#endif
4639
4740
41+ // option to enable compilation with FairMQ support
4842#ifdef WITH_FAIRMQ
4943#include < fairmq/FairMQLogger.h>
44+ #include < InfoLogger/InfoLoggerFMQ.hxx>
5045#endif
5146
5247
48+ // namespace used
5349using namespace AliceO2 ::InfoLogger;
5450using namespace AliceO2 ::Common;
5551
5652
57- #define LOG_TRACE printf (" %d\n " ,__LINE__);fflush(stdout);
58-
59-
6053// global entry point to log system
6154InfoLogger theLog;
6255
6356
57+ // global signal handler to end program
6458static int ShutdownRequest=0 ; // set to 1 to request termination, e.g. on SIGTERM/SIGQUIT signals
65- static void signalHandler (int ){
66- printf (" *** break ***\n " );
59+ static void signalHandler (int signalId) {
60+ theLog.log (" Received signal %d" ,signalId);
61+ printf (" *** break ***\n " );
6762 if (ShutdownRequest) {
6863 // immediate exit if pending exit request
6964 exit (1 );
7065 }
7166 ShutdownRequest=1 ;
7267}
7368
74-
75-
76-
77-
78-
79-
80-
81-
82-
83-
69+ // the main program loop
8470int main (int argc, char * argv[])
8571{
8672 ConfigFile cfg;
@@ -103,37 +89,11 @@ int main(int argc, char* argv[])
10389 theLog.log (" Readout process starting" );
10490 theLog.log (" Optional built features enabled:" );
10591 #ifdef WITH_FAIRMQ
106- theLog.log (" FAIRMQ : yes" );
107- fair::Logger::SetConsoleColor (true );
108- fair::Logger::SetConsoleSeverity (" nolog" );
109- fair::Logger::AddCustomSink (" infoLogger" , " trace" , [&](const std::string& content, // log content
110- const fair::LogMetaData& metadata) // log metadata (see docs for details)
111- {
112- std::string message= " FMQ : "
113- // + std::to_string(metadata.timestamp) + " "
114- + std::to_string (metadata.us .count ()) + " "
115- // + metadata.process_name + " "
116- // + metadata.file + " "
117- // + metadata.line + " "
118- // + metadata.func + " "
119- + content;
120- /* struct LogMetaData
121- {
122- std::time_t timestamp;
123- std::chrono::microseconds us;
124- std::string process_name;
125- std::string file;
126- std::string line;
127- std::string func;
128- std::string severity_name;
129- fair::Severity severity;
130- };
131- */
132- theLog.logInfo (message);
133- });
134-
92+ theLog.log (" FAIRMQ : yes" );
93+ // redirect FMQ logs to infologger
94+ setFMQLogsToInfoLogger (&theLog);
13595 #else
136- theLog.log (" FAIRMQ : no" );
96+ theLog.log (" FAIRMQ : no" );
13797 #endif
13898
13999 // load configuration file
@@ -374,22 +334,11 @@ int main(int argc, char* argv[])
374334 theLog.log (" Automatic exit in %.2f seconds" ,cfgExitTimeout);
375335 }
376336 int isRunning=1 ;
377- AliceO2::Common::Timer t0;
378- t0.reset ();
379-
380-
381- /*
382- // reset stats
383- unsigned long long nBlocks=0;
384- unsigned long long nBytes=0;
385- double t1=0.0;
386- */
387-
388337
389338 theLog.log (" Entering loop" );
390339 #ifdef CALLGRIND
391- theLog.log (" Starting callgrind instrumentation" );
392- CALLGRIND_START_INSTRUMENTATION;
340+ theLog.log (" Starting callgrind instrumentation" );
341+ CALLGRIND_START_INSTRUMENTATION;
393342 #endif
394343
395344 while (1 ) {
@@ -421,11 +370,11 @@ int main(int argc, char* argv[])
421370
422371 if (bc!=nullptr ) {
423372 // push to data sampling, if configured
424- #ifdef WITH_DATASAMPLING
425- if (dataSampling) {
426- dataSamplingInjector->injectSamples (bc);
427- }
428- #endif
373+ #ifdef WITH_DATASAMPLING
374+ if (dataSampling) {
375+ dataSamplingInjector->injectSamples (bc);
376+ }
377+ #endif
429378 // todo: datasampling can become a consumer, now that consumer interface accepts datasets instead of blocks
430379
431380 for (auto & c : dataConsumers) {
@@ -445,17 +394,10 @@ int main(int argc, char* argv[])
445394 #endif
446395
447396
448-
449397 theLog.log (" Stopping aggregator" );
450398 agg.stop ();
451399
452-
453- // t1=t0.getTime();
454-
455- // theLog.log("Wait a bit");
456- // sleep(1);
457- theLog.log (" Stop consumers" );
458-
400+ theLog.log (" Stopping consumers" );
459401 // close consumers before closing readout equipments (owner of data blocks)
460402 dataConsumers.clear ();
461403
@@ -469,7 +411,6 @@ int main(int argc, char* argv[])
469411 readoutDevice->dataOut ->clear ();
470412 }
471413
472-
473414// printf("agg: in=%llu out=%llu\n",agg_output.getNumberIn(),agg_output.getNumberOut());
474415
475416 theLog.log (" Closing readout devices" );
@@ -478,14 +419,7 @@ int main(int argc, char* argv[])
478419 }
479420 readoutDevices.clear (); // to do it all in one go
480421
481- /*
482- theLog.log("%llu blocks in %.3lf seconds => %.1lf block/s",nBlocks,t1,nBlocks/t1);
483- theLog.log("%.1lf MB received",nBytes/(1024.0*1024.0));
484- theLog.log("%.3lf MB/s",nBytes/(1024.0*1024.0)/t1);
485- */
486-
487422 theLog.log (" Operations completed" );
488423
489424 return 0 ;
490-
491425}
0 commit comments