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 }
DTROS25FileReader::runNumber
edm::RunNumber_t runNumber
Definition: DTROS25FileReader.h:52
FEDNumbering.h
DTROS25FileReader::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: DTROS25FileReader.cc:119
DTROS25FileReader::isHeader
bool isHeader(uint32_t word)
check for a 32 bits word to be a ROS25 header
Definition: DTROS25FileReader.cc:135
mps_fire.i
i
Definition: mps_fire.py:428
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
DTROS25FileReader::eventNumber
edm::EventNumber_t eventNumber
Definition: DTROS25FileReader.h:53
DTROS25FileReader::rosWordLenght
static const int rosWordLenght
Definition: DTROS25FileReader.h:55
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
DTROS25FileReader::isTrailer
bool isTrailer(uint32_t word)
check for a 32 bits word to be a ROS25 trailer
Definition: DTROS25FileReader.cc:145
gather_cfg.cout
cout
Definition: gather_cfg.py:144
RawFile::eof
int eof()
Check end of file.
Definition: RawFile.cc:94
DTFileReaderHelpers.h
DTROS25FileReader::inputFile
RawFile inputFile
Definition: DTROS25FileReader.h:50
DTROS25FileReader::checkEndOfFile
virtual bool checkEndOfFile()
Definition: DTROS25FileReader.cc:154
FEDRawData.h
edm::Handle< FEDRawDataCollection >
FEDRawData
Definition: FEDRawData.h:19
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
EventID.h
DTROS25FileReader::DTROS25FileReader
DTROS25FileReader(const edm::ParameterSet &pset)
Constructor.
Definition: DTROS25FileReader.cc:31
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ParameterSet
Definition: ParameterSet.h:47
Timestamp.h
DTROS25FileReader::fillRawData
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Generate and fill FED raw data for a full event.
Definition: DTROS25FileReader.cc:43
twoNibble::msBits
uint16_t msBits
Definition: DTFileReaderHelpers.h:29
FEDRawDataCollection.h
edm::EventSetup
Definition: EventSetup.h:58
FEDNumbering::MINDTFEDID
Definition: FEDNumbering.h:55
RawFile::open
RawFile * open(const char *path)
Open file.
Definition: RawFile.cc:19
DTROS25FileReader::~DTROS25FileReader
~DTROS25FileReader() override
Destructor.
Definition: DTROS25FileReader.cc:41
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DTROS25FileReader::swap
void swap(uint32_t &word)
swapping the lsBits with the msBits
Definition: DTROS25FileReader.cc:127
DTROS25FileReader.h
twoNibble
Definition: DTFileReaderHelpers.h:27
Exception
Definition: hltDiff.cc:245
twoNibble::lsBits
uint16_t lsBits
Definition: DTFileReaderHelpers.h:28
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ParameterSet.h
RawFile::read
int read(void *data, size_t nbytes)
Read from file.
Definition: RawFile.cc:76
edm::EventID
Definition: EventID.h:31
edm::Event
Definition: Event.h:73
RawFile::fail
bool fail()
It is not OK.
Definition: RawFile.cc:72
RawFile::close
int close()
Close file if necessary.
Definition: RawFile.cc:52
FEDHeader.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
FEDTrailer.h