@@ -14,26 +14,56 @@ ReadoutEquipment::ReadoutEquipment(ConfigFile &cfg, std::string cfgEntryPoint) {
1414 // printf("%s.%s = %s\n",cfgEntryPoint.c_str(),cfgKey.c_str(),cfgValue.c_str());
1515 // }
1616
17-
1817 // by default, name the equipment as the config node entry point
1918 cfg.getOptionalValue <std::string>(cfgEntryPoint + " .name" , name, cfgEntryPoint);
2019
2120 // target readout rate in Hz, -1 for unlimited (default). Global parameter, same for all equipments.
22- cfg.getOptionalValue <double >(" readout.rate" ,readoutRate,-1.0 );
21+ cfg.getOptionalValue <double >(" readout.rate" , readoutRate, -1.0 );
2322
2423 // idle sleep time, in microseconds.
2524 int cfgIdleSleepTime=200 ;
2625 cfg.getOptionalValue <int >(cfgEntryPoint + " .idleSleepTime" , cfgIdleSleepTime);
2726
28- readoutThread=std::make_unique<Thread>(ReadoutEquipment::threadCallback,this ,name,cfgIdleSleepTime);
29-
3027 // size of equipment output FIFO
3128 int cfgOutputFifoSize=1000 ;
3229 cfg.getOptionalValue <int >(cfgEntryPoint + " .outputFifoSize" , cfgOutputFifoSize);
30+
31+ // get memory bank parameters
32+ cfg.getOptionalValue <std::string>(cfgEntryPoint + " .memoryBankName" , memoryBankName);
33+ std::string cfgMemoryPoolPageSize=" " ;
34+ cfg.getOptionalValue <std::string>(cfgEntryPoint + " .memoryPoolPageSize" ,cfgMemoryPoolPageSize);
35+ memoryPoolPageSize=(int )ReadoutUtils::getNumberOfBytesFromString (cfgMemoryPoolPageSize.c_str ());
36+ cfg.getOptionalValue <int >(cfgEntryPoint + " .memoryPoolNumberOfPages" , memoryPoolNumberOfPages);
3337
38+ // log config summary
39+ theLog.log (" Equipment %s: from config [%s], max rate=%lf Hz, idleSleepTime=%d us, outputFifoSize=%d" , name.c_str (), cfgEntryPoint.c_str (), readoutRate, cfgIdleSleepTime, cfgOutputFifoSize);
40+ theLog.log (" Equipment %s: memory pool %d pages x %d bytes from bank %s" , name.c_str (),(int ) memoryPoolNumberOfPages, (int ) memoryPoolPageSize, memoryBankName.c_str ());
41+
42+ // init stats
43+ equipmentStats.resize (EquipmentStatsIndexes::maxIndex);
44+
45+ // create output fifo
3446 dataOut=std::make_shared<AliceO2::Common::Fifo<DataBlockContainerReference>>(cfgOutputFifoSize);
47+ if (dataOut==nullptr ) {
48+ throw __LINE__;
49+ }
50+
51+ // creation of memory pool for data pages
52+ // todo: also allocate pool of DataBlockContainers? at the same time? reserve space at start of pages?
53+ if ((memoryPoolPageSize<=0 )||(memoryPoolNumberOfPages<=0 )) {
54+ theLog.log (" Equipment %s: wrong memory pool settings" , name.c_str ());
55+ throw __LINE__;
56+ }
57+ mp=theMemoryBankManager.getPagedPool (memoryPoolPageSize, memoryPoolNumberOfPages, memoryBankName);
58+ if (mp==nullptr ) {
59+ throw __LINE__;
60+ }
3561
36- equipmentStats.resize (EquipmentStatsIndexes::maxIndex);
62+ // create thread
63+ readoutThread=std::make_unique<Thread>(ReadoutEquipment::threadCallback, this , name, cfgIdleSleepTime);
64+ if (readoutThread==nullptr ) {
65+ throw __LINE__;
66+ }
3767}
3868
3969const std::string & ReadoutEquipment::getName () {
@@ -67,7 +97,10 @@ void ReadoutEquipment::stop() {
6797}
6898
6999ReadoutEquipment::~ReadoutEquipment () {
70- // printf("deleted %s\n",name.c_str());
100+ // check if mempool still referenced
101+ if (!mp.unique ()) {
102+ theLog.log (" Equipment %s : mempool still has %d references\n " ,name.c_str (),(int )mp.use_count ());
103+ }
71104}
72105
73106
@@ -149,12 +182,20 @@ Thread::CallbackResult ReadoutEquipment::threadCallback(void *arg) {
149182 isActive=true ;
150183 }
151184 ptr->equipmentStats [EquipmentStatsIndexes::nBlocksOut].increment (nPushedOut);
185+
186+ // consider inactive if we have not pushed much compared to free space in output fifo
187+ // todo: instead, have dynamic 'inactive sleep time' as function of actual outgoing page rate to optimize polling interval
188+ if (nPushedOut<ptr->dataOut ->getNumberOfFreeSlots ()/4 ) {
189+ isActive=0 ;
190+ }
152191
153192 // todo: add SLICER to aggregate together time-range data
154193 // todo: get other FIFO status
155194
156195 break ;
157196 }
197+
198+
158199
159200 if (!isActive) {
160201 ptr->equipmentStats [EquipmentStatsIndexes::nIdle].increment ();
0 commit comments