Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:02

0001 #ifndef FWCore_Framework_EventPrincipal_h
0002 #define FWCore_Framework_EventPrincipal_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 EventPrincipal: This is the class responsible for management of
0007 per event EDProducts. It is not seen by reconstruction code;
0008 such code sees the Event class, which is a proxy for EventPrincipal.
0009 
0010 The major internal component of the EventPrincipal
0011 is the DataBlock.
0012 
0013 ----------------------------------------------------------------------*/
0014 
0015 #include "DataFormats/Common/interface/WrapperBase.h"
0016 #include "DataFormats/Provenance/interface/BranchListIndex.h"
0017 #include "FWCore/Framework/interface/ProductProvenanceRetriever.h"
0018 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0019 #include "DataFormats/Provenance/interface/EventSelectionID.h"
0020 #include "DataFormats/Provenance/interface/EventToProcessBlockIndexes.h"
0021 #include "FWCore/Common/interface/FWCoreCommonFwd.h"
0022 #include "FWCore/Utilities/interface/StreamID.h"
0023 #include "FWCore/Utilities/interface/Signal.h"
0024 #include "FWCore/Utilities/interface/get_underlying_safe.h"
0025 #include "FWCore/Framework/interface/Principal.h"
0026 
0027 #include <map>
0028 #include <memory>
0029 #include <string>
0030 #include <vector>
0031 #include <optional>
0032 
0033 namespace edm {
0034   class BranchID;
0035   class BranchIDListHelper;
0036   class ProductProvenanceRetriever;
0037   class DelayedReader;
0038   class EventID;
0039   class HistoryAppender;
0040   class LuminosityBlockPrincipal;
0041   class ModuleCallingContext;
0042   class ProductID;
0043   class StreamContext;
0044   class ThinnedAssociation;
0045   class ThinnedAssociationsHelper;
0046   class RunPrincipal;
0047 
0048   class EventPrincipal : public Principal {
0049   public:
0050     typedef EventAuxiliary Auxiliary;
0051     typedef Principal Base;
0052 
0053     typedef Base::ConstProductResolverPtr ConstProductResolverPtr;
0054     static int const invalidBunchXing = EventAuxiliary::invalidBunchXing;
0055     static int const invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
0056     EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
0057                    std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
0058                    std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
0059                    ProcessConfiguration const& pc,
0060                    HistoryAppender* historyAppender,
0061                    unsigned int streamIndex = 0,
0062                    bool isForPrimaryProcess = true,
0063                    ProcessBlockHelperBase const* processBlockHelper = nullptr);
0064     ~EventPrincipal() override {}
0065 
0066     void fillEventPrincipal(EventAuxiliary const& aux,
0067                             ProcessHistory const* processHistory,
0068                             DelayedReader* reader = nullptr);
0069     void fillEventPrincipal(EventAuxiliary const& aux,
0070                             ProcessHistory const* processHistory,
0071                             EventSelectionIDVector eventSelectionIDs,
0072                             BranchListIndexes branchListIndexes,
0073                             DelayedReader* reader = nullptr);
0074     //provRetriever is changed via a call to ProductProvenanceRetriever::deepSwap
0075     void fillEventPrincipal(EventAuxiliary const& aux,
0076                             ProcessHistory const* processHistory,
0077                             EventSelectionIDVector eventSelectionIDs,
0078                             BranchListIndexes branchListIndexes,
0079                             EventToProcessBlockIndexes const&,
0080                             ProductProvenanceRetriever const& provRetriever,
0081                             DelayedReader* reader = nullptr,
0082                             bool deepCopyRetriever = true);
0083 
0084     void clearEventPrincipal();
0085 
0086     LuminosityBlockPrincipal const& luminosityBlockPrincipal() const { return *luminosityBlockPrincipal_; }
0087 
0088     LuminosityBlockPrincipal& luminosityBlockPrincipal() { return *luminosityBlockPrincipal_; }
0089 
0090     bool luminosityBlockPrincipalPtrValid() const { return luminosityBlockPrincipal_ != nullptr; }
0091 
0092     //does not share ownership
0093     void setLuminosityBlockPrincipal(LuminosityBlockPrincipal* lbp);
0094 
0095     void setRunAndLumiNumber(RunNumber_t run, LuminosityBlockNumber_t lumi);
0096 
0097     EventID const& id() const { return aux().id(); }
0098 
0099     Timestamp const& time() const { return aux().time(); }
0100 
0101     bool isReal() const { return aux().isRealData(); }
0102 
0103     EventAuxiliary::ExperimentType ExperimentType() const { return aux().experimentType(); }
0104 
0105     int bunchCrossing() const { return aux().bunchCrossing(); }
0106 
0107     int storeNumber() const { return aux().storeNumber(); }
0108 
0109     EventAuxiliary const& aux() const { return aux_; }
0110 
0111     StreamID streamID() const { return streamID_; }
0112 
0113     LuminosityBlockNumber_t luminosityBlock() const { return id().luminosityBlock(); }
0114 
0115     RunNumber_t run() const { return id().run(); }
0116 
0117     RunPrincipal const& runPrincipal() const;
0118 
0119     ProductProvenanceRetriever const* productProvenanceRetrieverPtr() const { return provRetrieverPtr_.get(); }
0120 
0121     EventSelectionIDVector const& eventSelectionIDs() const;
0122 
0123     BranchListIndexes const& branchListIndexes() const;
0124 
0125     EventToProcessBlockIndexes const& eventToProcessBlockIndexes() const;
0126 
0127     Provenance const& getProvenance(ProductID const& pid) const;
0128     StableProvenance const& getStableProvenance(ProductID const& pid) const;
0129 
0130     BasicHandle getByProductID(ProductID const& oid) const;
0131 
0132     void put(BranchDescription const& bd,
0133              std::unique_ptr<WrapperBase> edp,
0134              ProductProvenance const& productProvenance) const;
0135 
0136     void put(ProductResolverIndex index, std::unique_ptr<WrapperBase> edp, ParentageID productProvenance) const;
0137 
0138     void putOnRead(BranchDescription const& bd,
0139                    std::unique_ptr<WrapperBase> edp,
0140                    std::optional<ProductProvenance> productProvenance) const;
0141 
0142     WrapperBase const* getIt(ProductID const& pid) const override;
0143     std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const& pid,
0144                                                                                   unsigned int key) const override;
0145     void getThinnedProducts(ProductID const& pid,
0146                             std::vector<WrapperBase const*>& foundContainers,
0147                             std::vector<unsigned int>& keys) const override;
0148     OptionalThinnedKey getThinnedKeyFrom(ProductID const& parent,
0149                                          unsigned int key,
0150                                          ProductID const& thinned) const override;
0151 
0152     ProductID branchIDToProductID(BranchID const& bid) const;
0153 
0154     void mergeProvenanceRetrievers(EventPrincipal& other) {
0155       provRetrieverPtr_->mergeProvenanceRetrievers(other.provRetrieverPtr());
0156     }
0157 
0158     using Base::getProvenance;
0159     using Base::getStableProvenance;
0160 
0161     unsigned int processBlockIndex(std::string const& processName) const override;
0162 
0163   private:
0164     BranchID pidToBid(ProductID const& pid) const;
0165 
0166     edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID) const;
0167 
0168     unsigned int transitionIndex_() const override;
0169     void changedIndexes_() final;
0170 
0171     std::shared_ptr<ProductProvenanceRetriever const> provRetrieverPtr() const {
0172       return get_underlying_safe(provRetrieverPtr_);
0173     }
0174     std::shared_ptr<ProductProvenanceRetriever>& provRetrieverPtr() { return get_underlying_safe(provRetrieverPtr_); }
0175 
0176     bool wasBranchListIndexesChangedFromInput(BranchListIndexes const&) const;
0177     void updateBranchListIndexes(BranchListIndexes&&);
0178     void commonFillEventPrincipal(EventAuxiliary const& aux,
0179                                   ProcessHistory const* processHistory,
0180                                   DelayedReader* reader);
0181 
0182   private:
0183     EventAuxiliary aux_;
0184 
0185     edm::propagate_const<LuminosityBlockPrincipal*> luminosityBlockPrincipal_;
0186 
0187     // Pointer to the 'retriever' that will get provenance information from the persistent store.
0188     edm::propagate_const<std::shared_ptr<ProductProvenanceRetriever>> provRetrieverPtr_;
0189 
0190     EventSelectionIDVector eventSelectionIDs_;
0191 
0192     std::shared_ptr<BranchIDListHelper const> branchIDListHelper_;
0193     ProcessBlockHelperBase const* processBlockHelper_;
0194     std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper_;
0195 
0196     BranchListIndexes branchListIndexes_;
0197 
0198     EventToProcessBlockIndexes eventToProcessBlockIndexes_;
0199 
0200     std::vector<ProcessIndex> branchListIndexToProcessIndex_;
0201 
0202     StreamID streamID_;
0203   };
0204 
0205   inline bool isSameEvent(EventPrincipal const& a, EventPrincipal const& b) { return isSameEvent(a.aux(), b.aux()); }
0206 }  // namespace edm
0207 #endif