@@ -210,7 +210,7 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
210210
211211 AliceO2::roc::ChannelFactory::DmaChannelSharedPtr channel; // channel to ROC device
212212 // std::shared_ptr<ReadoutMemoryHandler> mReadoutMemoryHandler; // object to get memory from
213- std::shared_ptr<MemoryHandler> mReadoutMemoryHandler ; // object to get memory from
213+ // std::shared_ptr<MemoryHandler> mReadoutMemoryHandler; // object to get memory from
214214
215215 DataBlockId currentId=0 ; // current data id, kept for auto-increment
216216
@@ -227,13 +227,17 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
227227
228228 AliceO2::Common::Timer timeframeClock; // timeframe id should be increased at each clock cycle
229229 int currentTimeframe=0 ; // id of current timeframe
230+
231+ size_t superPageSize=0 ; // usable size of a superpage
230232};
231233
232234
233235std::mutex readoutEquipmentRORCLock;
234236bool isDriverInitialized=false ;
235237
236238
239+ struct ReadoutEquipmentRORCException : virtual Exception {};
240+
237241ReadoutEquipmentRORC::ReadoutEquipmentRORC (ConfigFile &cfg, std::string name) : ReadoutEquipment(cfg, name) {
238242
239243 try {
@@ -274,19 +278,27 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
274278 cfg.getOptionalValue <int >(name + " .rdhCheckEnabled" , cfgRdhCheckEnabled);
275279 cfg.getOptionalValue <int >(name + " .rdhDumpEnabled" , cfgRdhDumpEnabled);
276280
277- // get readout memory buffer parameters
281+ /* // get readout memory buffer parameters
278282 std::string sMemorySize=cfg.getValue<std::string>(name + ".memoryBufferSize");
279283 std::string sPageSize=cfg.getValue<std::string>(name + ".memoryPageSize");
280284 long long mMemorySize=ReadoutUtils::getNumberOfBytesFromString(sMemorySize.c_str());
281285 long long mPageSize=ReadoutUtils::getNumberOfBytesFromString(sPageSize.c_str());
282286
283287 std::string cfgHugePageSize="1GB";
284288 cfg.getOptionalValue<std::string>(name + ".memoryHugePageSize",cfgHugePageSize);
285-
289+ */
286290 // unique identifier based on card ID
287291 std::string uid=" readout." + cardId + " ." + std::to_string (cfgChannelNumber);
288292 // sleep((cfgChannelNumber+1)*2); // trick to avoid all channels open at once - fail to acquire lock
289293
294+ // define usable superpagesize
295+ superPageSize=mp->getPageSize ()-sizeof (DataBlock); // Keep space at beginning for DataBlock object
296+ superPageSize-=superPageSize % (32 *1024 ); // Must be a multiple of 32Kb for ROC
297+ theLog.log (" Using superpage size %ld" ,superPageSize);
298+ if (superPageSize==0 ) {
299+ BOOST_THROW_EXCEPTION (ReadoutEquipmentRORCException () << ErrorInfo::Message (" Superpage must be at least 32kB" ));
300+ }
301+
290302 // make sure ROC driver is initialized once
291303 readoutEquipmentRORCLock.lock ();
292304 if (!isDriverInitialized) {
@@ -297,7 +309,7 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
297309
298310 // create memory pool
299311 // mReadoutMemoryHandler=std::make_shared<ReadoutMemoryHandler>((long)mMemorySize,(int)mPageSize,uid,cfgHugePageSize);
300- mReadoutMemoryHandler =std::make_shared<MemoryHandler>(mPageSize ,mMemorySize /mPageSize );
312+ // mReadoutMemoryHandler=std::make_shared<MemoryHandler>(mPageSize,mMemorySize/mPageSize);
301313
302314 // open and configure ROC
303315 theLog.log (" Opening ROC %s:%d" ,cardId.c_str (),cfgChannelNumber);
@@ -318,19 +330,19 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
318330
319331 // card readout mode : experimental, not needed
320332 // params.setReadoutMode(AliceO2::roc::ReadoutMode::fromString(cfgReadoutMode));
321-
322- // register the memory block for DMA
323333
324-
325- theLog.log (" Loop DMA block %p:%lu" ,(void *)mReadoutMemoryHandler ->getBaseAddress (),mReadoutMemoryHandler ->getSize ());
326- char *ptr=(char *)mReadoutMemoryHandler ->getBaseAddress ();
327- for (size_t i=0 ;i<mReadoutMemoryHandler ->getSize ();i++) {
328- ptr[i]=0 ;
329- }
330- theLog.log (" Register DMA block %p:%lu" ,(void *)mReadoutMemoryHandler ->getBaseAddress (),mReadoutMemoryHandler ->getSize ());
334+ // theLog.log("Loop DMA block %p:%lu", mp->getBaseBlockAddress(), mp->getBaseBlockSize()); //(void *)mReadoutMemoryHandler->getBaseAddress(),mReadoutMemoryHandler->getSize());
335+ // char *ptr=(char *)mp->getBaseBlockAddress();
336+ // for (size_t i=0;i<mp->getBaseBlockSize();i++) {
337+ // ptr[i]=0;
338+ // }
339+
340+ // register the memory block for DMA
341+ theLog.log (" Register DMA block %p:%lu" ,(void *)mp->getBaseBlockAddress (),mp->getBaseBlockSize ());
331342 params.setBufferParameters (AliceO2::roc::buffer_parameters::Memory {
332343// (void *)mReadoutMemoryHandler->baseAddress, mReadoutMemoryHandler->memorySize
333- (void *)mReadoutMemoryHandler ->getBaseAddress (), mReadoutMemoryHandler ->getSize ()
344+ // (void *)mReadoutMemoryHandler->getBaseAddress(), mReadoutMemoryHandler->getSize()
345+ mp->getBaseBlockAddress (), mp->getBaseBlockSize ()
334346 });
335347
336348 // clear locks if necessary
@@ -413,15 +425,17 @@ Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks(){
413425 // give free pages to the driver
414426 int nPushed=0 ; // number of free pages pushed this iteration
415427 while (channel->getTransferQueueAvailable () != 0 ) {
416- long offset=0 ;
417- void *newPage=mReadoutMemoryHandler ->getPage ();
428+ // long offset=0;
429+ // void *newPage=mReadoutMemoryHandler->getPage();
430+ void *newPage=mp->getPage ();
418431 // if (mReadoutMemoryHandler->pagesAvailable->pop(offset)==0) {
419432 if (newPage!=nullptr ) {
420433 AliceO2::roc::Superpage superpage;
421434 // superpage.offset=offset;
422- superpage.offset =(char *)newPage-(char *)mReadoutMemoryHandler ->getBaseAddress ();
423- superpage.size =mReadoutMemoryHandler ->getPageSize ();
424- superpage.userData =NULL ; // &mReadoutMemoryHandler; // bad - looses shared_ptr
435+ // superpage.offset=(char *)newPage-(char *)mReadoutMemoryHandler->getBaseAddress();
436+ superpage.offset =(char *)newPage-(char *)mp->getBaseBlockAddress ()+sizeof (DataBlock);
437+ superpage.size =superPageSize;
438+ superpage.userData =newPage; // &mReadoutMemoryHandler; // bad - looses shared_ptr // todo: keep track of datablock object instead?
425439 channel->pushSuperpage (superpage);
426440 isActive=1 ;
427441 nPushed++;
@@ -476,15 +490,19 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
476490 if ((channel->getReadyQueueSize ()>0 )) {
477491 auto superpage = channel->getSuperpage (); // this is the first superpage in FIFO ... let's check its state
478492 if (superpage.isFilled ()) {
479- std::shared_ptr<DataBlockContainerFromRORC >d=nullptr ;
493+ std::shared_ptr<DataBlockContainer >d=nullptr ;
480494 try {
481- d=std::make_shared<DataBlockContainerFromRORC>(channel, superpage, mReadoutMemoryHandler );
495+ // d=std::make_shared<DataBlockContainerFromRORC>(channel, superpage, mReadoutMemoryHandler);
496+ d=mp->getNewDataBlockContainer ((void *)(superpage.userData ));
482497 }
483498 catch (...) {
484499 // todo: increment a stats counter?
485500 theLog.log (" make_shared<DataBlock> failed" );
486501 }
487502 if (d!=nullptr ) {
503+ d->getData ()->header .dataSize =superpage.getReceived ();
504+ d->getData ()->header .linkId =0 ; // TODO
505+
488506 channel->popSuperpage ();
489507 nextBlock=d;
490508
@@ -495,25 +513,54 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
495513 d->getData ()->header .id =currentTimeframe;
496514
497515 // validate RDH structure, if configured to do so
516+ int linkId=-1 ;
498517 if (cfgRdhCheckEnabled) {
499518 std::string errorDescription;
500519 size_t blockSize=d->getData ()->header .dataSize ;
501520 uint8_t *baseAddress=(uint8_t *)(d->getData ()->data );
502521 for (size_t pageOffset=0 ;pageOffset<blockSize;) {
503522 RdhHandle h (baseAddress+pageOffset);
523+
524+ if (linkId==-1 ) {
525+ linkId=h.getLinkId ();
526+ } else {
527+ if (linkId!=h.getLinkId ()) {
528+ printf (" incosistent link ids: %d != %d\n " ,linkId,h.getLinkId ());
529+ }
530+ }
531+
532+ // data format:
533+ // RDH v3 = https://docs.google.com/document/d/1otkSDYasqpVBDnxplBI7dWNxaZohctA-bvhyrzvtLoQ/edit?usp=sharing
504534 if (h.validateRdh (errorDescription)) {
505- if (cfgRdhDumpEnabled) {
535+ if (cfgRdhDumpEnabled) {
536+ for (int i=0 ;i<16 ;i++) {
537+ printf (" %08X " ,(int )(((uint32_t *)baseAddress)[i]));
538+ }
539+ printf (" \n " );
506540 printf (" Page 0x%p + %ld\n %s" ,(void *)baseAddress,pageOffset,errorDescription.c_str ());
507541 h.dumpRdh ();
508542 errorDescription.clear ();
509543 }
510544 statsRdhCheckErr++;
511545 } else {
512546 statsRdhCheckOk++;
547+
548+ if (cfgRdhDumpEnabled) {
549+ h.dumpRdh ();
550+ for (int i=0 ;i<16 ;i++) {
551+ printf (" %08X " ,(int )(((uint32_t *)baseAddress+pageOffset)[i]));
552+ }
553+ printf (" \n " );
554+
555+ }
513556 }
514- pageOffset+=h.getBlockLengthBytes ();
557+ pageOffset+=h.getBlockLength ();
515558 }
516559 }
560+ if (linkId>=0 ) {
561+ d->getData ()->header .linkId =linkId;
562+ }
563+
517564 }
518565 }
519566 }
0 commit comments