CMS 3D CMS Logo

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 
32  //const string & filename = pset.getParameter<string>("fileName"); // Don't work, it produces an error saying that the DTNewROS8FileReader plugin doesn't exist!!!
33 
34  const string& filename = pset.getUntrackedParameter<string>("fileName");
35 
36  inputFile.open(filename.c_str());
37  if (inputFile.fail()) {
38  throw cms::Exception("InputFileMissing") << "DTROS8FileReader: the input file: " << filename << " is not present";
39  }
40 
41  produces<FEDRawDataCollection>();
42 }
43 
45 
47  // Timestamp& tstamp,
49  EventID eID = e.id();
50  data = new FEDRawDataCollection();
51 
52  try {
53  if (checkEndOfFile())
54  throw 1;
55 
56  // Get the total number of words from the 1st word in the payload
57  int numberOfWords = 0;
58  int nread = 0;
59  nread = inputFile.read(dataPointer<int>(&numberOfWords), ros8WordLenght);
60  if (nread <= 0)
61  throw 1;
62 
63  // Get the event data (all words but the 1st)
64  int* eventData = new int[numberOfWords];
65  nread = inputFile.read(dataPointer<int>(eventData + 1), (numberOfWords - 1) * ros8WordLenght);
66  if (nread <= 0)
67  throw 1;
68 
69  // Check that the event data size corresponds to the 1st word datum
70  if (numberOfWords <= 0 || eventData[numberOfWords - 1] != numberOfWords) {
71  cout << "[DTROS8FileReader]: word counter mismatch exception: " << numberOfWords << " "
72  << eventData[numberOfWords - 1] << endl;
73  throw 99;
74  }
75 
76  // The header added by the local DAQ occupies 8 words, starting from the 2nd
77  int* head = eventData + 1;
78 
79  /*
80  Header word 0: run number
81  Header word 1: spill number
82  Header word 2: event number
83  Header word 3: reserved
84  Header word 4: ROS data offset
85  Header word 5: PU data offset
86  Header word 6: reserved
87  Header word 7: reserved
88  */
89 
90  // WARNING: the event number is reset at a new spill
91  eID = EventID(head[0], 1U, head[1] * head[2]);
92 
93  // The pointer to the ROS payload (the 1st word being the ROS words counter)
94  int* rosData = eventData + head[4];
95 
96  // The ROS payload size
97  int eventDataSize = *rosData * ros8WordLenght;
98  // It has to be a multiple of 8 bytes. if not, adjust the size of the FED payload
99  int adjustment = (eventDataSize / 4) % 2 == 1 ? 4 : 0;
100 
101  //if ( (eventDataSize/4)%2 ) adjustment = 4;
102 
103  // The FED ID is always the first in the DT range
105  fedRawData.resize(eventDataSize + adjustment);
106 
107  // I pass only the ROS data to the Event
108  copy(reinterpret_cast<unsigned char*>(rosData),
109  reinterpret_cast<unsigned char*>(rosData) + eventDataSize,
110  fedRawData.data());
111 
112  // needed to get rid of memory leaks (?)
113  delete[] eventData;
114 
115  return true;
116  }
117 
118  catch (int i) {
119  if (i == 1) {
120  cout << "[DTROS8FileReader]: END OF FILE REACHED. "
121  << "No information read for the requested event" << endl;
122  delete data;
123  data = nullptr;
124  return false;
125  } else {
126  cout << "[DTROS8FileReader]: PROBLEM WITH EVENT INFORMATION ON THE FILE. "
127  << "EVENT DATA READING FAILED code= " << i << endl;
128  delete data;
129  data = nullptr;
130  return false;
131  }
132  }
133 }
134 
137  FEDRawDataCollection* fedcoll = nullptr;
138  fillRawData(e, fedcoll);
139  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
140  e.put(std::move(bare_product));
141 }
142 
144  bool retval = false;
145  if (inputFile.eof())
146  retval = true;
147  return retval;
148 }
~DTROS8FileReader() override
Destructor.
virtual bool checkEndOfFile()
void produce(edm::Event &, edm::EventSetup const &) override
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:19
bool fail()
It is not OK.
Definition: RawFile.cc:72
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:76
int close()
Close file if necessary.
Definition: RawFile.cc:52
int eof()
Check end of file.
Definition: RawFile.cc:94
static const int ros8WordLenght
DTROS8FileReader(const edm::ParameterSet &pset)
Constructor.
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
def move(src, dest)
Definition: eostools.py:511