File indexing completed on 2024-09-07 04:36:16
0001 #ifndef EventFilter_Utilities_DAQSourceModelsFRD_h
0002 #define EventFilter_Utilities_DAQSourceModelsFRD_h
0003
0004 #include <filesystem>
0005
0006 #include "EventFilter/Utilities/interface/DAQSourceModels.h"
0007
0008 class FEDRawDataCollection;
0009
0010 class DataModeFRD : public DataMode {
0011 public:
0012 DataModeFRD(DAQSource* daqSource) : DataMode(daqSource) {}
0013 ~DataModeFRD() override {}
0014 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
0015 void readEvent(edm::EventPrincipal& eventPrincipal) override;
0016
0017
0018 edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection& rawData,
0019 bool& tcdsInRange,
0020 unsigned char*& tcds_pointer);
0021
0022 int dataVersion() const override { return detectedFRDversion_; }
0023 void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
0024 detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
0025 }
0026
0027 uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
0028
0029 bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
0030
0031 uint64_t dataBlockSize() const override { return event_->size(); }
0032
0033 void makeDataBlockView(unsigned char* addr,
0034 size_t maxSize,
0035 std::vector<uint64_t> const& fileSizes,
0036 size_t fileHeaderSize) override {
0037 dataBlockAddr_ = addr;
0038 dataBlockMax_ = maxSize;
0039 eventCached_ = false;
0040 nextEventView();
0041 eventCached_ = true;
0042 }
0043
0044 bool nextEventView() override;
0045 bool checksumValid() override;
0046 std::string getChecksumError() const override;
0047
0048 bool isRealData() const override { return event_->isRealData(); }
0049
0050 uint32_t run() const override { return event_->run(); }
0051
0052
0053 bool dataBlockCompleted() const override { return true; }
0054
0055 bool requireHeader() const override { return true; }
0056
0057 bool fitToBuffer() const override { return false; }
0058 bool dataBlockInitialized() const override { return true; }
0059
0060 void setDataBlockInitialized(bool) override {}
0061
0062 void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
0063 MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
0064 MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
0065 }
0066
0067 void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
0068 std::vector<int> const& numSources,
0069 std::string const& runDir) override {}
0070
0071 std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName, bool) const override {
0072 return std::make_pair(true, std::vector<std::string>());
0073 }
0074
0075 private:
0076 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
0077 uint16_t detectedFRDversion_ = 0;
0078 size_t headerSize_ = 0;
0079 std::unique_ptr<edm::streamer::FRDEventMsgView> event_;
0080 uint32_t crc_ = 0;
0081 unsigned char* dataBlockAddr_ = nullptr;
0082 size_t dataBlockMax_ = 0;
0083 size_t fileHeaderSize_ = 0;
0084 uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
0085 uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;
0086 bool eventCached_ = false;
0087 };
0088
0089
0090
0091
0092
0093
0094 class DataModeFRDStriped : public DataMode {
0095 public:
0096 DataModeFRDStriped(DAQSource* daqSource) : DataMode(daqSource) {}
0097 ~DataModeFRDStriped() override {}
0098 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
0099 void readEvent(edm::EventPrincipal& eventPrincipal) override;
0100
0101
0102 edm::Timestamp fillFRDCollection(FEDRawDataCollection& rawData, bool& tcdsInRange, unsigned char*& tcds_pointer);
0103
0104 int dataVersion() const override { return detectedFRDversion_; }
0105 void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
0106 detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
0107 }
0108
0109 uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
0110
0111 bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
0112
0113 uint64_t dataBlockSize() const override {
0114
0115 if (events_.empty())
0116 throw cms::Exception("DataModeFRDStriped::dataBlockSize") << " empty event array";
0117 return events_[0]->size();
0118 }
0119
0120 void makeDataBlockView(unsigned char* addr,
0121 size_t maxSize,
0122 std::vector<uint64_t> const& fileSizes,
0123 size_t fileHeaderSize) override {
0124 fileHeaderSize_ = fileHeaderSize;
0125 numFiles_ = fileSizes.size();
0126
0127 dataBlockAddrs_.clear();
0128 dataBlockAddrs_.push_back(addr);
0129 dataBlockMaxAddrs_.clear();
0130 dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
0131 auto fileAddr = addr;
0132 for (unsigned int i = 1; i < fileSizes.size(); i++) {
0133 fileAddr += fileSizes[i - 1];
0134 dataBlockAddrs_.push_back(fileAddr);
0135 dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
0136 }
0137
0138 dataBlockMax_ = maxSize;
0139 blockCompleted_ = false;
0140
0141 bool result = makeEvents();
0142 assert(result);
0143 eventCached_ = true;
0144 setDataBlockInitialized(true);
0145 }
0146
0147 bool nextEventView() override;
0148 bool checksumValid() override;
0149 std::string getChecksumError() const override;
0150
0151 bool isRealData() const override {
0152 assert(!events_.empty());
0153 return events_[0]->isRealData();
0154 }
0155
0156 uint32_t run() const override {
0157 assert(!events_.empty());
0158 return events_[0]->run();
0159 }
0160
0161 bool dataBlockCompleted() const override { return blockCompleted_; }
0162
0163 bool requireHeader() const override { return true; }
0164
0165 bool fitToBuffer() const override { return true; }
0166
0167 bool dataBlockInitialized() const override { return dataBlockInitialized_; }
0168
0169 void setDataBlockInitialized(bool val) override { dataBlockInitialized_ = val; }
0170
0171 void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {
0172 MINTCDSuTCAFEDID_ = MINTCDSuTCAFEDID;
0173 MAXTCDSuTCAFEDID_ = MAXTCDSuTCAFEDID;
0174 }
0175
0176 void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
0177 std::vector<int> const& numSources,
0178 std::string const& runDir) override;
0179
0180 std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
0181 bool fileListMode) const override;
0182
0183 private:
0184 bool makeEvents();
0185 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
0186 uint16_t detectedFRDversion_ = 0;
0187 size_t fileHeaderSize_ = 0;
0188 size_t headerSize_ = 0;
0189 std::vector<std::unique_ptr<edm::streamer::FRDEventMsgView>> events_;
0190 std::string crcMsg_;
0191 unsigned char* dataBlockAddr_ = nullptr;
0192 std::vector<unsigned char*> dataBlockAddrs_;
0193 std::vector<unsigned char*> dataBlockMaxAddrs_;
0194 size_t dataBlockMax_ = 0;
0195 short numFiles_ = 0;
0196 bool dataBlockInitialized_ = false;
0197 bool blockCompleted_ = true;
0198 bool eventCached_ = false;
0199 uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
0200 uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;
0201 std::vector<std::filesystem::path> buPaths_;
0202 };
0203
0204 #endif