LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::ProductPtr< T > Class Template Reference

#include "fwd.h"

Public Types

using value_type = T
 
using const_pointer = T const *
 
using const_reference = T const &
 

Public Member Functions

 ProductPtr ()=default
 
template<typename H >
 ProductPtr (H const &handle)
 
 ProductPtr (ProductID const &productID, EDProductGetter const *prodGetter)
 
template<typename U >
 ProductPtr (ProductPtr< U > const &pu, std::enable_if_t< std::is_base_of_v< T, U >> *=nullptr)
 
template<typename U >
 ProductPtr (ProductPtr< U > const &pu, std::enable_if_t< std::is_base_of_v< U, T >> *=nullptr)
 
T const & operator* () const
 
T const * get () const
 
T const * operator-> () const
 
 operator bool () const
 
RefCore const & refCore () const noexcept
 
ProductID id () const noexcept
 
EDProductGetter const * productGetter () const noexcept
 
bool isAvailable () const
 
bool hasCache () const noexcept
 

Static Public Member Functions

static constexpr short Class_Version () noexcept
 

Private Member Functions

T const * product_ () const
 

Private Attributes

RefCore core_ {}
 

Detailed Description

template<typename T>
class art::ProductPtr< T >

Definition at line 24 of file fwd.h.

Member Typedef Documentation

template<typename T>
using art::ProductPtr< T >::const_pointer = T const*

Definition at line 50 of file ProductPtr.h.

template<typename T>
using art::ProductPtr< T >::const_reference = T const&

Definition at line 51 of file ProductPtr.h.

template<typename T>
using art::ProductPtr< T >::value_type = T

Definition at line 49 of file ProductPtr.h.

Constructor & Destructor Documentation

template<typename T>
art::ProductPtr< T >::ProductPtr ( )
default
template<typename T>
template<typename H >
art::ProductPtr< T >::ProductPtr ( H const &  handle)
inlineexplicit

Definition at line 57 of file ProductPtr.h.

References art::ProductPtr< T >::core_, art::RefCore::id(), art::errors::InvalidReference, and art::RefCore::isNull().

58  : core_{handle.id(), handle.product(), nullptr}
59  {
60  if (core_.isNull()) {
62  << "Attempt to construct a ProductPtr from a Handle with invalid "
63  "ProductID. "
64  "Perhaps a\n"
65  "default-constructed ProductPtr is what you want?";
66  }
67  }
constexpr bool isNull() const noexcept
Definition: RefCore.h:33
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
art::ProductPtr< T >::ProductPtr ( ProductID const &  productID,
EDProductGetter const *  prodGetter 
)
inline

Definition at line 70 of file ProductPtr.h.

71  : core_{productID, nullptr, prodGetter}
72  {}
template<typename T>
template<typename U >
art::ProductPtr< T >::ProductPtr ( ProductPtr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< T, U >> *  = nullptr 
)
inline

Definition at line 76 of file ProductPtr.h.

78  : core_{pu.id(),
79  (pu.hasCache() ? static_cast<T const*>(pu.get()) : nullptr),
80  pu.productGetter()}
81  {}
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
template<typename U >
art::ProductPtr< T >::ProductPtr ( ProductPtr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< U, T >> *  = nullptr 
)
inline

Definition at line 84 of file ProductPtr.h.

86  : core_{pu.id(), static_cast<T const*>(pu.get()), nullptr}
87  {}
constexpr ProductID id() const noexcept
Definition: RefCore.h:50

Member Function Documentation

template<typename T>
static constexpr short art::ProductPtr< T >::Class_Version ( )
inlinestaticnoexcept

Definition at line 151 of file ProductPtr.h.

152  {
153  return 10;
154  }
template<typename T>
T const* art::ProductPtr< T >::get ( ) const
inline

Definition at line 101 of file ProductPtr.h.

References art::ProductPtr< T >::core_, art::RefCore::isNull(), and art::ProductPtr< T >::operator->().

102  {
103  return core_.isNull() ? nullptr : operator->();
104  }
constexpr bool isNull() const noexcept
Definition: RefCore.h:33
T const * operator->() const
Definition: ProductPtr.h:107
template<typename T>
bool art::ProductPtr< T >::hasCache ( ) const
inlinenoexcept

Definition at line 144 of file ProductPtr.h.

References art::ProductPtr< T >::core_, and art::RefCore::productPtr().

