72 #ifndef ASSOCIATIONUTIL_H 73 #define ASSOCIATIONUTIL_H 84 #include "canvas/Persistency/Common/FindMany.h" 85 #include "canvas/Persistency/Common/FindManyP.h" 86 #include "canvas/Persistency/Common/FindOne.h" 87 #include "canvas/Persistency/Common/FindOneP.h" 152 template<
class T,
class U>
154 std::vector<T>
const&
a,
158 size_t index=UINT_MAX
208 template<
class T,
class U>
210 std::vector<T>
const&
a,
213 size_t index=UINT_MAX)
231 template<
class T,
class U>
257 template<
class T,
class U>
260 std::vector<T>
const& a,
263 size_t index = UINT_MAX
285 template<
class T,
class U>
311 template<
class T,
class U>
314 std::vector<T>
const& a,
317 size_t index = UINT_MAX
347 template<
class T,
class U>
350 std::vector<T>
const& a,
351 std::vector<U>
const& b,
355 size_t index = UINT_MAX
384 template<
class T,
class U>
387 std::vector<T>
const& a,
388 std::vector<U>
const& b,
390 std::vector<size_t>
const&
indices,
391 size_t index = UINT_MAX
432 template <
typename T,
typename U,
typename Iter>
437 Iter from_second_index,
497 template <
typename T,
typename U,
typename D>
506 template <
typename T,
typename U,
typename D>
524 template<
class T,
class U>
525 std::vector<const U*>
537 template<
class T,
class U>
538 std::vector< art::Ptr<U> >
557 template<
class T,
class U>
561 template<
class T,
class U>
562 std::vector<const U*>
566 template<
class T,
class U>
567 std::vector< std::vector<size_t> >
570 template<
class T,
class U>
571 std::vector< std::vector<const U*> >
580 template<
class T,
class U>
583 std::vector<T>
const&
a,
590 if (index == UINT_MAX) index = a.size()-1;
598 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
607 template<
class T,
class U>
620 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
630 template<
class T,
class U>
633 std::vector<T>
const&
a,
638 if(index == UINT_MAX) index = a.size() - 1;
646 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
655 template<
class T,
class U>
668 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
677 template<
class T,
class U>
680 std::vector<T>
const&
a,
686 if (index == UINT_MAX) index = a.size() - 1;
694 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
703 template<
class T,
class U>
706 std::vector<T>
const&
a,
707 std::vector<U>
const& ,
714 if(index == UINT_MAX) index = a.size() - 1;
719 for(
size_t i = startU; i < endU; ++i){
725 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
734 template<
class T,
class U>
737 std::vector<T>
const&
a,
738 std::vector<U>
const& ,
740 std::vector<size_t>
const&
indices,
744 if(index == UINT_MAX) index = a.size() - 1;
749 for(
size_t index: indices){
755 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
764 template <
typename T,
typename U,
typename Iter>
769 Iter from_second_index,
782 for (; from_second_index != to_second_index; ++from_second_index) {
783 assn.
addSingle(first_ptr, make_second_ptr(*from_second_index));
788 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
798 template <
typename T,
typename U,
typename D>
820 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
827 template <
typename T,
typename U,
typename D>
845 assn.
addSingle(first_ptr, second_ptr, data);
849 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
857 template<
class T,
class U>
858 inline std::vector<const U*>
867 std::vector<const U*> notAssociated;
869 art::FindOne<T>
const fa(b, evt, label);
871 for(
size_t u = 0; u < b->size(); ++u){
875 notAssociated.push_back(ptr.
get());
879 return notAssociated;
883 template<
class T,
class U>
884 inline std::vector< art::Ptr<U> >
893 std::vector< art::Ptr<U> > notAssociated;
895 art::FindOneP<T>
const fa(b, evt, label);
897 for(
size_t u = 0; u < b->size(); ++u){
900 notAssociated.emplace_back(b, u);
904 return notAssociated;
909 template<
class T,
class U>
910 inline std::vector<size_t>
914 std::vector<size_t> associated_index(index_p->size());
915 for(
auto const& pair : *
h)
916 associated_index.at(pair.first.key()) = pair.second.key();
917 return associated_index;
920 template<
class T,
class U>
921 inline std::vector<const U*>
925 std::vector<const U*> associated_pointer(index_p->size());
926 for(
auto const& pair : *
h)
927 associated_pointer.at(pair.first.key()) = &(*(pair.second));
928 return associated_pointer;
931 template<
class T,
class U>
932 inline std::vector< std::vector<size_t> >
936 std::vector< std::vector<size_t> > associated_indices(index_p->size());
937 for(
auto const& pair : *
h)
938 associated_indices.at(pair.first.key()).push_back(pair.second.key());
939 return associated_indices;
942 template<
class T,
class U>
943 inline std::vector< std::vector<const U*> >
947 std::vector< std::vector<const U*> > associated_pointers(index_p->size());
948 for(
auto const& pair : *
h)
949 associated_pointers.at(pair.first.key()).push_back( &(*(pair.second)) );
950 return associated_pointers;
966 template <
typename Producer,
typename... Args>
967 std::enable_if_t<std::is_base_of_v<art::EDProducer, Producer>,
bool>
972 template <
typename Producer,
typename... Args>
973 std::enable_if_t<std::is_base_of_v<art::EDProducer, Producer>,
bool>
979 #endif //ASSOCIATIONUTIL_H
bool CreateAssnD(art::Event &evt, art::Assns< T, U, D > &assn, size_t first_index, size_t second_index, typename art::Assns< T, U, D >::data_t &&data)
Creates a single one-to-one association with associated data.
Namespace for general, non-LArSoft-specific utilities.
std::vector< const U * > GetAssociatedVectorOneP(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
std::vector< size_t > GetAssociatedVectorOneI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::vector< art::Ptr< U > > FindUNotAssociatedToTP(art::Handle< U > b, art::Event const &evt, std::string const &label)
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< const U * > FindUNotAssociatedToT(art::Handle< U > b, art::Event const &evt, std::string const &label)
cet::coded_exception< error, detail::translate > exception
std::vector< std::vector< const U * > > GetAssociatedVectorManyP(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)