CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Static Private Attributes
DTDDUFileReader Class Reference

#include <DTDDUFileReader.h>

Inheritance diagram for DTDDUFileReader:
DaqBaseReader

Public Member Functions

virtual bool checkEndOfFile ()
 
uint64_t dmaUnpack (bool &isData, int &nread)
 pre-unpack the data if read via DMA More...
 
 DTDDUFileReader (const edm::ParameterSet &pset)
 Constructor. More...
 
virtual int fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
 Generate and fill FED raw data for a full event. More...
 
bool isHeader (uint64_t word, bool dataTag)
 check for a 64 bits word to be a DDU header More...
 
bool isTrailer (uint64_t word, bool dataTag, int wordCount)
 check for a 64 bits word to be a DDU trailer More...
 
void swap (uint64_t &word)
 swapping the lsBits with the msBits More...
 
virtual ~DTDDUFileReader ()
 Destructor. More...
 
- Public Member Functions inherited from DaqBaseReader
 DaqBaseReader ()
 
virtual void setRunNumber (edm::RunNumber_t runNumber)
 set the run number More...
 
virtual ~DaqBaseReader ()
 

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
 

Detailed Description

Read DT ROS8 raw data files

Date:
2010/02/03 16:58:24
Revision:
1.11
Author
M. Zanetti - INFN Padova

Definition at line 20 of file DTDDUFileReader.h.

Constructor & Destructor Documentation

DTDDUFileReader::DTDDUFileReader ( const edm::ParameterSet pset)

Constructor.

Definition at line 32 of file DTDDUFileReader.cc.

References gather_cfg::cout, edm::hlt::Exception, RawFile::fail(), lut2db_cfg::filename, edm::ParameterSet::getUntrackedParameter(), RawFile::ignore(), inputFile, numberOfHeaderWords, RawFile::open(), RawFile::read(), readFromDMA, runNumber, and skipEvents.

32  :
33  runNumber(1), eventNumber(1) {
34 
35  const string & filename = pset.getUntrackedParameter<string>("fileName");
36 
37  readFromDMA = pset.getUntrackedParameter<bool>("readFromDMA",true);
38  numberOfHeaderWords = pset.getUntrackedParameter<int>("numberOfHeaderWords",10);
39  skipEvents = pset.getUntrackedParameter<int>("skipEvents",0);
40 
41  inputFile.open(filename.c_str());
42  if( inputFile.fail() ) {
43  throw cms::Exception("InputFileMissing")
44  << "[DTDDUFileReader]: the input file: " << filename <<" is not present";
45  } else {
46  cout << "DTDDUFileReader: DaqSource file '" << filename << "' was succesfully opened" << endl;
47  }
48 
49  uint32_t runNumber_tmp;
50  inputFile.read(dataPointer<uint32_t>( &runNumber_tmp ), 4);
51  runNumber = runNumber_tmp;
52 
53  inputFile.ignore(4*(numberOfHeaderWords-1));
54 
55  if (skipEvents) {
56  cout<<""<<endl;
57  cout<<" Dear user, pleas be patient, "<<skipEvents<<" are being skipped .."<<endl;
58  cout<<""<<endl;
59  }
60 
61 }
T getUntrackedParameter(std::string const &, T const &) const
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:27
bool fail()
It is not OK.
Definition: RawFile.cc:78
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:82
edm::RunNumber_t runNumber
edm::EventNumber_t eventNumber
int ignore(long offset)
Ignore some bytes.
Definition: RawFile.cc:98
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
DTDDUFileReader::~DTDDUFileReader ( )
virtual

Destructor.

Definition at line 64 of file DTDDUFileReader.cc.

References RawFile::close(), and inputFile.

64  {
65  inputFile.close();
66 }
int close()
Close file if necessary.
Definition: RawFile.cc:60

Member Function Documentation

bool DTDDUFileReader::checkEndOfFile ( )
virtual

Definition at line 235 of file DTDDUFileReader.cc.

References RawFile::eof(), and inputFile.

235  {
236 
237  bool retval=false;
238  if ( inputFile.eof() ) retval=true;
239  return retval;
240 
241 }
int eof()
Check end of file.
Definition: RawFile.cc:100
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().

178  {
179 
180  uint64_t dduWord = 0;
181 
182  uint32_t td[4];
183  // read 4 32-bits word from the file;
184  nread = inputFile.read(dataPointer<uint32_t>( &td[0] ), 4);
185  nread += inputFile.read(dataPointer<uint32_t>( &td[1] ), 4);
186  nread += inputFile.read(dataPointer<uint32_t>( &td[2] ), 4);
187  nread += inputFile.read(dataPointer<uint32_t>( &td[3] ), 4);
188 
189  uint32_t data[2] = {0, 0};
190  // adjust 4 32-bits words into 2 32-bits words
191  data[0] |= td[3] & 0x3ffff;
192  data[0] |= (td[2] << 18 ) & 0xfffc0000;
193  data[1] |= (td[2] >> 14 ) & 0x0f;
194  data[1] |= (td[1] << 4 ) & 0x3ffff0;
195  data[1] |= (td[0] << 22 ) & 0xffc00000;
196 
197  isData = ( td[0] >> 10 ) & 0x01;
198 
199  // push_back to a 64 word
200  dduWord = (uint64_t(data[1]) << 32) | data[0];
201 
202  return dduWord;
203 }
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:82
unsigned long long uint64_t
Definition: Time.h:15
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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, FEDRawData::data(), data, dduID, dduWordLength, dmaUnpack(), eventNumber, FEDRawDataCollection::FEDData(), inputFile, isHeader(), isTrailer(), FEDNumbering::MINDTFEDID, RawFile::read(), readFromDMA, FEDRawData::resize(), runNumber, skipEvents, and swap().

