CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProductHolder.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
6 
9 
10 #include <cassert>
11 
12 namespace edm {
13 
16  exception << "ProductHolderBase::resolveProduct_: The product matching all criteria was already deleted\n"
17  << "Looking for type: " << branchDescription().unwrappedTypeID() << "\n"
18  << "Looking for module label: " << moduleLabel() << "\n"
19  << "Looking for productInstanceName: " << productInstanceName() << "\n"
20  << (processName().empty() ? "" : "Looking for process: ") << processName() << "\n"
21  << "This means there is a configuration error.\n"
22  << "The module which is asking for this data must be configured to state that it will read this data.";
23  throw exception;
24 
25  }
26 
28 
37 
38  ProductData const*
39  InputProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool) const {
40  if(productWasDeleted()) {
42  }
43  if(!productUnavailable()) {
44  principal_->resolveProduct(*this, false);
45  // If the product is a dummy filler, product holder will now be marked unavailable.
46  if(product() && !productUnavailable()) {
47  // Found the match
48  resolveStatus = ProductFound;
49  return &productData_;
50  }
51  }
52  resolveStatus = ProductNotFound;
53  return nullptr;
54  }
55 
56  ProductData const*
57  ScheduledProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess) const {
58  if (!skipCurrentProcess) {
59  if(productWasDeleted()) {
61  }
62  if(product() && wrapper().isPresent()) {
63  resolveStatus = ProductFound;
64  return &productData_;
65  }
66  }
67  resolveStatus = ProductNotFound;
68  return nullptr;
69  }
70 
71  ProductData const*
72  SourceProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess) const {
73  if (!skipCurrentProcess) {
74  if(productWasDeleted()) {
76  }
77  if(product() && wrapper().isPresent()) {
78  resolveStatus = ProductFound;
79  return &productData_;
80  }
81  }
82  resolveStatus = ProductNotFound;
83  return nullptr;
84  }
85 
86  ProductData const*
87  UnscheduledProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess) const {
88  if (!skipCurrentProcess) {
89  if(productWasDeleted()) {
91  }
92  if(product() && wrapper().isPresent()) {
93  resolveStatus = ProductFound;
94  return &productData_;
95  }
97  if(product() && wrapper().isPresent()) {
98  resolveStatus = ProductFound;
99  return &productData_;
100  }
101  }
102  resolveStatus = ProductNotFound;
103  return nullptr;
104  }
105 
106  void
108  WrapperOwningHolder const& edp,
109  ProductProvenance const& productProvenance) {
110  if(product()) {
112  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
113  }
114  assert(branchDescription().produced());
115  assert(edp.isValid());
116  assert(!provenance()->productProvenanceValid());
117  assert(status() != Present);
118  assert(status() != Uninitialized);
119  setProductProvenance(productProvenance);
120  assert(provenance()->productProvenanceValid());
121  if(productData().getInterface() != 0) {
122  assert(productData().getInterface()->sameType(*edp.interface()));
123  }
124  productData().wrapper_ = edp.product();
125  status_() = Present;
126  }
127 
128  void
130  WrapperOwningHolder const& edp,
131  ProductProvenance& productProvenance) {
132  assert(provenance()->productProvenanceValid());
133  assert(status() == Present);
134  setProductProvenance(productProvenance);
135  mergeTheProduct(edp);
136  }
137 
138  bool
140  return productUnavailable();
141  }
142 
143  void
145  assert(status() == Present);
146  mergeTheProduct(edp);
147  }
148 
149  void
151  if(product()) {
153  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
154  }
155  assert(branchDescription().produced());
156  assert(edp.isValid());
157  assert(status() != Present);
158  assert(status() != Uninitialized);
159  if(productData().getInterface() != 0) {
160  assert(productData().getInterface()->sameType(*edp.interface()));
161  }
162  productData().wrapper_ = edp.product();
163  status_() = Present;
164  }
165 
166  void
168  WrapperOwningHolder const& edp,
169  ProductProvenance const& productProvenance) {
170  assert(!product());
171  assert(!provenance()->productProvenanceValid());
172  setProductProvenance(productProvenance);
173  assert(provenance()->productProvenanceValid());
174  setProduct(edp);
175  }
176 
177  void
179  WrapperOwningHolder const&,
181  assert(nullptr);
182  }
183 
184  void
186  mergeTheProduct(edp);
187  }
188 
189  bool
191  return(!product());
192  }
193 
194  void
196  assert(!product());
197  setProduct(edp);
198  }
199 
200  void
202  if(wrapper().isMergeable()) {
203  wrapper().mergeProduct(edp.wrapper());
204  } else if(wrapper().hasIsProductEqual()) {
205  if(!wrapper().isProductEqual(edp.wrapper())) {
206  LogError("RunLumiMerging")
207  << "ProductHolderBase::mergeTheProduct\n"
208  << "Two run/lumi products for the same run/lumi which should be equal are not\n"
209  << "Using the first, ignoring the second\n"
210  << "className = " << branchDescription().className() << "\n"
211  << "moduleLabel = " << moduleLabel() << "\n"
212  << "instance = " << productInstanceName() << "\n"
213  << "process = " << processName() << "\n";
214  }
215  } else {
216  LogWarning("RunLumiMerging")
217  << "ProductHolderBase::mergeTheProduct\n"
218  << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n"
219  << "Using the first, ignoring the second in merge\n"
220  << "className = " << branchDescription().className() << "\n"
221  << "moduleLabel = " << moduleLabel() << "\n"
222  << "instance = " << productInstanceName() << "\n"
223  << "process = " << processName() << "\n";
224  }
225  }
226 
227  void
229  assert (!product());
230  if(!prod.isValid() || !prod.isPresent()) {
232  }
233  assert(!prod.isValid() || productData().getInterface()->sameType(*prod.interface()));
234  productData().wrapper_ = prod.product();
235  }
236 
237  void InputProductHolder::setProvenance_(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid) {
239  productData().prov_.setStore(mapper);
241  }
242 
245  }
246 
248  return provenance()->productProvenance();
249  }
250 
253  resetStatus();
254  }
255 
257  return true;
258  }
259 
262  }
263 
264  void
267  }
268 
269  // This routine returns true if it is known that currently there is no real product.
270  // If there is a real product, it returns false.
271  // If it is not known if there is a real product, it returns false.
272  bool
274  if(productIsUnavailable()) {
275  return true;
276  }
277  // If there is a product, we know if it is real or a dummy.
278  if(product()) {
279  bool unavailable = !(wrapper().isPresent());
280  if(unavailable) {
282  }
283  return unavailable;
284  }
285  return false;
286  }
287 
288  // This routine returns true if it is known that currently there is no real product.
289  // If there is a real product, it returns false.
290  // If it is not known if there is a real product, it returns false.
291  bool
293  // If unscheduled production, the product is potentially available.
294  if(onDemand()) return false;
295  // The product is available if and only if a product has been put.
296  bool unavailable = !(product() && wrapper().isPresent());
297  return unavailable;
298  }
299 
300  // This routine returns true if the product was deleted early in order to save memory
301  bool
303  return status() == ProductDeleted;
304  }
305 
306  void
309  }
310 
311  void ProducedProductHolder::setProvenance_(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid) {
313  productData().prov_.setStore(mapper);
315  }
316 
319  }
320 
322  return provenance()->productProvenance();
323  }
324 
327  resetStatus();
328  }
329 
331  return true;
332  }
333 
336  << "ProducedProductHolder::setPrincipal__() not implemented and should never be called.\n"
337  << "Contact a Framework developer\n";
338  }
339 
340  bool
342  // If this product is from a the current process,
343  // the provenance is available if and only if a product has been put.
344  if(branchDescription().produced()) {
345  return product() && wrapper().isPresent();
346  }
347  // If this product is from a prior process, the provenance is available,
348  // although the per event part may have been dropped.
349  return true;
350  }
351 
352  TypeID
354  return TypeID(wrapper().interface()->wrappedTypeInfo());
355  }
356 
357  void
359  // Check if the types match.
360  TypeID typeID(prod.dynamicTypeInfo());
361  if(typeID != branchDescription().unwrappedTypeID()) {
362  // Types do not match.
364  << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
365  << "It is supposed to be of type " << branchDescription().className() << ".\n"
366  << "It is actually of type " << typeID.className() << ".\n";
367  }
368  }
369 
370  Provenance*
372  return &(productData().prov_);
373  }
374 
375  void
376  ProductHolderBase::write(std::ostream& os) const {
377  // This is grossly inadequate. It is also not critical for the
378  // first pass.
379  os << std::string("ProductHolder for product with ID: ")
380  << productID();
381  }
382 
384  NoProcessProductHolder(std::vector<ProductHolderIndex> const& matchingHolders,
385  std::vector<bool> const& ambiguous,
386  Principal* principal) :
387  matchingHolders_(matchingHolders),
388  ambiguous_(ambiguous),
389  principal_(principal) {
390  assert(ambiguous_.size() == matchingHolders_.size());
391  }
392 
395  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
396  << "Contact a Framework developer\n";
397  }
398 
401  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
402  << "Contact a Framework developer\n";
403  }
404 
405  ProductData const* NoProcessProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess) const {
406  std::vector<unsigned int> const& lookupProcessOrder = principal_->lookupProcessOrder();
407  for(unsigned int k : lookupProcessOrder) {
408  assert(k < ambiguous_.size());
409  if(k == 0) break; // Done
410  if(ambiguous_[k]) {
411  resolveStatus = Ambiguous;
412  return nullptr;
413  }
415  ProductHolderBase const* productHolder = principal_->getProductByIndex(matchingHolders_[k], false, false);
416  ProductData const* pd = productHolder->resolveProduct(resolveStatus, skipCurrentProcess);
417  if(pd != nullptr) return pd;
418  }
419  }
420  resolveStatus = ProductNotFound;
421  return nullptr;
422  }
423 
424  void AliasProductHolder::setProvenance_(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid) {
426  productData().prov_.setStore(mapper);
428  }
429 
432  }
433 
435  return provenance()->productProvenance();
436  }
437 
440  resetStatus();
441  }
442 
444  return true;
445  }
446 
448  }
449 
451  NoProcessProductHolder& other = dynamic_cast<NoProcessProductHolder&>(rhs);
452  ambiguous_.swap(other.ambiguous_);
455  }
456 
458  }
459 
460  void NoProcessProductHolder::setProvenance_(boost::shared_ptr<BranchMapper> mapper, ProcessHistoryID const& phid, ProductID const& pid) {
461  }
462 
464  }
465 
467  return nullptr;
468  }
469 
471  }
472 
474  return false;
475  }
476 
479  << "NoProcessProductHolder::setPrincipal__() not implemented and should never be called.\n"
480  << "Contact a Framework developer\n";
481  }
482 
485  << "NoProcessProductHolder::onDemand_() not implemented and should never be called.\n"
486  << "Contact a Framework developer\n";
487  }
488 
491  << "NoProcessProductHolder::productUnavailable_() not implemented and should never be called.\n"
492  << "Contact a Framework developer\n";
493  }
494 
497  << "NoProcessProductHolder::productWasDeleted_() not implemented and should never be called.\n"
498  << "Contact a Framework developer\n";
499  }
500 
501  void NoProcessProductHolder::putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance) {
503  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
504  << "Contact a Framework developer\n";
505  }
506 
509  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
510  << "Contact a Framework developer\n";
511  }
512 
515  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
516  << "Contact a Framework developer\n";
517  }
518 
521  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
522  << "Contact a Framework developer\n";
523  }
524 
527  << "NoProcessProductHolder::putOrMergeProduct_() not implemented and should never be called.\n"
528  << "Contact a Framework developer\n";
529  }
530 
533  << "NoProcessProductHolder::checkType_() not implemented and should never be called.\n"
534  << "Contact a Framework developer\n";
535  }
536 
539  << "NoProcessProductHolder::setProductDeleted_() not implemented and should never be called.\n"
540  << "Contact a Framework developer\n";
541  }
542 
545  << "NoProcessProductHolder::branchDescription_() not implemented and should never be called.\n"
546  << "Contact a Framework developer\n";
547  }
548 
549  void NoProcessProductHolder::resetBranchDescription_(boost::shared_ptr<ConstBranchDescription> bd) {
551  << "NoProcessProductHolder::resetBranchDescription_() not implemented and should never be called.\n"
552  << "Contact a Framework developer\n";
553  }
554 }
virtual bool productUnavailable_() const
void resolveProduct(ProductHolderBase const &phb, bool fillOnDemand) const
Definition: Principal.h:167
virtual bool singleProduct_() const
virtual void setProcessHistoryID_(ProcessHistoryID const &phid)
virtual ProductStatus & status_() const =0
virtual void setProvenance_(boost::shared_ptr< BranchMapper > mapper, ProcessHistoryID const &phid, ProductID const &pid)
virtual void setPrincipal_(Principal *principal)
virtual void resetProductData_()
bool provenanceAvailable() const
WrapperInterfaceBase const * getInterface() const
Definition: ProductData.h:25
virtual void mergeProduct_(WrapperOwningHolder const &edp, ProductProvenance &productProvenance)
bool sameType(WrapperInterfaceBase const &other) const
ConstProductPtr getProductByIndex(ProductHolderIndex const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:408
virtual bool singleProduct_() const
virtual ProductProvenance * productProvenancePtr_() const
std::vector< ProductHolderIndex > matchingHolders_
void setProcessHistoryID(ProcessHistoryID const &phid)
Definition: Provenance.h:86
virtual void setProcessHistoryID_(ProcessHistoryID const &phid)
ConstBranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
virtual bool productUnavailable_() const
virtual void setProcessHistoryID_(ProcessHistoryID const &phid)
ProductProvenance * productProvenance() const
Definition: Provenance.h:51
std::type_info const & dynamicTypeInfo() const
Definition: WrapperHolder.h:68
bool mergeProduct(void const *newProduct)
Definition: WrapperHolder.h:57
NoProcessProductHolder(std::vector< ProductHolderIndex > const &matchingHolders, std::vector< bool > const &ambiguous, Principal *principal)
virtual ProductProvenance * productProvenancePtr_() const
virtual void setProductDeleted_()
boost::shared_ptr< void const > product() const
virtual bool productUnavailable_() const
void write(std::ostream &os) const
virtual void mergeProduct_(WrapperOwningHolder const &edp, ProductProvenance &productProvenance)
virtual void setPrincipal_(Principal *principal)
boost::shared_ptr< void const > product() const
Definition: ProductHolder.h:81
std::string const & moduleLabel() const
virtual void resetBranchDescription_(boost::shared_ptr< ConstBranchDescription > bd)
bool productIsUnavailable() const
bool isProductEqual(void const *newProduct) const
Definition: WrapperHolder.h:60
virtual ConstBranchDescription const & branchDescription_() const
virtual void swap_(ProductHolderBase &rhs)
Provenance * provenance() const
WrapperInterfaceBase const * interface() const
Definition: WrapperHolder.h:80
Provenance prov_
Definition: ProductData.h:51
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
virtual void mergeProduct_(WrapperOwningHolder const &edp, ProductProvenance &productProvenance)
virtual bool putOrMergeProduct_() const
virtual ProductData const & getProductData() const
virtual void setPrincipal_(Principal *principal)
bool hasIsProductEqual() const
Definition: WrapperHolder.h:53
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ProductData const * resolveProduct(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
Definition: ProductHolder.h:49
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:171
virtual void putProduct_(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
bool onDemand() const
Definition: ProductHolder.h:75
virtual void setProductDeleted_()
virtual bool singleProduct_() const
boost::shared_ptr< void const > wrapper_
Definition: ProductData.h:50
ProductID const & productID() const
void setStore(boost::shared_ptr< BranchMapper > store) const
Definition: Provenance.h:84
virtual void checkType_(WrapperOwningHolder const &prod) const
bool productWasDeleted() const
Definition: ProductHolder.h:78
ProductData const & productData() const
Definition: ProductHolder.h:41
virtual void setProcessHistoryID_(ProcessHistoryID const &phid)
virtual bool putOrMergeProduct_() const
void setProductUnavailable() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
virtual bool singleProduct_() const
void resetProductData()
Definition: ProductData.h:40
virtual void setProvenance_(boost::shared_ptr< BranchMapper > mapper, ProcessHistoryID const &phid, ProductID const &pid)
void mergeTheProduct(WrapperOwningHolder const &edp) const
int k[5][pyjets_maxn]
void throwProductDeletedException() const
void setProductProvenance(ProductProvenance const &prov) const
eventsetup::produce::Produce produced
Definition: ESProducts.cc:21
virtual void resetProductData_()
virtual void setProvenance_(boost::shared_ptr< BranchMapper > mapper, ProcessHistoryID const &phid, ProductID const &pid)
std::string const & processName() const
std::string const & className() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
void reallyCheckType(WrapperOwningHolder const &prod) const
virtual bool putOrMergeProduct_() const
std::vector< bool > ambiguous_
virtual bool productWasDeleted_() const
virtual void putProduct_(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
void setProductID(ProductID const &pid)
Definition: Provenance.h:92
void setProduct(WrapperOwningHolder const &prod) const
std::string const & branchName() const
virtual void resetProductData_()
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
virtual bool unscheduledFill(std::string const &moduleLabel) const =0
virtual void setProvenance_(boost::shared_ptr< BranchMapper > mapper, ProcessHistoryID const &phid, ProductID const &pid)
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess) const
virtual void setPrincipal_(Principal *principal)
ProductStatus & status() const
bool isValid() const
Definition: WrapperHolder.h:27
void setProductProvenance(ProductProvenance const &prov) const
Definition: Provenance.cc:125
virtual bool onDemand_() const
bool isPresent() const
Definition: WrapperHolder.h:64
virtual ProductProvenance * productProvenancePtr_() const
void const * wrapper() const
Definition: WrapperHolder.h:76
virtual void putProduct_(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
TypeID productType() const
virtual ProductProvenance * productProvenancePtr_() const
std::string const & productInstanceName() const
virtual bool productWasDeleted_() const
WrapperHolder wrapper() const
Definition: ProductHolder.h:84
virtual void resetProductData_()
bool productUnavailable() const
Definition: ProductHolder.h:69