Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-28 06:19:07

0001 #ifndef EventFilter_Utilities_DAQSourceModelsDTH_h
0002 #define EventFilter_Utilities_DAQSourceModelsDTH_h
0003 
0004 /*
0005  * DAQ Source module for DTH readout
0006  * Used by modular DAQSource to read files containing raw DTH orbit payload.
0007  * Orbits are unpacked into individual events which are queued to the framework as FedRawDataCollection object.
0008  * If more than one sourceID blocks is included they will all be unpacked, they need to be adjacent in the file
0009  * for the same orbit. Exception to this is reading from multiple file sources,
0010  * in that case that is only required locally in a file, but orbits need to come in the same order in all files.
0011  * See test/RunBUFU.sh and test/testDTH.sh for example how to run with this module
0012  * Also see documentation in doc/README=DTH.md
0013 */
0014 
0015 #include <filesystem>
0016 #include <queue>
0017 #include <regex>
0018 
0019 #include "EventFilter/Utilities/interface/DAQSourceModels.h"
0020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0021 #include "DataFormats/FEDRawData/interface/RawDataBuffer.h"
0022 #include "EventFilter/Utilities/interface/DTHHeaders.h"
0023 
0024 //class FEDRawDataCollection;
0025 
0026 class DataModeDTH : public DataMode {
0027 public:
0028   DataModeDTH(DAQSource* daqSource, bool verifyChecksum, bool legacyFRDCollection)
0029       : DataMode(daqSource), verifyChecksum_(verifyChecksum), legacyFRDCollection_(legacyFRDCollection) {}
0030   ~DataModeDTH() override {}
0031   std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
0032   void readEvent(edm::EventPrincipal& eventPrincipal) override;
0033 
0034   //non-virtual
0035   edm::Timestamp fillFEDRawDataCollection(FEDRawDataCollection& rawData);
0036   edm::Timestamp fillFEDRawData(RawDataBuffer& rawData);
0037 
0038   int dataVersion() const override { return detectedDTHversion_; }
0039   void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
0040     detectedDTHversion_ = 1;  //TODO: read version
0041   }
0042 
0043   uint32_t headerSize() const override { return sizeof(evf::DTHOrbitHeader_v1); }
0044 
0045   bool versionCheck() const override { return detectedDTHversion_ == 1; }
0046 
0047   uint64_t dataBlockSize() const override { return dataBlockSize_; }
0048 
0049   void makeDataBlockView(unsigned char* addr, RawInputFile* rawFile) override;
0050 
0051   bool nextEventView(RawInputFile*) override;
0052   bool blockChecksumValid() override { return checksumValid_; }
0053   bool checksumValid() override { return checksumValid_; }
0054   std::string getChecksumError() const override { return checksumError_; }
0055 
0056   bool isRealData() const { return true; }  //this flag could be added to RU/BU-generated index
0057 
0058   uint32_t run() const override { return firstOrbitHeader_->runNumber(); }
0059 
0060   bool dataBlockCompleted() const override { return blockCompleted_; }
0061 
0062   bool requireHeader() const override { return false; }
0063 
0064   bool fitToBuffer() const override { return true; }
0065 
0066   bool isMultiDir() const override { return true; }
0067 
0068   void unpackFile(RawInputFile*) override {}
0069 
0070   bool dataBlockInitialized() const override { return dataBlockInitialized_; }
0071 
0072   void setDataBlockInitialized(bool val) override { dataBlockInitialized_ = val; }
0073 
0074   void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override {}
0075 
0076   void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
0077                             std::vector<int> const& numSources,
0078                             std::vector<int> const& sourceIDs,
0079                             std::string const& sourceIdentifier,
0080                             std::string const& runDir) override;
0081 
0082   std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
0083                                                                   bool fileListMode) const override;
0084 
0085   bool hasEventCounterCallback() const override { return true; }
0086   int eventCounterCallback(std::string const& name, int& fd, int64_t& fsize, uint32_t sLS, bool& found) const override;
0087 
0088 private:
0089   bool verifyChecksum_;
0090   bool legacyFRDCollection_;
0091   std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;
0092   std::vector<std::filesystem::path> buPaths_;
0093   std::vector<int> buNumSources_;
0094   std::vector<std::string> buSourceStrings_;
0095   std::regex sid_pattern_;
0096   uint16_t detectedDTHversion_ = 0;
0097   evf::DTHOrbitHeader_v1* firstOrbitHeader_ = nullptr;
0098   uint64_t nextEventID_ = 0;
0099   std::vector<evf::DTHFragmentTrailer_v1*> eventFragments_;  //events in block (DTH trailer)
0100   uint32_t totalEventSize_ = 0;
0101   //numFiles_ = 0;
0102   bool dataBlockInitialized_ = false;
0103   bool blockCompleted_ = true;
0104 
0105   std::vector<uint8_t*> addrsStart_;  //start of orbit payloads per source
0106   std::vector<uint8_t*> addrsEnd_;    //dth trailers per source (go through events from the end)
0107 
0108   bool checksumValid_ = false;
0109   std::string checksumError_;
0110   //total
0111   size_t dataBlockSize_ = 0;
0112   bool eventCached_ = false;
0113 };
0114 
0115 #endif  // EventFilter_Utilities_DAQSourceModelsDTH_h