CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTROS8FileReader.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  runNum(1), eventNum(0) {
34 
35  const string & filename = pset.getParameter<string>("fileName");
36 
37  inputFile.open(filename.c_str());
38  if( inputFile.fail() ) {
39  throw cms::Exception("InputFileMissing")
40  << "DTROS8FileReader: 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  try {
56 
57 
58  if( checkEndOfFile() ) throw 1;
59 
60 
61  // Get the total number of words from the 1st word in the payload
62  int numberOfWords;
63  int nread = 0;
64  nread = inputFile.read(dataPointer<int>( &numberOfWords ), ros8WordLenght);
65  if ( nread<=0 ) throw 1;
66 
67 
68  // Get the event data (all words but the 1st)
69  int* eventData = new int[numberOfWords];
70  nread = inputFile.read(dataPointer<int>( eventData + 1 ), (numberOfWords-1) * ros8WordLenght );
71  if ( nread<=0 ) throw 1;
72 
73 
74  // Check that the event data size corresponds to the 1st word datum
75  if ( eventData[numberOfWords-1] != numberOfWords ) {
76  cout << "[DTROS8FileReader]: word counter mismatch exception: "
77  << numberOfWords << " " << eventData[numberOfWords-1] << endl;
78  throw 99;
79  }
80 
81  // The header added by the local DAQ occupies 8 words, starting from the 2nd
82  int* head = eventData + 1;
83 
84  /*
85  Header word 0: run number
86  Header word 1: spill number
87  Header word 2: event number
88  Header word 3: reserved
89  Header word 4: ROS data offset
90  Header word 5: PU data offset
91  Header word 6: reserved
92  Header word 7: reserved
93  */
94 
95  // WARNING: the event number is reset at a new spill
96  eID = EventID( head[0], 1U, head[1]*head[2]);
97 
98  // The pointer to the ROS payload (the 1st word being the ROS words counter)
99  int* rosData = eventData + head[4];
100 
101  // The ROS payload size
102  int eventDataSize = *rosData * ros8WordLenght;
103  // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
104  int adjustment = (eventDataSize/4)%2 == 1 ? 4 : 0;
105 
106  //if ( (eventDataSize/4)%2 ) adjustment = 4;
107 
108 
109  // The FED ID is always the first in the DT range
110  FEDRawData& fedRawData = data->FEDData( FEDNumbering::MINDTFEDID );
111  fedRawData.resize(eventDataSize+adjustment);
112 
113  // I pass only the ROS data to the Event
114  copy(reinterpret_cast<unsigned char*>(rosData),
115  reinterpret_cast<unsigned char*>(rosData) + eventDataSize, fedRawData.data());
116 
117  // needed to get rid of memory leaks (?)
118  delete[] eventData;
119 
120  return true;
121  }
122 
123  catch( int i ) {
124 
125  if ( i == 1 ){
126  cout << "[DTROS8FileReader]: END OF FILE REACHED. "
127  << "No information read for the requested event" << endl;
128  delete data; data=0;
129  return false;
130  }
131  else {
132  cout << "[DTROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
133  << "EVENT DATA READING FAILED code= " << i << endl;
134  delete data; data=0;
135  return false;
136  }
137 
138  }
139 
140 }
141 
142 
144 
145  bool retval=false;
146  if ( inputFile.eof() ) retval=true;
147  return retval;
148 
149 }
150 
151 
152 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual bool checkEndOfFile()
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
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 ~DTROS8FileReader()
Destructor.
int eof()
Check end of file.
Definition: RawFile.cc:100
static const int ros8WordLenght
DTROS8FileReader(const edm::ParameterSet &pset)
Constructor.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual int fillRawData(edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
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