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:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

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::Event &e, 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...
 
virtual void produce (edm::Event &, edm::EventSetup const &)
 
void swap (uint64_t &word)
 swapping the lsBits with the msBits More...
 
virtual ~DTDDUFileReader ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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 22 of file DTDDUFileReader.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 33 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.

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

Destructor.

Definition at line 66 of file DTDDUFileReader.cc.

References RawFile::close(), and inputFile.

66  {
67  inputFile.close();
68 }
int close()
Close file if necessary.
Definition: RawFile.cc:66

Member Function Documentation

bool DTDDUFileReader::checkEndOfFile ( )
virtual

Definition at line 246 of file DTDDUFileReader.cc.

References RawFile::eof(), and inputFile.

246  {
247 
248  bool retval=false;
249  if ( inputFile.eof() ) retval=true;
250  return retval;
251 
252 }
int eof()
Check end of file.
Definition: RawFile.cc:118
uint64_t DTDDUFileReader::dmaUnpack ( bool &  isData,
int &  nread 
)

pre-unpack the data if read via DMA

Definition at line 189 of file DTDDUFileReader.cc.

References data, inputFile, and RawFile::read().

Referenced by fillRawData().

189  {
190 
191  uint64_t dduWord = 0;
192 
193  uint32_t td[4];
194  // read 4 32-bits word from the file;
195  nread = inputFile.read(dataPointer<uint32_t>( &td[0] ), 4);
196  nread += inputFile.read(dataPointer<uint32_t>( &td[1] ), 4);
197  nread += inputFile.read(dataPointer<uint32_t>( &td[2] ), 4);
198  nread += inputFile.read(dataPointer<uint32_t>( &td[3] ), 4);
199 
200  uint32_t data[2] = {0, 0};
201  // adjust 4 32-bits words into 2 32-bits words
202  data[0] |= td[3] & 0x3ffff;
203  data[0] |= (td[2] << 18 ) & 0xfffc0000;
204  data[1] |= (td[2] >> 14 ) & 0x0f;
205  data[1] |= (td[1] << 4 ) & 0x3ffff0;
206  data[1] |= (td[0] << 22 ) & 0xffc00000;
207 
208  isData = ( td[0] >> 10 ) & 0x01;
209 
210  // push_back to a 64 word
211  dduWord = (uint64_t(data[1]) << 32) | data[0];
212 
213  return dduWord;
214 }
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:94
unsigned long long uint64_t
Definition: Time.h:15
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int DTDDUFileReader::fillRawData ( edm::Event e,
FEDRawDataCollection *&  data 
)
virtual

Generate and fill FED raw data for a full event.

Definition at line 70 of file DTDDUFileReader.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, FEDRawData::data(), data, dduID, dduWordLength, dmaUnpack(), eventNumber, FEDRawDataCollection::FEDData(), edm::EventBase::id(), inputFile, isHeader(), isTrailer(), FEDNumbering::MINDTFEDID, RawFile::read(), readFromDMA, FEDRawData::resize(), runNumber, skipEvents, and swap().

Referenced by produce().

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

References FEDHeader::check(), dduID, eventNumber, and FEDHeader::sourceID().

Referenced by fillRawData().

216  {
217 
218  bool it_is = false;
219  FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word));
220  if ( candidate.check() ) {
221  // if ( candidate.check() && !dataTag) {
222  it_is = true;
223  dduID = candidate.sourceID();
224  eventNumber++;
225  }
226 
227  return it_is;
228 }
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 231 of file DTDDUFileReader.cc.

References FEDTrailer::check(), and FEDTrailer::lenght().

Referenced by fillRawData().

231  {
232 
233  bool it_is = false;
234  FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
235  if ( candidate.check() ) {
236  // if ( candidate.check() && !dataTag) {
237  //cout<<"[DTDDUFileReader] "<<wordCount<<" - "<<candidate.lenght()<<endl;
238  if ( wordCount == candidate.lenght())
239  it_is = true;
240  }
241 
242  return it_is;
243 }
void DTDDUFileReader::produce ( edm::Event e,
edm::EventSetup const &  es 
)
virtual

Implements edm::EDProducer.

Definition at line 171 of file DTDDUFileReader.cc.

References fillRawData(), edm::Event::put(), and lumiPlot::rawdata.

171  {
173  FEDRawDataCollection *fedcoll = 0;
174  fillRawData(e,fedcoll);
175  std::auto_ptr<FEDRawDataCollection> bare_product(fedcoll);
176  e.put(bare_product);
177  }
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
dictionary rawdata
Definition: lumiPlot.py:393
void DTDDUFileReader::swap ( uint64_t &  word)

swapping the lsBits with the msBits

Definition at line 179 of file DTDDUFileReader.cc.

References twoNibble64::lsBits, and twoNibble64::msBits.

Referenced by fillRawData().

179  {
180 
181  twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word);
182 
183  uint32_t msBits_tmp = newWorld->msBits;
184  newWorld->msBits = newWorld->lsBits;
185  newWorld->lsBits = msBits_tmp;
186 }

Member Data Documentation

int DTDDUFileReader::dduID
private

Definition at line 61 of file DTDDUFileReader.h.

Referenced by fillRawData(), and isHeader().

const int DTDDUFileReader::dduWordLength = 8
staticprivate

Definition at line 67 of file DTDDUFileReader.h.

Referenced by fillRawData().

edm::EventNumber_t DTDDUFileReader::eventNumber
private
RawFile DTDDUFileReader::inputFile
private
int DTDDUFileReader::numberOfHeaderWords
private

Definition at line 65 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader().

bool DTDDUFileReader::readFromDMA
private

Definition at line 63 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().

edm::RunNumber_t DTDDUFileReader::runNumber
private

Definition at line 58 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().

int DTDDUFileReader::skipEvents
private

Definition at line 64 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().