1 #ifndef canvas_Persistency_Common_Wrapper_h 2 #define canvas_Persistency_Common_Wrapper_h 21 #include "cetlib/metaprogramming.h" 22 #include "cetlib_except/demangle.h" 38 using cet::enable_if_function_exists_t;
44 template <
typename T,
typename =
void>
52 template <
typename T,
typename =
void>
58 enable_if_function_exists_t<std::unique_ptr<EDProduct> (T::*)(
59 std::type_info const&) const,
60 &T::makePartner>> : std::true_type {};
83 explicit Wrapper(std::unique_ptr<T> ptr);
86 T
const* product()
const;
87 T
const* operator->()
const;
97 std::vector<void const*> getView()
const override;
99 std::string productSize()
const override;
102 std::unique_ptr<EDProduct> do_makePartner(
103 std::type_info
const& wanted_type)
const override;
105 unsigned do_getRangeSetID()
const override;
106 void do_setRangeSetID(
unsigned)
override;
107 void do_combine(
EDProduct const* product)
override;
108 std::unique_ptr<EDProduct> do_createEmptySampledProduct(
109 InputTag const& tag)
const override;
114 void do_insertIfSampledProduct(std::string
const& dataset,
116 std::unique_ptr<EDProduct> product)
override;
123 std::type_info
const* typeInfo_()
const override;
125 void const* do_getElementAddress(std::type_info
const& toType,
126 unsigned long index)
const override;
128 std::vector<void const*> do_getElementAddresses(
129 std::type_info
const& toType,
130 std::vector<unsigned long>
const&
indices)
const override;
132 T&& refOrThrow(T* ptr);
135 unsigned rangeSetID{-1u};
154 #include <type_traits> 160 template <
typename T>
165 template <
typename T>
172 template <
typename T>
179 template <
typename T>
180 std::type_info
const*
186 template <
typename T>
187 std::vector<void const*>
193 template <
typename T>
205 template <
typename T>
220 template <
typename T>
227 template <
typename T>
234 template <
typename T>
241 template <
typename T>
242 std::unique_ptr<art::EDProduct>
245 std::unique_ptr<art::EDProduct> retval;
247 retval =
obj.makePartner(wanted_wrapper);
250 <<
"Attempted to make partner of a product (" 251 << cet::demangle_symbol(
typeid(T).name()) <<
") that does not know how!\n" 252 <<
"Please report to the art framework developers.\n";
258 template <
typename T>
260 static std::unique_ptr<EDProduct>
263 auto emptySampledProduct = std::make_unique<Sampled<T>>(tag);
264 return std::make_unique<Wrapper<Sampled<T>>>(
265 std::move(emptySampledProduct));
268 [[noreturn]]
static void 270 std::string
const& dataset,
272 std::unique_ptr<EDProduct>)
275 <<
"An attempt was made to insert a product from dataset '" << dataset
276 <<
"'\ninto a non-sampled product of type '" 277 << cet::demangle_symbol(
typeid(T).name()) <<
"'.\n" 278 <<
"Please contact artists@fnal.gov for guidance.";
282 template <
typename T>
284 [[noreturn]]
static std::unique_ptr<EDProduct>
288 <<
"An attempt was made to create an empty sampled product\n" 289 <<
"for a sampled product. This type of recursion is not allowed.\n" 290 <<
"Please contact artists@fnal.gov for guidance.";
295 std::string
const& dataset,
297 std::unique_ptr<EDProduct>
product)
299 auto& wp =
dynamic_cast<Wrapper<T>&
>(*product);
300 obj.
insert(dataset,
id, std::move(wp.obj));
305 template <
typename T>
306 std::unique_ptr<art::EDProduct>
312 template <
typename T>
316 std::unique_ptr<EDProduct>
product)
319 obj, dataset,
id, std::move(product));
322 template <
typename T>
325 unsigned long const index
326 [[maybe_unused]])
const 332 void const* result{
nullptr};
337 <<
"The product type " << cet::demangle_symbol(
typeid(T).name())
338 <<
" does not support art::Ptr\n";
342 template <
typename T>
343 inline std::vector<void const*>
345 std::type_info
const& toType,
346 std::vector<unsigned long>
const&
indices)
const 354 std::vector<void const*> result;
359 <<
"The product type " << cet::demangle_symbol(
typeid(T).name())
360 <<
" does not support art::PtrVector\n";
364 template <
typename T>
369 return std::move(*ptr);
372 <<
"Attempt to construct " << cet::demangle_symbol(
typeid(*this).name())
373 <<
" from nullptr.\n";
static product_typeids_t get()
static void insert_if_sampled_product(Sampled< T > &obj, std::string const &dataset, SubRunID const &id, std::unique_ptr< EDProduct > product)
unsigned do_getRangeSetID() const override
T const * operator->() const
std::unique_ptr< EDProduct > do_makePartner(std::type_info const &wanted_type) const override
decltype(std::declval< T const >().size()) size_expression_t
std::unique_ptr< EDProduct > do_createEmptySampledProduct(InputTag const &tag) const override
void do_insertIfSampledProduct(std::string const &dataset, SubRunID const &id, std::unique_ptr< EDProduct > product) override
static std::type_info const * type_id()
std::type_info const * typeInfo_() const override
bool isPresent_() const override
static short Class_Version()
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void do_combine(EDProduct const *product) override
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
void setPtr(COLLECTION const &coll, std::type_info const &iToType, unsigned long iIndex, void const *&oPtr)
static void aggregate(T &, T const &)
void const * do_getElementAddress(std::type_info const &toType, unsigned long index) const override
T const * product() const
std::vector< void const * > do_getElementAddresses(std::type_info const &toType, std::vector< unsigned long > const &indices) const override
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
void getElementAddresses(Collection const &coll, std::type_info const &iToType, std::vector< unsigned long > const &indices, std::vector< void const * > &oPtr)
void insert(std::string const &dataset, SubRunID const &id, T &&value)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
static std::vector< void const * > get(T const &)
std::map< product_metatype, TypeID > product_typeids_t
std::vector< void const * > getElementAddresses(std::type_info const &toType, std::vector< unsigned long > const &indices) const
product_typeids_t do_getTypeIDs() const override
static std::unique_ptr< EDProduct > create_empty_sampled_product(InputTag const &)
static std::unique_ptr< EDProduct > create_empty_sampled_product(InputTag const &tag)
std::string productSize() const override
std::vector< void const * > getView() const override
static void insert_if_sampled_product(T &, std::string const &dataset, SubRunID const &, std::unique_ptr< EDProduct >)
std::string to_string(ModuleType const mt)
void do_setRangeSetID(unsigned) override
constexpr ProductStatus present() noexcept