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  Principal const& principal,
41  bool,
43  ModuleCallingContext const* mcc) const {
44  if(productWasDeleted()) {
46  }
47  if(!productUnavailable()) {
48  principal.readFromSource(*this, mcc);
49  // If the product is a dummy filler, product holder will now be marked unavailable.
50  if(product() && !productUnavailable()) {
51  // Found the match
52  resolveStatus = ProductFound;
53  return &productData_;
54  }
55  }
56  resolveStatus = ProductNotFound;
57  return nullptr;
58  }
59 
60  ProductData const*
62  Principal const&,
63  bool skipCurrentProcess,
65  ModuleCallingContext const*) const {
66  if (!skipCurrentProcess) {
67  if(productWasDeleted()) {
69  }
70  if(product() && product()->isPresent()) {
71  resolveStatus = ProductFound;
72  return &productData_;
73  }
74  }
75  resolveStatus = ProductNotFound;
76  return nullptr;
77  }
78 
79  ProductData const*
81  Principal const& principal,
82  bool skipCurrentProcess,
84  ModuleCallingContext const*) const {
85  if (!skipCurrentProcess) {
86  if(productWasDeleted()) {
88  }
89  if(product() && product()->isPresent()) {
90  resolveStatus = ProductFound;
91  return &productData_;
92  }
93  }
94  resolveStatus = ProductNotFound;
95  return nullptr;
96  }
97 
98  ProductData const*
100  Principal const& principal,
101  bool skipCurrentProcess,
103  ModuleCallingContext const* mcc) const {
104  if (!skipCurrentProcess) {
105  if(productWasDeleted()) {
107  }
108  if(product() && product()->isPresent()) {
109  resolveStatus = ProductFound;
110  return &productData_;
111  }
112  principal.unscheduledFill(moduleLabel(), sra, mcc);
113  if(product() && product()->isPresent()) {
114  resolveStatus = ProductFound;
115  return &productData_;
116  }
117  }
118  resolveStatus = ProductNotFound;
119  return nullptr;
120  }
121 
122  void
124  std::unique_ptr<WrapperBase> edp,
125  ProductProvenance const& productProvenance) const {
126  if(product()) {
128  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
129  }
131  assert(edp.get() != nullptr);
132  assert(status() != Present);
134  productData().unsafe_setWrapper(std::move(edp)); // ProductHolder takes ownership
135  status_() = Present;
136  }
137 
138  void
140  std::unique_ptr<WrapperBase> edp,
141  ProductProvenance const& productProvenance) const {
142  assert(status() == Present);
144  }
145 
146  bool
148  return productUnavailable();
149  }
150 
151  void
152  ProducedProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> edp) const {
153  assert(status() == Present);
155  }
156 
157  void
158  ProducedProductHolder::putProduct_(std::unique_ptr<WrapperBase> edp) const {
159  if(product()) {
161  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
162  }
164  assert(edp.get() != nullptr);
165  assert(status() != Present);
167  productData().unsafe_setWrapper(std::move(edp)); // ProductHolder takes ownership
168  status_() = Present;
169  }
170 
171  void
173  std::unique_ptr<WrapperBase> edp,
174  ProductProvenance const& productProvenance) const {
175  assert(!product());
176  setProduct(std::move(edp));
177  }
178 
179  void
181  std::unique_ptr<WrapperBase>,
182  ProductProvenance const&) const {
183  assert(nullptr);
184  }
185 
186  void
187  InputProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> edp) const {
189  }
190 
191  bool
193  return(!product());
194  }
195 
196  void
197  InputProductHolder::putProduct_(std::unique_ptr<WrapperBase> edp) const {
198  assert(!product());
199  setProduct(std::move(edp));
200  }
201 
202  void
203  ProductHolderBase::mergeTheProduct(std::unique_ptr<WrapperBase> edp) const {
204  if(product()->isMergeable()) {
205  unsafe_product()->mergeProduct(edp.get());
206  } else if(product()->hasIsProductEqual()) {
207  if(!product()->isProductEqual(edp.get())) {
208  LogError("RunLumiMerging")
209  << "ProductHolderBase::mergeTheProduct\n"
210  << "Two run/lumi products for the same run/lumi which should be equal are not\n"
211  << "Using the first, ignoring the second\n"
212  << "className = " << branchDescription().className() << "\n"
213  << "moduleLabel = " << moduleLabel() << "\n"
214  << "instance = " << productInstanceName() << "\n"
215  << "process = " << processName() << "\n";
216  }
217  } else {
218  LogWarning("RunLumiMerging")
219  << "ProductHolderBase::mergeTheProduct\n"
220  << "Run/lumi product has neither a mergeProduct nor isProductEqual function\n"
221  << "Using the first, ignoring the second in merge\n"
222  << "className = " << branchDescription().className() << "\n"
223  << "moduleLabel = " << moduleLabel() << "\n"
224  << "instance = " << productInstanceName() << "\n"
225  << "process = " << processName() << "\n";
226  }
227  }
228 
229  void
230  InputProductHolder::setProduct(std::unique_ptr<WrapperBase> prod) const {
231  assert (!product());
232  if(prod.get() == nullptr || !prod->isPresent()) {
234  }
235  productData().unsafe_setWrapper(std::move(prod)); // ProductHolder takes ownership
236  }
237 
239  productData().setProvenance(provRetriever,ph,pid);
240  }
241 
244  }
245 
247  return provenance()->productProvenance();
248  }
249 
252  resetStatus();
253  }
254 
256  return true;
257  }
258 
259  // This routine returns true if it is known that currently there is no real product.
260  // If there is a real product, it returns false.
261  // If it is not known if there is a real product, it returns false.
262  bool
264  if(productIsUnavailable()) {
265  return true;
266  }
267  // If there is a product, we know if it is real or a dummy.
268  if(product()) {
269  bool unavailable = !(product()->isPresent());
270  if(unavailable) {
272  }
273  return unavailable;
274  }
275  return false;
276  }
277 
278  // This routine returns true if it is known that currently there is no real product.
279  // If there is a real product, it returns false.
280  // If it is not known if there is a real product, it returns false.
281  bool
283  // If unscheduled production, the product is potentially available.
284  if(onDemand()) return false;
285  // The product is available if and only if a product has been put.
286  bool unavailable = !(product() && product()->isPresent());
287  return unavailable;
288  }
289 
290  // This routine returns true if the product was deleted early in order to save memory
291  bool
293  return status() == ProductDeleted;
294  }
295 
296  void
299  }
300 
302  productData().setProvenance(provRetriever,ph,pid);
303  }
304 
307  }
308 
310  return provenance()->productProvenance();
311  }
312 
315  resetStatus();
316  }
317 
319  return true;
320  }
321 
322  bool
324  // If this product is from a the current process,
325  // the provenance is available if and only if a product has been put.
326  if(branchDescription().produced()) {
327  return product() && product()->isPresent();
328  }
329  // If this product is from a prior process, the provenance is available,
330  // although the per event part may have been dropped.
331  return true;
332  }
333 
334  TypeID
336  return TypeID(product()->wrappedTypeInfo());
337  }
338 
339  void
341  // Check if the types match.
342  TypeID typeID(prod.dynamicTypeInfo());
343  if(typeID != branchDescription().unwrappedTypeID()) {
344  // Types do not match.
346  << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
347  << "It is supposed to be of type " << branchDescription().className() << ".\n"
348  << "It is actually of type " << typeID.className() << ".\n";
349  }
350  }
351 
352  Provenance const*
354  return &(productData().provenance());
355  }
356 
357  void
358  ProductHolderBase::write(std::ostream& os) const {
359  // This is grossly inadequate. It is also not critical for the
360  // first pass.
361  os << std::string("ProductHolder for product with ID: ")
362  << productID();
363  }
364 
366  NoProcessProductHolder(std::vector<ProductHolderIndex> const& matchingHolders,
367  std::vector<bool> const& ambiguous) :
368  matchingHolders_(matchingHolders),
369  ambiguous_(ambiguous) {
370  assert(ambiguous_.size() == matchingHolders_.size());
371  }
372 
375  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
376  << "Contact a Framework developer\n";
377  }
378 
381  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
382  << "Contact a Framework developer\n";
383  }
384 
386  Principal const& principal,
387  bool skipCurrentProcess,
389  ModuleCallingContext const* mcc) const {
390  std::vector<unsigned int> const& lookupProcessOrder = principal.lookupProcessOrder();
391  for(unsigned int k : lookupProcessOrder) {
392  assert(k < ambiguous_.size());
393  if(k == 0) break; // Done
394  if(ambiguous_[k]) {
395  resolveStatus = Ambiguous;
396  return nullptr;
397  }
399  ProductHolderBase const* productHolder = principal.getProductHolderByIndex(matchingHolders_[k]);
400  ProductData const* pd = productHolder->resolveProduct(resolveStatus, principal, skipCurrentProcess, sra, mcc);
401  if(pd != nullptr) return pd;
402  }
403  }
404  resolveStatus = ProductNotFound;
405  return nullptr;
406  }
407 
409  productData().setProvenance(provRetriever,ph,pid);
410  }
411 
414  }
415 
417  return provenance()->productProvenance();
418  }
419 
422  resetStatus();
423  }
424 
426  return true;
427  }
428 
430  NoProcessProductHolder& other = dynamic_cast<NoProcessProductHolder&>(rhs);
431  ambiguous_.swap(other.ambiguous_);
433  }
434 
436  }
437 
439  }
440 
442  }
443 
445  return nullptr;
446  }
447 
449  }
450 
452  return false;
453  }
454 
457  << "NoProcessProductHolder::onDemand_() not implemented and should never be called.\n"
458  << "Contact a Framework developer\n";
459  }
460 
463  << "NoProcessProductHolder::productUnavailable_() not implemented and should never be called.\n"
464  << "Contact a Framework developer\n";
465  }
466 
469  << "NoProcessProductHolder::productWasDeleted_() not implemented and should never be called.\n"
470  << "Contact a Framework developer\n";
471  }
472 
473  void NoProcessProductHolder::putProduct_(std::unique_ptr<WrapperBase> , ProductProvenance const& ) const {
475  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
476  << "Contact a Framework developer\n";
477  }
478 
479  void NoProcessProductHolder::putProduct_(std::unique_ptr<WrapperBase> ) const {
481  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
482  << "Contact a Framework developer\n";
483  }
484 
485  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> , ProductProvenance const& ) const {
487  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
488  << "Contact a Framework developer\n";
489  }
490 
491  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase>) const {
493  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
494  << "Contact a Framework developer\n";
495  }
496 
499  << "NoProcessProductHolder::putOrMergeProduct_() not implemented and should never be called.\n"
500  << "Contact a Framework developer\n";
501  }
502 
505  << "NoProcessProductHolder::checkType_() not implemented and should never be called.\n"
506  << "Contact a Framework developer\n";
507  }
508 
511  << "NoProcessProductHolder::setProductDeleted_() not implemented and should never be called.\n"
512  << "Contact a Framework developer\n";
513  }
514 
517  << "NoProcessProductHolder::branchDescription_() not implemented and should never be called.\n"
518  << "Contact a Framework developer\n";
519  }
520 
521  void NoProcessProductHolder::resetBranchDescription_(std::shared_ptr<BranchDescription const>) {
523  << "NoProcessProductHolder::resetBranchDescription_() not implemented and should never be called.\n"
524  << "Contact a Framework developer\n";
525  }
526 }
void setProduct(std::unique_ptr< WrapperBase > prod) const
Provenance const & provenance() const
Definition: ProductData.h:30
bool mergeProduct(WrapperBase const *newProduct)
Definition: WrapperBase.h:47
virtual ProductStatus & status_() const =0
std::string const & branchName() const
WrapperBase const * product() const
Definition: ProductHolder.h:85
bool provenanceAvailable() const
virtual void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
virtual ProductProvenance const * productProvenancePtr_() const override
void setProcessHistory(ProcessHistory const &ph)
Definition: ProductData.h:59
virtual void resetProductData_() override
std::vector< ProductHolderIndex > matchingHolders_
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:196
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) override
virtual void resetStatus_() override
assert(m_qm.get())
virtual void setProductDeleted_() const override
ProductProvenance const * productProvenance() const
Definition: Provenance.cc:28
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual ProductProvenance const * productProvenancePtr_() const override
virtual bool singleProduct_() const override
virtual void checkType_(WrapperBase const &prod) const override
void write(std::ostream &os) const
bool isPresent() const
Definition: WrapperBase.h:22
std::string const & moduleLabel() const
bool productIsUnavailable() const
virtual void setProcessHistory_(ProcessHistory const &ph) override
void unsafe_setWrapper(std::unique_ptr< WrapperBase > iValue) const
Definition: ProductData.cc:36
virtual bool singleProduct_() const override
virtual void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) override
void setProvenance(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid)
Definition: ProductData.h:63
virtual bool putOrMergeProduct_() const override
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
std::string const & className() const
Provenance const * provenance() const
virtual void setProcessHistory_(ProcessHistory const &ph) override
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:469
void resetProductData()
Definition: ProductData.h:51
virtual void resetProductData_() override
virtual bool productUnavailable_() const override
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:206
bool onDemand() const
Definition: ProductHolder.h:79
virtual bool putOrMergeProduct_() const override
virtual void resetProductData_() override
def move
Definition: eostools.py:510
TypeID unwrappedTypeID() const
ProductID const & productID() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual bool productUnavailable_() const override
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
bool productWasDeleted() const
Definition: ProductHolder.h:82
ProductData const & productData() const
Definition: ProductHolder.h:41
void setProductUnavailable() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual void setProductDeleted_() const override
virtual ProductProvenance const * productProvenancePtr_() const override
virtual bool onDemand_() const override
NoProcessProductHolder(std::vector< ProductHolderIndex > const &matchingHolders, std::vector< bool > const &ambiguous)
virtual ProductProvenance const * productProvenancePtr_() const override
void throwProductDeletedException() const
eventsetup::produce::Produce produced
Definition: ESProducts.cc:20
void reallyCheckType(WrapperBase const &prod) const
std::string const & processName() const
tuple pid
Definition: sysUtil.py:22
void mergeTheProduct(std::unique_ptr< WrapperBase > edp) const
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
std::vector< bool > ambiguous_
virtual bool singleProduct_() const override
virtual void swap_(ProductHolderBase &rhs) override
virtual BranchDescription const & branchDescription_() const override
virtual bool putOrMergeProduct_() const override
virtual bool productUnavailable_() const override
ProductData const * resolveProduct(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: ProductHolder.h:49
virtual void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) override
ProductStatus & status() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual ProductData const & getProductData() const override
WrapperBase * unsafe_product() const
virtual void putProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
virtual bool singleProduct_() const override
virtual void resetProductData_() override
virtual bool productWasDeleted_() const override
bool hasIsProductEqual() const
Definition: WrapperBase.h:48
TypeID productType() const
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
virtual bool unscheduledFill(std::string const &moduleLabel, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
bool isProductEqual(WrapperBase const *newProduct) const
Definition: WrapperBase.h:49
virtual void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) override
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
virtual bool productWasDeleted_() const override
virtual void mergeProduct_(std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const override
std::string const & productInstanceName() const
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
bool productUnavailable() const
Definition: ProductHolder.h:73