Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:01

0001 #ifndef SourceModule_H
0002 #define SourceModule_H
0003 
0004 #include <vector>
0005 #include <string>
0006 #include <cinttypes>
0007 #include <fstream>
0008 
0009 #include "FWCore/Sources/interface/ProducerSourceBase.h"
0010 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0011 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0012 #include "DataFormats/Provenance/interface/Timestamp.h"
0013 
0014 class LmfSource : public edm::ProducerSourceBase {
0015 private:
0016   struct IndexRecord {
0017     uint32_t orbit;
0018     uint32_t filePos;
0019     //    bool operator<(const IndexRecord& i) const { return orbit < i.orbit; }
0020   };
0021 
0022 public:
0023   LmfSource(const edm::ParameterSet& pset, const edm::InputSourceDescription& isd);
0024   ~LmfSource() override {}
0025 
0026 private:
0027   /** Called by the framework after setRunAndEventInfo()
0028    */
0029   void produce(edm::Event& e) override;
0030 
0031   /** Callback funtion to set run and event information
0032    * (lumi block, run number, event number, timestamp)
0033    * Called by the framework before produce()
0034    */
0035   bool setRunAndEventInfo(edm::EventID& id,
0036                           edm::TimeValue_t& time,
0037                           edm::EventAuxiliary::ExperimentType& eType) override;
0038 
0039   bool openFile(int iFile);
0040 
0041   bool readFileHeader();
0042 
0043   /** Read event from current opened file. Called by readEvent, which
0044    * deals with file chaining
0045    * Beware: readEventHeader must be called beforehand.
0046    * @param doSkip if true skip event instead of reading it
0047    * @return true iff succeeded
0048    */
0049   bool readEventWithinFile(bool doSkip);
0050 
0051   /** timeval to string conversion
0052    * @param t timestamp
0053    * @return human readable character string
0054    */
0055   std::string toString(edm::TimeValue_t& t) const;
0056 
0057 private:
0058   /** List of names of the input files
0059    */
0060   std::vector<std::string> fileNames_;
0061 
0062   /** Index of the current process file
0063    */
0064   int iFile_;
0065 
0066   /** Buffer for FED block collection
0067    */
0068   FEDRawDataCollection fedColl_;
0069 
0070   /** empty fed block
0071    */
0072   FEDRawData emptyFedBlock_;
0073 
0074   /** FED ID present in FED data collection
0075    * (only one FED at a time)
0076    */
0077   int fedId_;
0078 
0079   /** Buffer for event header readout
0080    */
0081   std::vector<uint32_t> header_;
0082 
0083   static const unsigned fileHeaderSize;
0084 
0085   /** Buffer for file header readout
0086    */
0087   std::vector<uint32_t> fileHeader_;
0088 
0089   /** Minimal LMF data format version supported.
0090    */
0091   static const unsigned char minDataFormatVersion_;
0092 
0093   /** Maximal LMF data format version supported.
0094    */
0095   static const unsigned char maxDataFormatVersion_;
0096 
0097   /** Filtering events. Used for prescale.
0098    * @return true of event accepted, false if rejected
0099    */
0100   bool filter() const;
0101 
0102   /** Reading next event
0103    * @param doSkip if true skip event instead of reading it
0104    * @return true iff read out succeeded
0105    */
0106   bool readEvent(bool doSkip = false);
0107 
0108   /** Move to next event within the same file.
0109    * Called by nextEvent method.
0110    * @return false in case of failure (end of file)
0111    */
0112   bool nextEventWithinFile();
0113 
0114   /** Checks paths specified in fileNames_ and remove eventual
0115    * file: prefix.
0116    * @throw cms::Exception in case of a non valid path
0117    */
0118   void checkFileNames();
0119 
0120   /** Reads event index table from input file. readFileHeader()
0121    * must be called beforehand.
0122    */
0123   void readIndexTable();
0124 
0125   uint64_t timeStamp_;
0126   uint32_t lumiBlock_;
0127   uint32_t runNum_;
0128   uint32_t bx_;
0129   uint32_t eventNum_;
0130   uint32_t orbitNum_;
0131 
0132   unsigned char dataFormatVers_;
0133 
0134   std::ifstream in_;
0135 
0136   /** Flags of last event read success: true->succeeded, false->failed
0137    */
0138   bool rcRead_;
0139 
0140   unsigned preScale_;
0141 
0142   /** Sequential number of event.
0143    */
0144   uint32_t iEvent_;
0145 
0146   /** Sequential number of event reset at each newly opened file
0147    */
0148   uint32_t iEventInFile_;
0149 
0150   uint32_t indexTablePos_;
0151 
0152   int calibTrig_;
0153 
0154   int nFeds_;
0155 
0156   /** Table with file position of each event order by event time
0157    * (orbit id used as time measurement).
0158    */
0159   std::vector<IndexRecord> indexTable_;
0160 
0161   /** Limit of number of events to prevent exhausting memory
0162    * with indexTable_ in case of file corruption.
0163    */
0164   static const unsigned maxEvents_ = 1 << 20;
0165 
0166   /** Limit on event size to prevent exhausting memory
0167    * in case of error in the event size read from file.
0168    */
0169   static const unsigned maxEventSize_ = 1 << 20;  //1MB. (full DCC event is 49kB)
0170 
0171   /** Switch for enabling reading event in ordered using
0172    * event index table
0173    */
0174   bool orderedRead_;
0175 
0176   /** enable reading input file list from text file
0177    *  and keep watching the text file for updates
0178    */
0179   bool watchFileList_;
0180 
0181   /** name of the textfile with the input file list
0182    */
0183   std::string fileListName_;
0184 
0185   /** absolute path from which filename in fileListName_ is valid
0186    */
0187   std::string inputDir_;
0188 
0189   /** currently open file
0190    */
0191   std::string currentFileName_;
0192 
0193   std::ifstream fileList_;
0194 
0195   /** seconds to sleep before checking fileList_ for updates
0196    */
0197   int nSecondsToSleep_;
0198 
0199   /** Debugging level
0200    */
0201   int verbosity_;
0202 };
0203 #endif  //SourceModule_H not defined