CMS 3D CMS Logo

DAQSourceModelsScoutingRun3.h
Go to the documentation of this file.
1 #ifndef EventFilter_Utilities_DAQSourceModelsScoutingRun3_h
2 #define EventFilter_Utilities_DAQSourceModelsScoutingRun3_h
3 
8 
12 
13 #include <sys/types.h>
14 #include <filesystem>
15 #include <sstream>
16 #include <iostream>
17 #include <memory>
18 #include <vector>
19 
21 public:
22  DataModeScoutingRun3(DAQSource* daqSource) : DataMode(daqSource) {}
23  ~DataModeScoutingRun3() override{};
24  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
25  void readEvent(edm::EventPrincipal& eventPrincipal) override;
26 
27  void fillSDSRawDataCollection(SDSRawDataCollection& rawData, char* buff, size_t len);
28 
29  //reuse FRD file and event headers
30  int dataVersion() const override { return detectedFRDversion_; }
31  void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
32  detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
33  }
36 
37  uint64_t dataBlockSize() const override {
38  // get event size from the first data source (main)
39  return events_[0]->size();
40  }
41 
42  void makeDataBlockView(unsigned char* addr,
43  size_t maxSize,
44  std::vector<uint64_t> const& fileSizes,
45  size_t fileHeaderSize) override {
46  fileHeaderSize_ = fileHeaderSize;
47  numFiles_ = fileSizes.size();
48 
49  // initalize vectors keeping tracks of valid orbits and completed blocks
50  sourceValidOrbitPair_.clear();
51  completedBlocks_.clear();
52  for (unsigned int i = 0; i < fileSizes.size(); i++) {
53  completedBlocks_.push_back(false);
54  }
55 
56  //add offset address for each file payload
57  dataBlockAddrs_.clear();
58  dataBlockAddrs_.push_back(addr);
59  dataBlockMaxAddrs_.clear();
60  dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
61  auto fileAddr = addr;
62  for (unsigned int i = 1; i < fileSizes.size(); i++) {
63  fileAddr += fileSizes[i - 1];
64  dataBlockAddrs_.push_back(fileAddr);
65  dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
66  }
67 
69  blockCompleted_ = false;
70  //set event cached as we set initial address here
71  bool result = makeEvents();
72  assert(result);
73  eventCached_ = true;
75  }
76 
77  bool nextEventView() override;
78  bool checksumValid() override;
79  std::string getChecksumError() const override;
80 
81  bool isRealData() const override {
82  assert(!events_.empty());
83  return events_[0]->isRealData();
84  }
85 
86  uint32_t run() const override {
87  assert(!events_.empty());
88  return events_[0]->run();
89  }
90 
91  bool dataBlockCompleted() const override { return blockCompleted_; }
92 
93  bool requireHeader() const override { return true; }
94 
95  bool fitToBuffer() const override { return true; }
96 
97  bool dataBlockInitialized() const override { return dataBlockInitialized_; }
98 
100 
101  void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override { return; }
102 
103  void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
104  std::vector<int> const& numSources,
105  std::string const& runDir) override;
106 
107  std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
108  bool fileListMode) const override;
109 
110 private:
111  bool makeEvents();
112  std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_; //
113  uint16_t detectedFRDversion_ = 0;
114  size_t fileHeaderSize_ = 0;
115  size_t headerSize_ = 0;
116  std::vector<std::unique_ptr<edm::streamer::FRDEventMsgView>> events_;
117  unsigned char* dataBlockAddr_ = nullptr;
118  std::vector<unsigned char*> dataBlockAddrs_;
119  std::vector<unsigned char*> dataBlockMaxAddrs_;
120  size_t dataBlockMax_ = 0;
121  short numFiles_ = 0;
122  bool dataBlockInitialized_ = false;
123  bool blockCompleted_ = true;
124  bool eventCached_ = false;
125  std::vector<std::filesystem::path> buPaths_;
126  std::vector<int> buNumSources_;
127 
128  // keep track of valid (=aligned) orbits from different data sources
129  std::vector<std::pair<int, int>> sourceValidOrbitPair_;
130  unsigned int currOrbit_ = 0xFFFFFFFF;
131 
132  std::vector<bool> completedBlocks_;
133 };
134 
135 #endif // EventFilter_Utilities_DAQSourceModelsScoutingRun3_h
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::vector< int > const &numSources, std::string const &runDir) override
std::vector< std::filesystem::path > buPaths_
std::vector< std::pair< int, int > > sourceValidOrbitPair_
void fillSDSRawDataCollection(SDSRawDataCollection &rawData, char *buff, size_t len)
bool requireHeader() const override
constexpr std::array< uint32, FRDHeaderMaxVersion+1 > FRDHeaderVersionSize
uint32_t headerSize() const override
std::vector< bool > completedBlocks_
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override
bool isRealData() const override
constexpr size_t FRDHeaderMaxVersion
std::vector< unsigned char * > dataBlockAddrs_
assert(be >=bs)
bool dataBlockInitialized() const override
std::vector< unsigned char * > dataBlockMaxAddrs_
void makeDataBlockView(unsigned char *addr, size_t maxSize, std::vector< uint64_t > const &fileSizes, size_t fileHeaderSize) override
bool versionCheck() const override
DataModeScoutingRun3(DAQSource *daqSource)
std::vector< std::unique_ptr< edm::streamer::FRDEventMsgView > > events_
int dataVersion() const override
bool dataBlockCompleted() const override
uint64_t dataBlockSize() const override
std::string getChecksumError() const override
bool fitToBuffer() const override
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool fileListMode) const override
unsigned long long uint64_t
Definition: Time.h:13
void detectVersion(unsigned char *fileBuf, uint32_t fileHeaderOffset) override
void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override
void setDataBlockInitialized(bool val) override
uint32_t run() const override
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > daqProvenanceHelpers_
void readEvent(edm::EventPrincipal &eventPrincipal) override