CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes | Static Private Attributes
DTDDUFileReader Class Reference

#include <DTDDUFileReader.h>

Inheritance diagram for DTDDUFileReader:
edm::one::EDProducer<> edm::one::EDProducerBase 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, unsigned int wordCount)
 check for a 64 bits word to be a DDU trailer More...
 
void produce (edm::Event &, edm::EventSetup const &) override
 
void swap (uint64_t &word)
 swapping the lsBits with the msBits More...
 
 ~DTDDUFileReader () override
 Destructor. More...
 
- Public Member Functions inherited from edm::one::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const noexcept
 
bool wantsStreamRuns () const noexcept
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

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::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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::DTDDUFileReader ( const edm::ParameterSet pset)

Constructor.

Definition at line 31 of file DTDDUFileReader.cc.

References gather_cfg::cout, Exception, RawFile::fail(), corrVsCorr::filename, RawFile::ignore(), inputFile, numberOfHeaderWords, RawFile::open(), muonDTDigis_cfi::pset, RawFile::read(), readFromDMA, runNumber, and skipEvents.

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

◆ ~DTDDUFileReader()

DTDDUFileReader::~DTDDUFileReader ( )
override

Destructor.

Definition at line 60 of file DTDDUFileReader.cc.

References RawFile::close(), and inputFile.

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

Member Function Documentation

◆ checkEndOfFile()

bool DTDDUFileReader::checkEndOfFile ( )
virtual

Definition at line 228 of file DTDDUFileReader.cc.

References RawFile::eof(), and inputFile.

228  {
229  bool retval = false;
230  if (inputFile.eof())
231  retval = true;
232  return retval;
233 }
int eof()
Check end of file.
Definition: RawFile.cc:94

◆ dmaUnpack()

uint64_t DTDDUFileReader::dmaUnpack ( bool &  isData,
int &  nread 
)

pre-unpack the data if read via DMA

Definition at line 176 of file DTDDUFileReader.cc.

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

Referenced by fillRawData().

176  {
177  uint64_t dduWord = 0;
178 
179  uint32_t td[4];
180  // read 4 32-bits word from the file;
181  nread = inputFile.read(dataPointer<uint32_t>(&td[0]), 4);
182  nread += inputFile.read(dataPointer<uint32_t>(&td[1]), 4);
183  nread += inputFile.read(dataPointer<uint32_t>(&td[2]), 4);
184  nread += inputFile.read(dataPointer<uint32_t>(&td[3]), 4);
185 
186  uint32_t data[2] = {0, 0};
187  // adjust 4 32-bits words into 2 32-bits words
188  data[0] |= td[3] & 0x3ffff;
189  data[0] |= (td[2] << 18) & 0xfffc0000;
190  data[1] |= (td[2] >> 14) & 0x0f;
191  data[1] |= (td[1] << 4) & 0x3ffff0;
192  data[1] |= (td[0] << 22) & 0xffc00000;
193 
194  isData = (td[0] >> 10) & 0x01;
195 
196  // push_back to a 64 word
197  dduWord = (uint64_t(data[1]) << 32) | data[0];
198 
199  return dduWord;
200 }
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:76
unsigned long long uint64_t
Definition: Time.h:13
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ fillRawData()

int DTDDUFileReader::fillRawData ( edm::Event e,
FEDRawDataCollection *&  data 
)
virtual

Generate and fill FED raw data for a full event.

Definition at line 62 of file DTDDUFileReader.cc.

References filterCSVwithJSON::copy, gather_cfg::cout, data, RPCCPPFLinkMapPopConAnalyzer_cfi::dataTag, dduID, dduWordLength, dmaUnpack(), MillePedeFileConverter_cfg::e, eventNumber, l1t_dqm_sourceclient-live_cfg::fedRawData, EcalFEDMonitor_cfi::FEDRawDataCollection, inputFile, isHeader(), isTrailer(), FEDNumbering::MINDTFEDID, RawFile::read(), readFromDMA, runNumber, skipEvents, swap(), and mitigatedMETSequence_cff::U.

Referenced by produce().

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

◆ isHeader()

bool DTDDUFileReader::isHeader ( uint64_t  word,
bool  dataTag 
)

check for a 64 bits word to be a DDU header

Definition at line 202 of file DTDDUFileReader.cc.

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

Referenced by fillRawData().

202  {
203  bool it_is = false;
204  FEDHeader candidate(reinterpret_cast<const unsigned char*>(&word));
205  if (candidate.check()) {
206  // if ( candidate.check() && !dataTag) {
207  it_is = true;
208  dduID = candidate.sourceID();
209  eventNumber++;
210  }
211 
212  return it_is;
213 }
uint64_t word
edm::EventNumber_t eventNumber

◆ isTrailer()

bool DTDDUFileReader::isTrailer ( uint64_t  word,
bool  dataTag,
unsigned int  wordCount 
)

check for a 64 bits word to be a DDU trailer

Definition at line 215 of file DTDDUFileReader.cc.

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

Referenced by fillRawData().

215  {
216  bool it_is = false;
217  FEDTrailer candidate(reinterpret_cast<const unsigned char*>(&word));
218  if (candidate.check()) {
219  // if ( candidate.check() && !dataTag) {
220  //cout<<"[DTDDUFileReader] "<<wordCount<<" - "<<candidate.fragmentLength()<<endl;
221  if (wordCount == candidate.fragmentLength())
222  it_is = true;
223  }
224 
225  return it_is;
226 }
uint64_t word

◆ produce()

void DTDDUFileReader::produce ( edm::Event e,
edm::EventSetup const &  es 
)
overridevirtual

Implements edm::one::EDProducerBase.

Definition at line 160 of file DTDDUFileReader.cc.

References MillePedeFileConverter_cfg::e, fillRawData(), and eostools::move().

160  {
162  FEDRawDataCollection* fedcoll = nullptr;
163  fillRawData(e, fedcoll);
164  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
165  e.put(std::move(bare_product));
166 }
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
def move(src, dest)
Definition: eostools.py:511

◆ swap()

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  twoNibble64* newWorld = reinterpret_cast<twoNibble64*>(&word);
170 
171  uint32_t msBits_tmp = newWorld->msBits;
172  newWorld->msBits = newWorld->lsBits;
173  newWorld->lsBits = msBits_tmp;
174 }
uint64_t word

Member Data Documentation

◆ dduID

int DTDDUFileReader::dduID
private

Definition at line 58 of file DTDDUFileReader.h.

Referenced by fillRawData(), and isHeader().

◆ dduWordLength

const int DTDDUFileReader::dduWordLength = 8
staticprivate

Definition at line 64 of file DTDDUFileReader.h.

Referenced by fillRawData().

◆ eventNumber

edm::EventNumber_t DTDDUFileReader::eventNumber
private

Definition at line 56 of file DTDDUFileReader.h.

Referenced by fillRawData(), and isHeader().

◆ inputFile

RawFile DTDDUFileReader::inputFile
private

◆ numberOfHeaderWords

int DTDDUFileReader::numberOfHeaderWords
private

Definition at line 62 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader().

◆ readFromDMA

bool DTDDUFileReader::readFromDMA
private

Definition at line 60 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().

◆ runNumber

edm::RunNumber_t DTDDUFileReader::runNumber
private

Definition at line 55 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().

◆ skipEvents

int DTDDUFileReader::skipEvents
private

Definition at line 61 of file DTDDUFileReader.h.

Referenced by DTDDUFileReader(), and fillRawData().