Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ install(
FILES readout.cfg
DESTINATION ${CMAKE_INSTALL_PREFIX}/etc
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)

install(
FILES src/RAWDataHeader.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${MODULE_NAME}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)

2 changes: 1 addition & 1 deletion cmake/ReadoutDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Boost COMPONENTS unit_test_framework program_options system thread system timer program_options random filesystem regex signals REQUIRED)
find_package(Boost COMPONENTS container unit_test_framework program_options system thread system timer program_options random filesystem regex signals REQUIRED)
find_package(Git QUIET)
find_package(Monitoring REQUIRED)
find_package(Configuration REQUIRED)
Expand Down
9 changes: 9 additions & 0 deletions src/ReadoutEquipment.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ Thread::CallbackResult ReadoutEquipment::threadCallback(void *arg) {
}
return Thread::CallbackResult::Ok;
}


void ReadoutEquipment::setDataOn() {
isDataOn=true;
}

void ReadoutEquipment::setDataOff() {
isDataOn=false;
}
10 changes: 8 additions & 2 deletions src/ReadoutEquipment.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ReadoutEquipment {
void stop();
const std::string & getName();

// enable / disable data production by the equipment
virtual void setDataOn();
virtual void setDataOff();

// protected:
// todo: give direct access to output FIFO?
std::shared_ptr<AliceO2::Common::Fifo<DataBlockContainerReference>> dataOut;
Expand All @@ -44,9 +48,11 @@ class ReadoutEquipment {
virtual Thread::CallbackResult prepareBlocks() {return Thread::CallbackResult::Idle;};
virtual DataBlockContainerReference getNextBlock() {return nullptr;};


protected:

// data enabled ? controlled by setDataOn/setDataOff
bool isDataOn=false;


// Definition of performance counters for readout statistics.
// Each counter is assigned a unique integer index (incremental, starting 0).
// The last element can be used to get the number of counters defined.
Expand Down
75 changes: 43 additions & 32 deletions src/ReadoutEquipmentRORC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <ReadoutCard/MemoryMappedFile.h>
#include <ReadoutCard/DmaChannelInterface.h>
#include <ReadoutCard/Exception.h>
#include <ReadoutCard/Driver.h>


#include <string>
#include <mutex>
Expand All @@ -27,10 +27,12 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
ReadoutEquipmentRORC(ConfigFile &cfg, std::string name="rorcReadout");
~ReadoutEquipmentRORC();

private:
Thread::CallbackResult prepareBlocks();
DataBlockContainerReference getNextBlock();

private:
void setDataOn();
void setDataOff();

Thread::CallbackResult populateFifoOut(); // the data readout loop function

AliceO2::roc::ChannelFactory::DmaChannelSharedPtr channel; // channel to ROC device
Expand Down Expand Up @@ -66,8 +68,8 @@ class ReadoutEquipmentRORC : public ReadoutEquipment {
};


std::mutex readoutEquipmentRORCLock;
bool isDriverInitialized=false;
//std::mutex readoutEquipmentRORCLock;



struct ReadoutEquipmentRORCException : virtual Exception {};
Expand Down Expand Up @@ -133,14 +135,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
BOOST_THROW_EXCEPTION(ReadoutEquipmentRORCException() << ErrorInfo::Message("Superpage must be at least 32kB"));
}

// make sure ROC driver is initialized once
readoutEquipmentRORCLock.lock();
if (!isDriverInitialized) {
AliceO2::roc::driver::initialize();
isDriverInitialized=true;
}
readoutEquipmentRORCLock.unlock();

// open and configure ROC
theLog.log("Opening ROC %s:%d",cardId.c_str(),cfgChannelNumber);
AliceO2::roc::Parameters params;
Expand Down Expand Up @@ -180,9 +174,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :
baseAddress, blockSize
});

// clear locks if necessary
params.setForcedUnlockEnabled(true);

// define link mask
// this is harmless for C-RORC
params.setLinkMask(AliceO2::roc::Parameters::linkMaskFromString(cfgLinkMask));
Expand All @@ -207,14 +198,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :

// todo: log parameters ?

// start DMA
theLog.log("Starting DMA for ROC %s:%d",cardId.c_str(),cfgChannelNumber);
channel->startDma();

// get FIFO depth (it should be fully empty when starting)
RocFifoSize=channel->getTransferQueueAvailable();
theLog.log("ROC input queue size = %d pages",RocFifoSize);
if (RocFifoSize==0) {RocFifoSize=1;}

