1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
#ifndef EventFilter_Utilities_DAQSourceModelsFRD_h
#define EventFilter_Utilities_DAQSourceModelsFRD_h
/*
* DAQSource data model classes for reading Run3 FRD format and unpacking into the FedRawDataCollection
* FRD: standard readout of input from the event builder
* FRDPreUNpack: variant unpacking events tns nto FedRawDataCollection class in reader threads
* FRSStiped: more generic version able to read from multiple source
* directories (Super-Fragmeng Builder DAQ)
* */
#include <filesystem>
#include <queue>
#include "oneapi/tbb/concurrent_unordered_set.h"
#include "EventFilter/Utilities/interface/DAQSourceModels.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
class FEDRawDataCollection;
/*
* FRD unpacker equivalent to the FedRawDataInputSource
*/
class DataModeFRD : public DataMode {
public:
DataModeFRD(DAQSource* daqSource, bool verifyFEDs) : DataMode(daqSource), verifyFEDs_(verifyFEDs) {}
DataModeFRD(DAQSource* daqSource) : DataMode(daqSource) {}
~DataModeFRD() override {}
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
void readEvent(edm::EventPrincipal& eventPrincipal) override;
//non-virtual
edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection& rawData,
bool& tcdsInRange,
unsigned char*& tcds_pointer);
int dataVersion() const override { return detectedFRDversion_; }
void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
}
uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
uint64_t dataBlockSize() const override { return event_->size(); }
void makeDataBlockView(unsigned char* addr, RawInputFile* rawFile) override;
bool nextEventView(RawInputFile*) override;
bool blockChecksumValid() override { return true; }
bool checksumValid() override;
std::string getChecksumError() const override;
//bool isRealData() const override { return event_->isRealData(); }
uint32_t run() const override { return event_->run(); }
//true for DAQ3 FRD
bool dataBlockCompleted() const override { return true; }
bool requireHeader() const override { return true; }
bool fitToBuffer() const override { return false; }
void unpackFile(RawInputFile*) override {}
bool dataBlockInitialized() const override { return true; }
void setDataBlockInitialized(bool) override {}
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
}
void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
std::vector<int> const& numSources,
std::vector<int> const& sourceIDs,
std::string const& sourceIdentifier,
std::string const& runDir) override {}
std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
return std::make_pair(true, std::vector<std::string>());
}
private:
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
uint16_t detectedFRDversion_ = 0;
size_t headerSize_ = 0;
std::unique_ptr<edm::streamer::FRDEventMsgView> event_;
uint32_t crc_ = 0;
unsigned char* dataBlockAddr_ = nullptr;
size_t dataBlockMax_ = 0;
size_t fileHeaderSize_ = 0;
uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;
bool eventCached_ = false;
std::unordered_set<unsigned short> fedIdSet_;
unsigned int expectedFedsInEvent_ = 0;
bool verifyFEDs_ = true;
};
/*
* FRD source prebuffering in the reader thread
*/
class DataModeFRDPreUnpack : public DataMode {
public:
DataModeFRDPreUnpack(DAQSource* daqSource, bool verifyFEDs) : DataMode(daqSource), verifyFEDs_(verifyFEDs) {}
~DataModeFRDPreUnpack() override {};
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
void readEvent(edm::EventPrincipal& eventPrincipal) override;
//non-virtual
void unpackEvent(edm::streamer::FRDEventMsgView* eview, UnpackedRawEventWrapper* ec, unsigned int ls);
void unpackFile(RawInputFile*) override;
edm::Timestamp fillFEDRawDataCollection(edm::streamer::FRDEventMsgView* eview,
FEDRawDataCollection& rawData,
bool& tcdsInRange,
unsigned char*& tcds_pointer,
bool& err,
std::string& errmsg);
int dataVersion() const override { return detectedFRDversion_; }
void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
}
uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
//used
uint64_t dataBlockSize() const override { return event_->size(); }
void makeDataBlockView(unsigned char* addr, RawInputFile* rawFile) override;
bool nextEventView(RawInputFile*) override;
bool blockChecksumValid() override { return true; }
bool checksumValid() override;
std::string getChecksumError() const override;
uint32_t run() const override { return ec_->run(); }
//true for DAQ3 FRD
bool dataBlockCompleted() const override { return true; }
bool requireHeader() const override { return true; }
bool fitToBuffer() const override { return true; }
bool dataBlockInitialized() const override { return true; }
void setDataBlockInitialized(bool) override {};
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
}
void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
std::vector<int> const& numSources,
std::vector<int> const& sourceIDs,
std::string const& sourceIdentifier,
std::string const& runDir) override {}
std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
return std::make_pair(true, std::vector<std::string>());
}
private:
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
uint16_t detectedFRDversion_ = 0;
size_t headerSize_ = 0;
std::unique_ptr<edm::streamer::FRDEventMsgView> event_;
std::unique_ptr<UnpackedRawEventWrapper> ec_;
uint32_t crc_ = 0;
unsigned char* dataBlockAddr_ = nullptr;
size_t dataBlockMax_ = 0;
size_t fileHeaderSize_ = 0;
uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;
bool eventCached_ = false;
oneapi::tbb::concurrent_unordered_set<unsigned short> fedIdSet_;
std::atomic<unsigned int> expectedFedsInEvent_ = 0;
bool verifyFEDs_ = true;
};
/*
* FRD source reading files from multiple striped destinations (Super-Fragment Builder DAQ)
*
* */
class DataModeFRDStriped : public DataMode {
public:
DataModeFRDStriped(DAQSource* daqSource, bool verifyFEDs) : DataMode(daqSource), verifyFEDs_(verifyFEDs) {}
~DataModeFRDStriped() override {}
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
void readEvent(edm::EventPrincipal& eventPrincipal) override;
//non-virtual
edm::Timestamp fillFRDCollection(FEDRawDataCollection& rawData, bool& tcdsInRange, unsigned char*& tcds_pointer);
int dataVersion() const override { return detectedFRDversion_; }
void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
}
uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
uint64_t dataBlockSize() const override {
//just get first event size
if (events_.empty())
throw cms::Exception("DataModeFRDStriped::dataBlockSize") << " empty event array";
return events_[0]->size();
}
void makeDataBlockView(unsigned char* addr, RawInputFile* rawFile) override;
bool nextEventView(RawInputFile*) override;
bool blockChecksumValid() override { return true; }
bool checksumValid() override;
std::string getChecksumError() const override;
//bool isRealData() const override {
// assert(!events_.empty());
// return events_[0]->isRealData();
//}
uint32_t run() const override {
assert(!events_.empty());
return events_[0]->run();
}
bool dataBlockCompleted() const override { return blockCompleted_; }
bool requireHeader() const override { return true; }
bool fitToBuffer() const override { return true; }
void unpackFile(RawInputFile*) override {}
bool dataBlockInitialized() const override { return dataBlockInitialized_; }
void setDataBlockInitialized(bool val) override { dataBlockInitialized_ = val; }
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
}
void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
std::vector<int> const& numSources,
std::vector<int> const& sourceIDs,
std::string const& sourceIdentifier,
std::string const& runDir) override;
std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
bool fileListMode) const override;
private:
bool makeEvents();
std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_; //
uint16_t detectedFRDversion_ = 0;
size_t fileHeaderSize_ = 0;
size_t headerSize_ = 0;
std::vector<std::unique_ptr<edm::streamer::FRDEventMsgView>> events_;
std::string crcMsg_;
unsigned char* dataBlockAddr_ = nullptr;
std::vector<unsigned char*> dataBlockAddrs_;
std::vector<unsigned char*> dataBlockMaxAddrs_;
size_t dataBlockMax_ = 0;
short numFiles_ = 0;
bool dataBlockInitialized_ = false;
bool blockCompleted_ = true;
bool eventCached_ = false;
uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;
std::vector<std::filesystem::path> buPaths_;
std::unordered_set<unsigned short> fedIdSet_;
unsigned int expectedFedsInEvent_ = 0;
bool verifyFEDs_ = true;
};
#endif // EventFilter_Utilities_DAQSourceModelsFRD_h
|