1 #ifndef canvas_Persistency_Common_Assns_h 2 #define canvas_Persistency_Common_Assns_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>
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;
142 virtual ~
Assns() =
default;
155 template <
typename Ls>
156 void addMany(Ls
const& lefts, Ptr<right_t>
const&
right);
158 template <
typename Rs>
163 std::unique_ptr<EDProduct> makePartner(
164 std::type_info
const& wanted_wrapper_type)
const;
179 virtual std::unique_ptr<EDProduct> makePartner_(
180 std::type_info
const& wanted_wrapper_type)
const;
183 friend class detail::AssnsStreamer;
191 #ifdef ROOT_CAN_REGISTER_IOREADS_PROPERLY 198 #ifndef ROOT_CAN_REGISTER_IOREADS_PROPERLY 203 void fill_transients()
override;
204 void fill_from_transients()
override;
214 template <
typename L,
typename R,
typename D>
225 !std::is_same_v<D, bool>,
226 "\n\nart error: An 'Assns<A, B, D>' object with D = bool is not allowed.\n" 227 " If you decide that D must represent a boolean type, then we\n" 228 " recommend that you wrap a boolean value in a struct (e.g.):\n\n" 229 " struct WrappedBool { bool flag; };\n\n" 230 " Please contact artists@fnal.gov for guidance.\n");
251 using base::operator[];
254 data_t const&
data(
typename std::vector<data_t>::size_type
index)
const;
259 Ptr<right_t>
const&
right,
262 template <
typename Ls,
typename Ds>
263 void addMany(Ls
const& lefts, Ptr<right_t>
const&
right, Ds
const&
data);
265 template <
typename Rs,
typename Ds>
272 std::unique_ptr<EDProduct> makePartner(
273 std::type_info
const& wanted_wrapper_type)
const;
290 std::type_info
const& wanted_wrapper_type)
const override;
298 template <
typename L,
typename R>
302 template <
typename L,
typename R>
305 ptrs_.reserve(other.ptrs_.
size());
307 other.ptrs_, std::back_inserter(ptrs_), [](
auto const& pr) {
308 using pr_t = typename ptrs_t::value_type;
309 return pr_t{pr.second, pr.first};
313 template <
typename L,
typename R>
317 return ptrs_.begin();
320 template <
typename L,
typename R>
327 template <
typename L,
typename R>
334 template <
typename L,
typename R>
338 return ptrs_.at(index);
341 template <
typename L,
typename R>
348 template <
typename L,
typename R>
356 template <
typename L,
typename R>
361 ptrs_.emplace_back(left, right);
364 template <
typename L,
typename R>
365 template <
typename Ls>
369 static_assert(std::is_same_v<
typename Ls::value_type,
art::Ptr<L>>,
370 "\n\nart error: The first argument must be a container whose " 371 "value_type is art::Ptr<L>\n" 372 " corresponding to an Assns<L, R(, D)> object.\n");
373 for (
auto const&
left : lefts) {
378 template <
typename L,
typename R>
379 template <
typename Rs>
383 static_assert(std::is_same_v<
typename Rs::value_type,
art::Ptr<R>>,
384 "\n\nart error: The second argument must be a container whose " 385 "value_type is art::Ptr<R>\n" 386 " corresponding to an Assns<L, R(, D)> object.\n");
387 for (
auto const&
right : rights) {
392 template <
typename L,
typename R>
399 template <
typename L,
typename R>
400 inline std::unique_ptr<art::EDProduct>
402 std::type_info
const& wanted_wrapper_type)
const 407 template <
typename L,
typename R>
417 template <
typename L,
typename R>
418 std::unique_ptr<art::EDProduct>
420 std::type_info
const& wanted_wrapper_type)
const 425 return std::make_unique<Wrapper<partner_t>>(
426 std::make_unique<partner_t>(*this));
429 template <
typename L,
typename R>
438 template <
typename L,
typename R>
444 ptrs_.reserve(ptr_data_1_.size());
445 ptr_data_t const& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
446 ptr_data_t const& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
456 ptr_data_1_.
swap(tmp1);
457 ptr_data_2_.swap(tmp2);
460 template <
typename L,
typename R>
464 if (!ptr_data_1_.empty()) {
465 assert(ptr_data_1_.size() == ptr_data_2_.size() &&
466 ptr_data_2_.size() == ptrs_.size() &&
467 "Assns: internal inconsistency between transient and persistent " 473 ptr_data_t& l_ref = left_first() ? ptr_data_1_ : ptr_data_2_;
474 ptr_data_t& r_ref = left_first() ? ptr_data_2_ : ptr_data_1_;
475 l_ref.reserve(ptrs_.size());
476 r_ref.reserve(ptrs_.size());
477 for (
auto const& pr : ptrs_) {
478 l_ref.emplace_back(pr.first.refCore(), pr.first.key());
479 r_ref.emplace_back(pr.second.refCore(), pr.second.key());
483 template <
typename L,
typename R,
typename D>
486 static_assert(!std::is_pointer_v<D>,
487 "Data template argument must not be pointer type!");
490 template <
typename L,
typename R,
typename D>
495 template <
typename L,
typename R,
typename D>
502 template <
typename L,
typename R,
typename D>
509 template <
typename L,
typename R,
typename D>
516 template <
typename L,
typename R,
typename D>
523 template <
typename L,
typename R,
typename D>
530 template <
typename L,
typename R,
typename D>
534 return data_.at(index);
537 template <
typename L,
typename R,
typename D>
541 return data_.at(it.getIndex());
544 template <
typename L,
typename R,
typename D>
551 data_.push_back(data);
554 template <
typename L,
typename R,
typename D>
555 template <
typename Ls,
typename Ds>
561 static_assert(std::is_same_v<typename Ds::value_type, D>,
562 "\n\nart error: The data argument must be a container whose " 563 "value_type is D corresponding\n" 564 " to an Assns<L, R, D> object.\n");
565 assert(lefts.size() == data.size());
567 data_.insert(
data_.end(), data.begin(), data.end());
570 template <
typename L,
typename R,
typename D>
571 template <
typename Rs,
typename Ds>
577 static_assert(std::is_same_v<typename Ds::value_type, D>,
578 "\n\nart error: The data argument must be a container whose " 579 "value_type is D corresponding\n" 580 " to an Assns<L, R, D> object.\n");
581 assert(rights.size() == data.size());
583 data_.insert(
data_.end(), data.begin(), data.end());
586 template <
typename L,
typename R,
typename D>
595 template <
typename L,
typename R,
typename D>
596 inline std::unique_ptr<art::EDProduct>
598 std::type_info
const& wanted_wrapper_type)
const 603 template <
typename L,
typename R,
typename D>
610 catch (std::bad_cast
const&) {
612 <<
"Attempt to swap base with derived!\n";
616 template <
typename L,
typename R,
typename D>
617 std::unique_ptr<art::EDProduct>
619 std::type_info
const& wanted_wrapper_type)
const 622 std::unique_ptr<art::EDProduct>
result;
625 std::make_unique<Wrapper<partner_t>>(std::make_unique<partner_t>(*this));
627 result = std::make_unique<Wrapper<base>>(
628 std::make_unique<base>(
static_cast<base>(*this)));
629 }
else if (wanted_wrapper_type ==
typeid(
Wrapper<bp>)) {
630 result = std::make_unique<Wrapper<bp>>(
631 std::make_unique<bp>(
static_cast<base>(*this)));
typename ptrs_t::const_iterator const_iterator
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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
static QCString className
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 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
std::string className() const
auto transform_all(Container &, OutputIt, UnaryOp)
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()