// reset timeframe id
currentTimeframe=0;
Expand All @@ -241,10 +224,6 @@ ReadoutEquipmentRORC::ReadoutEquipmentRORC(ConfigFile &cfg, std::string name) :


ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {
if (isInitialized) {
channel->stopDma();
}

if (cfgRdhCheckEnabled) {
theLog.log("Equipment %s : %llu timeframes, %llu pages, RDH checks %llu ok, %llu errors",name.c_str(),statsNumberOfTimeframes,statsNumberOfPages,statsRdhCheckOk,statsRdhCheckErr);
}
Expand All @@ -253,6 +232,8 @@ ReadoutEquipmentRORC::~ReadoutEquipmentRORC() {

Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks(){
if (!isInitialized) return Thread::CallbackResult::Error;
if (!isDataOn) return Thread::CallbackResult::Idle;

int isActive=0;

// keep track of situations where the queue is completely empty
Expand All @@ -274,9 +255,9 @@ Thread::CallbackResult ReadoutEquipmentRORC::prepareBlocks(){
if (newPage!=nullptr) {
// todo: check page is aligned as expected
AliceO2::roc::Superpage superpage;
superpage.offset=(char *)newPage-(char *)mp->getBaseBlockAddress()+pageSpaceReserved;
superpage.size=superPageSize;
superpage.userData=newPage;
superpage.setOffset((char *)newPage-(char *)mp->getBaseBlockAddress()+pageSpaceReserved);
superpage.setSize(superPageSize);
superpage.setUserData(newPage);
channel->pushSuperpage(superpage);
isActive=1;
nPushed++;
Expand Down Expand Up @@ -325,16 +306,21 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {

DataBlockContainerReference nextBlock=nullptr;

// ensure the initialization was fine in the main thread
if (!isInitialized) {
return nullptr;
}
//channel->fillSuperpages();

// check for completed page
if ((channel->getReadyQueueSize()>0)) {
auto superpage = channel->getSuperpage(); // this is the first superpage in FIFO ... let's check its state
if (superpage.isFilled()) {
std::shared_ptr<DataBlockContainer>d=nullptr;
// printf ("received a page with %d bytes - isFilled=%d isREady=%d\n",(int)superpage.getReceived(),(int)superpage.isFilled(),(int)superpage.isReady());
try {
if (pageSpaceReserved>=sizeof(DataBlock)) {
d=mp->getNewDataBlockContainer((void *)(superpage.userData));
d=mp->getNewDataBlockContainer((void *)(superpage.getUserData()));
} else {
// todo: allocate data block container elsewhere than beginning of page
//d=mp->getNewDataBlockContainer(nullptr);
Expand Down Expand Up @@ -420,6 +406,8 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
errorDescription.clear();
}
statsRdhCheckErr++;
// stop on first RDH error (should distinguich valid/invalid block length)
break;
} else {
statsRdhCheckOk++;

Expand Down Expand Up @@ -462,3 +450,26 @@ DataBlockContainerReference ReadoutEquipmentRORC::getNextBlock() {
std::unique_ptr<ReadoutEquipment> getReadoutEquipmentRORC(ConfigFile &cfg, std::string cfgEntryPoint) {
return std::make_unique<ReadoutEquipmentRORC>(cfg,cfgEntryPoint);
}


void ReadoutEquipmentRORC::setDataOn() {
if (isInitialized) {
// start DMA
theLog.log("Starting DMA for ROC %s",getName().c_str());
channel->startDma();

// get FIFO depth (it should be fully empty when starting)
RocFifoSize=channel->getTransferQueueAvailable();
theLog.log("ROC input queue size = %d pages",RocFifoSize);
if (RocFifoSize==0) {RocFifoSize=1;}
}
ReadoutEquipment::setDataOn();
}

void ReadoutEquipmentRORC::setDataOff() {
if (isInitialized) {
theLog.log("Stopping DMA for ROC %s",getName().c_str());
channel->stopDma();
}
ReadoutEquipment::setDataOff();
}
17 changes: 12 additions & 5 deletions src/mainReadout.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ int main(int argc, char* argv[])
readoutDevice->start();
}

for (auto && readoutDevice : readoutDevices) {
readoutDevice->setDataOn();
}
theLog.log("Running");

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

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


for (auto && readoutDevice : readoutDevices) {
readoutDevice->stop();
}
theLog.log("Readout stopped");

theLog.log("Stopping aggregator");
agg->stop();

Expand Down
14 changes: 5 additions & 9 deletions src/testROC.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ InfoLogger theLog;
#include <ReadoutCard/MemoryMappedFile.h>
#include <ReadoutCard/DmaChannelInterface.h>
#include <ReadoutCard/Exception.h>
#include <ReadoutCard/Driver.h>

#include <vector>
#include <time.h>
Expand Down Expand Up @@ -96,7 +95,6 @@ ROCdevice::ROCdevice(std::string id) {
mp->getBaseBlockAddress(), mp->getBaseBlockSize()
});

params.setForcedUnlockEnabled(true);
params.setLinkMask(AliceO2::roc::Parameters::linkMaskFromString(cfgLinkMask));


Expand Down Expand Up @@ -153,10 +151,10 @@ int ROCdevice::doLoop() {
while ((channel->getReadyQueueSize()>0)) {
auto superpage = channel->getSuperpage(); // this is the first superpage in FIFO ... let's check its state
if (superpage.isFilled()) {
mp->releasePage(superpage.userData);
mp->releasePage(superpage.getUserData());
channel->popSuperpage();
nPop++;
nBytes+=superpage.size;
nBytes+=superpage.getSize();
} else {
break;
}
Expand All @@ -171,9 +169,9 @@ int ROCdevice::doLoop() {
void *newPage=mp->getPage();
if (newPage!=nullptr) {
AliceO2::roc::Superpage superpage;
superpage.offset=(char *)newPage-(char *)mp->getBaseBlockAddress();
superpage.size=superPageSize;
superpage.userData=newPage;
superpage.setOffset((char *)newPage-(char *)mp->getBaseBlockAddress());
superpage.setSize(superPageSize);
superpage.setUserData(newPage);
channel->pushSuperpage(superpage);
nPush++;
} else {
Expand Down Expand Up @@ -257,8 +255,6 @@ int main(int argc, char**argv) {



AliceO2::roc::driver::initialize();

std::vector<ROCdevice> devices;

for (int i=argMin;i<argc;i++) {
Expand Down