CMS 3D CMS Logo

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