1 #ifndef canvas_Persistency_Common_Assns_h 2 #define canvas_Persistency_Common_Assns_h 92 #include "cetlib/container_algorithms.h" 93 #include "cetlib_except/demangle.h" 101 template <
typename L,
typename R,
typename D =
void>
106 template <
typename LR>
107 class Assns<LR, LR, void>;
109 template <
typename LR,
typename D>
110 class Assns<LR, LR, D>;
112 template <
typename L,
typename R>
122 template <
typename L,
typename R>
131 using ptr_data_t = std::vector<std::pair<RefCore, std::size_t>>;
134 using assn_t =
typename ptrs_t::value_type;
141 virtual ~
Assns() =
default;
149 std::string className()
const;
155 std::unique_ptr<EDProduct> makePartner(
156 std::type_info
const& wanted_wrapper_type)
const;
171 virtual std::unique_ptr<EDProduct> makePartner_(
172 std::type_info
const& wanted_wrapper_type)
const;
175 friend class detail::AssnsStreamer;
183 #ifdef ROOT_CAN_REGISTER_IOREADS_PROPERLY 190 #ifndef ROOT_CAN_REGISTER_IOREADS_PROPERLY 195 void fill_transients()
override;
196 void fill_from_transients()
override;
206 template <
typename L,
typename R,
typename D>
231 using base::operator[];
234 data_t const& data(
typename std::vector<data_t>::size_type index)
const;
238 Ptr<right_t>
const&
right,
244 std::unique_ptr<EDProduct> makePartner(
245 std::type_info
const& wanted_wrapper_type)
const;
262 std::type_info
const& wanted_wrapper_type)
const override;
270 template <
typename L,
typename R>
274 template <
typename L,
typename R>
277 ptrs_.reserve(other.ptrs_.
size());
279 other.ptrs_, std::back_inserter(ptrs_), [](
auto const& pr) {
280 using pr_t = typename ptrs_t::value_type;
281 return pr_t{pr.second, pr.first};
285 template <
typename L,
typename R>
289 return ptrs_.begin();
292 template <
typename L,
typename R>
299 template <
typename L,
typename R>
306 template <
typename L,
typename R>
310 return ptrs_.at(index);
313 template <
typename L,
typename R>
320 template <
typename L,
typename R>
328 template <
typename L,
typename R>
333 ptrs_.emplace_back(left, right);
336 template <
typename L,
typename R>
343 template <
typename L,
typename R>
344 inline std::unique_ptr<art::EDProduct>
346 std::type_info
const& wanted_wrapper_type)
const 351 template <
typename L,
typename R>
361 template <
typename L,
typename R>
362 std::unique_ptr<art::EDProduct>
364 std::type_info
const& wanted_wrapper_type)
const 369 return std::make_unique<Wrapper<partner_t>>(
370 std::make_unique<partner_t>(*this));
373 template <
typename L,
typename R>
382 template <
typename L,
typename R>
388 ptrs_.reserve(ptr_data_1_.size());
389 ptr_data_t const& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
390 ptr_data_t const& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
391 for (
auto l = cbegin(l_ref),
e = cend(l_ref), r = cbegin(r_ref); l !=
e;
394 Ptr<left_t>{l->first.
id(), l->second, l->first.productGetter()},
395 Ptr<right_t>{r->first.
id(), r->second, r->first.productGetter()});
399 ptr_data_1_.
swap(tmp1);
400 ptr_data_2_.swap(tmp2);
403 template <
typename L,
typename R>
407 if (!ptr_data_1_.empty()) {
408 assert(ptr_data_1_.size() == ptr_data_2_.size() &&
409 ptr_data_2_.size() == ptrs_.size() &&
410 "Assns: internal inconsistency between transient and persistent " 416 ptr_data_t& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
417 ptr_data_t& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
418 l_ref.reserve(ptrs_.size());
419 r_ref.reserve(ptrs_.size());
420 for (
auto const& pr : ptrs_) {
421 l_ref.emplace_back(pr.first.refCore(), pr.first.key());
422 r_ref.emplace_back(pr.second.refCore(), pr.second.key());
426 template <
typename L,
typename R,
typename D>
430 "Data template argument must not be pointer type!");
433 template <
typename L,
typename R,
typename D>
438 template <
typename L,
typename R,
typename D>
445 template <
typename L,
typename R,
typename D>
452 template <
typename L,
typename R,
typename D>
459 template <
typename L,
typename R,
typename D>
466 template <
typename L,
typename R,
typename D>
473 template <
typename L,
typename R,
typename D>
477 return data_.at(index);
480 template <
typename L,
typename R,
typename D>
484 return data_.at(it.getIndex());
487 template <
typename L,
typename R,
typename D>
494 data_.push_back(data);
497 template <
typename L,
typename R,
typename D>
506 template <
typename L,
typename R,
typename D>
507 inline std::unique_ptr<art::EDProduct>
509 std::type_info
const& wanted_wrapper_type)
const 514 template <
typename L,
typename R,
typename D>
521 catch (std::bad_cast
const&) {
523 <<
"Attempt to swap base with derived!\n";
527 template <
typename L,
typename R,
typename D>
528 std::unique_ptr<art::EDProduct>
530 std::type_info
const& wanted_wrapper_type)
const 533 std::unique_ptr<art::EDProduct> result;
536 std::make_unique<Wrapper<partner_t>>(std::make_unique<partner_t>(*this));
538 result = std::make_unique<Wrapper<base>>(
539 std::make_unique<base>(
static_cast<base>(*this)));
540 }
else if (wanted_wrapper_type ==
typeid(
Wrapper<bp>)) {
541 result = std::make_unique<Wrapper<bp>>(
542 std::make_unique<bp>(
static_cast<base>(*this)));
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
typename ptrs_t::const_iterator assn_iterator
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
const_iterator begin() const
std::unique_ptr< EDProduct > makePartner_(std::type_info const &wanted_wrapper_type) const override
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
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
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)
std::string value(boost::any const &)
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
art::Assns< right_t, left_t, data_t > partner_t
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
void aggregate(Assns const &) const
const_reverse_iterator rbegin() const
typename art::const_AssnsIter< recob::PFParticle, recob::SpacePoint, D, Direction::Reverse > const_reverse_iterator
ptr_data_t ptr_data_1_
transient
typename art::const_AssnsIter< recob::PFParticle, recob::SpacePoint, D, Direction::Forward > const_iterator
static short Class_Version()
typename base::right_t right_t
static short Class_Version()