70  {
71  data = new FEDRawDataCollection();
72 
73  vector<uint64_t> eventData;
74  size_t estimatedEventDimension = 102400; // dimensione hardcoded
75  eventData.reserve(estimatedEventDimension);
76  uint64_t word = 0;
77 
78  bool haederTag = false;
79  bool dataTag = true;
80  bool headerAlreadyFound = false;
81 
82  int wordCount = 0;
83 
84  // getting the data word by word from the file
85  // do it until you get the DDU trailer
86  while ( !isTrailer(word, dataTag, wordCount) ) {
87  //while ( !isTrailer(word) ) {
88 
89  if (readFromDMA) {
90  int nread;
91  word = dmaUnpack(dataTag,nread);
92  if ( nread<=0 ) {
93  cout<<"[DTDDUFileReader]: ERROR! no more words and failed to get the trailer"<<endl;
94  delete data; data=0;
95  return false;
96  }
97  }
98 
99  else {
100  int nread = inputFile.read(dataPointer<uint64_t>( &word ), dduWordLength);
101  dataTag = false;
102  if ( nread<=0 ) {
103  cout<<"[DTDDUFileReader]: ERROR! failed to get the trailer"<<endl;
104  delete data; data=0;
105  return false;
106  }
107  }
108 
109  // get the DDU header
110  if (!headerAlreadyFound)
111  if ( isHeader(word,dataTag)) {
112  headerAlreadyFound=true;
113  haederTag=true;
114  }
115 
116  // from now on fill the eventData with the ROS data
117  if (haederTag) {
118 
119  if (readFromDMA) {
120  // swapping only the 8 byte words
121  if (dataTag) {
122  swap(word);
123  } // WARNING also the ddu status words have been swapped!
124  // Control the correct interpretation in DDUUnpacker
125  }
126 
127  eventData.push_back(word);
128  wordCount++;
129  }
130 
131  }
132 
133  // FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
134  // cout<<"EventSize: pushed back "<<eventData.size()
135  // <<"; From trailer "<<candidate.lenght()<<endl;
136 
137  // next event reading will start with meaningless trailer+header from DTLocalDAQ
138  // those will be skipped automatically when seeking for the DDU header
139  //if (eventData.size() > estimatedEventDimension) throw 2;
140 
141  // Eventually skipping events
142  if ((int)eventNumber >= skipEvents) {
143 
144  // Setting the Event ID
145  eID = EventID( runNumber, 1U, eventNumber);
146 
147  // eventDataSize = (Number Of Words)* (Word Size)
148  int eventDataSize = eventData.size()*dduWordLength;
149 
150 
151  if ( dduID<770 || dduID > 775 ) {
152  cout<<"[DTDDUFileReader]: ERROR. DDU ID out of range. DDU id="<<dduID<<endl;
153  // The FED ID is always the first in the DT range
155  }
156  FEDRawData& fedRawData = data->FEDData( dduID );
157  fedRawData.resize(eventDataSize);
158 
159  copy(reinterpret_cast<unsigned char*>(&eventData[0]),
160  reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data());
161 
162  }
163 
164  return true;
165 
166 }
bool isHeader(uint64_t word, bool dataTag)
check for a 64 bits word to be a DDU header
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:82
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
void swap(uint64_t &word)
swapping the lsBits with the msBits
edm::RunNumber_t runNumber
edm::EventNumber_t eventNumber
unsigned long long uint64_t
Definition: Time.h:15
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
uint64_t dmaUnpack(bool &isData, int &nread)
pre-unpack the data if read via DMA
tuple cout
Definition: gather_cfg.py:121
bool isTrailer(uint64_t word, bool dataTag, int wordCount)
check for a 64 bits word to be a DDU trailer
static const int dduWordLength
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().

205  {
206 
207  bool it_is = false;
208  FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word));
209  if ( candidate.check() ) {
210  // if ( candidate.check() && !dataTag) {
211  it_is = true;
212  dduID = candidate.sourceID();
213  eventNumber++;
214  }
215 
216  return it_is;
217 }
edm::EventNumber_t eventNumber
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().

220  {
221 
222  bool it_is = false;
223  FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
224  if ( candidate.check() ) {
225  // if ( candidate.check() && !dataTag) {
226  //cout<<"[DTDDUFileReader] "<<wordCount<<" - "<<candidate.lenght()<<endl;
227  if ( wordCount == candidate.lenght())
228  it_is = true;
229  }
230 
231  return it_is;
232 }
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().

168  {
169 
170  twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word);
171 
172  uint32_t msBits_tmp = newWorld->msBits;
173  newWorld->msBits = newWorld->lsBits;
174  newWorld->lsBits = msBits_tmp;
175 }

Member Data Documentation

int DTDDUFileReader::dduID
private

Definition at line 58 of file DTDDUFileReader.h.

Referenced by fillRawData(), and isHeader().

const int DTDDUFileReader::dduWordLength = 8
staticprivate

Definition at line 64 of file DTDDUFileReader.h.

Referenced by fillRawData().

edm::EventNumber_t DTDDUFileReader::eventNumber
private
RawFile DTDDUFileReader::inputFile
private
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().