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*
40  ModuleCallingContext const* mcc) const {
41  if(productWasDeleted()) {
43  }
44  if(!productUnavailable()) {
45  principal_->readFromSource(*this, mcc);
46  // If the product is a dummy filler, product holder will now be marked unavailable.
47  if(product() && !productUnavailable()) {
48  // Found the match
49  resolveStatus = ProductFound;
50  return &productData_;
51  }
52  }
53  resolveStatus = ProductNotFound;
54  return nullptr;
55  }
56 
57  ProductData const*
58  ScheduledProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess,
59  ModuleCallingContext const*) const {
60  if (!skipCurrentProcess) {
61  if(productWasDeleted()) {
63  }
64  if(product() && wrapper().isPresent()) {
65  resolveStatus = ProductFound;
66  return &productData_;
67  }
68  }
69  resolveStatus = ProductNotFound;
70  return nullptr;
71  }
72 
73  ProductData const*
74  SourceProductHolder::resolveProduct_(ResolveStatus& resolveStatus, bool skipCurrentProcess,
75  ModuleCallingContext const*) const {
76  if (!skipCurrentProcess) {
77  if(productWasDeleted()) {
79  }
80  if(product() && wrapper().isPresent()) {
81  resolveStatus = ProductFound;
82  return &productData_;
83  }
84  }
85  resolveStatus = ProductNotFound;
86  return nullptr;
87  }
88 
89  ProductData const*
91  bool skipCurrentProcess,
92  ModuleCallingContext const* mcc) const {
93  if (!skipCurrentProcess) {
94  if(productWasDeleted()) {
96  }
97  if(product() && wrapper().isPresent()) {
98  resolveStatus = ProductFound;
99  return &productData_;
100  }
102  if(product() && wrapper().isPresent()) {
103  resolveStatus = ProductFound;
104  return &productData_;
105  }
106  }
107  resolveStatus = ProductNotFound;
108  return nullptr;
109  }
110 
111  void
113  WrapperOwningHolder const& edp,
114  ProductProvenance const& productProvenance) {
115  if(product()) {
117  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
118  }
119  assert(branchDescription().produced());
120  assert(edp.isValid());
121  assert(!provenance()->productProvenanceValid());
122  assert(status() != Present);
123  assert(status() != Uninitialized);
124  setProductProvenance(productProvenance);
125  assert(provenance()->productProvenanceValid());
126  if(productData().getInterface() != 0) {
127  assert(productData().getInterface()->sameType(*edp.interface()));
128  }
129  productData().wrapper_ = edp.product();
130  status_() = Present;
131  }
132 
133  void
135  WrapperOwningHolder const& edp,
136  ProductProvenance& productProvenance) {
137  assert(provenance()->productProvenanceValid());
138  assert(status() == Present);
139  setProductProvenance(productProvenance);
140  mergeTheProduct(edp);
141  }
142 
143  bool
145  return productUnavailable();
146  }
147 
148  void
150  assert(status() == Present);
151  mergeTheProduct(edp);
152  }
153 
154  void
156  if(product()) {
158  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
159  }
160  assert(branchDescription().produced());
161  assert(edp.isValid());
162  assert(status() != Present);
163  assert(status() != Uninitialized);
164  if(productData().getInterface() != 0) {
165  assert(productData().getInterface()->sameType(*edp.interface()));
166  }
167  productData().wrapper_ = edp.product();
168  status_() = Present;
169  }
170 
171  void
173  WrapperOwningHolder const& edp,
174  ProductProvenance const& productProvenance) {
175  assert(!product());
176  assert(!provenance()->productProvenanceValid());
177  setProductProvenance(productProvenance);
178  assert(provenance()->productProvenanceValid());
179  setProduct(edp);
180  }
181 
182  void
184  WrapperOwningHolder const&,
186  assert(nullptr);
187  }
188 
189  void
191  mergeTheProduct(edp);
192  }
193 
194  bool
196  return(!product());
197  }
198 
199  void
201  assert(!product());
202  setProduct(edp);
203  }
204 
205  void
207  if(wrapper().isMergeable()) {
208  wrapper().mergeProduct(edp.wrapper());
209  } else if(wrapper().hasIsProductEqual()) {
210  if(!wrapper().isProductEqual(edp.wrapper())) {
211  LogError("RunLumiMerging")
212  << "ProductHolderBase::mergeTheProduct\n"
213  << "Two run/lumi products for the same run/lumi which should be equal are not\n"
214  << "Using the first, ignoring the second\n"
215  << "className = " << branchDescription().className() << "\n"
216  << "moduleLabel = " << moduleLabel() << "\n"
217  << "instance = " << productInstanceName() << "\n"
218  << "process = " << processName() << "\n";
219  }
220  } else {
221  LogWarning("RunLumiMerging")
222  << "ProductHolderBase::mergeTheProduct\n"
223  << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n"
224  << "Using the first, ignoring the second in merge\n"
225  << "className = " << branchDescription().className() << "\n"
226  << "moduleLabel = " << moduleLabel() << "\n"
227  << "instance = " << productInstanceName() << "\n"
228  << "process = " << processName() << "\n";
229  }
230  }
231 
232  void
234  assert (!product());
235  if(!prod.isValid() || !prod.isPresent()) {
237  }
238  assert(!prod.isValid() || productData().getInterface()->sameType(*prod.interface()));
239  productData().wrapper_ = prod.product();
240  }
241 
242  void InputProductHolder::setProvenance_(boost::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
244  productData().prov_.setStore(provRetriever);
246  }
247 
250  }
251 
253  return provenance()->productProvenance();
254  }
255 
258  resetStatus();
259  }
260 
262  return true;
263  }
264 
267  }
268 
269  void
272  }
273 
274  // This routine returns true if it is known that currently there is no real product.
275  // If there is a real product, it returns false.
276  // If it is not known if there is a real product, it returns false.
277  bool
279  if(productIsUnavailable()) {
280  return true;
281  }
282  // If there is a product, we know if it is real or a dummy.
283  if(product()) {
284  bool unavailable = !(wrapper().isPresent());
285  if(unavailable) {
287  }
288  return unavailable;
289  }
290  return false;
291  }
292 
293  // This routine returns true if it is known that currently there is no real product.
294  // If there is a real product, it returns false.
295  // If it is not known if there is a real product, it returns false.
296  bool
298  // If unscheduled production, the product is potentially available.
299  if(onDemand()) return false;
300  // The product is available if and only if a product has been put.
301  bool unavailable = !(product() && wrapper().isPresent());
302  return unavailable;
303  }
304 
305  // This routine returns true if the product was deleted early in order to save memory
306  bool
308  return status() == ProductDeleted;
309  }
310 
311  void
314  }
315 
316  void ProducedProductHolder::setProvenance_(boost::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
318  productData().prov_.setStore(provRetriever);
320  }
321 
324  }
325 
327  return provenance()->productProvenance();
328  }
329 
332  resetStatus();
333  }
334 
336  return true;
337  }
338 
341  << "ProducedProductHolder::setPrincipal__() not implemented and should never be called.\n"
342  << "Contact a Framework developer\n";
343  }
344 
345  bool
347  // If this product is from a the current process,
348  // the provenance is available if and only if a product has been put.
349  if(branchDescription().produced()) {
350  return product() && wrapper().isPresent();
351  }
352  // If this product is from a prior process, the provenance is available,
353  // although the per event part may have been dropped.
354  return true;
355  }
356 
357  TypeID
359  return TypeID(wrapper().interface()->wrappedTypeInfo());
360  }
361 
362  void
364  // Check if the types match.
365  TypeID typeID(prod.dynamicTypeInfo());
366  if(typeID != branchDescription().unwrappedTypeID()) {
367  // Types do not match.
369  << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
370  << "It is supposed to be of type " << branchDescription().className() << ".\n"
371  << "It is actually of type " << typeID.className() << ".\n";
372  }
373  }
374 
375  Provenance*
377  return &(productData().prov_);
378  }
379 
380  void
381  ProductHolderBase::write(std::ostream& os) const {
382  // This is grossly inadequate. It is also not critical for the
383  // first pass.
384  os << std::string("ProductHolder for product with ID: ")
385  << productID();
386  }
387 
389  NoProcessProductHolder(std::vector<ProductHolderIndex> const& matchingHolders,
390  std::vector<bool> const& ambiguous,
391  Principal* principal) :
392  matchingHolders_(matchingHolders),
393  ambiguous_(ambiguous),
394  principal_(principal) {
395  assert(ambiguous_.size() == matchingHolders_.size());
396  }
397 
400  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
401  << "Contact a Framework developer\n";
402  }
403 
406  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
407  << "Contact a Framework developer\n";
408  }
409 
411  bool skipCurrentProcess,
412  ModuleCallingContext const* mcc) const {
413  std::vector<unsigned int> const& lookupProcessOrder = principal_->lookupProcessOrder();
414  for(unsigned int k : lookupProcessOrder) {
415  assert(k < ambiguous_.size());
416  if(k == 0) break; // Done
417  if(ambiguous_[k]) {
418  resolveStatus = Ambiguous;
419  return nullptr;
420  }
423  ProductData const* pd = productHolder->resolveProduct(resolveStatus, skipCurrentProcess, mcc);
424  if(pd != nullptr) return pd;
425  }
426  }
427  resolveStatus = ProductNotFound;
428  return nullptr;
429  }
430 
431  void AliasProductHolder::setProvenance_(boost::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
433  productData().prov_.setStore(provRetriever);
435  }
436 
439  }
440 
442  return provenance()->productProvenance();
443  }
444 
447  resetStatus();
448  }
449 
451  return true;
452  }
453 
455  }
456 
458  NoProcessProductHolder& other = dynamic_cast<NoProcessProductHolder&>(rhs);
459  ambiguous_.swap(other.ambiguous_);
462  }
463 
465  }
466 
467  void NoProcessProductHolder::setProvenance_(boost::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
468  }
469 
471  }
472 
474  return nullptr;
475  }
476 
478  }
479 
481  return false;
482  }
483 
486  << "NoProcessProductHolder::setPrincipal__() not implemented and should never be called.\n"
487  << "Contact a Framework developer\n";
488  }
489 
492  << "NoProcessProductHolder::onDemand_() not implemented and should never be called.\n"
493  << "Contact a Framework developer\n";
494  }
495 
498  << "NoProcessProductHolder::productUnavailable_() not implemented and should never be called.\n"
499  << "Contact a Framework developer\n";
500  }
501 
504  << "NoProcessProductHolder::productWasDeleted_() not implemented and should never be called.\n"
505  << "Contact a Framework developer\n";
506  }
507 
508  void NoProcessProductHolder::putProduct_(WrapperOwningHolder const& edp, ProductProvenance const& productProvenance) {
510  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
511  << "Contact a Framework developer\n";
512  }
513 
516  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
517  << "Contact a Framework developer\n";
518  }
519 
522  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
523  << "Contact a Framework developer\n";
524  }
525 
528  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
529  << "Contact a Framework developer\n";
530  }
531 
534  << "NoProcessProductHolder::putOrMergeProduct_() not implemented and should never be called.\n"
535  << "Contact a Framework developer\n";
536  }
537 
540  << "NoProcessProductHolder::checkType_() not implemented and should never be called.\n"
541  << "Contact a Framework developer\n";
542  }
543 
546  << "NoProcessProductHolder::setProductDeleted_() not implemented and should never be called.\n"
547  << "Contact a Framework developer\n";
548  }
549 
552  << "NoProcessProductHolder::branchDescription_() not implemented and should never be called.\n"
553  << "Contact a Framework developer\n";
554  }
555 
556  void NoProcessProductHolder::resetBranchDescription_(boost::shared_ptr<BranchDescription const> bd) {
558  << "NoProcessProductHolder::resetBranchDescription_() not implemented and should never be called.\n"
559  << "Contact a Framework developer\n";
560  }
561 }
virtual bool productUnavailable_() const
virtual bool singleProduct_() const
virtual ProductStatus & status_() const =0
virtual void setProcessHistory_(ProcessHistory const &ph)
std::string const & branchName() const
virtual void setProvenance_(boost::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, 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
virtual bool singleProduct_() const
virtual ProductProvenance * productProvenancePtr_() const
std::vector< ProductHolderIndex > matchingHolders_
virtual BranchDescription const & branchDescription_() const
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:184
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
virtual bool productUnavailable_() const
ProductProvenance * productProvenance() const
Definition: Provenance.h:49
std::type_info const & dynamicTypeInfo() const
Definition: WrapperHolder.h:68
ProductData const * resolveProduct(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
Definition: ProductHolder.h:50
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
void setStore(boost::shared_ptr< ProductProvenanceRetriever > store) const
Definition: Provenance.h:74
virtual bool productUnavailable_() const
void write(std::ostream &os) const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
virtual void mergeProduct_(WrapperOwningHolder const &edp, ProductProvenance &productProvenance)
virtual void setPrincipal_(Principal *principal)
boost::shared_ptr< void const > product() const
Definition: ProductHolder.h:83
std::string const & moduleLabel() const
bool productIsUnavailable() const
bool isProductEqual(void const *newProduct) const
Definition: WrapperHolder.h:60
virtual void setProcessHistory_(ProcessHistory const &ph)
virtual void swap_(ProductHolderBase &rhs)
Provenance * provenance() const
WrapperInterfaceBase const * interface() const
Definition: WrapperHolder.h:80
Provenance prov_
Definition: ProductData.h:51
virtual bool unscheduledFill(std::string const &moduleLabel, ModuleCallingContext const *mcc) const =0
virtual void mergeProduct_(WrapperOwningHolder const &edp, ProductProvenance &productProvenance)
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:95
std::string const & className() const
virtual bool putOrMergeProduct_() const
virtual ProductData const & getProductData() const
virtual void setProvenance_(boost::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid)
virtual void setPrincipal_(Principal *principal)
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:438
bool hasIsProductEqual() const
Definition: WrapperHolder.h:53
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:191
virtual void putProduct_(WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
bool onDemand() const
Definition: ProductHolder.h:77
virtual void setProductDeleted_()
virtual bool singleProduct_() const
TypeID unwrappedTypeID() const
boost::shared_ptr< void const > wrapper_
Definition: ProductData.h:50
ProductID const & productID() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
virtual void checkType_(WrapperOwningHolder const &prod) const
bool productWasDeleted() const
Definition: ProductHolder.h:80
ProductData const & productData() const
Definition: ProductHolder.h:42
virtual void resetBranchDescription_(boost::shared_ptr< BranchDescription const > bd)
virtual void setProvenance_(boost::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid)
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
virtual bool putOrMergeProduct_() const
void setProductUnavailable() const
virtual bool singleProduct_() const
virtual void setProvenance_(boost::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid)
void resetProductData()
Definition: ProductData.h:40
virtual void setProcessHistory_(ProcessHistory const &ph)
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:20
virtual void resetProductData_()
std::string const & processName() const
void reallyCheckType(WrapperOwningHolder const &prod) const
tuple pid
Definition: sysUtil.py:22
virtual void setProcessHistory_(ProcessHistory const &ph)
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:82
void setProduct(WrapperOwningHolder const &prod) const
virtual void resetProductData_()
void setProcessHistory(ProcessHistory const &ph)
Definition: Provenance.h:76
virtual void setPrincipal_(Principal *principal)
ProductStatus & status() const
bool isValid() const
Definition: WrapperHolder.h:27
void setProductProvenance(ProductProvenance const &prov) const
Definition: Provenance.cc:78
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)
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
TypeID productType() const
virtual ProductProvenance * productProvenancePtr_() const
std::string const & productInstanceName() const
virtual bool productWasDeleted_() const
WrapperHolder wrapper() const
Definition: ProductHolder.h:86
virtual void resetProductData_()
bool productUnavailable() const
Definition: ProductHolder.h:71