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