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 U>
68 operator==(Ptr<T>
const& lhs, Ptr<U>
const& rhs);
69 template <
typename T,
typename U>
73 operator!=(Ptr<T>
const& lhs, Ptr<U>
const& rhs);
74 template <
typename T,
typename U>
78 operator<(Ptr<T>
const& lhs, Ptr<U>
const& rhs);
82 template <
typename T,
typename H>
86 template <
typename T,
typename H>
91 template <
typename TO,
typename PTRVAL>
92 struct EnsurePointer<TO, Ptr<PTRVAL>>;
96 std::ostream& operator<<(std::ostream&, Ptr<T>
const&);
111 template <
typename H>
112 Ptr(H
const& handle, key_type idx);
123 template <
typename U>
127 template <
typename U>
132 Ptr(
ProductID const productID, T
const* item, key_type itemKey);
136 T
const* operator->()
const;
137 T
const*
get()
const;
139 bool isNonnull()
const;
143 bool isAvailable()
const;
146 key_type key()
const;
147 bool hasCache()
const;
148 RefCore const& refCore()
const;
150 explicit operator bool()
const;
161 template <
typename C>
162 T
const* getItem_(C
const* product, key_type iKey);
163 void getData_()
const;
169 template <
typename TO,
typename PTRVAL>
183 template <
typename T,
typename C>
185 template <
typename T>
187 template <typename T>
188 class
ItemGetter<std::pair<cet::map_vector_key, T>, cet::map_vector<T>>;
192 template <typename T, typename C>
195 T
const* operator()(C
const* product,
typename Ptr<T>::key_type iKey)
const;
198 template <
typename T,
typename C>
203 assert(product !=
nullptr);
204 auto it = product->begin();
210 template <
typename T>
213 T
const* operator()(cet::map_vector<T>
const* product,
217 template <
typename T>
220 cet::map_vector<T>
const* product,
223 assert(product !=
nullptr);
224 cet::map_vector_key k(iKey);
225 return product->getOrNull(k);
228 template <
typename T>
230 cet::map_vector<T>> {
232 std::pair<cet::map_vector_key, T>
const* operator()(
233 cet::map_vector<T>
const* product,
237 template <
typename T>
238 inline std::pair<cet::map_vector_key, T>
const*
240 operator()(cet::map_vector<T>
const* product,
243 assert(product !=
nullptr);
244 cet::map_vector_key k(static_cast<unsigned>(iKey));
245 auto it = product->find(k);
246 if (it == product->end()) {
256 template <
typename T>
257 template <
typename H>
259 : core_{handle.id(),
getItem_(handle.product(), idx),
nullptr},
key_{idx}
263 <<
"Attempt to construct a Ptr from a Handle with invalid ProductID. " 264 "Perhaps a\ndefault-constructed Ptr is what you want?";
268 template <
typename T>
273 template <
typename T>
277 :
core_{productID, 0, prodGetter},
key_{itemKey}
280 template <
typename T>
281 template <
typename U>
285 (iOther.
hasCache() ? static_cast<T const*>(iOther.
get()) :
286 static_cast<T const*>(nullptr)),
291 template <
typename T>
292 template <
typename U>
295 :
core_{iOther.
id(),
dynamic_cast<T const*
>(iOther.
get()),
nullptr}
299 template <
typename T>
303 :
core_{productID, item,
nullptr},
key_{itemKey}
306 template <
typename T>
312 template <
typename T>
319 template <
typename T>
326 template <
typename T>
333 template <
typename T>
340 template <
typename T>
347 template <
typename T>
354 template <
typename T>
361 template <
typename T>
368 template <
typename T>
375 template <
typename T>
381 template <
typename T>
388 template <
typename T>
389 template <
typename C>
396 template <
typename T>
403 if (prod ==
nullptr) {
405 e <<
"A request to resolve an art::Ptr to a product containing items of " 407 << cet::demangle_symbol(
typeid(T).name()) <<
" with ProductID " 409 <<
"\ncannot be satisfied because the product cannot be found.\n";
411 e <<
"The productGetter was not set -- are you trying to dereference a " 412 "Ptr during mixing?\n";
414 e <<
"Probably the branch containing the product is not stored in the " 419 void const* ad =
nullptr;
425 template <
typename T,
typename U>
436 template <
typename T,
typename U>
444 return !(lhs == rhs);
447 template <
typename T,
typename U>
449 art::operator<(Ptr<T>
const& lhs,
Ptr<U> const& rhs)
458 return (lhs.refCore() == rhs.
refCore() ? lhs.key() < rhs.
key() :
459 lhs.refCore() < rhs.
refCore());
462 template <
typename T,
typename H>
466 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
467 ptrs.emplace_back(h, i);
471 template <
typename T,
typename H>
475 for (std::size_t i = 0, sz = h->size(); i != sz; ++i) {
476 ptrs.emplace_back(h, i);
480 template <
typename TO,
typename PTRVAL>
485 return detail::addr<TO, PTRVAL const>(*from);
488 template <
typename TO,
typename PTRVAL>
493 return detail::addr<TO, PTRVAL const>(*from);
496 template <
typename T>
498 art::operator<<(std::ostream& os, Ptr<T>
const& p)
500 os <<
"(" << p.id() <<
", " << p.key() <<
")";
virtual EDProduct const * getIt() const =0
EDProductGetter const * productGetter() const
static element_type const * address(iter const &i)
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
T const * operator->() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
EDProductGetter const * productGetter() const
RefCore const & refCore() const
T const & operator*() const
typename ptr_t::key_type key_t
T const * getItem_(C const *product, key_type iKey)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
void const * productPtr() const
void fill_ptr_list(std::list< Ptr< T >> &ptrs, H const &h)
std::string value(boost::any const &)
T const * operator()(C const *product, typename Ptr< T >::key_type iKey) const
static short Class_Version()
size_t operator()(ptr_t const &p) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
bool operator==(Provenance const &a, Provenance const &b)
QuadExpr operator*(double v, const QuadExpr &e)
void setPtr(std::type_info const &toType, unsigned long index, void const *&ptr) const
T const & const_reference
void setProductPtr(void const *prodPtr) const