Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:19:21

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