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() && product()->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() && product()->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() && product()->isPresent()) {
98  resolveStatus = ProductFound;
99  return &productData_;
100  }
102  if(product() && product()->isPresent()) {
103  resolveStatus = ProductFound;
104  return &productData_;
105  }
106  }
107  resolveStatus = ProductNotFound;
108  return nullptr;
109  }
110 
111  void
113  std::unique_ptr<WrapperBase> edp,
114  ProductProvenance const& productProvenance) {
115  if(product()) {
117  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
118  }
120  assert(edp.get() != nullptr);
121  assert(!provenance()->productProvenanceValid());
122  assert(status() != Present);
124  setProductProvenance(productProvenance);
125  assert(provenance()->productProvenanceValid());
126  productData().wrapper_ = std::move(edp); // ProductHolder takes ownership
127  status_() = Present;
128  }
129 
130  void
132  std::unique_ptr<WrapperBase> edp,
133  ProductProvenance& productProvenance) {
134  assert(provenance()->productProvenanceValid());
135  assert(status() == Present);
136  setProductProvenance(productProvenance);
137  mergeTheProduct(std::move(edp));
138  }
139 
140  bool
142  return productUnavailable();
143  }
144 
145  void
146  ProducedProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> edp) const {
147  assert(status() == Present);
148  mergeTheProduct(std::move(edp));
149  }
150 
151  void
152  ProducedProductHolder::putProduct_(std::unique_ptr<WrapperBase> edp) const {
153  if(product()) {
155  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
156  }
158  assert(edp.get() != nullptr);
159  assert(status() != Present);
161  productData().wrapper_ = std::move(edp); // ProductHolder takes ownership
162  status_() = Present;
163  }
164 
165  void
167  std::unique_ptr<WrapperBase> edp,
168  ProductProvenance const& productProvenance) {
169  assert(!product());
170  assert(!provenance()->productProvenanceValid());
171  setProductProvenance(productProvenance);
172  assert(provenance()->productProvenanceValid());
173  setProduct(std::move(edp));
174  }
175 
176  void
178  std::unique_ptr<WrapperBase>,
180  assert(nullptr);
181  }
182 
183  void
184  InputProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> edp) const {
185  mergeTheProduct(std::move(edp));
186  }
187 
188  bool
190  return(!product());
191  }
192 
193  void
194  InputProductHolder::putProduct_(std::unique_ptr<WrapperBase> edp) const {
195  assert(!product());
196  setProduct(std::move(edp));
197  }
198 
199  void
200  ProductHolderBase::mergeTheProduct(std::unique_ptr<WrapperBase> edp) const {
201  if(product()->isMergeable()) {
202  product()->mergeProduct(edp.get());
203  } else if(product()->hasIsProductEqual()) {
204  if(!product()->isProductEqual(edp.get())) {
205  LogError("RunLumiMerging")
206  << "ProductHolderBase::mergeTheProduct\n"
207  << "Two run/lumi products for the same run/lumi which should be equal are not\n"
208  << "Using the first, ignoring the second\n"
209  << "className = " << branchDescription().className() << "\n"
210  << "moduleLabel = " << moduleLabel() << "\n"
211  << "instance = " << productInstanceName() << "\n"
212  << "process = " << processName() << "\n";
213  }
214  } else {
215  LogWarning("RunLumiMerging")
216  << "ProductHolderBase::mergeTheProduct\n"
217  << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n"
218  << "Using the first, ignoring the second in merge\n"
219  << "className = " << branchDescription().className() << "\n"
220  << "moduleLabel = " << moduleLabel() << "\n"
221  << "instance = " << productInstanceName() << "\n"
222  << "process = " << processName() << "\n";
223  }
224  }
225 
226  void
227  InputProductHolder::setProduct(std::unique_ptr<WrapperBase> prod) const {
228  assert (!product());
229  if(prod.get() == nullptr || !prod->isPresent()) {
231  }
232  productData().wrapper_ = std::move(prod); // ProductHolder takes ownership
233  }
234 
235  void InputProductHolder::setProvenance_(std::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
237  productData().prov_.setStore(provRetriever);
239  }
240 
243  }
244 
246  return provenance()->productProvenance();
247  }
248 
251  resetStatus();
252  }
253 
255  return true;
256  }
257 
260  }
261 
262  void
265  }
266 
267  // This routine returns true if it is known that currently there is no real product.
268  // If there is a real product, it returns false.
269  // If it is not known if there is a real product, it returns false.
270  bool
272  if(productIsUnavailable()) {
273  return true;
274  }
275  // If there is a product, we know if it is real or a dummy.
276  if(product()) {
277  bool unavailable = !(product()->isPresent());
278  if(unavailable) {
280  }
281  return unavailable;
282  }
283  return false;
284  }
285 
286  // This routine returns true if it is known that currently there is no real product.
287  // If there is a real product, it returns false.
288  // If it is not known if there is a real product, it returns false.
289  bool
291  // If unscheduled production, the product is potentially available.
292  if(onDemand()) return false;
293  // The product is available if and only if a product has been put.
294  bool unavailable = !(product() && product()->isPresent());
295  return unavailable;
296  }
297 
298  // This routine returns true if the product was deleted early in order to save memory
299  bool
301  return status() == ProductDeleted;
302  }
303 
304  void
307  }
308 
309  void ProducedProductHolder::setProvenance_(std::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
311  productData().prov_.setStore(provRetriever);
313  }
314 
317  }
318 
320  return provenance()->productProvenance();
321  }
322 
325  resetStatus();
326  }
327 
329  return true;
330  }
331 
334  << "ProducedProductHolder::setPrincipal__() not implemented and should never be called.\n"
335  << "Contact a Framework developer\n";
336  }
337 
338  bool
340  // If this product is from a the current process,
341  // the provenance is available if and only if a product has been put.
342  if(branchDescription().produced()) {
343  return product() && product()->isPresent();
344  }
345  // If this product is from a prior process, the provenance is available,
346  // although the per event part may have been dropped.
347  return true;
348  }
349 
350  TypeID
352  return TypeID(product()->wrappedTypeInfo());
353  }
354 
355  void
357  // Check if the types match.
358  TypeID typeID(prod.dynamicTypeInfo());
359  if(typeID != branchDescription().unwrappedTypeID()) {
360  // Types do not match.
362  << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
363  << "It is supposed to be of type " << branchDescription().className() << ".\n"
364  << "It is actually of type " << typeID.className() << ".\n";
365  }
366  }
367 
368  Provenance*
370  return &(productData().prov_);
371  }
372 
373  void
374  ProductHolderBase::write(std::ostream& os) const {
375  // This is grossly inadequate. It is also not critical for the
376  // first pass.
377  os << std::string("ProductHolder for product with ID: ")
378  << productID();
379  }
380 
382  NoProcessProductHolder(std::vector<ProductHolderIndex> const& matchingHolders,
383  std::vector<bool> const& ambiguous,
384  Principal* principal) :
385  matchingHolders_(matchingHolders),
386  ambiguous_(ambiguous),
387  principal_(principal) {
388  assert(ambiguous_.size() == matchingHolders_.size());
389  }
390 
393  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
394  << "Contact a Framework developer\n";
395  }
396 
399  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
400  << "Contact a Framework developer\n";
401  }
402 
404  bool skipCurrentProcess,
405  ModuleCallingContext const* mcc) 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  }
416  ProductData const* pd = productHolder->resolveProduct(resolveStatus, skipCurrentProcess, mcc);
417  if(pd != nullptr) return pd;
418  }
419  }
420  resolveStatus = ProductNotFound;
421  return nullptr;
422  }
423 
424  void AliasProductHolder::setProvenance_(std::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
426  productData().prov_.setStore(provRetriever);
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_(std::shared_ptr<ProductProvenanceRetriever> , ProcessHistory const& , ProductID const& ) {
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_(std::unique_ptr<WrapperBase> , ProductProvenance const& ) {
503  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
504  << "Contact a Framework developer\n";
505  }
506 
507  void NoProcessProductHolder::putProduct_(std::unique_ptr<WrapperBase> ) const {
509  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
510  << "Contact a Framework developer\n";
511  }
512 
513  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> , ProductProvenance& ) {
515  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
516  << "Contact a Framework developer\n";
517  }
518 
519  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase>) const {
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_(std::shared_ptr<BranchDescription const>) {
551  << "NoProcessProductHolder::resetBranchDescription_() not implemented and should never be called.\n"
552  << "Contact a Framework developer\n";
553  }
554 }
void setProduct(std::unique_ptr< WrapperBase > prod) const
bool mergeProduct(WrapperBase const *newProduct)
Definition: WrapperBase.h:48
virtual ProductStatus & status_() const =0
std::string const & branchName() const
WrapperBase * product() const
Definition: ProductHolder.h:81
virtual void setPrincipal_(Principal *principal) override
bool provenanceAvailable() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const override
virtual void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
virtual void resetProductData_() override
std::vector< ProductHolderIndex > matchingHolders_
virtual void setProductDeleted_() override
virtual void setProductDeleted_() override
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:182
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const override
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual ProductProvenance * productProvenancePtr_() const override
virtual void setPrincipal_(Principal *principal) override
virtual void resetStatus_() override
assert(m_qm.get())
virtual void setProvenance_(std::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid) override
ProductProvenance * productProvenance() const
Definition: Provenance.h:49
ProductData const * resolveProduct(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
Definition: ProductHolder.h:48
NoProcessProductHolder(std::vector< ProductHolderIndex > const &matchingHolders, std::vector< bool > const &ambiguous, Principal *principal)
virtual bool singleProduct_() const override
virtual void checkType_(WrapperBase const &prod) const override
void write(std::ostream &os) const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const override
bool isPresent() const
Definition: WrapperBase.h:22
std::string const & moduleLabel() const
bool productIsUnavailable() const
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual void setPrincipal_(Principal *principal) override
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance &productProvenance) override
virtual bool singleProduct_() const override
Provenance * provenance() const
virtual bool putOrMergeProduct_() const override
Provenance prov_
Definition: ProductData.h:47
virtual bool unscheduledFill(std::string const &moduleLabel, ModuleCallingContext const *mcc) const =0
virtual ProductProvenance * productProvenancePtr_() const override
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:90
std::string const & className() const
virtual void setProcessHistory_(ProcessHistory const &ph) override
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:458
virtual void resetProductData_() override
virtual bool productUnavailable_() const override
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:189
bool onDemand() const
Definition: ProductHolder.h:75
virtual bool putOrMergeProduct_() const override
virtual void resetProductData_() override
TypeID unwrappedTypeID() const
virtual void setProvenance_(std::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid) override
ProductID const & productID() const
std::shared_ptr< WrapperBase > wrapper_
Definition: ProductData.h:46
virtual bool productUnavailable_() const override
bool productWasDeleted() const
Definition: ProductHolder.h:78
ProductData const & productData() const
Definition: ProductHolder.h:40
virtual void setProvenance_(std::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid) override
void setProductUnavailable() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const override
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance &productProvenance) override
void resetProductData()
Definition: ProductData.h:36
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual ProductProvenance * productProvenancePtr_() const override
virtual bool onDemand_() const override
void throwProductDeletedException() const
void setProductProvenance(ProductProvenance const &prov) const
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
void reallyCheckType(WrapperBase const &prod) const
std::string const & processName() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, ModuleCallingContext const *mcc) const override
tuple pid
Definition: sysUtil.py:22
void mergeTheProduct(std::unique_ptr< WrapperBase > edp) const
std::vector< bool > ambiguous_
virtual bool singleProduct_() const override
virtual void swap_(ProductHolderBase &rhs) override
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) override
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) override
virtual BranchDescription const & branchDescription_() const override
virtual bool putOrMergeProduct_() const override
void setProductID(ProductID const &pid)
Definition: Provenance.h:82
void setStore(std::shared_ptr< ProductProvenanceRetriever > store) const
Definition: Provenance.h:74
virtual bool productUnavailable_() const override
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance &productProvenance) override
void setProcessHistory(ProcessHistory const &ph)
Definition: Provenance.h:76
virtual void setPrincipal_(Principal *principal) override
ProductStatus & status() const
void setProductProvenance(ProductProvenance const &prov) const
Definition: Provenance.cc:78
virtual ProductData const & getProductData() const override
virtual bool singleProduct_() const override
virtual void resetProductData_() override
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) override
virtual bool productWasDeleted_() const override
bool hasIsProductEqual() const
Definition: WrapperBase.h:49
virtual ProductProvenance * productProvenancePtr_() const override
TypeID productType() const
virtual void setProvenance_(std::shared_ptr< ProductProvenanceRetriever > provRetriever, ProcessHistory const &ph, ProductID const &pid) override
bool isProductEqual(WrapperBase const *newProduct) const
Definition: WrapperBase.h:50
virtual bool productWasDeleted_() const override
std::string const & productInstanceName() const
bool productUnavailable() const
Definition: ProductHolder.h:69