8 #ifndef ASSOCIATIONUTIL_H
9 #define ASSOCIATIONUTIL_H
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Core/EDProducer.h"
13 #include "art/Framework/Core/EDFilter.h"
15 #include "canvas/Persistency/Common/Ptr.h"
16 #include "canvas/Persistency/Common/PtrVector.h"
17 #include "canvas/Persistency/Common/Assns.h"
18 #include "canvas/Persistency/Provenance/ProductID.h"
19 #include "canvas/Persistency/Common/FindOne.h"
20 #include "canvas/Persistency/Common/FindOneP.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
37 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
41 art::Assns<T,U> & assn,
43 std::string
const&
instance=std::string());
53 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
57 art::Assns<T,U> &assn,
60 std::string
const&
instance=std::string());
66 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
70 art::Assns<T,U> &assn);
78 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
82 art::Assns<T,U> &assn,
84 std::string
const&
instance=std::string());
90 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
94 art::Assns<T,U> &assn);
102 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
106 art::Assns<T,U> &assn,
107 size_t indx=UINT_MAX,
108 std::string
const&
instance=std::string());
119 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
123 art::Assns<T,U> &assn,
126 size_t indx=UINT_MAX,
127 std::string
const& instancea=std::string(),
128 std::string
const& instanceb=std::string());
138 template<
class T,
class U>
static bool CreateAssn(art::EDProducer
const& prod,
140 art::Assns<T,U> &assn,
143 size_t indxb=UINT_MAX,
144 size_t indxa=UINT_MAX,
145 std::string
const& instancea=std::string(),
146 std::string
const& instanceb=std::string());
158 art::Event
const& evt,
159 std::string
const& label);
170 art::Event
const& evt,
171 std::string
const& label);
187 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
191 art::Assns<T,U> &assn,
192 size_t indx=UINT_MAX,
193 std::string
const&
instance=std::string());
203 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
207 art::Assns<T,U> &assn,
210 std::string
const&
instance=std::string());
216 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
220 art::Assns<T,U> &assn);
228 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
232 art::Assns<T,U> &assn,
233 size_t indx=UINT_MAX,
234 std::string
const&
instance=std::string());
240 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
244 art::Assns<T,U> &assn);
252 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
256 art::Assns<T,U> &assn,
257 size_t indx=UINT_MAX,
258 std::string
const&
instance=std::string());
269 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
273 art::Assns<T,U> &assn,
276 size_t indx=UINT_MAX,
277 std::string
const& instancea=std::string(),
278 std::string
const& instanceb=std::string());
288 template<
class T,
class U>
static bool CreateAssn(art::EDFilter
const& prod,
290 art::Assns<T,U> &assn,
293 size_t indxb=UINT_MAX,
294 size_t indxa=UINT_MAX,
295 std::string
const& instancea=std::string(),
296 std::string
const& instanceb=std::string());
301 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
305 art::Assns<T,U> & assn,
311 if(indx == UINT_MAX) indx = a.size()-1;
314 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
315 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
316 assn.addSingle(aptr, b);
318 catch(cet::exception &
e){
319 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
320 <<
"art:Assns, exception thrown: "
329 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
333 art::Assns<T,U> &assn,
336 std::string
const& instance)
338 if(end_indx == UINT_MAX) end_indx = a.size();
341 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
342 auto getter = evt.productGetter(aid);
343 for(
size_t i = begin_indx; i < end_indx; ++i){
344 art::Ptr<T> aptr(aid, i, getter);
345 assn.addSingle(aptr, b);
348 catch(cet::exception &
e){
349 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
350 <<
"art:Assns, exception thrown: "
360 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
364 art::Assns<T,U> &assn)
369 assn.addSingle(a, b);
371 catch(cet::exception &
e){
372 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
373 <<
"art:Assns, exception thrown: "
382 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
386 art::Assns<T,U> &assn,
388 std::string
const& instance)
393 if(indx == UINT_MAX) indx = a.size()-1;
396 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
397 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
398 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
400 catch(cet::exception &
e){
401 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
402 <<
"art:Assns, exception thrown: "
411 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
415 art::Assns<T,U> &assn,
417 std::string
const& instance)
421 if(indx == UINT_MAX) indx = a.size()-1;
424 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
425 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
427 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
429 catch(cet::exception &
e){
430 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
431 <<
"art:Assns, exception thrown: "
440 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
444 art::Assns<T,U> &assn)
449 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(a, b[i]);
451 catch(cet::exception &
e){
452 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
453 <<
"art:Assns, exception thrown: "
462 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
466 art::Assns<T,U> &assn,
470 std::string
const& instancea,
471 std::string
const& instanceb)
476 if(indx == UINT_MAX) indx = a.size()-1;
479 art::ProductID aid = evt.getProductID< std::vector<T> >(instancea);
480 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
481 for(
size_t i = startU; i < endU; ++i){
482 art::ProductID bid = evt.getProductID< std::vector<U> >(instanceb);
483 art::Ptr<U> bptr(bid, i, evt.productGetter(bid));
484 assn.addSingle(aptr, bptr);
487 catch(cet::exception &
e){
488 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
489 <<
"art:Assns, exception thrown: "
498 template<
class T,
class U>
inline bool util::CreateAssn(art::EDProducer
const& prod,
500 art::Assns<T,U> &assn,
505 std::string
const& instancea,
506 std::string
const& instanceb)
511 if(indxa == UINT_MAX) indxa = a.size()-1;
512 if(indxb == UINT_MAX) indxb = b.size()-1;
515 art::ProductID aid = evt.getProductID< std::vector<T> >(instancea);
516 art::Ptr<T> aptr(aid, indxa, evt.productGetter(aid));
517 art::ProductID bid = evt.getProductID< std::vector<U> >(instanceb);
518 art::Ptr<U> bptr(bid, indxb, evt.productGetter(bid));
519 assn.addSingle(aptr, bptr);
521 catch(cet::exception &
e){
522 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
523 <<
"art:Assns, exception thrown: "
533 art::Event
const& evt,
534 std::string
const& label)
541 std::vector<const U*> notAssociated;
543 art::FindOne<T> fa(b, evt, label);
545 for(
size_t u = 0; u < b->size(); ++u){
546 cet::maybe_ref<T const> t(fa.at(u));
548 art::Ptr<U> ptr(b, u);
549 notAssociated.push_back(ptr.get());
553 return notAssociated;
558 art::Event
const& evt,
559 std::string
const& label)
566 std::vector< art::Ptr<U> > notAssociated;
568 art::FindOneP<T> fa(b, evt, label);
570 for(
size_t u = 0; u < b->size(); ++u){
571 cet::maybe_ref<T const> t(fa.at(u));
573 art::Ptr<U> ptr(b, u);
574 notAssociated.push_back(ptr);
578 return notAssociated;
585 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
589 art::Assns<T,U> &assn,
591 std::string
const& instance)
595 if(indx == UINT_MAX) indx = a.size()-1;
598 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
599 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
600 assn.addSingle(aptr, b);
602 catch(cet::exception &
e){
603 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
604 <<
"art:Assns, exception thrown: "
613 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
617 art::Assns<T,U> &assn,
620 std::string
const& instance)
622 if(end_indx == UINT_MAX) end_indx = a.size();
625 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
626 auto getter = evt.productGetter(aid);
627 for(
size_t i = begin_indx; i < end_indx; ++i){
628 art::Ptr<T> aptr(aid, i, getter);
629 assn.addSingle(aptr, b);
632 catch(cet::exception &
e){
633 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
634 <<
"art:Assns, exception thrown: "
644 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
648 art::Assns<T,U> &assn)
653 assn.addSingle(a, b);
655 catch(cet::exception &
e){
656 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
657 <<
"art:Assns, exception thrown: "
666 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
670 art::Assns<T,U> &assn,
672 std::string
const& instance)
677 if(indx == UINT_MAX) indx = a.size()-1;
680 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
681 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
682 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
684 catch(cet::exception &
e){
685 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
686 <<
"art:Assns, exception thrown: "
695 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
699 art::Assns<T,U> &assn,
701 std::string
const& instance)
705 if(indx == UINT_MAX) indx = a.size()-1;
708 art::ProductID aid = evt.getProductID< std::vector<T> >(
instance);
709 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
711 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
713 catch(cet::exception &
e){
714 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
715 <<
"art:Assns, exception thrown: "
724 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
728 art::Assns<T,U> &assn)
733 for(
size_t i = 0; i < b.size(); ++i) assn.addSingle(a, b[i]);
735 catch(cet::exception &
e){
736 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
737 <<
"art:Assns, exception thrown: "
746 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
750 art::Assns<T,U> &assn,
754 std::string
const& instancea,
755 std::string
const& instanceb)
760 if(indx == UINT_MAX) indx = a.size()-1;
763 art::ProductID aid = evt.getProductID< std::vector<T> >(instancea);
764 art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
765 for(
size_t i = startU; i < endU; ++i){
766 art::ProductID bid = evt.getProductID< std::vector<U> >(instanceb);
767 art::Ptr<U> bptr(bid, i, evt.productGetter(bid));
768 assn.addSingle(aptr, bptr);
771 catch(cet::exception &
e){
772 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
773 <<
"art:Assns, exception thrown: "
782 template<
class T,
class U>
inline bool util::CreateAssn(art::EDFilter
const& prod,
784 art::Assns<T,U> &assn,
789 std::string
const& instancea,
790 std::string
const& instanceb)
795 if(indxa == UINT_MAX) indxa = a.size()-1;
796 if(indxb == UINT_MAX) indxb = b.size()-1;
799 art::ProductID aid = evt.getProductID< std::vector<T> >(instancea);
800 art::Ptr<T> aptr(aid, indxa, evt.productGetter(aid));
801 art::ProductID bid = evt.getProductID< std::vector<U> >(instanceb);
802 art::Ptr<U> bptr(bid, indxb, evt.productGetter(bid));
803 assn.addSingle(aptr, bptr);
805 catch(cet::exception &
e){
806 mf::LogWarning(
"AssociationUtil") <<
"unable to create requested "
807 <<
"art:Assns, exception thrown: "
817 #endif //ASSOCIATIONUTIL_H
const std::string instance
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
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< const U * > FindUNotAssociatedToT(art::Handle< U > b, art::Event const &evt, std::string const &label)