CMS 3D CMS Logo

DAQSourceModelsFRD.h
Go to the documentation of this file.
1 #ifndef EventFilter_Utilities_DAQSourceModelsFRD_h
2 #define EventFilter_Utilities_DAQSourceModelsFRD_h
3 
4 #include <filesystem>
5 
7 
9 
10 class DataModeFRD : public DataMode {
11 public:
12  DataModeFRD(DAQSource* daqSource) : DataMode(daqSource) {}
13  ~DataModeFRD() override{};
14  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
15  void readEvent(edm::EventPrincipal& eventPrincipal) override;
16 
17  //non-virtual
19  bool& tcdsInRange,
20  unsigned char*& tcds_pointer);
21 
22  int dataVersion() const override { return detectedFRDversion_; }
23  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
24  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
25  }
26 
28 
30 
31  uint64_t dataBlockSize() const override { return event_->size(); }
32 
33  void makeDataBlockView(unsigned char* addr,
34  size_t maxSize,
35  std::vector<uint64_t> const& fileSizes,
36  size_t fileHeaderSize) override {
39  eventCached_ = false;
40  nextEventView();
41  eventCached_ = true;
42  }
43 
44  bool nextEventView() override;
45  bool checksumValid() override;
46  std::string getChecksumError() const override;
47 
48  bool isRealData() const override { return event_->isRealData(); }
49 
50  uint32_t run() const override { return event_->run(); }
51 
52  //true for DAQ3 FRD
53  bool dataBlockCompleted() const override { return true; }
54 
55  bool requireHeader() const override { return true; }
56 
57  bool fitToBuffer() const override { return false; }
58  bool dataBlockInitialized() const override { return true; }
59 
60  void setDataBlockInitialized(bool) override{};
61 
62  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
63  MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
64  MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
65  }
66 
67  void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
68  std::vector<int> const& numSources,
69  std::string const& runDir) override {}
70 
71  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
72  return std::make_pair(true, std::vector<std::string>());
73  }
74 
75 private:
76  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
77  uint16_t detectedFRDversion_ = 0;
78  size_t headerSize_ = 0;
79  std::unique_ptr<edm::streamer::FRDEventMsgView> event_;
80  uint32_t crc_ = 0;
81  unsigned char* dataBlockAddr_ = nullptr;
82  size_t dataBlockMax_ = 0;
83  size_t fileHeaderSize_ = 0;
86  bool eventCached_ = false;
87 };
88 
89 /*
90  * Demo for FRD source reading files from multiple striped destinations
91  *
92  * */
93 
94 class DataModeFRDStriped : public DataMode {
95 public:
96  DataModeFRDStriped(DAQSource* daqSource) : DataMode(daqSource) {}
97  ~DataModeFRDStriped() override{};
98  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
99  void readEvent(edm::EventPrincipal& eventPrincipal) override;
100 
101  //non-virtual
102  edm::Timestamp fillFRDCollection(FEDRawDataCollection& rawData, bool& tcdsInRange, unsigned char*& tcds_pointer);
103 
104  int dataVersion() const override { return detectedFRDversion_; }
105  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
106  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
107  }
108 
110 
112 
113  uint64_t dataBlockSize() const override {
114  //just get first event size
115  if (events_.empty())
116  throw cms::Exception("DataModeFRDStriped::dataBlockSize") << " empty event array";
117  return events_[0]->size();
118  }
119 
120  void makeDataBlockView(unsigned char* addr,
121  size_t maxSize,
122  std::vector<uint64_t> const& fileSizes,
123  size_t fileHeaderSize) override {
124  fileHeaderSize_ = fileHeaderSize;
125  numFiles_ = fileSizes.size();
126  //add offset address for each file payload
127  dataBlockAddrs_.clear();
128  dataBlockAddrs_.push_back(addr);
129  dataBlockMaxAddrs_.clear();
130  dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
131  auto fileAddr = addr;
132  for (unsigned int i = 1; i < fileSizes.size(); i++) {
133  fileAddr += fileSizes[i - 1];
134  dataBlockAddrs_.push_back(fileAddr);
135  dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
136  }
137 
139  blockCompleted_ = false;
140  //set event cached as we set initial address here
141  bool result = makeEvents();
142  assert(result);
143  eventCached_ = true;
145  }
146 
147  bool nextEventView() override;
148  bool checksumValid() override;
149  std::string getChecksumError() const override;
150 
151  bool isRealData() const override {
152  assert(!events_.empty());
153  return events_[0]->isRealData();
154  }
155 
156  uint32_t run() const override {
157  assert(!events_.empty());
158  return events_[0]->run();
159  }
160 
161  bool dataBlockCompleted() const override { return blockCompleted_; }
162 
163  bool requireHeader() const override { return true; }
164 
165  bool fitToBuffer() const override { return true; }
166 
167  bool dataBlockInitialized() const override { return dataBlockInitialized_; }
168 
170 
171  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
172  MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
173  MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
174  }
175 
176  void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
177  std::vector<int> const& numSources,
178  std::string const& runDir) override;
179 
180  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
181  bool fileListMode) const override;
182 
183 private:
184  bool makeEvents();
185  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_; //
186  uint16_t detectedFRDversion_ = 0;
187  size_t fileHeaderSize_ = 0;
188  size_t headerSize_ = 0;
189  std::vector<std::unique_ptr<edm::streamer::FRDEventMsgView>> events_;
191  unsigned char* dataBlockAddr_ = nullptr;
192  std::vector<unsigned char*> dataBlockAddrs_;
193  std::vector<unsigned char*> dataBlockMaxAddrs_;
194  size_t dataBlockMax_ = 0;
195  short numFiles_ = 0;
196  bool dataBlockInitialized_ = false;
197  bool blockCompleted_ = true;
198  bool eventCached_ = false;
201  std::vector<std::filesystem::path> buPaths_;
202 };
203 
204 #endif // EventFilter_Utilities_DAQSourceModelsFRD_h
std::string getChecksumError() const override
std::string getChecksumError() const override
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool fileListMode) const override
bool isRealData() const override
bool checksumValid() override
bool checksumValid() override
void detectVersion(unsigned char *fileBuf, uint32_t fileHeaderOffset) override
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
edm::Timestamp fillFRDCollection(FEDRawDataCollection &rawData, bool &tcdsInRange, unsigned char *&tcds_pointer)
~DataModeFRDStriped() override
uint64_t dataBlockSize() const override
edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection &rawData, bool &tcdsInRange, unsigned char *&tcds_pointer)
constexpr size_t FRDHeaderMaxVersion
bool versionCheck() const override
void makeDataBlockView(unsigned char *addr, size_t maxSize, std::vector< uint64_t > const &fileSizes, size_t fileHeaderSize) override
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
bool nextEventView() override
assert(be >=bs)
std::unique_ptr< edm::streamer::FRDEventMsgView > event_
void readEvent(edm::EventPrincipal &eventPrincipal) override
uint32_t headerSize() const override
std::vector< unsigned char * > dataBlockMaxAddrs_
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override
size_t fileHeaderSize_
std::vector< std::filesystem::path > buPaths_
bool dataBlockInitialized() const override
uint16_t detectedFRDversion_
uint32_t run() const override
bool nextEventView() override
void readEvent(edm::EventPrincipal &eventPrincipal) override
bool dataBlockCompleted() const override
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool) const override
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override
bool fitToBuffer() const override
DataModeFRDStriped(DAQSource *daqSource)
unsigned long long uint64_t
Definition: Time.h:13
bool fitToBuffer() const override
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::vector< int > const &numSources, std::string const &runDir) override
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
unsigned char * dataBlockAddr_
uint64_t dataBlockSize() const override
std::vector< std::unique_ptr< edm::streamer::FRDEventMsgView > > events_
int dataVersion() const override
DataModeFRD(DAQSource *daqSource)
bool versionCheck() const override
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::vector< int > const &numSources, std::string const &runDir) override
bool requireHeader() const override
bool dataBlockCompleted() const override
int dataVersion() const override
uint32_t run() const override
uint16_t MINTCDSuTCAFEDID_
uint16_t MAXTCDSuTCAFEDID_
bool dataBlockInitialized() const override
void detectVersion(unsigned char *fileBuf, uint32_t fileHeaderOffset) override
void setDataBlockInitialized(bool) override
~DataModeFRD() override
bool isRealData() const override
std::vector< unsigned char * > dataBlockAddrs_
bool requireHeader() const override
unsigned char * dataBlockAddr_
void setDataBlockInitialized(bool val) override
void makeDataBlockView(unsigned char *addr, size_t maxSize, std::vector< uint64_t > const &fileSizes, size_t fileHeaderSize) override
uint32_t headerSize() const override
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override