CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PrincipalCache.cc
Go to the documentation of this file.
2 
10 
11 namespace edm {
12 
13  PrincipalCache::PrincipalCache() : run_(0U), lumi_(0U) {}
14 
16 
18  eventPrincipals_.resize(iConfig.numberOfStreams());
19  }
20 
22  if (phid != reducedInputProcessHistoryID_ || run != run_ || runPrincipal_.get() == nullptr) {
24  }
25  return *runPrincipal_.get();
26  }
27 
28  std::shared_ptr<RunPrincipal> const& PrincipalCache::runPrincipalPtr(ProcessHistoryID const& phid,
29  RunNumber_t run) const {
30  if (phid != reducedInputProcessHistoryID_ || run != run_ || runPrincipal_.get() == nullptr) {
32  }
33  return runPrincipal_;
34  }
35 
37  if (runPrincipal_.get() == nullptr) {
39  }
40  return *runPrincipal_.get();
41  }
42 
43  std::shared_ptr<RunPrincipal> const& PrincipalCache::runPrincipalPtr() const {
44  if (runPrincipal_.get() == nullptr) {
46  }
47  return runPrincipal_;
48  }
49 
50  std::shared_ptr<LuminosityBlockPrincipal> PrincipalCache::getAvailableLumiPrincipalPtr() {
51  return lumiHolder_.tryToGet();
52  }
53 
54  void PrincipalCache::merge(std::shared_ptr<RunAuxiliary> aux, std::shared_ptr<ProductRegistry const> reg) {
55  if (runPrincipal_.get() == nullptr) {
56  throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::merge\n"
57  << "Illegal attempt to merge run into cache\n"
58  << "There is no run in cache to merge with\n"
59  << "Contact a Framework Developer\n";
60  }
61  if (inputProcessHistoryID_ != aux->processHistoryID()) {
64  << "PrincipalCache::merge\n"
65  << "Illegal attempt to merge run into cache\n"
66  << "Reduced ProcessHistoryID inconsistent with the one already in cache\n"
67  << "Contact a Framework Developer\n";
68  }
69  inputProcessHistoryID_ = aux->processHistoryID();
70  }
71  if (aux->run() != run_) {
72  throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::merge\n"
73  << "Illegal attempt to merge run into cache\n"
74  << "Run number inconsistent with run number already in cache\n"
75  << "Contact a Framework Developer\n";
76  }
77  bool runOK = runPrincipal_->adjustToNewProductRegistry(*reg);
78  assert(runOK);
79  runPrincipal_->mergeAuxiliary(*aux);
80  }
81 
82  void PrincipalCache::insert(std::shared_ptr<RunPrincipal> rp) {
83  if (runPrincipal_.get() != nullptr) {
84  throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::insert\n"
85  << "Illegal attempt to insert run into cache\n"
86  << "Contact a Framework Developer\n";
87  }
88  if (inputProcessHistoryID_ != rp->aux().processHistoryID()) {
90  inputProcessHistoryID_ = rp->aux().processHistoryID();
91  }
92  run_ = rp->run();
93  runPrincipal_ = rp;
94  }
95 
96  void PrincipalCache::insert(std::unique_ptr<ProcessBlockPrincipal> pb) { processBlockPrincipal_ = std::move(pb); }
97 
98  void PrincipalCache::insertForInput(std::unique_ptr<ProcessBlockPrincipal> pb) {
100  }
101 
102  void PrincipalCache::insert(std::unique_ptr<LuminosityBlockPrincipal> lbp) { lumiHolder_.add(std::move(lbp)); }
103 
104  void PrincipalCache::insert(std::shared_ptr<EventPrincipal> ep) {
105  unsigned int iStreamIndex = ep->streamID().value();
106  assert(iStreamIndex < eventPrincipals_.size());
107  eventPrincipals_[iStreamIndex] = ep;
108  }
109 
111  if (runPrincipal_.get() == nullptr) {
112  throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::deleteRun\n"
113  << "Illegal attempt to delete run from cache\n"
114  << "There is no run in cache to delete\n"
115  << "Contact a Framework Developer\n";
116  }
117  if (reducedInputProcessHistoryID_ != phid || run != run_) {
119  << "PrincipalCache::deleteRun\n"
120  << "Illegal attempt to delete run from cache\n"
121  << "Run number or reduced ProcessHistoryID inconsistent with those in cache\n"
122  << "Contact a Framework Developer\n";
123  }
124  runPrincipal_.reset();
125  }
126 
127  void PrincipalCache::adjustEventsToNewProductRegistry(std::shared_ptr<ProductRegistry const> reg) {
128  for (auto& eventPrincipal : eventPrincipals_) {
129  if (eventPrincipal) {
131  bool eventOK = eventPrincipal->adjustToNewProductRegistry(*reg);
132  assert(eventOK);
133  }
134  }
135  }
136 
138  if (runPrincipal_) {
139  runPrincipal_->adjustIndexesAfterProductRegistryAddition();
140  }
141  //Need to temporarily hold all the lumis to clear out the lumiHolder_
142  std::vector<std::shared_ptr<LuminosityBlockPrincipal>> temp;
143  while (auto p = lumiHolder_.tryToGet()) {
144  p->adjustIndexesAfterProductRegistryAddition();
145  temp.emplace_back(std::move(p));
146  }
147  }
148 
150  if (runPrincipal_) {
151  runPrincipal_->preReadFile();
152  }
153  }
154 
156  throw edm::Exception(edm::errors::LogicError) << "PrincipalCache::runPrincipal\n"
157  << "Requested a run that is not in the cache (should never happen)\n"
158  << "Contact a Framework Developer\n";
159  }
160 
163  << "PrincipalCache::lumiPrincipal or PrincipalCache::lumiPrincipalPtr\n"
164  << "Requested a luminosity block that is not in the cache (should never happen)\n"
165  << "Contact a Framework Developer\n";
166  }
167 } // namespace edm
void throwRunMissing() const
std::unique_ptr< ProcessBlockPrincipal > processBlockPrincipal_
void setNumberOfConcurrentPrincipals(PreallocationConfiguration const &)
std::shared_ptr< RunPrincipal > const & runPrincipalPtr() const
void throwLumiMissing() const
void adjustIndexesAfterProductRegistryAddition()
assert(be >=bs)
std::unique_ptr< ProcessBlockPrincipal > inputProcessBlockPrincipal_
RunPrincipal & runPrincipal() const
edm::ReusableObjectHolder< LuminosityBlockPrincipal > lumiHolder_
std::vector< std::shared_ptr< EventPrincipal > > eventPrincipals_
def move
Definition: eostools.py:511
ProcessHistoryID reducedInputProcessHistoryID_
ProcessHistoryID const & reducedProcessHistoryID(ProcessHistoryID const &fullID) const
void insert(std::unique_ptr< ProcessBlockPrincipal >)
void adjustEventsToNewProductRegistry(std::shared_ptr< ProductRegistry const > reg)
EventPrincipal & eventPrincipal(unsigned int iStreamIndex) const
void deleteRun(ProcessHistoryID const &phid, RunNumber_t run)
void insertForInput(std::unique_ptr< ProcessBlockPrincipal >)
ProcessHistoryID inputProcessHistoryID_
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:315
std::shared_ptr< LuminosityBlockPrincipal > getAvailableLumiPrincipalPtr()
unsigned int RunNumber_t
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:939
ProcessHistoryRegistry const * processHistoryRegistry_
std::shared_ptr< RunPrincipal > runPrincipal_
void merge(std::shared_ptr< RunAuxiliary > aux, std::shared_ptr< ProductRegistry const > reg)