CMS 3D CMS Logo

EventPrincipal.cc
Go to the documentation of this file.
2 
27 
28 #include <algorithm>
29 #include <cassert>
30 #include <limits>
31 #include <memory>
32 
33 namespace edm {
34  EventPrincipal::EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
35  std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
36  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
37  ProcessConfiguration const& pc,
38  HistoryAppender* historyAppender,
39  unsigned int streamIndex,
40  bool isForPrimaryProcess,
41  ProcessBlockHelperBase const* processBlockHelper)
42  : Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender, isForPrimaryProcess),
43  aux_(),
44  luminosityBlockPrincipal_(nullptr),
45  provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex, *reg)),
46  eventSelectionIDs_(),
47  branchIDListHelper_(branchIDListHelper),
48  processBlockHelper_(processBlockHelper),
49  thinnedAssociationsHelper_(thinnedAssociationsHelper),
50  branchListIndexes_(),
51  branchListIndexToProcessIndex_(),
52  streamID_(streamIndex) {
54 
55  for (auto& prod : *this) {
56  if (prod->singleProduct()) {
57  prod->setProductProvenanceRetriever(productProvenanceRetrieverPtr());
58  }
59  }
60  }
61 
64  aux_ = EventAuxiliary();
65  //do not clear luminosityBlockPrincipal_ since
66  // it is only connected at beginLumi transition
67  provRetrieverPtr_->reset();
68  }
69 
71  ProcessHistory const* processHistory,
72  EventSelectionIDVector eventSelectionIDs,
73  BranchListIndexes branchListIndexes,
74  EventToProcessBlockIndexes const& eventToProcessBlockIndexes,
75  ProductProvenanceRetriever const& provRetriever,
77  bool deepCopyRetriever) {
79  if (deepCopyRetriever) {
80  provRetrieverPtr_->deepCopy(provRetriever);
81  } else {
82  provRetrieverPtr_->mergeParentProcessRetriever(provRetriever);
83  }
85  if (branchIDListHelper_->hasProducedProducts()) {
86  // Add index into BranchIDListRegistry for products produced this process
87  branchListIndexes.push_back(branchIDListHelper_->producedBranchListIndex());
88  }
90  }
93  }
94 
96  ProcessHistory const* processHistory,
97  EventSelectionIDVector eventSelectionIDs,
98  BranchListIndexes branchListIndexes,
101 
103  if (branchIDListHelper_->hasProducedProducts()) {
104  // Add index into BranchIDListRegistry for products produced this process
105  branchListIndexes.push_back(branchIDListHelper_->producedBranchListIndex());
106  }
108  }
110  }
111 
113  ProcessHistory const* processHistory,
115  if (branchListIndexes_.empty() and branchIDListHelper_->hasProducedProducts()) {
116  // Add index into BranchIDListRegistry for products produced this process
117  // if it hasn't already been filled in by the other fillEventPrincipal or by an earlier call to this function
118  BranchListIndexes indexes;
119  indexes.push_back(branchIDListHelper_->producedBranchListIndex());
121  }
123  }
124 
126  ProcessHistory const* processHistory,
128  if (aux.event() == invalidEventNumber) {
129  throw Exception(errors::LogicError) << "EventPrincipal::fillEventPrincipal, Invalid event number provided in "
130  "EventAuxiliary, It is illegal for the event number to be 0\n";
131  }
132 
134  aux_ = aux;
136  }
137 
139  //fromInput does not contain entries for what is being produced in this job.
140  auto end = branchListIndexes_.end();
141  if (end != branchListIndexes_.begin() and branchIDListHelper_->hasProducedProducts()) {
142  --end;
143  }
144 
145  return not std::equal(fromInput.begin(), fromInput.end(), branchListIndexes_.begin(), end);
146  }
147 
151  // Fill in helper map for Branch to ProductID mapping
152  if (not branchListIndexes_.empty()) {
154  }
155 
156  // Fill in the product ID's in the product holders.
157  for (auto& prod : *this) {
158  if (prod->singleProduct()) {
159  // If an alias is in the same process as the original then isAlias will be true.
160  // Under that condition, we want the ProductID to be the same as the original.
161  // If not, then we've internally changed the original BranchID to the alias BranchID
162  // in the ProductID lookup so we need the alias BranchID.
163 
164  auto const& bd = prod->branchDescription();
165  prod->setProductID(branchIDToProductID(bd.isAlias() ? bd.originalBranchID() : bd.branchID()));
166  }
167  }
168  }
169 
171 
174  assert(lumi == luminosityBlockPrincipal_->luminosityBlock());
175  EventNumber_t event = aux_.id().event();
176  aux_.id() = EventID(run, lumi, event);
177  }
178 
180 
182  std::unique_ptr<WrapperBase> edp,
183  ProductProvenance const& productProvenance) const {
184  // assert commented out for DaqSource. When DaqSource no longer uses put(), the assert can be restored.
185  //assert(produced());
186  if (edp.get() == nullptr) {
187  throw Exception(errors::InsertFailure, "Null Pointer") << "put: Cannot put because ptr to product is null."
188  << "\n";
189  }
190  productProvenanceRetrieverPtr()->insertIntoSet(productProvenance);
191  auto phb = getExistingProduct(bd.branchID());
192  assert(phb);
193  // ProductResolver assumes ownership
194  dynamic_cast<ProductPutterBase const*>(phb)->putProduct(std::move(edp));
195  }
196 
197  void EventPrincipal::put(ProductResolverIndex index, std::unique_ptr<WrapperBase> edp, ParentageID parentage) const {
198  if (edp.get() == nullptr) {
199  throw Exception(errors::InsertFailure, "Null Pointer") << "put: Cannot put because ptr to product is null."
200  << "\n";
201  }
202  auto phb = getProductResolverByIndex(index);
203 
205  ProductProvenance(phb->branchDescription().branchID(), std::move(parentage)));
206 
207  assert(phb);
208  // ProductResolver assumes ownership
209  dynamic_cast<ProductPutterBase const*>(phb)->putProduct(std::move(edp));
210  }
211 
213  std::unique_ptr<WrapperBase> edp,
214  std::optional<ProductProvenance> productProvenance) const {
215  assert(!bd.produced());
216  if (productProvenance) {
217  productProvenanceRetrieverPtr()->insertIntoSet(std::move(*productProvenance));
218  }
219  auto phb = getExistingProduct(bd.branchID());
220  assert(phb);
221  // ProductResolver assumes ownership
222  dynamic_cast<ProductPutterBase const*>(phb)->putProduct(std::move(edp));
223  }
224 
226  if (!pid.isValid()) {
227  throw Exception(errors::ProductNotFound, "InvalidID") << "get by product ID: invalid ProductID supplied\n";
228  }
229  return productIDToBranchID(pid, branchIDListHelper_->branchIDLists(), branchListIndexes_);
230  }
231 
234  }
235 
238  }
239 
240  unsigned int EventPrincipal::transitionIndex_() const { return streamID_.value(); }
241 
243 
244  static void throwProductDeletedException(ProductID const& pid,
247  exception << "get by product ID: The product with given id: " << pid << "\ntype: " << phb->productType()
248  << "\nproduct instance name: " << phb->productInstanceName() << "\nprocess name: " << phb->processName()
249  << "\nwas already deleted. This is a configuration error. Please change the configuration of the module "
250  "which caused this exception to state it reads this data.";
251  throw exception;
252  }
253 
255  BranchID bid = pidToBid(pid);
257  if (phb == nullptr) {
258  return BasicHandle(makeHandleExceptionFactory([pid]() -> std::shared_ptr<cms::Exception> {
259  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
260  *whyFailed << "get by product ID: no product with given id: " << pid << "\n";
261  return whyFailed;
262  }));
263  }
264 
265  // Was this already deleted?
266  if (phb->productWasDeleted()) {
268  }
269  // Check for case where we tried on demand production and
270  // it failed to produce the object
271  if (phb->unscheduledWasNotRun()) {
272  return BasicHandle(makeHandleExceptionFactory([pid]() -> std::shared_ptr<cms::Exception> {
273  std::shared_ptr<cms::Exception> whyFailed(std::make_shared<Exception>(errors::ProductNotFound, "InvalidID"));
274  *whyFailed << "get by ProductID: could not get product with id: " << pid << "\n"
275  << "Unscheduled execution not allowed to get via ProductID.\n";
276  return whyFailed;
277  }));
278  }
279  auto resolution = phb->resolveProduct(*this, false, nullptr, nullptr);
280 
281  auto data = resolution.data();
282  if (data) {
283  return BasicHandle(data->wrapper(), &(data->provenance()));
284  }
285  return BasicHandle(nullptr, nullptr);
286  }
287 
288  WrapperBase const* EventPrincipal::getIt(ProductID const& pid) const { return getByProductID(pid).wrapper(); }
289 
290  std::optional<std::tuple<WrapperBase const*, unsigned int>> EventPrincipal::getThinnedProduct(
291  ProductID const& pid, unsigned int key) const {
293  pid,
294  key,
296  [this](ProductID const& p) { return pidToBid(p); },
297  [this](BranchID const& b) { return getThinnedAssociation(b); },
298  [this](ProductID const& p) { return getIt(p); });
299  }
300 
302  std::vector<WrapperBase const*>& foundContainers,
303  std::vector<unsigned int>& keys) const {
305  pid,
307  [this](ProductID const& p) { return pidToBid(p); },
308  [this](BranchID const& b) { return getThinnedAssociation(b); },
309  [this](ProductID const& p) { return getIt(p); },
310  foundContainers,
311  keys);
312  }
313 
315  unsigned int key,
316  ProductID const& thinnedID) const {
317  BranchID parent = pidToBid(parentID);
318  BranchID thinned = pidToBid(thinnedID);
319 
320  try {
322  parentID, parent, key, thinnedID, thinned, *thinnedAssociationsHelper_, [this](BranchID const& branchID) {
323  return getThinnedAssociation(branchID);
324  });
325  if (auto factory = std::get_if<detail::GetThinnedKeyFromExceptionFactory>(&ret)) {
326  return [func = *factory]() {
327  auto ex = func();
328  ex.addContext("Calling EventPrincipal::getThinnedKeyFrom()");
329  return ex;
330  };
331  } else {
332  return ret;
333  }
334  } catch (Exception& ex) {
335  ex.addContext("Calling EventPrincipal::getThinnedKeyFrom()");
336  throw ex;
337  }
338  }
339 
341  BranchID bid = pidToBid(pid);
342  return getProvenance(bid);
343  }
344 
346  BranchID bid = pidToBid(pid);
347  return getStableProvenance(bid);
348  }
349 
351 
353 
356  }
357 
359  ConstProductResolverPtr const phb = getProductResolver(branchID);
360 
361  if (phb == nullptr) {
363  << "EventPrincipal::getThinnedAssociation, ThinnedAssociation ProductResolver cannot be found\n"
364  << "This should never happen. Contact a Framework developer";
365  }
366  ProductData const* productData = (phb->resolveProduct(*this, false, nullptr, nullptr)).data();
367  if (productData == nullptr) {
368  return nullptr;
369  }
370  WrapperBase const* product = productData->wrapper();
371  if (!(typeid(edm::ThinnedAssociation) == product->dynamicTypeInfo())) {
373  << "EventPrincipal::getThinnedProduct, product has wrong type, not a ThinnedAssociation.\n";
374  }
376  return wrapper->product();
377  }
378 
379 } // namespace edm
void fillPrincipal(DelayedReader *reader)
Definition: Principal.cc:410
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper_
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &pid, unsigned int key) const override
void setLuminosityBlockPrincipal(LuminosityBlockPrincipal *lbp)
void clearPrincipal()
Definition: Principal.cc:390
void commonFillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader)
bool isValid() const
Definition: ProductID.h:32
unsigned int ProductResolverIndex
EventNumber_t event() const
EventAuxiliary const & aux() const
RunNumber_t run() const
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
EventToProcessBlockIndexes eventToProcessBlockIndexes_
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
EventSelectionIDVector eventSelectionIDs_
ret
prodAgent to be discontinued
unsigned int processBlockIndex(std::string const &processName) const override
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID) const
RunPrincipal const & runPrincipal() const
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &pid, unsigned int key, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID)
std::variant< unsigned int, GetThinnedKeyFromExceptionFactory, std::monostate > getThinnedKeyFrom_implementation(ProductID const &parentID, BranchID const &parent, unsigned int key, ProductID const &thinnedID, BranchID thinned, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F &&getThinnedAssociation)
BranchListIndexes branchListIndexes_
ProductResolverBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:509
unsigned long long EventNumber_t
LuminosityBlockPrincipal const & luminosityBlockPrincipal() const
edm::propagate_const< LuminosityBlockPrincipal * > luminosityBlockPrincipal_
void changedIndexes_() final
std::shared_ptr< BranchIDListHelper const > branchIDListHelper_
reader
Definition: DQM.py:105
EventAuxiliary aux_
Provenance const & getProvenance(ProductID const &pid) const
edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > provRetrieverPtr_
assert(be >=bs)
OptionalThinnedKey getThinnedKeyFrom(ProductID const &parent, unsigned int key, ProductID const &thinned) const override
WrapperBase const * wrapper() const
Definition: ProductData.h:35
unsigned int LuminosityBlockNumber_t
BasicHandle getByProductID(ProductID const &oid) const
EventPrincipal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< BranchIDListHelper const > branchIDListHelper, std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper, ProcessConfiguration const &pc, HistoryAppender *historyAppender, unsigned int streamIndex=0, bool isForPrimaryProcess=true, ProcessBlockHelperBase const *processBlockHelper=nullptr)
BranchID pidToBid(ProductID const &pid) const
bool equal(const T &first, const T &second)
Definition: Equal.h:32
std::vector< EventSelectionID > EventSelectionIDVector
EventToProcessBlockIndexes const & eventToProcessBlockIndexes() const
ProductID branchIDToProductID(BranchID const &bid, BranchIDListHelper const &branchIDListHelper, std::vector< ProcessIndex > const &branchListIndexToProcessIndex)
static void throwProductDeletedException(ProductID const &pid, edm::EventPrincipal::ConstProductResolverPtr const phb)
void getThinnedProducts(ProductID const &pid, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys)
EventID const & id() const
ProductID branchIDToProductID(BranchID const &bid) const
EventNumber_t const invalidEventNumber
std::vector< BranchListIndex > BranchListIndexes
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
BranchID productIDToBranchID(ProductID const &pid, BranchIDLists const &lists, BranchListIndexes const &indexes)
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:42
std::shared_ptr< HandleExceptionFactory > makeHandleExceptionFactory(T &&iFunctor)
Base::ConstProductResolverPtr ConstProductResolverPtr
void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys) const override
void updateBranchListIndexes(BranchListIndexes &&)
virtual unsigned int processBlockIndex(std::string const &processName, EventToProcessBlockIndexes const &) const =0
ProcessHistoryID const & processHistoryID() const
RunPrincipal const & runPrincipal() const
std::vector< ProcessIndex > branchListIndexToProcessIndex_
std::vector< ProcessIndex > makeBranchListIndexToProcessIndex(BranchListIndexes const &branchListIndexes)
WrapperBase const * getIt(ProductID const &pid) const override
WrapperBase const * wrapper() const noexcept(true)
Definition: BasicHandle.h:73
unsigned int transitionIndex_() const override
void putOnRead(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, std::optional< ProductProvenance > productProvenance) const
ProcessHistory const & processHistory() const
Definition: Principal.h:140
ProductProvenanceRetriever const * productProvenanceRetrieverPtr() const
double b
Definition: hdecay.h:118
void addContext(std::string const &context)
Definition: Exception.cc:165
void setProcessHistoryID(ProcessHistoryID const &phid)
bool wasBranchListIndexesChangedFromInput(BranchListIndexes const &) const
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
ProcessBlockHelperBase const * processBlockHelper_
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
StableProvenance const & getStableProvenance(ProductID const &pid) const
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:142
EventSelectionIDVector const & eventSelectionIDs() const
unsigned int RunNumber_t
unsigned int value() const
Definition: StreamID.h:43
void setRunAndLumiNumber(RunNumber_t run, LuminosityBlockNumber_t lumi)
BranchListIndexes const & branchListIndexes() const
const_iterator end() const
Definition: Principal.h:163
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:570
def move(src, dest)
Definition: eostools.py:511
EventNumber_t event() const
Definition: EventID.h:40
DelayedReader * reader() const
Definition: Principal.h:187
Definition: event.py:1
void insertIntoSet(ProductProvenance provenanceProduct) const
static HepMC::HEPEVT_Wrapper wrapper
ConstProductResolverPtr getProductResolver(BranchID const &oid) const
Definition: Principal.cc:562