1 #ifndef canvas_Persistency_Common_Ptr_h 2 #define canvas_Persistency_Common_Ptr_h 50 #include "cetlib_except/demangle.h" 57 #include <type_traits> 64 template <
typename T,
typename C>
71 class
ItemGetter<std::pair<cet::map_vector_key, T>, cet::map_vector<T>>;
92 handle.productGetter()}
97 <<
"Attempt to construct a Ptr from a Handle with invalid ProductID. " 99 "default-constructed Ptr is what you want?";
107 : core_{productID,
nullptr, prodGetter}, key_{itemKey}
111 template <
typename U>
112 Ptr(
Ptr<U> const& pu, std::enable_if_t<std::is_base_of_v<T, U>>* =
nullptr)
116 template <
typename U>
117 Ptr(
Ptr<U> const& pu, std::enable_if_t<std::is_base_of_v<U, T>>* =
nullptr)
118 : core_{pu.
id(),
static_cast<T const*
>(pu.
get()),
nullptr}, key_{pu.key()}
123 : core_{productID, item,
nullptr}, key_{itemKey}
140 return isNull() ?
nullptr : operator->();
146 if (core_.productPtr() ==
nullptr) {
147 EDProduct const* prod = parentProduct_();
149 core_.setProductPtr(ad);
151 return reinterpret_cast<T const*
>(core_.productPtr());
154 explicit operator bool()
const 156 return isNonnull() && core_.isAvailable();
172 template <
typename Collection>
177 auto product = parentProduct_();
179 if (wrapped_product ==
nullptr) {
181 <<
"A request to retrieve the parent collection of type: " 182 << cet::demangle_symbol(
typeid(Collection).name())
183 <<
" with ProductID " << core_.id()
184 <<
"\ncannot be satisfied due to a type mismatch.\n";
186 return *wrapped_product->product();
189 template <
template <
typename...>
class Collection,
typename U = T>
193 return parentAs<Collection<U>>();
221 return core_.isAvailable();
225 static constexpr
short 234 return core_.productGetter();
242 if (productGetter()) {
243 product = productGetter()->getIt();
245 if (product ==
nullptr) {
247 e <<
"A request to resolve an Ptr to a product containing items of " 249 << cet::demangle_symbol(
typeid(T).name()) <<
" with ProductID " 251 <<
"\ncannot be satisfied because the product cannot be found.\n";
252 if (productGetter() ==
nullptr) {
253 e <<
"The productGetter was not set -- are you trying to " 254 "dereference a Ptr during mixing?\n";
256 e <<
"Probably the branch containing the product is not stored in " 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>,
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>,
286 return !(lhs == rhs);
289 template <
typename T,
typename U>
290 std::enable_if_t<std::is_same_v<T, U> || std::is_base_of_v<T, U> ||
291 std::is_base_of_v<U, T>,
293 operator<(Ptr<T>
const& lhs,
Ptr<U> const& rhs)
298 return lhs.
refCore() == rhs.refCore() ? lhs.key() < rhs.key() :
299 lhs.refCore() < rhs.refCore();
304 template <
typename T,
typename H>
308 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
309 ptrs.emplace_back(h, i);
314 template <
typename T,
typename H>
318 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
319 ptrs.emplace_back(h, i);
323 template <
typename T>
325 operator<<(std::ostream& os, Ptr<T>
const& p)
327 os <<
"(" << p.id() <<
", " << p.key() <<
")";
334 template <
typename TO,
typename PTRVAL>
339 return addr<TO, PTRVAL const>(*from);
345 return addr<TO, PTRVAL const>(*from);
355 template <
typename T,
typename C>
361 assert(product !=
nullptr);
362 auto it = product->begin();
368 template <
typename T>
375 assert(product !=
nullptr);
376 return product->getOrNull(cet::map_vector_key{key});
380 template <
typename T>
383 std::pair<cet::map_vector_key, T>
const*
387 assert(product !=
nullptr);
388 auto it = product->find(cet::map_vector_key{key});
389 if (it == product->end()) {
396 template <
typename T>
398 using type =
typename T::value_type;
401 template <
typename T>
404 template <
typename T>
413 template <
typename H,
typename T>
420 template <
typename 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)
T const * operator()(cet::map_vector< T > const *product, typename Ptr< T >::key_type key) const
typename T::value_type type
EDProduct const * parentProduct_() const
size_t operator()(ptr_t const &p) const noexcept
T const & operator*() const
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
Collection const & parentAs() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Ptr(H, T) -> Ptr< detail::not_map_vector_t< typename H::element_type >>
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
typename NotMapVector< T >::type not_map_vector_t
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)
Collection< U > const & parentAs() const
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)
std::pair< cet::map_vector_key, T > const * operator()(cet::map_vector< T > const *product, typename Ptr< T >::key_type key) const
RefCore const & refCore() const noexcept
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept