CMS 3D CMS Logo

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