Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:11:38

0001 #ifndef Framework_Sources_IDGeneratorSourceBase_h
0002 #define Framework_Sources_IDGeneratorSourceBase_h
0003 
0004 /*----------------------------------------------------------------------
0005 ----------------------------------------------------------------------*/
0006 
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/EventPrincipal.h"
0009 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0010 #include "DataFormats/Provenance/interface/EventID.h"
0011 #include "DataFormats/Provenance/interface/Timestamp.h"
0012 #include "DataFormats/Provenance/interface/RunID.h"
0013 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0014 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0015 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0016 
0017 #include <memory>
0018 #include <vector>
0019 
0020 namespace edm {
0021   class ParameterSet;
0022   class ParameterSetDescription;
0023   template <typename BASE>
0024   class IDGeneratorSourceBase : public BASE {
0025   public:
0026     explicit IDGeneratorSourceBase(ParameterSet const& pset, InputSourceDescription const& desc, bool realData);
0027     ~IDGeneratorSourceBase() noexcept(false) override;
0028 
0029     unsigned int numberEventsInRun() const { return numberEventsInRun_; }
0030     unsigned int numberEventsInLumi() const { return numberEventsInLumi_; }
0031     TimeValue_t presentTime() const { return presentTime_; }
0032     unsigned int timeBetweenEvents() const { return timeBetweenEvents_; }
0033     unsigned int eventCreationDelay() const { return eventCreationDelay_; }
0034     unsigned int numberEventsInThisRun() const { return numberEventsInThisRun_; }
0035     unsigned int numberEventsInThisLumi() const { return numberEventsInThisLumi_; }
0036     EventID const& eventID() const { return eventID_; }
0037     RunNumber_t run() const { return eventID_.run(); }
0038     EventNumber_t event() const { return eventID_.event(); }
0039     LuminosityBlockNumber_t luminosityBlock() const { return eventID_.luminosityBlock(); }
0040 
0041     static void fillDescription(ParameterSetDescription& desc);
0042 
0043   protected:
0044     template <typename F>
0045     void doReadEvent(EventPrincipal& eventPrincipal, F&& f) {
0046       assert(BASE::eventCached() || BASE::processingMode() != BASE::RunsLumisAndEvents);
0047       EventAuxiliary aux(eventID_, BASE::processGUID(), Timestamp(presentTime_), isRealData_, eType_);
0048       auto history = BASE::processHistoryRegistry().getMapped(aux.processHistoryID());
0049       eventPrincipal.fillEventPrincipal(aux, history);
0050       f(eventPrincipal);
0051       BASE::resetEventCached();
0052     }
0053 
0054     void doReadEventWithDelayedReader(EventPrincipal& eventPrincipal,
0055                                       ProcessHistoryID const& historyID,
0056                                       EventSelectionIDVector eventSelectionIDs,
0057                                       BranchListIndexes branchListIndexes,
0058                                       DelayedReader* reader) {
0059       assert(BASE::eventCached() || BASE::processingMode() != BASE::RunsLumisAndEvents);
0060       EventAuxiliary aux(eventID_, BASE::processGUID(), Timestamp(presentTime_), isRealData_, eType_);
0061       aux.setProcessHistoryID(historyID);
0062       auto history = BASE::processHistoryRegistry().getMapped(aux.processHistoryID());
0063       eventPrincipal.fillEventPrincipal(
0064           aux, history, std::move(eventSelectionIDs), std::move(branchListIndexes), reader);
0065       BASE::resetEventCached();
0066     }
0067 
0068   private:
0069     typename BASE::ItemType getNextItemType() final;
0070     virtual void initialize(EventID& id, TimeValue_t& time, TimeValue_t& interval);
0071     virtual bool setRunAndEventInfo(EventID& id, TimeValue_t& time, EventAuxiliary::ExperimentType& etype) = 0;
0072     virtual bool noFiles() const;
0073     virtual size_t fileIndex() const;
0074     void beginJob() override;
0075 
0076     std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() override;
0077     std::shared_ptr<RunAuxiliary> readRunAuxiliary_() override;
0078     void skip(int offset) override;
0079     void rewind_() override;
0080 
0081     void advanceToNext(EventID& eventID, TimeValue_t& time);
0082     void retreatToPrevious(EventID& eventID, TimeValue_t& time);
0083     RunNumber_t runForLumi(LuminosityBlockNumber_t) const;
0084 
0085     std::vector<edm::LuminosityBlockID> firstLumiForRuns_;
0086     unsigned int numberEventsInRun_;
0087     unsigned int numberEventsInLumi_;
0088     TimeValue_t presentTime_;
0089     TimeValue_t origTime_;
0090     TimeValue_t timeBetweenEvents_;
0091     unsigned int eventCreationDelay_; /* microseconds */
0092 
0093     unsigned int numberEventsInThisRun_;
0094     unsigned int numberEventsInThisLumi_;
0095     EventNumber_t const zerothEvent_;
0096     EventID eventID_;
0097     EventID origEventID_;
0098     bool isRealData_;
0099     EventAuxiliary::ExperimentType eType_;
0100   };
0101 }  // namespace edm
0102 #endif