LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
AssnsGroup.cc
Go to the documentation of this file.
2 // vim: set sw=2:
3 
4 #include "cetlib_except/demangle.h"
5 
6 art::EDProduct const*
8 {
9  return uniqueProduct();
10 }
11 
12 art::EDProduct const*
14 {
15  art::EDProduct const* result = Group::anyProduct();
16  if (result == nullptr) {
17  result = partnerProduct_.get();
18  }
19  return result;
20 }
21 
22 art::EDProduct const*
24 {
25  throw Exception(errors::LogicError, "AmbiguousProduct")
26  << cet::demangle_symbol(typeid(*this).name())
27  << " was asked for a held product (uniqueProduct()) "
28  << "without specifying which one was wanted.\n";
29 }
30 
31 art::EDProduct const*
32 art::AssnsGroup::uniqueProduct(TypeID const& wanted_wrapper_type) const
33 {
34  EDProduct const* retval = nullptr;
35  if (wanted_wrapper_type == partnerWrapperType_) {
36  retval = partnerProduct_.get();
37  } else {
38  retval = Group::uniqueProduct();
39  }
40  return retval;
41 }
42 
43 bool
45  TypeID const& wanted_wrapper_type) const
46 {
47  // Ask us for something we can do.
48  if (!(wanted_wrapper_type == producedWrapperType() ||
49  wanted_wrapper_type == partnerWrapperType_)) {
50  throwResolveLogicError(wanted_wrapper_type);
51  }
53  if (!(productUnavailable() ||
54  (result = uniqueProduct(wanted_wrapper_type))) &&
55  Group::uniqueProduct() != nullptr) {
56  if (wanted_wrapper_type == partnerWrapperType_) {
57  // We know at this point that our wanted object has not been read
58  // or created yet.
59  result = makePartner(wanted_wrapper_type, partnerProduct_);
60  }
61  }
62  return result;
63 }
64 
65 void
67 {
69  partnerProduct_.reset();
70 }
EDProduct const * uniqueProduct() const override
Definition: AssnsGroup.cc:23
TypeID partnerWrapperType_
Definition: AssnsGroup.h:116
bool productUnavailable() const
Definition: Group.cc:84
EDProduct const * anyProduct() const override
Definition: AssnsGroup.cc:13
std::unique_ptr< EDProduct > partnerProduct_
Definition: AssnsGroup.h:117
TypeID const & producedWrapperType() const
Definition: Group.h:162
bool resolveProductIfAvailable(TypeID const &) const override
Definition: Group.cc:60
virtual void removeCachedProduct() const
Definition: Group.cc:106
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EDProduct const * getIt() const override
Definition: AssnsGroup.cc:7
EDProduct const * uniqueProduct() const override
Definition: Group.h:103
bool makePartner(TypeID const &wanted_wrapper_type, std::unique_ptr< EDProduct > &partner) const
Definition: AssnsGroup.h:103
bool resolveProductIfAvailable(TypeID const &) const override
Definition: AssnsGroup.cc:44
void throwResolveLogicError(TypeID const &wanted_wrapper_type) const
Definition: Group.cc:123
EDProduct const * anyProduct() const override
Definition: Group.h:97
void removeCachedProduct() const override
Definition: AssnsGroup.cc:66