LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Group.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
9 #include "cetlib_except/demangle.h"
10 
11 #include <string>
12 
15 {
16  if (dropped()) {
17  return productstatus::dropped();
18  }
19  cet::exempt_ptr<ProductProvenance const> pp(productProvenancePtr());
20  if (!pp) {
21  // No provenance, must be new.
22  if (product_.get()) {
23  if (product_->isPresent()) {
24  return productstatus::present();
25  }
27  }
28  return productstatus::unknown();
29  }
30  if (product_.get()) {
31  // Product has already been delay read, use the present flag
32  // from the wrapper.
33  // FIXME: Old CMS note said backward compatibility only?
34  if (product_->isPresent()) {
35  pp->setPresent();
36  } else {
37  pp->setNotPresent();
38  }
39  }
40  // Not new, and not yet read, use the status from the provenance.
41  return pp->productStatus();
42 }
43 
44 bool
45 art::Group::resolveProduct(TypeID const& wanted_wrapper_type) const
46 {
47  if (!productUnavailable()) {
48  return resolveProductIfAvailable(wanted_wrapper_type);
49  }
50  art::Exception e{errors::ProductNotFound, "InaccessibleProduct"};
51  e << "resolveProduct: product is not accessible\n"
52  << productDescription() << '\n';
53  if (productProvenancePtr()) {
54  e << *productProvenancePtr() << '\n';
55  }
56  throw e;
57 }
58 
59 bool
60 art::Group::resolveProductIfAvailable(TypeID const& wanted_wrapper_type) const
61 {
62  if (wanted_wrapper_type != wrapperType_) {
63  throwResolveLogicError(wanted_wrapper_type);
64  }
65  bool result = product_.get();
66  if (!(result || productUnavailable())) {
67  std::unique_ptr<EDProduct> edp{obtainDesiredProduct(wanted_wrapper_type)};
68  if ((result = edp.get())) {
69  setProduct(std::move(edp));
70  }
71  }
72  return result;
73 }
74 
75 std::unique_ptr<art::EDProduct>
76 art::Group::obtainDesiredProduct(TypeID const& wanted_wrapper_type) const
77 {
78  BranchKey const bk{productDescription()};
79  return productResolver_->getProduct(
80  bk, wanted_wrapper_type, rangeOfValidity_);
81 }
82 
83 bool
85 {
86  if (dropped()) {
87  return true;
88  }
90  return false;
91  }
92  return !productstatus::present(status());
93 }
94 
95 cet::exempt_ptr<art::ProductProvenance const>
97 {
98  if (!ppResolver_) {
99  return cet::exempt_ptr<ProductProvenance const>{};
100  }
101  return ppResolver_->branchToProductProvenance(
102  branchDescription_->productID());
103 }
104 
105 void
107 {
108  // This check should already have been done by the surrounding art
109  // code, therefore this is a precondition and valid for an assertion
110  // rather than a runtime check and throw.
111  assert(!(branchDescription_ && branchDescription_->produced()));
112  product_.reset();
113 }
114 
115 void
116 art::Group::setProduct(std::unique_ptr<EDProduct>&& prod) const
117 {
118  assert(!product_.get());
119  product_ = std::move(prod);
120 }
121 
122 void
123 art::Group::throwResolveLogicError(TypeID const& wanted_wrapper_type) const
124 {
125  throw Exception(errors::LogicError, "INTERNAL ERROR: ")
126  << cet::demangle_symbol(typeid(*this).name())
127  << " cannot resolve wanted product of type "
128  << wanted_wrapper_type.className() << ".\n";
129 }
130 
131 bool
133 {
134  assert(branchDescription_);
135  return branchDescription_->dropped();
136 }
137 
138 void
139 art::Group::write(std::ostream& os) const
140 {
141  // This is grossly inadequate. It is also not critical for the
142  // first pass.
143  os << "Group for product with ID: " << pid_;
144 }
cet::exempt_ptr< BranchDescription const > branchDescription_
Definition: Group.h:191
bool productUnavailable() const
Definition: Group.cc:84
ProductID pid_
Definition: Group.h:192
ProductStatus unknown()
Definition: ProductStatus.h:31
unsigned char ProductStatus
Definition: ProductStatus.h:12
cet::exempt_ptr< ProductProvenance const > productProvenancePtr() const
Definition: Group.cc:96
bool resolveProductIfAvailable(TypeID const &) const override
Definition: Group.cc:60
RangeSet rangeOfValidity_
Definition: Group.h:194
std::string className() const
Definition: TypeID.cc:21
std::unique_ptr< EDProduct > product_
Definition: Group.h:190
virtual void removeCachedProduct() const
Definition: Group.cc:106
void write(std::ostream &os) const
Definition: Group.cc:139
ProductStatus dropped()
Definition: ProductStatus.h:26
TypeID wrapperType_
Definition: Group.h:187
cet::exempt_ptr< BranchMapper const > ppResolver_
Definition: Group.h:188
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< EDProduct > obtainDesiredProduct(TypeID const &) const
Definition: Group.cc:76
ProductStatus status() const
Definition: Group.cc:14
void setProduct(std::unique_ptr< EDProduct > &&prod) const
Definition: Group.cc:116
void throwResolveLogicError(TypeID const &wanted_wrapper_type) const
Definition: Group.cc:123
bool resolveProduct(TypeID const &) const override
Definition: Group.cc:45
cet::exempt_ptr< DelayedReader const > productResolver_
Definition: Group.h:189
Float_t e
Definition: plot.C:34
ProductStatus present()
Definition: ProductStatus.h:16
bool dropped() const
Definition: Group.cc:132
BranchDescription const & productDescription() const
Definition: Group.h:117
ProductStatus neverCreated()
Definition: ProductStatus.h:21