#include <DTDDUFileReader.h>
Public Member Functions | |
virtual bool | checkEndOfFile () |
uint64_t | dmaUnpack (bool &isData, int &nread) |
pre-unpack the data if read via DMA | |
DTDDUFileReader (const edm::ParameterSet &pset) | |
Constructor. | |
virtual int | fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data) |
Generate and fill FED raw data for a full event. | |
bool | isHeader (uint64_t word, bool dataTag) |
check for a 64 bits word to be a DDU header | |
bool | isTrailer (uint64_t word, bool dataTag, int wordCount) |
check for a 64 bits word to be a DDU trailer | |
void | swap (uint64_t &word) |
swapping the lsBits with the msBits | |
virtual | ~DTDDUFileReader () |
Destructor. | |
Private Attributes | |
int | dduID |
edm::EventNumber_t | eventNumber |
RawFile | inputFile |
int | numberOfHeaderWords |
bool | readFromDMA |
edm::RunNumber_t | runNumber |
int | skipEvents |
Static Private Attributes | |
static const int | dduWordLength = 8 |
Read DT ROS8 raw data files
Definition at line 20 of file DTDDUFileReader.h.
DTDDUFileReader::DTDDUFileReader | ( | const edm::ParameterSet & | pset | ) |
Constructor.
Definition at line 32 of file DTDDUFileReader.cc.
References gather_cfg::cout, Exception, RawFile::fail(), lut2db_cfg::filename, edm::ParameterSet::getUntrackedParameter(), RawFile::ignore(), inputFile, numberOfHeaderWords, RawFile::open(), RawFile::read(), readFromDMA, runNumber, and skipEvents.
: runNumber(1), eventNumber(1) { const string & filename = pset.getUntrackedParameter<string>("fileName"); readFromDMA = pset.getUntrackedParameter<bool>("readFromDMA",true); numberOfHeaderWords = pset.getUntrackedParameter<int>("numberOfHeaderWords",10); skipEvents = pset.getUntrackedParameter<int>("skipEvents",0); inputFile.open(filename.c_str()); if( inputFile.fail() ) { throw cms::Exception("InputFileMissing") << "[DTDDUFileReader]: the input file: " << filename <<" is not present"; } else { cout << "DTDDUFileReader: DaqSource file '" << filename << "' was succesfully opened" << endl; } uint32_t runNumber_tmp; inputFile.read(dataPointer<uint32_t>( &runNumber_tmp ), 4); runNumber = runNumber_tmp; inputFile.ignore(4*(numberOfHeaderWords-1)); if (skipEvents) { cout<<""<<endl; cout<<" Dear user, pleas be patient, "<<skipEvents<<" are being skipped .."<<endl; cout<<""<<endl; } }
DTDDUFileReader::~DTDDUFileReader | ( | ) | [virtual] |
Destructor.
Definition at line 64 of file DTDDUFileReader.cc.
References RawFile::close(), and inputFile.
bool DTDDUFileReader::checkEndOfFile | ( | ) | [virtual] |
Definition at line 235 of file DTDDUFileReader.cc.
References RawFile::eof(), and inputFile.
uint64_t DTDDUFileReader::dmaUnpack | ( | bool & | isData, |
int & | nread | ||
) |
pre-unpack the data if read via DMA
Definition at line 178 of file DTDDUFileReader.cc.
References data, inputFile, and RawFile::read().
Referenced by fillRawData().
{ uint64_t dduWord = 0; uint32_t td[4]; // read 4 32-bits word from the file; nread = inputFile.read(dataPointer<uint32_t>( &td[0] ), 4); nread += inputFile.read(dataPointer<uint32_t>( &td[1] ), 4); nread += inputFile.read(dataPointer<uint32_t>( &td[2] ), 4); nread += inputFile.read(dataPointer<uint32_t>( &td[3] ), 4); uint32_t data[2] = {0, 0}; // adjust 4 32-bits words into 2 32-bits words data[0] |= td[3] & 0x3ffff; data[0] |= (td[2] << 18 ) & 0xfffc0000; data[1] |= (td[2] >> 14 ) & 0x0f; data[1] |= (td[1] << 4 ) & 0x3ffff0; data[1] |= (td[0] << 22 ) & 0xffc00000; isData = ( td[0] >> 10 ) & 0x01; // push_back to a 64 word dduWord = (uint64_t(data[1]) << 32) | data[0]; return dduWord; }
int DTDDUFileReader::fillRawData | ( | edm::EventID & | eID, |
edm::Timestamp & | tstamp, | ||
FEDRawDataCollection *& | data | ||
) | [virtual] |
Generate and fill FED raw data for a full event.
Implements DaqBaseReader.
Definition at line 68 of file DTDDUFileReader.cc.
References filterCSVwithJSON::copy, gather_cfg::cout, data, FEDRawData::data(), dduID, dduWordLength, dmaUnpack(), eventNumber, FEDRawDataCollection::FEDData(), inputFile, isHeader(), isTrailer(), FEDNumbering::MINDTFEDID, RawFile::read(), readFromDMA, FEDRawData::resize(), runNumber, skipEvents, and swap().
{ data = new FEDRawDataCollection(); vector<uint64_t> eventData; size_t estimatedEventDimension = 102400; // dimensione hardcoded eventData.reserve(estimatedEventDimension); uint64_t word = 0; bool haederTag = false; bool dataTag = true; bool headerAlreadyFound = false; int wordCount = 0; // getting the data word by word from the file // do it until you get the DDU trailer while ( !isTrailer(word, dataTag, wordCount) ) { //while ( !isTrailer(word) ) { if (readFromDMA) { int nread; word = dmaUnpack(dataTag,nread); if ( nread<=0 ) { cout<<"[DTDDUFileReader]: ERROR! no more words and failed to get the trailer"<<endl; delete data; data=0; return false; } } else { int nread = inputFile.read(dataPointer<uint64_t>( &word ), dduWordLength); dataTag = false; if ( nread<=0 ) { cout<<"[DTDDUFileReader]: ERROR! failed to get the trailer"<<endl; delete data; data=0; return false; } } // get the DDU header if (!headerAlreadyFound) if ( isHeader(word,dataTag)) { headerAlreadyFound=true; haederTag=true; } // from now on fill the eventData with the ROS data if (haederTag) { if (readFromDMA) { // swapping only the 8 byte words if (dataTag) { swap(word); } // WARNING also the ddu status words have been swapped! // Control the correct interpretation in DDUUnpacker } eventData.push_back(word); wordCount++; } } // FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word)); // cout<<"EventSize: pushed back "<<eventData.size() // <<"; From trailer "<<candidate.lenght()<<endl; // next event reading will start with meaningless trailer+header from DTLocalDAQ // those will be skipped automatically when seeking for the DDU header //if (eventData.size() > estimatedEventDimension) throw 2; // Eventually skipping events if ((int)eventNumber >= skipEvents) { // Setting the Event ID eID = EventID( runNumber, 1U, eventNumber); // eventDataSize = (Number Of Words)* (Word Size) int eventDataSize = eventData.size()*dduWordLength; if ( dduID<770 || dduID > 775 ) { cout<<"[DTDDUFileReader]: ERROR. DDU ID out of range. DDU id="<<dduID<<endl; // The FED ID is always the first in the DT range dduID = FEDNumbering::MINDTFEDID; } FEDRawData& fedRawData = data->FEDData( dduID ); fedRawData.resize(eventDataSize); copy(reinterpret_cast<unsigned char*>(&eventData[0]), reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data()); } return true; }
bool DTDDUFileReader::isHeader | ( | uint64_t | word, |
bool | dataTag | ||
) |
check for a 64 bits word to be a DDU header
Definition at line 205 of file DTDDUFileReader.cc.
References FEDHeader::check(), dduID, eventNumber, and FEDHeader::sourceID().
Referenced by fillRawData().
{ bool it_is = false; FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word)); if ( candidate.check() ) { // if ( candidate.check() && !dataTag) { it_is = true; dduID = candidate.sourceID(); eventNumber++; } return it_is; }
bool DTDDUFileReader::isTrailer | ( | uint64_t | word, |
bool | dataTag, | ||
int | wordCount | ||
) |
check for a 64 bits word to be a DDU trailer
Definition at line 220 of file DTDDUFileReader.cc.
References FEDTrailer::check(), and FEDTrailer::lenght().
Referenced by fillRawData().
{ bool it_is = false; FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word)); if ( candidate.check() ) { // if ( candidate.check() && !dataTag) { //cout<<"[DTDDUFileReader] "<<wordCount<<" - "<<candidate.lenght()<<endl; if ( wordCount == candidate.lenght()) it_is = true; } return it_is; }
void DTDDUFileReader::swap | ( | uint64_t & | word | ) |
swapping the lsBits with the msBits
Definition at line 168 of file DTDDUFileReader.cc.
References twoNibble64::lsBits, and twoNibble64::msBits.
Referenced by fillRawData().
{ twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word); uint32_t msBits_tmp = newWorld->msBits; newWorld->msBits = newWorld->lsBits; newWorld->lsBits = msBits_tmp; }
int DTDDUFileReader::dduID [private] |
Definition at line 58 of file DTDDUFileReader.h.
Referenced by fillRawData(), and isHeader().
const int DTDDUFileReader::dduWordLength = 8 [static, private] |
Definition at line 64 of file DTDDUFileReader.h.
Referenced by fillRawData().
Definition at line 56 of file DTDDUFileReader.h.
Referenced by fillRawData(), and isHeader().
RawFile DTDDUFileReader::inputFile [private] |
Definition at line 53 of file DTDDUFileReader.h.
Referenced by checkEndOfFile(), dmaUnpack(), DTDDUFileReader(), fillRawData(), and ~DTDDUFileReader().
int DTDDUFileReader::numberOfHeaderWords [private] |
Definition at line 62 of file DTDDUFileReader.h.
Referenced by DTDDUFileReader().
bool DTDDUFileReader::readFromDMA [private] |
Definition at line 60 of file DTDDUFileReader.h.
Referenced by DTDDUFileReader(), and fillRawData().
edm::RunNumber_t DTDDUFileReader::runNumber [private] |
Definition at line 55 of file DTDDUFileReader.h.
Referenced by DTDDUFileReader(), and fillRawData().
int DTDDUFileReader::skipEvents [private] |
Definition at line 61 of file DTDDUFileReader.h.
Referenced by DTDDUFileReader(), and fillRawData().