Skip to content

Commit 24ff97c

Browse files
authored
ReadourCard interface change (#26)
* added routines to enable/disable data, so that equipment buffers can be emptied at end of run * ReadoutCard interface change - AliceO2Group/ReadoutCard#21
1 parent 0ba0e9e commit 24ff97c

File tree

5 files changed

+74
-34
lines changed

5 files changed

+74
-34
lines changed

src/ReadoutEquipment.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,12 @@ Thread::CallbackResult ReadoutEquipment::threadCallback(void *arg) {
232232
}
233233
return Thread::CallbackResult::Ok;
234234
}
235+
236+
237+
void ReadoutEquipment::setDataOn() {
238+
isDataOn=true;
239+
}
240+
241+
void ReadoutEquipment::setDataOff() {
242+
isDataOn=false;
243+
}

src/ReadoutEquipment.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class ReadoutEquipment {
2929
void stop();
3030
const std::string & getName();
3131

32+
// enable / disable data production by the equipment
33+
virtual void setDataOn();
34+
virtual void setDataOff();
35+
3236
// protected:
3337
// todo: give direct access to output FIFO?
3438
std::shared_ptr<AliceO2::Common::Fifo<DataBlockContainerReference>> dataOut;
@@ -44,9 +48,11 @@ class ReadoutEquipment {
4448
virtual Thread::CallbackResult prepareBlocks() {return Thread::CallbackResult::Idle;};
4549
virtual DataBlockContainerReference getNextBlock() {return nullptr;};
4650

47-
4851
protected:
49-
52+
// data enabled ? controlled by setDataOn/setDataOff
53+
bool isDataOn=false;
54+
55+
5056
// Definition of performance counters for readout statistics.
5157
// Each counter is assigned a unique integer index (incremental, starting 0).
5258
// The last element can be used to get the number of counters defined.

src/ReadoutEquipmentRORC.cxx

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

235226
ReadoutEquipmentRORC::~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

246233
Thread::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() {
454450
std::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+
}

src/mainReadout.cxx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ int main(int argc, char* argv[])
392392
readoutDevice->start();
393393
}
394394

395+
for (auto && readoutDevice : readoutDevices) {
396+
readoutDevice->setDataOn();
397+
}
395398
theLog.log("Running");
396399

397400
// reset exit timeout, if any
@@ -412,11 +415,11 @@ int main(int argc, char* argv[])
412415
if (isRunning) {
413416
if (((cfgExitTimeout>0)&&(t.isTimeout()))||(ShutdownRequest)) {
414417
isRunning=0;
415-
theLog.log("Stopping readout");
416-
for (auto && readoutDevice : readoutDevices) {
417-
readoutDevice->stop();
418+
theLog.log("Stopping data readout");
419+
for (auto && readoutDevice : readoutDevices) {
420+
readoutDevice->setDataOff();
418421
}
419-
theLog.log("Readout stopped");
422+
420423
t.reset(1000000); // add a delay before stopping aggregator - continune to empty FIFOs
421424

422425
// notify consumers of imminent data flow stop
@@ -452,7 +455,11 @@ int main(int argc, char* argv[])
452455
theLog.log("Stopping callgrind instrumentation");
453456
#endif
454457

455-
458+
for (auto && readoutDevice : readoutDevices) {
459+
readoutDevice->stop();
460+
}
461+
theLog.log("Readout stopped");
462+
456463
theLog.log("Stopping aggregator");
457464
agg->stop();
458465

src/testROC.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ ROCdevice::ROCdevice(std::string id) {
9595
mp->getBaseBlockAddress(), mp->getBaseBlockSize()
9696
});
9797

98-
params.setForcedUnlockEnabled(true);
9998
params.setLinkMask(AliceO2::roc::Parameters::linkMaskFromString(cfgLinkMask));
10099

101100

@@ -152,10 +151,10 @@ int ROCdevice::doLoop() {
152151
while ((channel->getReadyQueueSize()>0)) {
153152
auto superpage = channel->getSuperpage(); // this is the first superpage in FIFO ... let's check its state
154153
if (superpage.isFilled()) {
155-
mp->releasePage(superpage.userData);
154+
mp->releasePage(superpage.getUserData());
156155
channel->popSuperpage();
157156
nPop++;
158-
nBytes+=superpage.size;
157+
nBytes+=superpage.getSize();
159158
} else {
160159
break;
161160
}
@@ -170,9 +169,9 @@ int ROCdevice::doLoop() {
170169
void *newPage=mp->getPage();
171170
if (newPage!=nullptr) {
172171
AliceO2::roc::Superpage superpage;
173-
superpage.offset=(char *)newPage-(char *)mp->getBaseBlockAddress();
174-
superpage.size=superPageSize;
175-
superpage.userData=newPage;
172+
superpage.setOffset((char *)newPage-(char *)mp->getBaseBlockAddress());
173+
superpage.setSize(superPageSize);
174+
superpage.setUserData(newPage);
176175
channel->pushSuperpage(superpage);
177176
nPush++;
178177
} else {

0 commit comments

Comments
 (0)