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*
41  ModuleCallingContext const* mcc) const {
42  if(productWasDeleted()) {
44  }
45  if(!productUnavailable()) {
46  principal_->readFromSource(*this, mcc);
47  // If the product is a dummy filler, product holder will now be marked unavailable.
48  if(product() && !productUnavailable()) {
49  // Found the match
50  resolveStatus = ProductFound;
51  return &productData_;
52  }
53  }
54  resolveStatus = ProductNotFound;
55  return nullptr;
56  }
57 
58  ProductData const*
60  bool skipCurrentProcess,
62  ModuleCallingContext const*) const {
63  if (!skipCurrentProcess) {
64  if(productWasDeleted()) {
66  }
67  if(product() && product()->isPresent()) {
68  resolveStatus = ProductFound;
69  return &productData_;
70  }
71  }
72  resolveStatus = ProductNotFound;
73  return nullptr;
74  }
75 
76  ProductData const*
78  bool skipCurrentProcess,
80  ModuleCallingContext const*) const {
81  if (!skipCurrentProcess) {
82  if(productWasDeleted()) {
84  }
85  if(product() && product()->isPresent()) {
86  resolveStatus = ProductFound;
87  return &productData_;
88  }
89  }
90  resolveStatus = ProductNotFound;
91  return nullptr;
92  }
93 
94  ProductData const*
96  bool skipCurrentProcess,
98  ModuleCallingContext const* mcc) const {
99  if (!skipCurrentProcess) {
100  if(productWasDeleted()) {
102  }
103  if(product() && product()->isPresent()) {
104  resolveStatus = ProductFound;
105  return &productData_;
106  }
107  principal_->unscheduledFill(moduleLabel(), sra, mcc);
108  if(product() && product()->isPresent()) {
109  resolveStatus = ProductFound;
110  return &productData_;
111  }
112  }
113  resolveStatus = ProductNotFound;
114  return nullptr;
115  }
116 
117  void
119  std::unique_ptr<WrapperBase> edp,
120  ProductProvenance const& productProvenance) {
121  if(product()) {
123  << "Attempt to insert more than one product on branch " << branchDescription().branchName() << "\n";
124  }
126  assert(edp.get() != nullptr);
127  assert(!provenance()->productProvenanceValid());
128  assert(status() != Present);
130  setProductProvenance(productProvenance);
131  assert(provenance()->productProvenanceValid());
132  productData().wrapper_ = std::move(edp); // ProductHolder takes ownership
133  status_() = Present;
134  }
135 
136  void
138  std::unique_ptr<WrapperBase> edp,
139  ProductProvenance& productProvenance) {
140  assert(provenance()->productProvenanceValid());
141  assert(status() == Present);
142  setProductProvenance(productProvenance);
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().wrapper_ = std::move(edp); // ProductHolder takes ownership
168  status_() = Present;
169  }
170 
171  void
173  std::unique_ptr<WrapperBase> edp,
174  ProductProvenance const& productProvenance) {
175  assert(!product());
176  assert(!provenance()->productProvenanceValid());
177  setProductProvenance(productProvenance);
178  assert(provenance()->productProvenanceValid());
179  setProduct(std::move(edp));
180  }
181 
182  void
184  std::unique_ptr<WrapperBase>,
186  assert(nullptr);
187  }
188 
189  void
190  InputProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> edp) const {
192  }
193 
194  bool
196  return(!product());
197  }
198 
199  void
200  InputProductHolder::putProduct_(std::unique_ptr<WrapperBase> edp) const {
201  assert(!product());
202  setProduct(std::move(edp));
203  }
204 
205  void
206  ProductHolderBase::mergeTheProduct(std::unique_ptr<WrapperBase> edp) const {
207  if(product()->isMergeable()) {
208  product()->mergeProduct(edp.get());
209  } else if(product()->hasIsProductEqual()) {
210  if(!product()->isProductEqual(edp.get())) {
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
233  InputProductHolder::setProduct(std::unique_ptr<WrapperBase> prod) const {
234  assert (!product());
235  if(prod.get() == nullptr || !prod->isPresent()) {
237  }
238  productData().wrapper_ = std::move(prod); // ProductHolder takes ownership
239  }
240 
241  void InputProductHolder::setProvenance_(std::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
243  productData().prov_.setStore(provRetriever);
245  }
246 
249  }
250 
252  return provenance()->productProvenance();
253  }
254 
257  resetStatus();
258  }
259 
261  return true;
262  }
263 
266  }
267 
268  void
271  }
272 
273  // This routine returns true if it is known that currently there is no real product.
274  // If there is a real product, it returns false.
275  // If it is not known if there is a real product, it returns false.
276  bool
278  if(productIsUnavailable()) {
279  return true;
280  }
281  // If there is a product, we know if it is real or a dummy.
282  if(product()) {
283  bool unavailable = !(product()->isPresent());
284  if(unavailable) {
286  }
287  return unavailable;
288  }
289  return false;
290  }
291 
292  // This routine returns true if it is known that currently there is no real product.
293  // If there is a real product, it returns false.
294  // If it is not known if there is a real product, it returns false.
295  bool
297  // If unscheduled production, the product is potentially available.
298  if(onDemand()) return false;
299  // The product is available if and only if a product has been put.
300  bool unavailable = !(product() && product()->isPresent());
301  return unavailable;
302  }
303 
304  // This routine returns true if the product was deleted early in order to save memory
305  bool
307  return status() == ProductDeleted;
308  }
309 
310  void
313  }
314 
315  void ProducedProductHolder::setProvenance_(std::shared_ptr<ProductProvenanceRetriever> provRetriever, ProcessHistory const& ph, ProductID const& pid) {
317  productData().prov_.setStore(provRetriever);
319  }
320 
323  }
324 
326  return provenance()->productProvenance();
327  }
328 
331  resetStatus();
332  }
333 
335  return true;
336  }
337 
340  << "ProducedProductHolder::setPrincipal__() not implemented and should never be called.\n"
341  << "Contact a Framework developer\n";
342  }
343 
344  bool
346  // If this product is from a the current process,
347  // the provenance is available if and only if a product has been put.
348  if(branchDescription().produced()) {
349  return product() && product()->isPresent();
350  }
351  // If this product is from a prior process, the provenance is available,
352  // although the per event part may have been dropped.
353  return true;
354  }
355 
356  TypeID
358  return TypeID(product()->wrappedTypeInfo());
359  }
360 
361  void
363  // Check if the types match.
364  TypeID typeID(prod.dynamicTypeInfo());
365  if(typeID != branchDescription().unwrappedTypeID()) {
366  // Types do not match.
368  << "Product on branch " << branchDescription().branchName() << " is of wrong type.\n"
369  << "It is supposed to be of type " << branchDescription().className() << ".\n"
370  << "It is actually of type " << typeID.className() << ".\n";
371  }
372  }
373 
374  Provenance*
376  return &(productData().prov_);
377  }
378 
379  void
380  ProductHolderBase::write(std::ostream& os) const {
381  // This is grossly inadequate. It is also not critical for the
382  // first pass.
383  os << std::string("ProductHolder for product with ID: ")
384  << productID();
385  }
386 
388  NoProcessProductHolder(std::vector<ProductHolderIndex> const& matchingHolders,
389  std::vector<bool> const& ambiguous,
390  Principal* principal) :
391  matchingHolders_(matchingHolders),
392  ambiguous_(ambiguous),
393  principal_(principal) {
394  assert(ambiguous_.size() == matchingHolders_.size());
395  }
396 
399  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
400  << "Contact a Framework developer\n";
401  }
402 
405  << "NoProcessProductHolder::getProductData() not implemented and should never be called.\n"
406  << "Contact a Framework developer\n";
407  }
408 
410  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, sra, mcc);
424  if(pd != nullptr) return pd;
425  }
426  }
427  resolveStatus = ProductNotFound;
428  return nullptr;
429  }
430 
431  void AliasProductHolder::setProvenance_(std::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_(std::shared_ptr<ProductProvenanceRetriever> , ProcessHistory const& , ProductID const& ) {
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_(std::unique_ptr<WrapperBase> , ProductProvenance const& ) {
510  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
511  << "Contact a Framework developer\n";
512  }
513 
514  void NoProcessProductHolder::putProduct_(std::unique_ptr<WrapperBase> ) const {
516  << "NoProcessProductHolder::putProduct_() not implemented and should never be called.\n"
517  << "Contact a Framework developer\n";
518  }
519 
520  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase> , ProductProvenance& ) {
522  << "NoProcessProductHolder::mergeProduct_() not implemented and should never be called.\n"
523  << "Contact a Framework developer\n";
524  }
525 
526  void NoProcessProductHolder::mergeProduct_(std::unique_ptr<WrapperBase>) const {
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_(std::shared_ptr<BranchDescription const>) {
558  << "NoProcessProductHolder::resetBranchDescription_() not implemented and should never be called.\n"
559  << "Contact a Framework developer\n";
560  }
561 }
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:84
virtual void setPrincipal_(Principal *principal) override
bool provenanceAvailable() const
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:187
virtual void setProcessHistory_(ProcessHistory const &ph) override
virtual ProductProvenance * productProvenancePtr_() const override
virtual void setPrincipal_(Principal *principal) override
virtual void resetStatus_() override
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const 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
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
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 ProductProvenance * productProvenancePtr_() const override
BranchDescription const & branchDescription() const
Definition: ProductHolder.h:93
std::string const & className() const
virtual void setProcessHistory_(ProcessHistory const &ph) override
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:463
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:195
bool onDemand() const
Definition: ProductHolder.h:78
virtual bool putOrMergeProduct_() const override
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual void resetProductData_() override
def move
Definition: eostools.py:510
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:81
ProductData const & productData() const
Definition: ProductHolder.h:41
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, SharedResourcesAcquirer *sra, 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
tuple pid
Definition: sysUtil.py:22
ProductData const * resolveProduct(ResolveStatus &resolveStatus, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: ProductHolder.h:49
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 * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
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
virtual ProductData const * resolveProduct_(ResolveStatus &resolveStatus, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) 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
virtual bool unscheduledFill(std::string const &moduleLabel, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
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:72