All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/CAFMaker/AssociationUtil.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 // \file AssociationUtil.h
3 // \brief Utility object to perform functions of association
4 // Ported from the NOvA Utilities package
5 // \author $Author: psihas@fnal.gov
6 ////////////////////////////////////////////////////////////////////////////
7 
8 #ifndef ASSOCIATIONUTIL_H
9 #define ASSOCIATIONUTIL_H
10 
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Core/EDProducer.h"
13 #include "art/Framework/Core/EDFilter.h"
14 
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"
21 
22 #include "messagefacility/MessageLogger/MessageLogger.h"
23 
24 namespace util {
25 
26  /// \name Create and query associations
27  /// see https://cdcvs.fnal.gov/redmine/projects/art/wiki/Inter-Product_References
28  /// for information about using art::Assns
29  //@{
30 
31  /// \brief Create a 1 to 1 association between a new product and one already in the event
32  ///
33  /// \param a The collection about to be added to the event
34  /// \param b The product already in the event
35  /// \param indx Which element of \a a to associate. By default the last one.
36  /// \param instance instance label for product, defaulted to be an empty string
37  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
38  art::Event & evt,
39  std::vector<T> & a,
40  art::Ptr<U> b,
41  art::Assns<T,U> & assn,
42  size_t indx=UINT_MAX,
43  std::string const& instance=std::string());
44 
45  /// \brief Create a 1 to 1 association between each of a series of new
46  /// products and one already in the event
47  ///
48  /// \param a The collection about to be added to the event
49  /// \param b The product already in the event
50  /// \param begin_indx Which element of \a a to associate first.
51  /// \param end_indx One more than the index of the last element to associate
52  /// \param instance instance label for product, defaulted to be an empty string
53  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
54  art::Event &evt,
55  std::vector<T> &a,
56  art::Ptr<U> b,
57  art::Assns<T,U> &assn,
58  size_t begin_indx,
59  size_t end_indx,
60  std::string const& instance=std::string());
61 
62  /// \brief Create a 1 to 1 association between two products already in the event
63  ///
64  /// \param a A product already in the event
65  /// \param b Another product already in the event
66  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
67  art::Event &evt,
68  art::Ptr<T> &a,
69  art::Ptr<U> b,
70  art::Assns<T,U> &assn);
71 
72  /// \brief Create a 1 to many association between a new product and a PtrVector already in the event
73  ///
74  /// \param a The collection about to be added to the event
75  /// \param b The products already in the event
76  /// \param indx Which element of \a a to associate. By default the last one.
77  /// \param instance instance label for product, defaulted to be an empty string
78  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
79  art::Event &evt,
80  std::vector<T> &a,
81  art::PtrVector<U> b,
82  art::Assns<T,U> &assn,
83  size_t indx=UINT_MAX,
84  std::string const& instance=std::string());
85 
86  /// \brief Create a 1 to many association between products already in the event
87  ///
88  /// \param a A product already in the event
89  /// \param b A vector of products already in the event (the many)
90  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
91  art::Event &evt,
92  art::Ptr<T> &a,
93  std::vector< art::Ptr<U> > b,
94  art::Assns<T,U> &assn);
95 
96  /// \brief Create a 1 to many association between a new product and a vector of Ptrs already in the event
97  ///
98  /// \param a The collection about to be added to the event
99  /// \param b The products already in the event
100  /// \param indx Which element of \a a to associate. By default the last one.
101  /// \param instance instance label for product, defaulted to be an empty string
102  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
103  art::Event &evt,
104  std::vector<T> &a,
105  std::vector< art::Ptr<U> > b,
106  art::Assns<T,U> &assn,
107  size_t indx=UINT_MAX,
108  std::string const& instance=std::string());
109 
110  /// \brief Create a 1 to many association between new products
111  ///
112  /// \param a A collection about to be added to the event
113  /// \param b Another collection about to be added to the event
114  /// \param startU The first element of \a b to associate
115  /// \param endU The last element of \a b to associate +1 (like STL begin() and end())
116  /// \param indx Which element of \a a to associate. By default the last one.
117  /// \param instancea instance label for product a, defaulted to be an empty string
118  /// \param instanceb instance label for product b, defaulted to be an empty string
119  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
120  art::Event &evt,
121  std::vector<T> &a,
122  std::vector<U> &b,
123  art::Assns<T,U> &assn,
124  size_t startU,
125  size_t endU,
126  size_t indx=UINT_MAX,
127  std::string const& instancea=std::string(),
128  std::string const& instanceb=std::string());
129 
130  /// \brief Create a 1 to 1 between new products
131  ///
132  /// \param a A collection about to be added to the event
133  /// \param b Another collection about to be added to the event
134  /// \param indxb Which element of \a b to associate. By default the last one.
135  /// \param indxa Which element of \a a to associate. By default the last one.
136  /// \param instancea instance label for product a, defaulted to be an empty string
137  /// \param instanceb instance label for product b, defaulted to be an empty string
138  template<class T, class U> static bool CreateAssn(art::EDProducer const& prod,
139  art::Event &evt,
140  art::Assns<T,U> &assn,
141  std::vector<T> &a,
142  std::vector<U> &b,
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());
147 
148  /// \brief Return all objects of type U that are not associated to objects of
149  /// type T.
150  ///
151  /// Label is the module label that would have produced
152  /// the associations and likely the objects of type T
153  /// this method assumes there is a one to many relationship between T and U
154  /// for example if you want to get all rb::CellHits
155  /// that are not associated to rb::Clusters
156  /// std::vector<const rb::CellHit*> hits = FindUNotAssociatedToU<rb::Cluster>(art::Handle<rb::CellHit>, ...);
157  template<class T, class U> static std::vector<const U*> FindUNotAssociatedToT(art::Handle<U> b,
158  art::Event const& evt,
159  std::string const& label);
160 
161  /// \brief Return all objects of type U that are not associated to objects of
162  /// type T.
163  ///
164  /// Label is the module label that would have produced the associations and
165  /// likely the objects of type T this method assumes there is a one to many
166  /// relationship between T and U for example if you want to get all rb::CellHits
167  /// that are not associated to rb::Clusters std::vector<art::Ptr<rb::CellHit> > hits =
168  /// FindUNotAssociatedToTP<rb::Cluster>(art::Handle<rb::CellHit>, ...);
169  template<class T, class U> static std::vector< art::Ptr<U> > FindUNotAssociatedToTP(art::Handle<U> b,
170  art::Event const& evt,
171  std::string const& label);
172 
173  //@}
174 
175 
176  /// \name Create and query associations
177  /// see https://cdcvs.fnal.gov/redmine/projects/art/wiki/Inter-Product_References
178  /// for information about using art::Assns
179  //@{
180 
181  /// \brief Create a 1 to 1 association between a new product and one already in the event
182  ///
183  /// \param a The collection about to be added to the event
184  /// \param b The product already in the event
185  /// \param indx Which element of \a a to associate. By default the last one.
186  /// \param instance instance label for product, defaulted to be an empty string
187  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
188  art::Event &evt,
189  std::vector<T> &a,
190  art::Ptr<U> b,
191  art::Assns<T,U> &assn,
192  size_t indx=UINT_MAX,
193  std::string const& instance=std::string());
194 
195  /// \brief Create a 1 to 1 association between each of a series of new
196  /// products and one already in the event
197  ///
198  /// \param a The collection about to be added to the event
199  /// \param b The product already in the event
200  /// \param begin_indx Which element of \a a to associate first.
201  /// \param end_indx One more than the index of the last element to associate
202  /// \param instance instance label for product, defaulted to be an empty string
203  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
204  art::Event &evt,
205  std::vector<T> &a,
206  art::Ptr<U> b,
207  art::Assns<T,U> &assn,
208  size_t begin_indx,
209  size_t end_indx,
210  std::string const& instance=std::string());
211 
212  /// \brief Create a 1 to 1 association between two products already in the event
213  ///
214  /// \param a A product already in the event
215  /// \param b Another product already in the event
216  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
217  art::Event &evt,
218  art::Ptr<T> &a,
219  art::Ptr<U> b,
220  art::Assns<T,U> &assn);
221 
222  /// \brief Create a 1 to many association between a new product and a PtrVector already in the event
223  ///
224  /// \param a The collection about to be added to the event
225  /// \param b The products already in the event
226  /// \param indx Which element of \a a to associate. By default the last one.
227  /// \param instance instance label for product, defaulted to be an empty string
228  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
229  art::Event &evt,
230  std::vector<T> &a,
231  art::PtrVector<U> b,
232  art::Assns<T,U> &assn,
233  size_t indx=UINT_MAX,
234  std::string const& instance=std::string());
235 
236  /// \brief Create a 1 to many association between products already in the event
237  ///
238  /// \param a A product already in the event
239  /// \param b A vector of products already in the event (the many)
240  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
241  art::Event &evt,
242  art::Ptr<T> &a,
243  std::vector< art::Ptr<U> > b,
244  art::Assns<T,U> &assn);
245 
246  /// \brief Create a 1 to many association between a new product and a vector of Ptrs already in the event
247  ///
248  /// \param a The collection about to be added to the event
249  /// \param b The products already in the event
250  /// \param indx Which element of \a a to associate. By default the last one.
251  /// \param instance instance label for product, defaulted to be an empty string
252  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
253  art::Event &evt,
254  std::vector<T> &a,
255  std::vector< art::Ptr<U> > b,
256  art::Assns<T,U> &assn,
257  size_t indx=UINT_MAX,
258  std::string const& instance=std::string());
259 
260  /// \brief Create a 1 to many association between new products
261  ///
262  /// \param a A collection about to be added to the event
263  /// \param b Another collection about to be added to the event
264  /// \param startU The first element of \a b to associate
265  /// \param endU The last element of \a b to associate +1 (like STL begin() and end())
266  /// \param indx Which element of \a a to associate. By default the last one.
267  /// \param instancea instance label for product a, defaulted to be an empty string
268  /// \param instanceb instance label for product b, defaulted to be an empty string
269  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
270  art::Event &evt,
271  std::vector<T> &a,
272  std::vector<U> &b,
273  art::Assns<T,U> &assn,
274  size_t startU,
275  size_t endU,
276  size_t indx=UINT_MAX,
277  std::string const& instancea=std::string(),
278  std::string const& instanceb=std::string());
279 
280  /// \brief Create a 1 to 1 between new products
281  ///
282  /// \param a A collection about to be added to the event
283  /// \param b Another collection about to be added to the event
284  /// \param indxb Which element of \a b to associate. By default the last one.
285  /// \param indxa Which element of \a a to associate. By default the last one.
286  /// \param instancea instance label for product a, defaulted to be an empty string
287  /// \param instanceb instance label for product b, defaulted to be an empty string
288  template<class T, class U> static bool CreateAssn(art::EDFilter const& prod,
289  art::Event &evt,
290  art::Assns<T,U> &assn,
291  std::vector<T> &a,
292  std::vector<U> &b,
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());
297 
298 }// end namespace
299 
300 //----------------------------------------------------------------------
301 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
302  art::Event & evt,
303  std::vector<T> & a,
304  art::Ptr<U> b,
305  art::Assns<T,U> & assn,
306  size_t indx,
307  std::string const& instance)
308 {
309  bool ret = true;
310 
311  if(indx == UINT_MAX) indx = a.size()-1;
312 
313  try{
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);
317  }
318  catch(cet::exception &e){
319  mf::LogWarning("AssociationUtil") << "unable to create requested "
320  << "art:Assns, exception thrown: "
321  << e;
322  ret = false;
323  }
324 
325  return ret;
326 }
327 
328 //----------------------------------------------------------------------
329 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
330  art::Event &evt,
331  std::vector<T> &a,
332  art::Ptr<U> b,
333  art::Assns<T,U> &assn,
334  size_t begin_indx,
335  size_t end_indx,
336  std::string const& instance)
337 {
338  if(end_indx == UINT_MAX) end_indx = a.size();
339 
340  try{
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);
346  }
347  }
348  catch(cet::exception &e){
349  mf::LogWarning("AssociationUtil") << "unable to create requested "
350  << "art:Assns, exception thrown: "
351  << e;
352  return false;
353  }
354 
355  return true;
356 }
357 
358 
359 //----------------------------------------------------------------------
360 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
361  art::Event &evt,
362  art::Ptr<T> &a,
363  art::Ptr<U> b,
364  art::Assns<T,U> &assn)
365 {
366  bool ret = true;
367 
368  try{
369  assn.addSingle(a, b);
370  }
371  catch(cet::exception &e){
372  mf::LogWarning("AssociationUtil") << "unable to create requested "
373  << "art:Assns, exception thrown: "
374  << e;
375  ret = false;
376  }
377 
378  return ret;
379 }
380 
381 //----------------------------------------------------------------------
382 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
383  art::Event &evt,
384  std::vector<T> &a,
385  art::PtrVector<U> b,
386  art::Assns<T,U> &assn,
387  size_t indx,
388  std::string const& instance)
389 {
390 
391  bool ret = true;
392 
393  if(indx == UINT_MAX) indx = a.size()-1;
394 
395  try{
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]);
399  }
400  catch(cet::exception &e){
401  mf::LogWarning("AssociationUtil") << "unable to create requested "
402  << "art:Assns, exception thrown: "
403  << e;
404  ret = false;
405  }
406 
407  return ret;
408 }
409 
410 //----------------------------------------------------------------------
411 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
412  art::Event &evt,
413  std::vector<T> &a,
414  std::vector<art::Ptr<U> > b,
415  art::Assns<T,U> &assn,
416  size_t indx,
417  std::string const& instance)
418 {
419  bool ret = true;
420 
421  if(indx == UINT_MAX) indx = a.size()-1;
422 
423  try{
424  art::ProductID aid = evt.getProductID< std::vector<T> >(instance);
425  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
426 
427  for(size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
428  }
429  catch(cet::exception &e){
430  mf::LogWarning("AssociationUtil") << "unable to create requested "
431  << "art:Assns, exception thrown: "
432  << e;
433  ret = false;
434  }
435 
436  return ret;
437 }
438 
439 //----------------------------------------------------------------------
440 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
441  art::Event &evt,
442  art::Ptr<T> &a,
443  std::vector<art::Ptr<U> > b,
444  art::Assns<T,U> &assn)
445 {
446  bool ret = true;
447 
448  try{
449  for(size_t i = 0; i < b.size(); ++i) assn.addSingle(a, b[i]);
450  }
451  catch(cet::exception &e){
452  mf::LogWarning("AssociationUtil") << "unable to create requested "
453  << "art:Assns, exception thrown: "
454  << e;
455  ret = false;
456  }
457 
458  return ret;
459 }
460 
461 //----------------------------------------------------------------------
462 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
463  art::Event &evt,
464  std::vector<T> &a,
465  std::vector<U> &b,
466  art::Assns<T,U> &assn,
467  size_t startU,
468  size_t endU,
469  size_t indx,
470  std::string const& instancea,
471  std::string const& instanceb)
472 {
473 
474  bool ret = true;
475 
476  if(indx == UINT_MAX) indx = a.size()-1;
477 
478  try{
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);
485  }
486  }
487  catch(cet::exception &e){
488  mf::LogWarning("AssociationUtil") << "unable to create requested "
489  << "art:Assns, exception thrown: "
490  << e;
491  ret = false;
492  }
493 
494  return ret;
495 }
496 
497 //----------------------------------------------------------------------
498 template<class T, class U> inline bool util::CreateAssn(art::EDProducer const& prod,
499  art::Event &evt,
500  art::Assns<T,U> &assn,
501  std::vector<T> &a,
502  std::vector<U> &b,
503  size_t indxb,
504  size_t indxa,
505  std::string const& instancea,
506  std::string const& instanceb)
507 {
508 
509  bool ret = true;
510 
511  if(indxa == UINT_MAX) indxa = a.size()-1;
512  if(indxb == UINT_MAX) indxb = b.size()-1;
513 
514  try{
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);
520  }
521  catch(cet::exception &e){
522  mf::LogWarning("AssociationUtil") << "unable to create requested "
523  << "art:Assns, exception thrown: "
524  << e;
525  ret = false;
526  }
527 
528  return ret;
529 }
530 
531 //----------------------------------------------------------------------
532 template<class T, class U> inline std::vector<const U*> util::FindUNotAssociatedToT(art::Handle<U> b,
533  art::Event const& evt,
534  std::string const& label)
535 {
536 
537  // Do a FindOne for type T for each object of type U
538  // If the FindOne returns an invalid maybe ref, add the pointer
539  // of object type U to the return vector
540 
541  std::vector<const U*> notAssociated;
542 
543  art::FindOne<T> fa(b, evt, label);
544 
545  for(size_t u = 0; u < b->size(); ++u){
546  cet::maybe_ref<T const> t(fa.at(u));
547  if( !t.isValid() ){
548  art::Ptr<U> ptr(b, u);
549  notAssociated.push_back(ptr.get());
550  }
551  }
552 
553  return notAssociated;
554 }
555 
556 //----------------------------------------------------------------------
557 template<class T, class U> inline std::vector< art::Ptr<U> > util::FindUNotAssociatedToTP(art::Handle<U> b,
558  art::Event const& evt,
559  std::string const& label)
560 {
561 
562  // Do a FindOneP for type T for each object of type U
563  // If the FindOne returns an invalid maybe ref, add the pointer
564  // of object type U to the return vector
565 
566  std::vector< art::Ptr<U> > notAssociated;
567 
568  art::FindOneP<T> fa(b, evt, label);
569 
570  for(size_t u = 0; u < b->size(); ++u){
571  cet::maybe_ref<T const> t(fa.at(u));
572  if( !t.isValid() ){
573  art::Ptr<U> ptr(b, u);
574  notAssociated.push_back(ptr);
575  }
576  }
577 
578  return notAssociated;
579 }
580 
581 
582 
583 
584 //----------------------------------------------------------------------
585 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
586  art::Event &evt,
587  std::vector<T> &a,
588  art::Ptr<U> b,
589  art::Assns<T,U> &assn,
590  size_t indx,
591  std::string const& instance)
592 {
593  bool ret = true;
594 
595  if(indx == UINT_MAX) indx = a.size()-1;
596 
597  try{
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);
601  }
602  catch(cet::exception &e){
603  mf::LogWarning("AssociationUtil") << "unable to create requested "
604  << "art:Assns, exception thrown: "
605  << e;
606  ret = false;
607  }
608 
609  return ret;
610 }
611 
612 //----------------------------------------------------------------------
613 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
614  art::Event &evt,
615  std::vector<T> &a,
616  art::Ptr<U> b,
617  art::Assns<T,U> &assn,
618  size_t begin_indx,
619  size_t end_indx,
620  std::string const& instance)
621 {
622  if(end_indx == UINT_MAX) end_indx = a.size();
623 
624  try{
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);
630  }
631  }
632  catch(cet::exception &e){
633  mf::LogWarning("AssociationUtil") << "unable to create requested "
634  << "art:Assns, exception thrown: "
635  << e;
636  return false;
637  }
638 
639  return true;
640 }
641 
642 
643 //----------------------------------------------------------------------
644 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
645  art::Event &evt,
646  art::Ptr<T> &a,
647  art::Ptr<U> b,
648  art::Assns<T,U> &assn)
649 {
650  bool ret = true;
651 
652  try{
653  assn.addSingle(a, b);
654  }
655  catch(cet::exception &e){
656  mf::LogWarning("AssociationUtil") << "unable to create requested "
657  << "art:Assns, exception thrown: "
658  << e;
659  ret = false;
660  }
661 
662  return ret;
663 }
664 
665 //----------------------------------------------------------------------
666 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
667  art::Event &evt,
668  std::vector<T> &a,
669  art::PtrVector<U> b,
670  art::Assns<T,U> &assn,
671  size_t indx,
672  std::string const& instance)
673 {
674 
675  bool ret = true;
676 
677  if(indx == UINT_MAX) indx = a.size()-1;
678 
679  try{
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]);
683  }
684  catch(cet::exception &e){
685  mf::LogWarning("AssociationUtil") << "unable to create requested "
686  << "art:Assns, exception thrown: "
687  << e;
688  ret = false;
689  }
690 
691  return ret;
692 }
693 
694 //----------------------------------------------------------------------
695 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
696  art::Event &evt,
697  std::vector<T> &a,
698  std::vector<art::Ptr<U> > b,
699  art::Assns<T,U> &assn,
700  size_t indx,
701  std::string const& instance)
702 {
703  bool ret = true;
704 
705  if(indx == UINT_MAX) indx = a.size()-1;
706 
707  try{
708  art::ProductID aid = evt.getProductID< std::vector<T> >(instance);
709  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
710 
711  for(size_t i = 0; i < b.size(); ++i) assn.addSingle(aptr, b[i]);
712  }
713  catch(cet::exception &e){
714  mf::LogWarning("AssociationUtil") << "unable to create requested "
715  << "art:Assns, exception thrown: "
716  << e;
717  ret = false;
718  }
719 
720  return ret;
721 }
722 
723 //----------------------------------------------------------------------
724 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
725  art::Event &evt,
726  art::Ptr<T> &a,
727  std::vector<art::Ptr<U> > b,
728  art::Assns<T,U> &assn)
729 {
730  bool ret = true;
731 
732  try{
733  for(size_t i = 0; i < b.size(); ++i) assn.addSingle(a, b[i]);
734  }
735  catch(cet::exception &e){
736  mf::LogWarning("AssociationUtil") << "unable to create requested "
737  << "art:Assns, exception thrown: "
738  << e;
739  ret = false;
740  }
741 
742  return ret;
743 }
744 
745 //----------------------------------------------------------------------
746 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
747  art::Event &evt,
748  std::vector<T> &a,
749  std::vector<U> &b,
750  art::Assns<T,U> &assn,
751  size_t startU,
752  size_t endU,
753  size_t indx,
754  std::string const& instancea,
755  std::string const& instanceb)
756 {
757 
758  bool ret = true;
759 
760  if(indx == UINT_MAX) indx = a.size()-1;
761 
762  try{
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);
769  }
770  }
771  catch(cet::exception &e){
772  mf::LogWarning("AssociationUtil") << "unable to create requested "
773  << "art:Assns, exception thrown: "
774  << e;
775  ret = false;
776  }
777 
778  return ret;
779 }
780 
781 //----------------------------------------------------------------------
782 template<class T, class U> inline bool util::CreateAssn(art::EDFilter const& prod,
783  art::Event &evt,
784  art::Assns<T,U> &assn,
785  std::vector<T> &a,
786  std::vector<U> &b,
787  size_t indxb,
788  size_t indxa,
789  std::string const& instancea,
790  std::string const& instanceb)
791 {
792 
793  bool ret = true;
794 
795  if(indxa == UINT_MAX) indxa = a.size()-1;
796  if(indxb == UINT_MAX) indxb = b.size()-1;
797 
798  try{
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);
804  }
805  catch(cet::exception &e){
806  mf::LogWarning("AssociationUtil") << "unable to create requested "
807  << "art:Assns, exception thrown: "
808  << e;
809  ret = false;
810  }
811 
812  return ret;
813 }
814 
815 
816 
817 #endif //ASSOCIATIONUTIL_H
const std::string instance
process_name gaushit a
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
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)
do i e
std::vector< const U * > FindUNotAssociatedToT(art::Handle< U > b, art::Event const &evt, std::string const &label)
TCEvent evt
Definition: DataStructs.cxx:8