CMS 3D CMS Logo

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