1 #ifndef canvas_Persistency_Common_Ptr_h 2 #define canvas_Persistency_Common_Ptr_h 51 #include "cetlib_except/demangle.h" 58 #include <type_traits> 65 template <
typename T,
typename C>
72 class
ItemGetter<std::pair<cet::map_vector_key, T>, cet::map_vector<T>>;
91 std::remove_const_t<std::remove_pointer_t<
92 decltype(handle.product())>>>()(
100 <<
"Attempt to construct a Ptr from a Handle with invalid ProductID. " 102 "default-constructed Ptr is what you want?";
108 : core_{productID,
nullptr,
nullptr}
115 : core_{productID,
nullptr, prodGetter}, key_{itemKey}
119 template <
typename U>
120 Ptr(
Ptr<U> const& pu, std::enable_if_t<std::is_base_of_v<T, U>>* =
nullptr)
127 template <
typename U>
128 Ptr(
Ptr<U> const& pu, std::enable_if_t<std::is_base_of_v<U, T>>* =
nullptr)
129 : core_{pu.
id(),
static_cast<T const*
>(pu.
get()),
nullptr}, key_{pu.key()}
134 : core_{productID, item,
nullptr}, key_{itemKey}
151 return isNull() ?
nullptr : operator->();
156 if (core_.productPtr() ==
nullptr) {
157 EDProduct const* prod = parentProduct_();
159 core_.setProductPtr(ad);
161 return reinterpret_cast<T const*
>(core_.productPtr());
198 return core_.productGetter();
206 return core_.isAvailable();
212 return core_.productPtr() !=
nullptr;
222 static constexpr
short 233 if (productGetter()) {
234 product = productGetter()->getIt();
236 if (product ==
nullptr) {
238 e <<
"A request to resolve an Ptr to a product containing items of " 240 << cet::demangle_symbol(
typeid(
T).
name()) <<
" with ProductID " 242 <<
"\ncannot be satisfied because the product cannot be found.\n";
243 if (productGetter() ==
nullptr) {
244 e <<
"The productGetter was not set -- are you trying to " 245 "dereference a Ptr during mixing?\n";
247 e <<
"Probably the branch containing the product is not stored in " 262 template <
typename T,
typename U>
263 std::enable_if_t<std::is_same_v<T, U> || std::is_base_of_v<T, U> ||
264 std::is_base_of_v<U, T>,
271 template <
typename T,
typename U>
272 std::enable_if_t<std::is_same_v<T, U> || std::is_base_of_v<T, U> ||
273 std::is_base_of_v<U, T>,
277 return !(lhs == rhs);
280 template <
typename T,
typename U>
281 std::enable_if_t<std::is_same_v<T, U> || std::is_base_of_v<T, U> ||
282 std::is_base_of_v<U, T>,
284 operator<(Ptr<T>
const& lhs,
Ptr<U> const& rhs)
289 return lhs.
refCore() == rhs.refCore() ? lhs.key() < rhs.key() :
290 lhs.refCore() < rhs.refCore();
295 template <
typename T,
typename H>
299 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
300 ptrs.emplace_back(h, i);
305 template <
typename T,
typename H>
309 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
310 ptrs.emplace_back(h, i);
314 template <
typename T>
316 operator<<(std::ostream& os, Ptr<T>
const&
p)
318 os <<
"(" <<
p.id() <<
", " <<
p.key() <<
")";
325 template <
typename TO,
typename PTRVAL>
331 return addr<TO, PTRVAL const>(*from);
337 return addr<TO, PTRVAL const>(*from);
347 template <
typename T,
typename C>
354 assert(product !=
nullptr);
355 auto it = product->begin();
362 template <
typename T>
370 assert(product !=
nullptr);
376 template <
typename T>
380 std::pair<cet::map_vector_key, T>
const*
384 assert(product !=
nullptr);
386 auto it = product->
find(k);
387 if (it == product->
end()) {
400 template <
typename T>
401 struct hash<
art::Ptr<T>> {
Ptr(Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< T, U >> *=nullptr)
Ptr(ProductID const &productID, T const *item, key_type const itemKey)
bool hasCache() const noexcept
iterator find(key_type key)
EDProduct const * parentProduct_() const
std::pair< cet::map_vector_key, T > const * operator()(cet::map_vector< T > const *product, typename Ptr< T >::key_type iKey) const
size_t operator()(ptr_t const &p) const noexcept
T const & operator*() const
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
Ptr(ProductID const &productID)
T const * operator()(cet::map_vector< T > const *product, typename Ptr< T >::key_type iKey) const
T const * operator->() const
key_type key() const noexcept
T const * operator()(C const *product, typename Ptr< T >::key_type iKey) const
typename ptr_t::key_type key_t
bool isNull() const noexcept
ProductID id() const noexcept
TO operator()(Ptr< PTRVAL > &from) const
static auto const * address(const_iterator const &i)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
bool isNonnull() const noexcept
void fill_ptr_list(std::list< Ptr< T >> &ptrs, H const &h)
TO operator()(Ptr< PTRVAL > const &from) const
EDProductGetter const * productGetter() const noexcept
Ptr(H const &handle, typename Ptr< T >::key_type key)
Ptr(ProductID const &productID, key_type itemKey, EDProductGetter const *prodGetter)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
L const & const_reference
void const * getElementAddress(std::type_info const &toType, unsigned long index) const
static constexpr short Class_Version() noexcept
Ptr(Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< U, T >> *=nullptr)
RefCore const & refCore() const noexcept
mapped_type * getOrNull(key_type key)
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept