72 #ifndef ASSOCIATIONUTIL_H 73 #define ASSOCIATIONUTIL_H 155 template <
class T,
class U>
157 std::vector<T>
const& a,
160 std::string a_instance,
161 size_t index = UINT_MAX);
210 template <
class T,
class U>
212 std::vector<T>
const& a,
215 size_t index = UINT_MAX)
217 return CreateAssn(evt, a, b, assn, std::string(), index);
234 template <
class T,
class U>
258 template <
class T,
class U>
260 std::vector<T>
const& a,
263 size_t index = UINT_MAX);
284 template <
class T,
class U>
308 template <
class T,
class U>
310 std::vector<T>
const& a,
313 size_t index = UINT_MAX);
342 template <
class T,
class U>
344 std::vector<T>
const& a,
345 std::vector<U>
const& b,
349 size_t index = UINT_MAX);
377 template <
class T,
class U>
379 std::vector<T>
const& a,
380 std::vector<U>
const& b,
382 std::vector<size_t>
const&
indices,
383 size_t index = UINT_MAX);
423 template <
typename T,
typename U,
typename Iter>
427 Iter from_second_index,
428 Iter to_second_index);
486 template <
typename T,
typename U,
typename D>
493 template <
typename T,
typename U,
typename D>
508 template <
class T,
class U>
511 std::string
const& label);
520 template <
class T,
class U>
523 std::string
const& label);
539 template <
class T,
class U>
542 template <
class T,
class U>
546 template <
class T,
class U>
549 template <
class T,
class U>
557 template <
class T,
class U>
559 std::vector<T>
const& a,
562 std::string a_instance,
566 if (index == UINT_MAX) index = a.size() - 1;
574 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
582 template <
class T,
class U>
594 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
603 template <
class T,
class U>
605 std::vector<T>
const& a,
611 if (index == UINT_MAX) index = a.size() - 1;
620 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
629 template <
class T,
class U>
642 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
651 template <
class T,
class U>
653 std::vector<T>
const& a,
660 if (index == UINT_MAX) index = a.size() - 1;
669 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
678 template <
class T,
class U>
680 std::vector<T>
const& a,
681 std::vector<U>
const& ,
689 if (index == UINT_MAX) index = a.size() - 1;
694 for (
size_t i = startU; i < endU; ++i) {
700 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
709 template <
class T,
class U>
711 std::vector<T>
const& a,
712 std::vector<U>
const& ,
714 std::vector<size_t>
const&
indices,
719 if (index == UINT_MAX) index = a.size() - 1;
724 for (
size_t index : indices) {
730 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
739 template <
typename T,
typename U,
typename Iter>
743 Iter from_second_index,
744 Iter to_second_index)
756 for (; from_second_index != to_second_index; ++from_second_index) {
757 assn.
addSingle(first_ptr, make_second_ptr(*from_second_index));
762 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
771 template <
typename T,
typename U,
typename D>
788 assn.
addSingle(first_ptr, second_ptr, std::move(data));
792 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
799 template <
typename T,
typename U,
typename D>
816 assn.
addSingle(first_ptr, second_ptr, data);
820 <<
"unable to create requested art:Assns, exception thrown: " <<
e;
828 template <
class T,
class U>
831 std::string
const& label)
837 std::vector<const U*> notAssociated;
841 for (
size_t u = 0; u < b->size(); ++u) {
842 cet::maybe_ref<T const> t(fa.at(u));
845 notAssociated.push_back(ptr.
get());
849 return notAssociated;
853 template <
class T,
class U>
856 std::string
const& label)
862 std::vector<art::Ptr<U>> notAssociated;
866 for (
size_t u = 0; u < b->size(); ++u) {
867 cet::maybe_ref<T const> t(fa.at(u));
868 if (!t.isValid()) { notAssociated.emplace_back(b, u); }
871 return notAssociated;
874 template <
class T,
class U>
878 std::vector<size_t> associated_index(index_p->size());
879 for (
auto const& pair : *h)
880 associated_index.at(pair.first.key()) = pair.second.key();
881 return associated_index;
884 template <
class T,
class U>
888 std::vector<const U*> associated_pointer(index_p->size());
889 for (
auto const& pair : *h)
890 associated_pointer.at(pair.first.key()) = &(*(pair.second));
891 return associated_pointer;
894 template <
class T,
class U>
899 std::vector<std::vector<size_t>> associated_indices(index_p->size());
900 for (
auto const& pair : *h)
901 associated_indices.at(pair.first.key()).push_back(pair.second.key());
902 return associated_indices;
905 template <
class T,
class U>
910 std::vector<std::vector<const U*>> associated_pointers(index_p->size());
911 for (
auto const& pair : *h)
912 associated_pointers.at(pair.first.key()).push_back(&(*(pair.second)));
913 return associated_pointers;
929 template <
typename Producer,
typename... Args>
930 std::enable_if_t<std::is_base_of_v<art::EDProducer, Producer>,
bool>
CreateAssn(Producer
const&,
933 return CreateAssn(std::forward<Args>(args)...);
936 template <
typename Producer,
typename... Args>
937 std::enable_if_t<std::is_base_of_v<art::EDProducer, Producer>,
bool>
CreateAssnD(Producer
const&,
944 #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< std::vector< const U * > > GetAssociatedVectorManyP(art::Handle< art::Assns< T, U >> h, art::Handle< std::vector< T >> index_p)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
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)
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)
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U >> h, art::Handle< std::vector< T >> index_p)
cet::coded_exception< error, detail::translate > exception