1 #ifndef canvas_Persistency_Common_Assns_h 2 #define canvas_Persistency_Common_Assns_h 93 #include "cetlib/container_algorithms.h" 94 #include "cetlib_except/demangle.h" 102 template <
typename L,
typename R,
typename D =
void>
107 template <
typename LR>
108 class Assns<LR, LR, void>;
110 template <
typename LR,
typename D>
111 class Assns<LR, LR, D>;
113 template <
typename L,
typename R>
114 class Assns<L, R, void>;
123 template <
typename L,
typename R>
132 using ptr_data_t = std::vector<std::pair<RefCore, std::size_t>>;
135 using assn_t =
typename ptrs_t::value_type;
143 virtual ~
Assns() =
default;
151 std::string className()
const;
156 template <
typename Ls>
157 void addMany(Ls
const& lefts, Ptr<right_t>
const&
right);
159 template <
typename Rs>
164 std::unique_ptr<EDProduct> makePartner(
165 std::type_info
const& wanted_wrapper_type)
const;
180 virtual std::unique_ptr<EDProduct> makePartner_(
181 std::type_info
const& wanted_wrapper_type)
const;
184 friend class detail::AssnsStreamer;
193 #ifdef ROOT_CAN_REGISTER_IOREADS_PROPERLY 200 #ifndef ROOT_CAN_REGISTER_IOREADS_PROPERLY 205 void fill_transients()
override;
206 void fill_from_transients()
override;
216 template <
typename L,
typename R,
typename D>
227 !std::is_same_v<D, bool>,
228 "\n\nart error: An 'Assns<A, B, D>' object with D = bool is not allowed.\n" 229 " If you decide that D must represent a boolean type, then we\n" 230 " recommend that you wrap a boolean value in a struct (e.g.):\n\n" 231 " struct WrappedBool { bool flag; };\n\n" 232 " Please contact artists@fnal.gov for guidance.\n");
253 using base::operator[];
256 data_t const& data(
typename std::vector<data_t>::size_type index)
const;
261 Ptr<right_t>
const&
right,
264 template <
typename Ls,
typename Ds>
265 void addMany(Ls
const& lefts, Ptr<right_t>
const&
right, Ds
const& data);
267 template <
typename Rs,
typename Ds>
268 void addMany(
Ptr<left_t> const&
left, Rs
const& rights, Ds
const& data);
274 std::unique_ptr<EDProduct> makePartner(
275 std::type_info
const& wanted_wrapper_type)
const;
292 std::type_info
const& wanted_wrapper_type)
const override;
301 template <
typename L,
typename R>
305 template <
typename L,
typename R>
308 ptrs_.reserve(other.ptrs_.
size());
310 other.ptrs_, std::back_inserter(ptrs_), [](
auto const& pr) {
311 using pr_t = typename ptrs_t::value_type;
312 return pr_t{pr.second, pr.first};
316 template <
typename L,
typename R>
320 return ptrs_.begin();
323 template <
typename L,
typename R>
330 template <
typename L,
typename R>
337 template <
typename L,
typename R>
341 return ptrs_.at(index);
344 template <
typename L,
typename R>
351 template <
typename L,
typename R>
359 template <
typename L,
typename R>
364 ptrs_.emplace_back(left, right);
367 template <
typename L,
typename R>
368 template <
typename Ls>
372 static_assert(std::is_same_v<
typename Ls::value_type,
art::Ptr<L>>,
373 "\n\nart error: The first argument must be a container whose " 374 "value_type is art::Ptr<L>\n" 375 " corresponding to an Assns<L, R(, D)> object.\n");
376 for (
auto const&
left : lefts) {
381 template <
typename L,
typename R>
382 template <
typename Rs>
386 static_assert(std::is_same_v<
typename Rs::value_type,
art::Ptr<R>>,
387 "\n\nart error: The second argument must be a container whose " 388 "value_type is art::Ptr<R>\n" 389 " corresponding to an Assns<L, R(, D)> object.\n");
390 for (
auto const&
right : rights) {
395 template <
typename L,
typename R>
402 template <
typename L,
typename R>
403 inline std::unique_ptr<art::EDProduct>
405 std::type_info
const& wanted_wrapper_type)
const 410 template <
typename L,
typename R>
420 template <
typename L,
typename R>
421 std::unique_ptr<art::EDProduct>
423 std::type_info
const& wanted_wrapper_type)
const 428 return std::make_unique<Wrapper<partner_t>>(
429 std::make_unique<partner_t>(*this));
432 template <
typename L,
typename R>
441 template <
typename L,
typename R>
447 ptrs_.reserve(ptr_data_1_.size());
448 ptr_data_t const& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
449 ptr_data_t const& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
454 Ptr<left_t>{l->first.
id(), l->second, l->first.productGetter()},
459 ptr_data_1_.
swap(tmp1);
460 ptr_data_2_.swap(tmp2);
463 template <
typename L,
typename R>
467 if (!ptr_data_1_.empty()) {
468 assert(ptr_data_1_.size() == ptr_data_2_.size() &&
469 ptr_data_2_.size() == ptrs_.size() &&
470 "Assns: internal inconsistency between transient and persistent " 476 ptr_data_t& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
477 ptr_data_t& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
478 l_ref.reserve(ptrs_.size());
479 r_ref.reserve(ptrs_.size());
480 for (
auto const& pr : ptrs_) {
481 l_ref.emplace_back(pr.first.refCore(), pr.first.key());
482 r_ref.emplace_back(pr.second.refCore(), pr.second.key());
486 template <
typename L,
typename R,
typename D>
489 static_assert(!std::is_pointer_v<D>,
490 "Data template argument must not be pointer type!");
493 template <
typename L,
typename R,
typename D>
498 template <
typename L,
typename R,
typename D>
505 template <
typename L,
typename R,
typename D>
512 template <
typename L,
typename R,
typename D>
519 template <
typename L,
typename R,
typename D>
526 template <
typename L,
typename R,
typename D>
533 template <
typename L,
typename R,
typename D>
537 return data_.at(index);
540 template <
typename L,
typename R,
typename D>
544 return data_.at(it.getIndex());
547 template <
typename L,
typename R,
typename D>
554 data_.push_back(data);
557 template <
typename L,
typename R,
typename D>
558 template <
typename Ls,
typename Ds>
564 static_assert(std::is_same_v<typename Ds::value_type, D>,
565 "\n\nart error: The data argument must be a container whose " 566 "value_type is D corresponding\n" 567 " to an Assns<L, R, D> object.\n");
568 assert(lefts.size() == data.size());
570 data_.insert(
data_.end(), data.begin(), data.end());
573 template <
typename L,
typename R,
typename D>
574 template <
typename Rs,
typename Ds>
580 static_assert(std::is_same_v<typename Ds::value_type, D>,
581 "\n\nart error: The data argument must be a container whose " 582 "value_type is D corresponding\n" 583 " to an Assns<L, R, D> object.\n");
584 assert(rights.size() == data.size());
586 data_.insert(
data_.end(), data.begin(), data.end());
589 template <
typename L,
typename R,
typename D>
598 template <
typename L,
typename R,
typename D>
599 inline std::unique_ptr<art::EDProduct>
601 std::type_info
const& wanted_wrapper_type)
const 606 template <
typename L,
typename R,
typename D>
613 catch (std::bad_cast
const&) {
615 <<
"Attempt to swap base with derived!\n";
619 template <
typename L,
typename R,
typename D>
620 std::unique_ptr<art::EDProduct>
622 std::type_info
const& wanted_wrapper_type)
const 625 std::unique_ptr<art::EDProduct> result;
628 std::make_unique<Wrapper<partner_t>>(std::make_unique<partner_t>(*this));
630 result = std::make_unique<Wrapper<base>>(
631 std::make_unique<base>(
static_cast<base>(*this)));
632 }
else if (wanted_wrapper_type ==
typeid(
Wrapper<bp>)) {
633 result = std::make_unique<Wrapper<bp>>(
634 std::make_unique<bp>(
static_cast<base>(*this)));
typename ptrs_t::const_iterator const_iterator
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
typename base::left_t left_t
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
void aggregate(Assns const &) const
std::vector< std::pair< Ptr< left_t >, Ptr< right_t >>> ptrs_t
void swap(art::Assns< L, R, D > &other)
std::unique_ptr< EDProduct > makePartner(std::type_info const &wanted_wrapper_type) const
void addMany(Ls const &lefts, Ptr< right_t > const &right, Ds const &data)
const_iterator begin() const
std::unique_ptr< EDProduct > makePartner_(std::type_info const &wanted_wrapper_type) const override
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
data_t const & data(typename std::vector< data_t >::size_type index) const
void throwPartnerException(std::type_info const &generator, std::type_info const &wanted_wrapper_type)
void swap(Handle< T > &a, Handle< T > &b)
void swap_(art::Assns< L, R, void > &other) override
ProductID id() const noexcept
std::string className() const
typename ptrs_t::value_type assn_t
typename base::size_type size_type
const_iterator end() const
typename ptrs_t::size_type size_type
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::vector< data_t > data_
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
const_reverse_iterator rend() const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
std::vector< std::pair< RefCore, std::size_t >> ptr_data_t
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
art::Assns< right_t, left_t, data_t > partner_t
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
void aggregate(Assns const &) const
const_reverse_iterator rbegin() const
typename art::const_AssnsIter< recob::Hit, recob::SpacePoint, D, Direction::Reverse > const_reverse_iterator
ptr_data_t ptr_data_1_
transient
typename art::const_AssnsIter< recob::Hit, recob::SpacePoint, D, Direction::Forward > const_iterator
static short Class_Version()
typename base::right_t right_t
static short Class_Version()