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 
27  uint32_t headerSize() const override { return FRDHeaderVersionSize[detectedFRDversion_]; }
28 
29  bool versionCheck() const override { return detectedFRDversion_ <= FRDHeaderMaxVersion; }
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, std::string const& runDir) override {}
68 
69  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
70  return std::make_pair(true, std::vector<std::string>());
71  }
72 
73 private:
74  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
75  uint16_t detectedFRDversion_ = 0;
76  size_t headerSize_ = 0;
77  std::unique_ptr<FRDEventMsgView> event_;
78  uint32_t crc_ = 0;
79  unsigned char* dataBlockAddr_ = nullptr;
80  size_t dataBlockMax_ = 0;
81  size_t fileHeaderSize_ = 0;
84  bool eventCached_ = false;
85 };
86 
87 /*
88  * Demo for FRD source reading files from multiple striped destinations
89  *
90  * */
91 
92 class DataModeFRDStriped : public DataMode {
93 public:
94  DataModeFRDStriped(DAQSource* daqSource) : DataMode(daqSource) {}
95  ~DataModeFRDStriped() override{};
96  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
97  void readEvent(edm::EventPrincipal& eventPrincipal) override;
98 
99  //non-virtual
100  edm::Timestamp fillFRDCollection(FEDRawDataCollection& rawData, bool& tcdsInRange, unsigned char*& tcds_pointer);
101 
102  int dataVersion() const override { return detectedFRDversion_; }
103  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
104  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
105  }
106 
107  uint32_t headerSize() const override { return FRDHeaderVersionSize[detectedFRDversion_]; }
108 
109  bool versionCheck() const override { return detectedFRDversion_ <= FRDHeaderMaxVersion; }
110 
111  uint64_t dataBlockSize() const override {
112  //just get first event size
113  if (events_.empty())
114  throw cms::Exception("DataModeFRDStriped::dataBlockSize") << " empty event array";
115  return events_[0]->size();
116  }
117 
118  void makeDataBlockView(unsigned char* addr,
119  size_t maxSize,
120  std::vector<uint64_t> const& fileSizes,
121  size_t fileHeaderSize) override {
122  fileHeaderSize_ = fileHeaderSize;
123  numFiles_ = fileSizes.size();
124  //add offset address for each file payload
125  dataBlockAddrs_.clear();
126  dataBlockAddrs_.push_back(addr);
127  dataBlockMaxAddrs_.clear();
128  dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
129  auto fileAddr = addr;
130  for (unsigned int i = 1; i < fileSizes.size(); i++) {
131  fileAddr += fileSizes[i - 1];
132  dataBlockAddrs_.push_back(fileAddr);
133  dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
134  }
135 
137  blockCompleted_ = false;
138  //set event cached as we set initial address here
139  bool result = makeEvents();
140  assert(result);
141  eventCached_ = true;
143  }
144 
145  bool nextEventView() override;
146  bool checksumValid() override;
147  std::string getChecksumError() const override;
148 
149  bool isRealData() const override {
150  assert(!events_.empty());
151  return events_[0]->isRealData();
152  }
153 
154  uint32_t run() const override {
155  assert(!events_.empty());
156  return events_[0]->run();
157  }
158 
159  bool dataBlockCompleted() const override { return blockCompleted_; }
160 
161  bool requireHeader() const override { return true; }
162 
163  bool fitToBuffer() const override { return true; }
164 
165  bool dataBlockInitialized() const override { return dataBlockInitialized_; }
166 
168 
169  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
170  MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
171  MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
172  }
173 
174  void makeDirectoryEntries(std::vector<std::string> const& baseDirs, std::string const& runDir) override;
175 
176  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
177  bool fileListMode) const override;
178 
179 private:
180  bool makeEvents();
181  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_; //
182  uint16_t detectedFRDversion_ = 0;
183  size_t fileHeaderSize_ = 0;
184  size_t headerSize_ = 0;
185  std::vector<std::unique_ptr<FRDEventMsgView>> events_;
187  unsigned char* dataBlockAddr_ = nullptr;
188  std::vector<unsigned char*> dataBlockAddrs_;
189  std::vector<unsigned char*> dataBlockMaxAddrs_;
190  size_t dataBlockMax_ = 0;
191  short numFiles_ = 0;
192  bool dataBlockInitialized_ = false;
193  bool blockCompleted_ = true;
194  bool eventCached_ = false;
197  std::vector<std::filesystem::path> buPaths_;
198 };
199 
200 #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 size_t FRDHeaderMaxVersion
edm::Timestamp fillFRDCollection(FEDRawDataCollection &rawData, bool &tcdsInRange, unsigned char *&tcds_pointer)
~DataModeFRDStriped() override
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::string const &runDir) override
uint64_t dataBlockSize() const override
edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection &rawData, bool &tcdsInRange, unsigned char *&tcds_pointer)
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::unique_ptr< FRDEventMsgView > > events_
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
bool nextEventView() override
assert(be >=bs)
void readEvent(edm::EventPrincipal &eventPrincipal) override
std::unique_ptr< FRDEventMsgView > event_
uint32_t headerSize() const override
std::vector< unsigned char * > dataBlockMaxAddrs_
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::string const &runDir) override
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
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
unsigned char * dataBlockAddr_
uint64_t dataBlockSize() const override
int dataVersion() const override
DataModeFRD(DAQSource *daqSource)
bool versionCheck() const 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
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
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