CMS 3D CMS Logo

DTROS25FileReader.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 
31 
33  runNumber(1), eventNumber(0) {
34 
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  << "DTROS25FileReader: the input file: " << filename <<" is not present";
41  }
42  produces<FEDRawDataCollection>();
43 }
44 
45 
47  inputFile.close();
48 }
49 
50 
52 // Timestamp& tstamp,
54  EventID eID = e.id();
55  data = new FEDRawDataCollection();
56 
57  vector<uint32_t> eventData;
58  size_t estimatedEventDimension = 102400; // dimensione hardcoded
59  eventData.reserve(estimatedEventDimension);
60  uint32_t word = 0;
61 
62 
63  try {
64 
65  bool marked = false;
66 
67  // getting the data word by word from the file
68  // do it until you get the ROS25 trailer
69  while ( !isTrailer(word) ) {
70 
71  // get the first word
72  int nread = inputFile.read(dataPointer<uint32_t>( &word ), rosWordLenght);
73 
74  // WARNING!!! ||swapping it|| (Check whether it is necessary)
75  swap(word);
76 
77  if ( nread<=0 ) throw 1;
78 
79  // get the ROS25 header
80  if (isHeader(word)) marked=true;
81 
82  // from now on fill the eventData with the ROS data
83  if (marked) {
84  eventData.push_back(word);
85 
86  }
87  }
88 
89  // next event reading will start with meaningless trailer+header from DTLocalDAQ
90  // those will be skipped automatically when seeking for the ROS25 header
91 
92  //if (eventData.size() > estimatedEventDimension) throw 2;
93 
94  // Setting the Event ID
95  eID = EventID( runNumber, 1U, eventNumber);
96 
97  // eventDataSize = (Number Of Words)* (Word Size)
98  int eventDataSize = eventData.size()*rosWordLenght;
99  // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
100  int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;
101 
102  // The FED ID is always the first in the DT range
103  FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
104  fedRawData.resize(eventDataSize+adjustment);
105 
106  copy(reinterpret_cast<unsigned char*>(&eventData[0]),
107  reinterpret_cast<unsigned char*>(&eventData[0]) + eventDataSize, fedRawData.data());
108 
109  return true;
110  }
111 
112  catch( int i ) {
113 
114  if ( i == 1 ){
115  cout<<"[DTROS25FileReader]: ERROR! failed to get the trailer"<<endl;
116  delete data; data=0;
117  return false;
118  }
119  else {
120  cout<<"[DTROS25FileReader]:"
121  <<" ERROR! ROS data exceeding estimated event dimension. Event size = "
122  <<eventData.size()<<endl;
123  delete data; data=0;
124  return false;
125  }
126 
127  }
128 
129 }
130 
133  FEDRawDataCollection *fedcoll = 0;
134  fillRawData(e,fedcoll);
135  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
136  e.put(std::move(bare_product));
137  }
138 
139 void DTROS25FileReader::swap(uint32_t & word) {
140 
141  twoNibble* newWorld = reinterpret_cast<twoNibble*>(&word);
142 
143  uint16_t msBits_tmp = newWorld->msBits;
144  newWorld->msBits = newWorld->lsBits;
145  newWorld->lsBits = msBits_tmp;
146 }
147 
148 
149 bool DTROS25FileReader::isHeader(uint32_t word) {
150 
151  bool it_is = false;
152  if ( (word >> 24 ) == 31 ) {
153  it_is = true;
154  ++eventNumber;
155  }
156 
157  return it_is;
158 }
159 
160 
161 bool DTROS25FileReader::isTrailer(uint32_t word) {
162 
163  bool it_is = false;
164  if ( (word >> 24 ) == 63 ) {
165  it_is = true;
166  }
167 
168  return it_is;
169 }
170 
171 
173 
174  bool retval=false;
175  if ( inputFile.eof() ) retval=true;
176  return retval;
177 
178 }
179 
180 
181 
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
edm::RunNumber_t runNumber
edm::EventNumber_t eventNumber
static const int rosWordLenght
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:20
bool fail()
It is not OK.
Definition: RawFile.cc:71
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:75
virtual void produce(edm::Event &, edm::EventSetup const &)
bool isTrailer(uint32_t word)
check for a 32 bits word to be a ROS25 trailer
virtual bool checkEndOfFile()
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
int close()
Close file if necessary.
Definition: RawFile.cc:52
void resize(size_t newsize)
Definition: FEDRawData.cc:32
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
virtual ~DTROS25FileReader()
Destructor.
DTROS25FileReader(const edm::ParameterSet &pset)
Constructor.
int eof()
Check end of file.
Definition: RawFile.cc:93
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void swap(uint32_t &word)
swapping the lsBits with the msBits
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
def move(src, dest)
Definition: eostools.py:510
bool isHeader(uint32_t word)
check for a 32 bits word to be a ROS25 header