145  {
146  return core_.productPtr() != nullptr;
147  }
void const * productPtr() const noexcept
Definition: RefCore.cc:34
template<typename T>
ProductID art::ProductPtr< T >::id ( ) const
inlinenoexcept

Definition at line 124 of file ProductPtr.h.

References art::ProductPtr< T >::core_, and art::RefCore::id().

Referenced by art::PtrRemapper::operator()(), and art::PtrRemapper::samePtrAs().

125  {
126  return core_.id();
127  }
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
bool art::ProductPtr< T >::isAvailable ( ) const
inline

Definition at line 138 of file ProductPtr.h.

References art::ProductPtr< T >::core_, and art::RefCore::isAvailable().

139  {
140  return core_.isAvailable();
141  }
bool isAvailable() const
Definition: RefCore.cc:24
template<typename T>
art::ProductPtr< T >::operator bool ( ) const
inlineexplicit

Definition at line 115 of file ProductPtr.h.

References art::ProductPtr< T >::core_, and art::RefCore::isAvailable().

115 { return core_.isAvailable(); }
bool isAvailable() const
Definition: RefCore.cc:24
template<typename T>
T const& art::ProductPtr< T >::operator* ( ) const
inline

Definition at line 94 of file ProductPtr.h.

95  {
96  // Warning: This causes a nullptr dereference if isNull!
97  return *get();
98  }
template<typename T>
T const* art::ProductPtr< T >::operator-> ( ) const
inline

Definition at line 107 of file ProductPtr.h.

References art::ProductPtr< T >::core_, art::ProductPtr< T >::product_(), art::RefCore::productPtr(), and art::RefCore::setProductPtr().

Referenced by art::ProductPtr< T >::get().

108  {
109  if (core_.productPtr() == nullptr) {
111  }
112  return reinterpret_cast<T const*>(core_.productPtr());
113  }
T const * product_() const
Definition: ProductPtr.h:158
void const * productPtr() const noexcept
Definition: RefCore.cc:34
void setProductPtr(void const *prodPtr) const noexcept
Definition: RefCore.cc:48
template<typename T>
T const* art::ProductPtr< T >::product_ ( ) const
inlineprivate

Definition at line 158 of file ProductPtr.h.

References art::ProductPtr< T >::core_, e, art::EDProductGetter::getIt(), art::RefCore::id(), art::ProductPtr< T >::productGetter(), and art::errors::ProductNotFound.

Referenced by art::ProductPtr< T >::operator->().

159  {
160  EDProduct const* product{nullptr};
161  if (productGetter()) {
162  product = productGetter()->getIt();
163  }
164  if (product == nullptr) {
166  e << "A request to resolve a ProductPtr to a product of type: "
167  << cet::demangle_symbol(typeid(T).name()) << " with ProductID "
168  << core_.id()
169  << "\ncannot be satisfied because the product cannot be found.\n";
170  if (productGetter() == nullptr) {
171  e << "The productGetter was not set -- are you trying to "
172  "dereference a ProductPtr during mixing?\n";
173  } else {
174  e << "Probably the branch containing the product is not stored in "
175  "the input file.\n";
176  }
177  throw e;
178  }
179  auto wrapped_product = dynamic_cast<Wrapper<T> const*>(product);
180  if (wrapped_product == nullptr) {
182  << "A request to resolve a Product Ptr to a product of type: "
183  << cet::demangle_symbol(typeid(T).name()) << " with ProductID"
184  << core_.id() << "\ncannot be satisfied due to a type mismatch.\n";
185  }
186  return wrapped_product->product();
187  }
EDProduct const * getIt() const
EDProductGetter const * productGetter() const noexcept
Definition: ProductPtr.h:130
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
Float_t e
Definition: plot.C:35
template<typename T>
EDProductGetter const* art::ProductPtr< T >::productGetter ( ) const
inlinenoexcept

Definition at line 130 of file ProductPtr.h.

References art::ProductPtr< T >::core_, and art::RefCore::productGetter().

Referenced by art::ProductPtr< T >::product_().

131  {
132  return core_.productGetter();
133  }
EDProductGetter const * productGetter() const noexcept
Definition: RefCore.cc:41
template<typename T>
RefCore const& art::ProductPtr< T >::refCore ( ) const
inlinenoexcept

Definition at line 118 of file ProductPtr.h.

References art::ProductPtr< T >::core_.

Referenced by art::operator<().

119  {
120  return core_;
121  }

Member Data Documentation


The documentation for this class was generated from the following files: