CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PrincipalCache.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_PrincipalCache_h
2 #define FWCore_Framework_PrincipalCache_h
3 
4 /*
5 Contains a shared pointer to the RunPrincipal,
6 LuminosityBlockPrincipal, and EventPrincipal.
7 Manages merging of run and luminosity block
8 principals when there is more than one principal
9 from the same run or luminosity block and having
10 the same reduced ProcessHistoryID.
11 
12 The EventPrincipal is reused each event and is created
13 by the EventProcessor or SubProcess which contains
14 an object of this type as a data member.
15 
16 The RunPrincipal and LuminosityBlockPrincipal is
17 created by the InputSource each time a different
18 run or luminosity block is encountered.
19 
20 Performs checks that process history IDs or runs and
21 lumis, run numbers, and luminosity numbers are consistent.
22 
23 Original Author: W. David Dagenhart
24 */
25 
30 
32 
33 #include <memory>
34 #include <vector>
35 #include <cassert>
36 
37 namespace edm {
38 
39  class ProcessBlockPrincipal;
40  class RunPrincipal;
41  class LuminosityBlockPrincipal;
42  class EventPrincipal;
43  class RunAuxiliary;
44  class LuminosityBlockAuxiliary;
45  class ProductRegistry;
46  class PreallocationConfiguration;
47 
49  public:
52  PrincipalCache(PrincipalCache&&) = default;
53 
56 
57  enum class ProcessBlockType { New, Input };
60  }
61 
63  std::shared_ptr<RunPrincipal> const& runPrincipalPtr(ProcessHistoryID const& phid, RunNumber_t run) const;
64  RunPrincipal& runPrincipal() const;
65  std::shared_ptr<RunPrincipal> const& runPrincipalPtr() const;
66  bool hasRunPrincipal() const { return bool(runPrincipal_); }
67 
68  std::shared_ptr<LuminosityBlockPrincipal> getAvailableLumiPrincipalPtr();
69 
70  EventPrincipal& eventPrincipal(unsigned int iStreamIndex) const { return *(eventPrincipals_[iStreamIndex]); }
71 
72  void merge(std::shared_ptr<RunAuxiliary> aux, std::shared_ptr<ProductRegistry const> reg);
73 
75  void insert(std::unique_ptr<ProcessBlockPrincipal>);
76  void insertForInput(std::unique_ptr<ProcessBlockPrincipal>);
77  void insert(std::shared_ptr<RunPrincipal> rp);
78  void insert(std::unique_ptr<LuminosityBlockPrincipal> lbp);
79  void insert(std::shared_ptr<EventPrincipal> ep);
80 
81  void deleteRun(ProcessHistoryID const& phid, RunNumber_t run);
82 
83  void adjustEventsToNewProductRegistry(std::shared_ptr<ProductRegistry const> reg);
84 
86 
88 
89  void preReadFile();
90 
91  private:
92  void throwRunMissing() const;
93  void throwLumiMissing() const;
94 
95  // These are explicitly cleared when finished with the processblock, run,
96  // lumi, or event
97  std::unique_ptr<ProcessBlockPrincipal> processBlockPrincipal_;
98  std::unique_ptr<ProcessBlockPrincipal> inputProcessBlockPrincipal_;
99  std::shared_ptr<RunPrincipal> runPrincipal_;
101  std::vector<std::shared_ptr<EventPrincipal>> eventPrincipals_;
102 
103  // This is just an accessor to the registry owned by the input source.
104  ProcessHistoryRegistry const* processHistoryRegistry_; // We don't own this
105 
106  // These are intentionally not cleared so that when inserting
107  // the next principal the conversion from full ProcessHistoryID_
108  // to reduced ProcessHistoryID_ is still in memory and does
109  // not need to be recalculated if the ID does not change. I
110  // expect that very often these ID's will not change from one
111  // principal to the next and a good amount of CPU can be saved
112  // by not recalculating.
117  };
118 } // namespace edm
119 
120 #endif
void throwRunMissing() const
std::unique_ptr< ProcessBlockPrincipal > processBlockPrincipal_
void setNumberOfConcurrentPrincipals(PreallocationConfiguration const &)
std::shared_ptr< RunPrincipal > const & runPrincipalPtr() const
void throwLumiMissing() const
bool hasRunPrincipal() const
LuminosityBlockNumber_t lumi_
void adjustIndexesAfterProductRegistryAddition()
ProcessBlockPrincipal & processBlockPrincipal(ProcessBlockType processBlockType) const
unsigned int LuminosityBlockNumber_t
std::unique_ptr< ProcessBlockPrincipal > inputProcessBlockPrincipal_
ProcessBlockPrincipal & inputProcessBlockPrincipal() const
RunPrincipal & runPrincipal() const
edm::ReusableObjectHolder< LuminosityBlockPrincipal > lumiHolder_
std::vector< std::shared_ptr< EventPrincipal > > eventPrincipals_
ProcessHistoryID reducedInputProcessHistoryID_
ProcessBlockPrincipal & processBlockPrincipal() const
void insert(std::unique_ptr< ProcessBlockPrincipal >)
void adjustEventsToNewProductRegistry(std::shared_ptr< ProductRegistry const > reg)
EventPrincipal & eventPrincipal(unsigned int iStreamIndex) const
void setProcessHistoryRegistry(ProcessHistoryRegistry const &phr)
void deleteRun(ProcessHistoryID const &phid, RunNumber_t run)
void insertForInput(std::unique_ptr< ProcessBlockPrincipal >)
ProcessHistoryID inputProcessHistoryID_
std::shared_ptr< LuminosityBlockPrincipal > getAvailableLumiPrincipalPtr()
unsigned int RunNumber_t
ProcessHistoryRegistry const * processHistoryRegistry_
std::shared_ptr< RunPrincipal > runPrincipal_
void merge(std::shared_ptr< RunAuxiliary > aux, std::shared_ptr< ProductRegistry const > reg)