Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:03

0001 #ifndef FWCore_Framework_PrincipalCache_h
0002 #define FWCore_Framework_PrincipalCache_h
0003 
0004 /*
0005 Contains a shared pointer to the RunPrincipal,
0006 LuminosityBlockPrincipal, and EventPrincipal.
0007 Manages merging of run and luminosity block
0008 principals when there is more than one principal
0009 from the same run or luminosity block and having
0010 the same reduced ProcessHistoryID.
0011 
0012 The EventPrincipal is reused each event and is created
0013 by the EventProcessor or SubProcess which contains
0014 an object of this type as a data member.
0015 
0016 The RunPrincipal and LuminosityBlockPrincipal is
0017 created by the InputSource each time a different
0018 run or luminosity block is encountered.
0019 
0020 Performs checks that process history IDs or runs and
0021 lumis, run numbers, and luminosity numbers are consistent.
0022 
0023 Original Author: W. David Dagenhart
0024 */
0025 
0026 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0027 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0028 #include "DataFormats/Provenance/interface/RunID.h"
0029 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0030 
0031 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0032 
0033 #include <memory>
0034 #include <vector>
0035 #include <cassert>
0036 
0037 namespace edm {
0038 
0039   class ProcessBlockPrincipal;
0040   class RunPrincipal;
0041   class LuminosityBlockPrincipal;
0042   class EventPrincipal;
0043   class RunAuxiliary;
0044   class LuminosityBlockAuxiliary;
0045   class ProductRegistry;
0046   class PreallocationConfiguration;
0047 
0048   class PrincipalCache {
0049   public:
0050     PrincipalCache();
0051     ~PrincipalCache();
0052     PrincipalCache(PrincipalCache&&) = default;
0053 
0054     ProcessBlockPrincipal& processBlockPrincipal() const { return *processBlockPrincipal_; }
0055     ProcessBlockPrincipal& inputProcessBlockPrincipal() const { return *inputProcessBlockPrincipal_; }
0056 
0057     enum class ProcessBlockType { New, Input };
0058     ProcessBlockPrincipal& processBlockPrincipal(ProcessBlockType processBlockType) const {
0059       return processBlockType == ProcessBlockType::Input ? *inputProcessBlockPrincipal_ : *processBlockPrincipal_;
0060     }
0061 
0062     RunPrincipal& runPrincipal(ProcessHistoryID const& phid, RunNumber_t run) const;
0063     std::shared_ptr<RunPrincipal> const& runPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run) const;
0064     RunPrincipal& runPrincipal() const;
0065     std::shared_ptr<RunPrincipal> const& runPrincipalPtr() const;
0066     bool hasRunPrincipal() const { return bool(runPrincipal_); }
0067 
0068     std::shared_ptr<LuminosityBlockPrincipal> getAvailableLumiPrincipalPtr();
0069 
0070     EventPrincipal& eventPrincipal(unsigned int iStreamIndex) const { return *(eventPrincipals_[iStreamIndex]); }
0071 
0072     void merge(std::shared_ptr<RunAuxiliary> aux, std::shared_ptr<ProductRegistry const> reg);
0073 
0074     void setNumberOfConcurrentPrincipals(PreallocationConfiguration const&);
0075     void insert(std::unique_ptr<ProcessBlockPrincipal>);
0076     void insertForInput(std::unique_ptr<ProcessBlockPrincipal>);
0077     void insert(std::shared_ptr<RunPrincipal> rp);
0078     void insert(std::unique_ptr<LuminosityBlockPrincipal> lbp);
0079     void insert(std::shared_ptr<EventPrincipal> ep);
0080 
0081     void deleteRun(ProcessHistoryID const& phid, RunNumber_t run);
0082 
0083     void adjustEventsToNewProductRegistry(std::shared_ptr<ProductRegistry const> reg);
0084 
0085     void adjustIndexesAfterProductRegistryAddition();
0086 
0087     void setProcessHistoryRegistry(ProcessHistoryRegistry const& phr) { processHistoryRegistry_ = &phr; }
0088 
0089     void preReadFile();
0090 
0091   private:
0092     void throwRunMissing() const;
0093     void throwLumiMissing() const;
0094 
0095     // These are explicitly cleared when finished with the processblock, run,
0096     // lumi, or event
0097     std::unique_ptr<ProcessBlockPrincipal> processBlockPrincipal_;
0098     std::unique_ptr<ProcessBlockPrincipal> inputProcessBlockPrincipal_;
0099     std::shared_ptr<RunPrincipal> runPrincipal_;
0100     edm::ReusableObjectHolder<LuminosityBlockPrincipal> lumiHolder_;
0101     std::vector<std::shared_ptr<EventPrincipal>> eventPrincipals_;
0102 
0103     // This is just an accessor to the registry owned by the input source.
0104     ProcessHistoryRegistry const* processHistoryRegistry_;  // We don't own this
0105 
0106     // These are intentionally not cleared so that when inserting
0107     // the next principal the conversion from full ProcessHistoryID_
0108     // to reduced ProcessHistoryID_ is still in memory and does
0109     // not need to be recalculated if the ID does not change. I
0110     // expect that very often these ID's will not change from one
0111     // principal to the next and a good amount of CPU can be saved
0112     // by not recalculating.
0113     ProcessHistoryID inputProcessHistoryID_;
0114     ProcessHistoryID reducedInputProcessHistoryID_;
0115     RunNumber_t run_;
0116     LuminosityBlockNumber_t lumi_;
0117   };
0118 }  // namespace edm
0119 
0120 #endif