@@ -27,10 +27,12 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
2727 ReadoutEquipmentRORC (ConfigFile &cfg, std::string name=" rorcReadout" );
2828 ~ReadoutEquipmentRORC ();
2929
30+ private:
3031 Thread::CallbackResult prepareBlocks ();
3132 DataBlockContainerReference getNextBlock ();
32-
33- private:
33+ void setDataOn ();
34+ void setDataOff ();
35+
3436 Thread::CallbackResult populateFifoOut (); // the data readout loop function
3537
3638 AliceO2::roc::ChannelFactory::DmaChannelSharedPtr channel; // channel to ROC device
@@ -172,9 +174,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
172174 baseAddress, blockSize
173175 });
174176
175- // clear locks if necessary
176- params.setForcedUnlockEnabled (true );
177-
178177 // define link mask
179178 // this is harmless for C-RORC
180179 params.setLinkMask (AliceO2::roc::Parameters::linkMaskFromString (cfgLinkMask));
@@ -199,14 +198,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
199198
200199 // todo: log parameters ?
201200
202- // start DMA
203- theLog.log (" Starting DMA for ROC %s:%d" ,cardId.c_str (),cfgChannelNumber);
204- channel->startDma ();
205-
206- // get FIFO depth (it should be fully empty when starting)
207- RocFifoSize=channel->getTransferQueueAvailable ();
208- theLog.log (" ROC input queue size = %d pages" ,RocFifoSize);
209- if (RocFifoSize==0 ) {RocFifoSize=1 ;}
210201
211202 // reset timeframe id
212203 currentTimeframe=0 ;
@@ -233,10 +224,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
233224
234225
235226ReadoutEquipmentRORC::~ReadoutEquipmentRORC () {
236- if (isInitialized) {
237- channel->stopDma ();
238- }
239-
240227 if (cfgRdhCheckEnabled) {
241228 theLog.log (" Equipment %s : %llu timeframes, %llu pages, RDH checks %llu ok, %llu errors" ,name.c_str (),statsNumberOfTimeframes,statsNumberOfPages,statsRdhCheckOk,statsRdhCheckErr);
242229 }
@@ -245,6 +232,8 @@ ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {
245232
246233Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks (){
247234 if (!isInitialized) return Thread::CallbackResult::Error;
235+ if (!isDataOn) return Thread::CallbackResult::Idle;
236+
248237 int isActive=0 ;
249238
250239 // keep track of situations where the queue is completely empty
@@ -266,9 +255,9 @@ Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks(){
266255 if (newPage!=nullptr ) {
267256 // todo: check page is aligned as expected
268257 AliceO2::roc::Superpage superpage;
269- superpage.offset =( char *)newPage-(char *)mp->getBaseBlockAddress ()+pageSpaceReserved;
270- superpage.size = superPageSize;
271- superpage.userData = newPage;
258+ superpage.setOffset (( char *)newPage-(char *)mp->getBaseBlockAddress ()+pageSpaceReserved) ;
259+ superpage.setSize ( superPageSize) ;
260+ superpage.setUserData ( newPage) ;
272261 channel->pushSuperpage (superpage);
273262 isActive=1 ;
274263 nPushed++;
@@ -317,16 +306,21 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
317306
318307 DataBlockContainerReference nextBlock=nullptr ;
319308
309+ // ensure the initialization was fine in the main thread
310+ if (!isInitialized) {
311+ return nullptr ;
312+ }
320313 // channel->fillSuperpages();
321314
322315 // check for completed page
323316 if ((channel->getReadyQueueSize ()>0 )) {
324317 auto superpage = channel->getSuperpage (); // this is the first superpage in FIFO ... let's check its state
325318 if (superpage.isFilled ()) {
326319 std::shared_ptr<DataBlockContainer>d=nullptr ;
320+ // printf ("received a page with %d bytes - isFilled=%d isREady=%d\n",(int)superpage.getReceived(),(int)superpage.isFilled(),(int)superpage.isReady());
327321 try {
328322 if (pageSpaceReserved>=sizeof (DataBlock)) {
329- d=mp->getNewDataBlockContainer ((void *)(superpage.userData ));
323+ d=mp->getNewDataBlockContainer ((void *)(superpage.getUserData () ));
330324 } else {
331325 // todo: allocate data block container elsewhere than beginning of page
332326 // d=mp->getNewDataBlockContainer(nullptr);
@@ -412,6 +406,8 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
412406 errorDescription.clear ();
413407 }
414408 statsRdhCheckErr++;
409+ // stop on first RDH error (should distinguich valid/invalid block length)
410+ break ;
415411 } else {
416412 statsRdhCheckOk++;
417413
@@ -454,3 +450,26 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
454450std::unique_ptr<ReadoutEquipment> getReadoutEquipmentRORC (ConfigFile &cfg, std::string cfgEntryPoint) {
455451 return std::make_unique<ReadoutEquipmentRORC>(cfg,cfgEntryPoint);
456452}
453+
454+
455+ void ReadoutEquipmentRORC::setDataOn () {
456+ if (isInitialized) {
457+ // start DMA
458+ theLog.log (" Starting DMA for ROC %s" ,getName ().c_str ());
459+ channel->startDma ();
460+
461+ // get FIFO depth (it should be fully empty when starting)
462+ RocFifoSize=channel->getTransferQueueAvailable ();
463+ theLog.log (" ROC input queue size = %d pages" ,RocFifoSize);
464+ if (RocFifoSize==0 ) {RocFifoSize=1 ;}
465+ }
466+ ReadoutEquipment::setDataOn ();
467+ }
468+
469+ void ReadoutEquipmentRORC::setDataOff () {
470+ if (isInitialized) {
471+ theLog.log (" Stopping DMA for ROC %s" ,getName ().c_str ());
472+ channel->stopDma ();
473+ }
474+ ReadoutEquipment::setDataOff ();
475+ }
0 commit comments