CMS 3D CMS Logo

DTDDUFileReader.cc
Go to the documentation of this file.
1 
10 
14 
19 
22 
23 #include <string>
24 #include <iosfwd>
25 #include <iostream>
26 #include <algorithm>
27 
28 using namespace std;
29 using namespace edm;
30 
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 }
59 
61 
63  // Timestamp& tstamp,
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 }
159 
162  FEDRawDataCollection* fedcoll = nullptr;
163  fillRawData(e, fedcoll);
164  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
165  e.put(std::move(bare_product));
166 }
167 
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 }
175 
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 }
201 
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 }
214 
215 bool DTDDUFileReader::isTrailer(uint64_t word, bool dataTag, unsigned int wordCount) {
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 }
227 
229  bool retval = false;
230  if (inputFile.eof())
231  retval = true;
232  return retval;
233 }
FEDNumbering.h
DTDDUFileReader.h
twoNibble64
Definition: DTFileReaderHelpers.h:32
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
twoNibble64::msBits
uint32_t msBits
Definition: DTFileReaderHelpers.h:34
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RawFile::eof
int eof()
Check end of file.
Definition: RawFile.cc:94
DTFileReaderHelpers.h
DTDDUFileReader::dduID
int dduID
Definition: DTDDUFileReader.h:58
DTDDUFileReader::dduWordLength
static const int dduWordLength
Definition: DTDDUFileReader.h:64
DTDDUFileReader::DTDDUFileReader
DTDDUFileReader(const edm::ParameterSet &pset)
Constructor.
Definition: DTDDUFileReader.cc:31
DTDDUFileReader::runNumber
edm::RunNumber_t runNumber
Definition: DTDDUFileReader.h:55
DTDDUFileReader::inputFile
RawFile inputFile
Definition: DTDDUFileReader.h:53
FEDRawData.h
edm::Handle< FEDRawDataCollection >
FEDRawData
Definition: FEDRawData.h:19
DTDDUFileReader::dmaUnpack
uint64_t dmaUnpack(bool &isData, int &nread)
pre-unpack the data if read via DMA
Definition: DTDDUFileReader.cc:176
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
FEDTrailer::check
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
DTDDUFileReader::skipEvents
int skipEvents
Definition: DTDDUFileReader.h:61
DTDDUFileReader::checkEndOfFile
virtual bool checkEndOfFile()
Definition: DTDDUFileReader.cc:228
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
EventID.h
HLTBitAnalyser_cfi.isData
isData
Definition: HLTBitAnalyser_cfi.py:29
twoNibble64::lsBits
uint32_t lsBits
Definition: DTFileReaderHelpers.h:33
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
DTDDUFileReader::isTrailer
bool isTrailer(uint64_t word, bool dataTag, unsigned int wordCount)
check for a 64 bits word to be a DDU trailer
Definition: DTDDUFileReader.cc:215
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
DTDDUFileReader::fillRawData
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
Definition: DTDDUFileReader.cc:62
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
Timestamp.h
RawFile::ignore
int ignore(long offset)
Ignore some bytes.
Definition: RawFile.cc:92
DTDDUFileReader::eventNumber
edm::EventNumber_t eventNumber
Definition: DTDDUFileReader.h:56
FEDRawDataCollection.h
edm::EventSetup
Definition: EventSetup.h:58
FEDNumbering::MINDTFEDID
Definition: FEDNumbering.h:55
RawFile::open
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:19
DTDDUFileReader::numberOfHeaderWords
int numberOfHeaderWords
Definition: DTDDUFileReader.h:62
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:245
DTDDUFileReader::~DTDDUFileReader
~DTDDUFileReader() override
Destructor.
Definition: DTDDUFileReader.cc:60
gctErrorAnalyzer_cfi.dataTag
dataTag
Definition: gctErrorAnalyzer_cfi.py:28
FEDHeader::check
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
FEDHeader::sourceID
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
DTDDUFileReader::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: DTDDUFileReader.cc:160
ParameterSet.h
RawFile::read
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:76
edm::EventID
Definition: EventID.h:31
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
RawFile::fail
bool fail()
It is not OK.
Definition: RawFile.cc:72
RawFile::close
int close()
Close file if necessary.
Definition: RawFile.cc:52
DTDDUFileReader::readFromDMA
bool readFromDMA
Definition: DTDDUFileReader.h:60
FEDHeader.h
DTDDUFileReader::isHeader
bool isHeader(uint64_t word, bool dataTag)
check for a 64 bits word to be a DDU header
Definition: DTDDUFileReader.cc:202
DTDDUFileReader::swap
void swap(uint64_t &word)
swapping the lsBits with the msBits
Definition: DTDDUFileReader.cc:168
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
FEDTrailer::fragmentLength
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
FEDTrailer.h