CMS 3D CMS Logo

DTNewROS8FileReader.cc
Go to the documentation of this file.
1 
13 
17 
22 
25 
26 #include <string>
27 #include <iosfwd>
28 #include <iostream>
29 #include <algorithm>
30 
31 using namespace std;
32 using namespace edm;
33 
35  const string& filename = pset.getUntrackedParameter<string>("fileName");
36 
37  inputFile.open(filename.c_str());
38  if (inputFile.fail()) {
39  throw cms::Exception("InputFileMissing")
40  << "DTNewROS8FileReader: the input file: " << filename << " is not present";
41  }
42 
43  produces<FEDRawDataCollection>();
44 }
45 
47 
49  // Timestamp& tstamp,
51  EventID eID = e.id();
52  data = new FEDRawDataCollection();
53 
54  try {
55  /* Structure of the DATA
56 
57  1.- NUMBER OF WORDS (it includes this word and the last counter)
58  2.- HEADER: 8 Words
59  Header word 0: run number
60  Header word 1: spill number
61  Header word 2: event number
62  Header word 3: reserved
63  Header word 4: ROS data offset
64  Header word 5: PU data offset
65  Header word 6: reserved
66  Header word 7: reserved
67  3.- ROS DATA ==> DECODE BY THE DTROS8Unpacker.cc in EventFilter
68  3.1 NUMBER OF ROS WORDS (it includes this counter)
69  3.2 Lock status Word
70  3.3 ROS DATA
71  3.3.1 ROS BOARD ID/ROS CHANNEL - 1 word
72  3.3.2 GLOBAL HEADER - 1 word
73  3.3.3 TDC Data Words - X words (depends on event)
74  3.3.4 GLOBAL TRAILER
75  4.- PU DATA (trigger) ==> DECODE BY THE DTROS8Unpacker.cc in EventFilter
76  Not always. If chamber is autotriggered doesn't have PU data except
77  the Number of PU words
78  4.1.- NUMBER OF WORDS (it includes this word, always present
79  even if there is not PU data)
80  4.2.- PATTERN UNIT ID - 1 word (data counter & PU-ID)
81  4.3.- DATA - X Words ?????
82  5.- NUMBER OF WORDS (include this word and the first counter)
83  */
84 
85  if (checkEndOfFile())
86  throw 1;
87 
88  // Number of words in the header, including the first word of header that is the number of words in the event
89  int numberEventHeadWords = 8;
90 
91  //1.- Get the total NUMBER OF WORDs from the 1st word in the payload
92  int numberOfWords = 0;
93  int nread = 0;
94  nread = inputFile.read(dataPointer<int>(&numberOfWords), ros8WordLenght); // ros8WordLength=4
95  if (nread <= 0)
96  throw 1;
97 
98  // inputFile.ignore(4*(numberEventHeadWords-1)); // Skip the header. The first word of header has been already read
99 
100  //2.- Get the HEADER ============================================================================
101  int datahead[numberEventHeadWords];
102  for (int iih = 0; iih < numberEventHeadWords; iih++) {
103  nread = inputFile.read(dataPointer<int>(&datahead[iih]), ros8WordLenght);
104  }
105 
106  //3.- ROS DATA & 4.- PU DATA (Trigger) =======================================================
107  // Get the event data (all words but the header and the first and the last counter)
108  int numberOfDataWords = numberOfWords - numberEventHeadWords - 2;
109  int* eventData = new int[numberOfDataWords];
110  nread = inputFile.read(dataPointer<int>(eventData), numberOfDataWords * ros8WordLenght);
111  if (nread <= 0)
112  throw 1;
113 
114  //5.- Get the total NUMBER OF WORDs from the last word in the payload
115  // Check that the event data size corresponds to the 1st word datum
116  int LastCounter = 0;
117  nread = inputFile.read(dataPointer<int>(&LastCounter), ros8WordLenght);
118  if (nread <= 0)
119  throw 1;
120 
121  if (LastCounter != numberOfWords) {
122  cout << "[DTNewROS8FileReader]: word counter mismatch exception: " << numberOfWords << " " << LastCounter << endl;
123  throw 99;
124  }
125 
126  //The first word in the header is the run number
127  runNumber = datahead[0];
128  cout << "[DTNewROS8FileReader]: Run Number: " << dec << runNumber << endl;
129 
130  //The third word in the header is the event number (without any reset)
131  //eventNum= datahead[2]; //francos system
132  eventNum = datahead[1]; //linux system
133  //cout<<"ëventNum "<<dec<<eventNum<<endl;
134  if (eventNum < 1)
135  eventNum = 1; // Event number must start at 1 but at TDCs it starts at cero,if not the program crashes
136  // files used for testing start in 1, but... just in case...
137 
138  eID = EventID(runNumber, 1U, eventNum);
139 
140  //cout << " EEEEE eID: " << eID << endl;
141  // Even if we have introducing the correct runNumber when running the runNumber appears always as =1
142 
143  int eventDataSize = numberOfDataWords * ros8WordLenght;
144  int adjustment = (eventDataSize / 4) % 2 == 1 ? 4 : 0;
145 
146  // The FED ID is always the first in the DT range
148  fedRawData.resize(eventDataSize + adjustment); // the size must be multiple of 8 bytes
149 
150  // Passing the data to the Event
151  copy(reinterpret_cast<unsigned char*>(eventData),
152  reinterpret_cast<unsigned char*>(eventData) + eventDataSize,
153  fedRawData.data());
154 
155  // needed to get rid of memory leaks (?)
156  delete[] eventData;
157 
158  return true;
159 
160  } catch (int i) {
161  if (i == 1) {
162  cout << "[DTNewROS8FileReader]: END OF FILE REACHED. "
163  << "No information read for the requested event" << endl;
164  delete data;
165  data = nullptr;
166  return false;
167  } else {
168  cout << "[DTNewROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
169  << "EVENT DATA READING FAILED code= " << i << endl;
170  delete data;
171  data = nullptr;
172  return false;
173  }
174  }
175 }
176 
179  FEDRawDataCollection* fedcoll = nullptr;
180  fillRawData(e, fedcoll);
181  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
182  e.put(std::move(bare_product));
183 }
184 
186  bool retval = false;
187  if (inputFile.eof())
188  retval = true;
189  return retval;
190 }
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:19
DTNewROS8FileReader(const edm::ParameterSet &pset)
Constructor.
bool fail()
It is not OK.
Definition: RawFile.cc:72
edm::EventNumber_t eventNum
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:76
int close()
Close file if necessary.
Definition: RawFile.cc:52
static const int ros8WordLenght
virtual bool checkEndOfFile()
void produce(edm::Event &, edm::EventSetup const &) override
int eof()
Check end of file.
Definition: RawFile.cc:94
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
~DTNewROS8FileReader() override
Destructor.
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
edm::RunNumber_t runNumber