Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:17

0001 #ifndef EventFilter_Utilities_DAQSourceModelsScoutingRun3_h
0002 #define EventFilter_Utilities_DAQSourceModelsScoutingRun3_h
0003 
0004 #include "EventFilter/Utilities/interface/DAQSource.h"
0005 #include "EventFilter/Utilities/interface/DAQSourceModels.h"
0006 #include "DataFormats/L1ScoutingRawData/interface/SDSRawDataCollection.h"
0007 #include "DataFormats/L1ScoutingRawData/interface/SDSNumbering.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0011 #include "DataFormats/Provenance/interface/EventID.h"
0012 
0013 #include <sys/types.h>
0014 #include <filesystem>
0015 #include <sstream>
0016 #include <iostream>
0017 #include <memory>
0018 #include <vector>
0019 
0020 class DataModeScoutingRun3 : public DataMode {
0021 public:
0022   DataModeScoutingRun3(DAQSource* daqSource) : DataMode(daqSource) {}
0023   ~DataModeScoutingRun3() override {}
0024   std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& makeDaqProvenanceHelpers() override;
0025   void readEvent(edm::EventPrincipal& eventPrincipal) override;
0026 
0027   void fillSDSRawDataCollection(SDSRawDataCollection& rawData, char* buff, size_t len);
0028 
0029   //reuse FRD file and event headers
0030   int dataVersion() const override { return detectedFRDversion_; }
0031   void detectVersion(unsigned char* fileBuf, uint32_t fileHeaderOffset) override {
0032     detectedFRDversion_ = *((uint16_t*)(fileBuf + fileHeaderOffset));
0033   }
0034   uint32_t headerSize() const override { return edm::streamer::FRDHeaderVersionSize[detectedFRDversion_]; }
0035   bool versionCheck() const override { return detectedFRDversion_ <= edm::streamer::FRDHeaderMaxVersion; }
0036 
0037   uint64_t dataBlockSize() const override {
0038     // get event size from the first data source (main)
0039     return events_[0]->size();
0040   }
0041 
0042   void makeDataBlockView(unsigned char* addr,
0043                          size_t maxSize,
0044                          std::vector<uint64_t> const& fileSizes,
0045                          size_t fileHeaderSize) override {
0046     fileHeaderSize_ = fileHeaderSize;
0047     numFiles_ = fileSizes.size();
0048 
0049     // initalize vectors keeping tracks of valid orbits and completed blocks
0050     sourceValidOrbitPair_.clear();
0051     completedBlocks_.clear();
0052     for (unsigned int i = 0; i < fileSizes.size(); i++) {
0053       completedBlocks_.push_back(false);
0054     }
0055 
0056     //add offset address for each file payload
0057     dataBlockAddrs_.clear();
0058     dataBlockAddrs_.push_back(addr);
0059     dataBlockMaxAddrs_.clear();
0060     dataBlockMaxAddrs_.push_back(addr + fileSizes[0] - fileHeaderSize);
0061     auto fileAddr = addr;
0062     for (unsigned int i = 1; i < fileSizes.size(); i++) {
0063       fileAddr += fileSizes[i - 1];
0064       dataBlockAddrs_.push_back(fileAddr);
0065       dataBlockMaxAddrs_.push_back(fileAddr + fileSizes[i] - fileHeaderSize);
0066     }
0067 
0068     dataBlockMax_ = maxSize;
0069     blockCompleted_ = false;
0070     //set event cached as we set initial address here
0071     bool result = makeEvents();
0072     assert(result);
0073     eventCached_ = true;
0074     setDataBlockInitialized(true);
0075   }
0076 
0077   bool nextEventView() override;
0078   bool checksumValid() override;
0079   std::string getChecksumError() const override;
0080 
0081   bool isRealData() const override {
0082     assert(!events_.empty());
0083     return events_[0]->isRealData();
0084   }
0085 
0086   uint32_t run() const override {
0087     assert(!events_.empty());
0088     return events_[0]->run();
0089   }
0090 
0091   bool dataBlockCompleted() const override { return blockCompleted_; }
0092 
0093   bool requireHeader() const override { return true; }
0094 
0095   bool fitToBuffer() const override { return true; }
0096 
0097   bool dataBlockInitialized() const override { return dataBlockInitialized_; }
0098 
0099   void setDataBlockInitialized(bool val) override { dataBlockInitialized_ = val; };
0100 
0101   void setTCDSSearchRange(uint16_t MINTCDSuTCAFEDID, uint16_t MAXTCDSuTCAFEDID) override { return; }
0102 
0103   void makeDirectoryEntries(std::vector<std::string> const& baseDirs,
0104                             std::vector<int> const& numSources,
0105                             std::string const& runDir) override;
0106 
0107   std::pair<bool, std::vector<std::string>> defineAdditionalFiles(std::string const& primaryName,
0108                                                                   bool fileListMode) const override;
0109 
0110 private:
0111   bool makeEvents();
0112   std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>> daqProvenanceHelpers_;  //
0113   uint16_t detectedFRDversion_ = 0;
0114   size_t fileHeaderSize_ = 0;
0115   size_t headerSize_ = 0;
0116   std::vector<std::unique_ptr<edm::streamer::FRDEventMsgView>> events_;
0117   unsigned char* dataBlockAddr_ = nullptr;
0118   std::vector<unsigned char*> dataBlockAddrs_;
0119   std::vector<unsigned char*> dataBlockMaxAddrs_;
0120   size_t dataBlockMax_ = 0;
0121   short numFiles_ = 0;
0122   bool dataBlockInitialized_ = false;
0123   bool blockCompleted_ = true;
0124   bool eventCached_ = false;
0125   std::vector<std::filesystem::path> buPaths_;
0126   std::vector<int> buNumSources_;
0127 
0128   // keep track of valid (=aligned) orbits from different data sources
0129   std::vector<std::pair<int, int>> sourceValidOrbitPair_;
0130   unsigned int currOrbit_ = 0xFFFFFFFF;
0131 
0132   std::vector<bool> completedBlocks_;
0133 };
0134 
0135 #endif  // EventFilter_Utilities_DAQSourceModelsScoutingRun3_h