Functions
evgb::util Namespace Reference

Functions

template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
 Creates a single one-to-one association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, size_t indx=UINT_MAX)
 Creates a single one-to-one association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, art::Ptr< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn)
 Creates a single one-to-one association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::PtrVector< U > const &b, art::Assns< T, U > &assn, size_t indx=UINT_MAX)
 Creates a single one-to-many association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, art::Ptr< T > const &a, std::vector< art::Ptr< U >> const &b, art::Assns< T, U > &assn)
 Creates a single one-to-many association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, std::vector< art::Ptr< U >> const &b, art::Assns< T, U > &assn, size_t indx=UINT_MAX)
 Creates a single one-to-many association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, std::vector< U > const &b, art::Assns< T, U > &assn, size_t startU, size_t endU, size_t indx=UINT_MAX)
 Creates a single one-to-many association. More...
 
template<class PRODUCER , class T , class U >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, std::vector< U > const &b, art::Assns< T, U > &assn, std::vector< size_t > const &indices, size_t indx=UINT_MAX)
 Creates a single one-to-many association. More...
 
template<typename PRODUCER , typename T , typename U , typename Iter >
bool CreateAssn (PRODUCER const &prod, art::Event &evt, art::Assns< T, U > &assn, size_t first_index, Iter from_second_index, Iter to_second_index)
 Creates a single one-to-many association. More...
 
template<class T , class U >
std::vector< const U * > FindUNotAssociatedToT (art::Handle< U > b, art::Event const &evt, std::string const &label)
 
template<class T , class U >
std::vector< art::Ptr< U > > FindUNotAssociatedToTP (art::Handle< U > b, art::Event const &evt, std::string const &label)
 
template<class T , class U >
std::vector< size_t > GetAssociatedVectorOneI (art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
 
template<class T , class U >
std::vector< const U * > GetAssociatedVectorOneP (art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
 
template<class T , class U >
std::vector< std::vector< size_t > > GetAssociatedVectorManyI (art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
 
template<class T , class U >
std::vector< std::vector< const U * > > GetAssociatedVectorManyP (art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
 
template<typename PRODUCER , typename T , typename U , typename D >
bool CreateAssnD (PRODUCER const &prod, 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. More...
 
template<typename PRODUCER , typename T , typename U , typename D >
bool CreateAssnD (PRODUCER const &prod, 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 const &data)
 

Function Documentation

template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
art::Ptr< U > const &  b,
art::Assns< U, T > &  assn,
std::string  a_instance,
size_t  indx = UINT_MAX 
)

Creates a single one-to-one association.

Template Parameters
Ttype of the new object to associate
Utype of the object already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bart::Ptr to the (new) object to be associated to the one in a
assnreference to association object where the new one will be put
a_instancename of the instance that will be used for a in evt
indxindex of the element in a to be associated with b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

As example of usage: create a wire/raw digit association. This code should live in the art::EDProduce::produce() method. The raw::RawDigit product was created already by a DigitModuleLabel module. The code is supposed to produce one recob::Wire for each existing raw::RawDigit, and contextually associate the new wire to the source digit. We are also assuming that there might be different RawDigit sets produced by the same producer: we identify the one we care of by the string spill_name and we create wires and associations with the same label for convenience.

// this is the original list of digits, thawed from the event
art::Handle< std::vector<raw::RawDigit>> digitVecHandle;
evt.getByLabel(DigitModuleLabel, spill_name, digitVecHandle);

// the collection of wires that will be written as data product
std::unique_ptr<std::vector<recob::Wire>> wirecol(new std::vector<recob::Wire>);
// ... and an association set
std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire>> WireDigitAssn
  (new art::Assns<raw::RawDigit,recob::Wire>);

for(size_t iDigit = 0; iDigit < digitVecHandle->size(); ++iDigit) {
  // turn the digit into a art::Ptr:
  art::Ptr<raw::RawDigit> digit_ptr(digitVecHandle, iDigit);

  // store the wire in its final position in the data product;
  // the new wire is currently the last of the list
  wirecol->push_back(std::move(wire));

  // add an association between the last object in wirecol
  // (that we just inserted) and digit_ptr
  if (!evgb::util::CreateAssn(*this, evt, *wirecol, digit_ptr, *WireDigitAssn, spill_name)) {
    throw art::Exception(art::errors::ProductRegistrationFailure)
      << "Can't associate wire #" << (wirecol->size() - 1)
      << " with raw digit #" << digit_ptr.key();
  } // if failed to add association

} // for digits

evt.put(std::move(wirecol), spill_name);
evt.put(std::move(WireDigitAssn), spill_name);

Definition at line 593 of file EVGBAssociationUtil.h.

602 {
603  if (indx == UINT_MAX) indx = a.size()-1;
604 
605  try{
606  art::ProductID aid = evt.getProductID< std::vector<T>>( a_instance);
607  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
608  assn.addSingle(b, aptr);
609  return true;
610  }
611  catch(cet::exception &e){
612  mf::LogWarning("AssociationUtil")
613  << "unable to create requested art:Assns, exception thrown: " << e;
614  return false;
615  }
616 
617 } // evgb::util::CreateAssn() [01]
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:358
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
art::Ptr< U > const &  b,
art::Assns< U, T > &  assn,
size_t  indx = UINT_MAX 
)
inline

Creates a single one-to-one association.

Template Parameters
Ttype of the new object to associate
Utype of the object already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bart::Ptr to the (new) object to be associated to the one in a
assnreference to association object where the new one will be put
indxindex of the element in a to be associated with b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

The instance name of the product a will be in is assumed empty. Example of usage:

// this is the original list of digits, thawed from the event
art::Handle< std::vector<raw::RawDigit>> digitVecHandle;
evt.getByLabel(DigitModuleLabel, digitVecHandle);

// the collection of wires that will be written as data product
std::unique_ptr<std::vector<recob::Wire>> wirecol(new std::vector<recob::Wire>);
// ... and an association set
std::unique_ptr<art::Assns<raw::RawDigit,recob::Wire>> WireDigitAssn
  (new art::Assns<raw::RawDigit,recob::Wire>);

for(size_t iDigit = 0; iDigit < digitVecHandle->size(); ++iDigit) {
  // turn the digit into a art::Ptr:
  art::Ptr<raw::RawDigit> digit_ptr(digitVecHandle, iDigit);

  // store the wire in its final position in the data product;
  // the new wire is currently the last of the list
  wirecol->push_back(std::move(wire));

  // add an association between the last object in wirecol
  // (that we just inserted) and digit_ptr
  if (!evgb::util::CreateAssn(*this, evt, *wirecol, digit_ptr, *WireDigitAssn)) {
    throw art::Exception(art::errors::ProductRegistrationFailure)
      << "Can't associate wire #" << (wirecol->size() - 1)
      << " with raw digit #" << digit_ptr.key();
  } // if failed to add association

} // for digits

evt.put(std::move(wirecol));
evt.put(std::move(WireDigitAssn));

Definition at line 214 of file EVGBAssociationUtil.h.

220  { return CreateAssn(prod, evt, a, b, assn, std::string(), indx); }
bool CreateAssn(PRODUCER const &prod, art::Event &evt, art::Assns< T, U > &assn, size_t first_index, Iter from_second_index, Iter to_second_index)
Creates a single one-to-many association.
std::string string
Definition: nybbler.cc:12
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
art::Ptr< T > const &  a,
art::Ptr< U > const &  b,
art::Assns< U, T > &  assn 
)

Creates a single one-to-one association.

Template Parameters
Ttype of one object to associate
Utype of the other object to associate
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
aart::Ptr to the first object in the association
bart::Ptr to the object to be associated to the one in a
assnreference to association object where the new one will be put
Returns
whether the operation was successful (can it ever fail??)

This is the simplest way ever. Neither the event not the producer references are used.

Definition at line 623 of file EVGBAssociationUtil.h.

629  {
630 
631  try{
632  assn.addSingle(b, a);
633  }
634  catch(cet::exception &e){
635  mf::LogWarning("AssociationUtil")
636  << "unable to create requested art:Assns, exception thrown: " << e;
637  return false;
638  }
639 
640  return true;
641 } // evgb::util::CreateAssn() [03]
const double e
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
art::PtrVector< U > const &  b,
art::Assns< T, U > &  assn,
size_t  indx = UINT_MAX 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bart::PtrVector to the (new) objects to be associated to the one in a
assnreference to association object where the new one will be put
indxindex of the element in a to be associated with all the ones in b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Definition at line 647 of file EVGBAssociationUtil.h.

654  {
655  if(indx == UINT_MAX) indx = a.size() - 1;
656 
657  try{
658  art::ProductID aid = evt.getProductID< std::vector<T> >();
659  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
660  for(art::Ptr<U> const& b_item: b) assn.addSingle(aptr, b_item);
661  }
662  catch(cet::exception &e){
663  mf::LogWarning("AssociationUtil")
664  << "unable to create requested art:Assns, exception thrown: " << e;
665  return false;
666  }
667 
668  return true;
669 } // evgb::util::CreateAssn() [04]
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:358
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
art::Ptr< T > const &  a,
std::vector< art::Ptr< U >> const &  b,
art::Assns< T, U > &  assn 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
aart::Ptr to the item to be associated with many
bvector to art::Ptr to the (new) objects to be associated to a
assnreference to association object where the new one will be put
Returns
whether the operation was successful (can it ever fail??)

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Definition at line 674 of file EVGBAssociationUtil.h.

680  {
681 
682  try{
683  for (art::Ptr<U> const& b_item: b) assn.addSingle(a, b_item);
684  }
685  catch(cet::exception const& e){
686  mf::LogWarning("AssociationUtil")
687  << "unable to create requested art:Assns, exception thrown: " << e;
688  return false;
689  }
690 
691  return true;
692 } // evgb::util::CreateAssn() [05]
const double e
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
std::vector< art::Ptr< U >> const &  b,
art::Assns< T, U > &  assn,
size_t  indx = UINT_MAX 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bvector to art::Ptr to the (new) objects to be associated to the one in a
assnreference to association object where the new one will be put
indxindex of the element in a to be associated with all the ones in b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Definition at line 697 of file EVGBAssociationUtil.h.

704  {
705 
706  if (indx == UINT_MAX) indx = a.size() - 1;
707 
708  try{
709  art::ProductID aid = evt.getProductID< std::vector<T> >();
710  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
711  for (art::Ptr<U> const& b_item: b) assn.addSingle(aptr, b_item);
712  }
713  catch(cet::exception &e){
714  mf::LogWarning("AssociationUtil")
715  << "unable to create requested art:Assns, exception thrown: " << e;
716  return false;
717  }
718 
719  return true;
720 } // evgb::util::CreateAssn() [06]
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:358
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
std::vector< U > const &  b,
art::Assns< T, U > &  assn,
size_t  startU,
size_t  endU,
size_t  indx = UINT_MAX 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bvector of the (new) objects to be associated to the one in a
assnreference to association object where the new one will be put
startUindex in b of the first element to be associated to the one in a
endUindex in b after the last element to be associated to the one in a
indxindex of the element in a to be associated with all the ones in b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

Use this when the objects in b are not yet stored in the event and are in a std::vector collection instead.

The method gets the product id for those as well as for the element in a. Also specify the range of entries to use from the std::vector collection of U objects.

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Definition at line 725 of file EVGBAssociationUtil.h.

734  {
735 
736  if(indx == UINT_MAX) indx = a.size() - 1;
737 
738  try{
739  art::ProductID aid = evt.getProductID< std::vector<T> >();
740  art::ProductID bid = evt.getProductID< std::vector<U> >();
741  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
742  auto const* getter = evt.productGetter(bid); // I don't want to know what it is
743  for(size_t i = startU; i < endU; ++i){
744  art::Ptr<U> bptr(bid, i, getter);
745  assn.addSingle(aptr, bptr);
746  }
747  }
748  catch(cet::exception &e){
749  mf::LogWarning("AssociationUtil")
750  << "unable to create requested art:Assns, exception thrown: " << e;
751  return false;
752  }
753 
754  return true;
755 } // evgb::util::CreateAssn() [07]
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:358
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class PRODUCER , class T , class U >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
std::vector< T > const &  a,
std::vector< U > const &  b,
art::Assns< T, U > &  assn,
std::vector< size_t > const &  indices,
size_t  indx = UINT_MAX 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
avector of data products that are in, or will be put into, evt
bvector of the (new) objects to be associated to the one in a
assnreference to association object where the new one will be put
indicesindices of the elements in b to be associated to the one in a
indxindex of the element in a to be associated with all the ones in b (default: the last element)
Returns
whether the operation was successful (can it ever fail??)

Use this when the objects in b are not yet stored in the event and are in a std::vector collection instead.

The method gets the product id for those as well as for the element in a. Also specify the entries to use from the std::vector collection of U objects.

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Definition at line 760 of file EVGBAssociationUtil.h.

768  {
769 
770  if(indx == UINT_MAX) indx = a.size() - 1;
771 
772  try{
773  art::ProductID aid = prod.template getProductID< std::vector<T> >();
774  art::ProductID bid = prod.template getProductID< std::vector<U> >();
775  art::Ptr<T> aptr(aid, indx, evt.productGetter(aid));
776  auto const* getter = evt.productGetter(bid); // I don't want to know what it is
777  for(size_t index: indices){
778  art::Ptr<U> bptr(bid, index, getter);
779  assn.addSingle(aptr, bptr);
780  }
781  }
782  catch(cet::exception &e){
783  mf::LogWarning("AssociationUtil")
784  << "unable to create requested art:Assns, exception thrown: " << e;
785  return false;
786  }
787 
788  return true;
789 } // evgb::util::CreateAssn() [07a]
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename PRODUCER , typename T , typename U , typename Iter >
bool evgb::util::CreateAssn ( PRODUCER const &  prod,
art::Event evt,
art::Assns< T, U > &  assn,
size_t  first_index,
Iter  from_second_index,
Iter  to_second_index 
)

Creates a single one-to-many association.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Iteriterator to size_t-compatible elements
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
assnreference to association object where the new one will be put
first_indexindex of the object of type T to be associated to all the others
from_second_indexiterator pointing to the first of the indices of U type objects to be associated to the one of the first type
to_second_indexiterator pointing after the last of the indices of U type objects to be associated to the one of the first type
Returns
whether the operation was successful (can it ever fail??)

A "one-to-many" association is actually a number of one-to-one associations. If you want to keep the information of the order of the many, you may have to use an association with a data member (the third template parameter that we pretent not to exist).

Use this if the objects that have to be associated to the one of type T are sparse, spread across a to-be-data-product, but you have a list of the indices in the data product of the elements to associate to the one of type T. In other words, given that you have a data product "a" of type std::vector<T> and a data product "b" of type std::vector<U>, this method creates an association betweena[first_index]and b[*(from_second_index)], another between a[first_index] and b[*(from_second_index + 1)], etc.

The surprising concept here is that you don't need to specify neither of the collections of T or U elements. The data product is uniquely defined by its type, producer, process and product label. Here we assume that the type of the products are std::vector<T> and std::vector<U>, and that the products have empty product labels, and that the producer is prod for both of them.

Definition at line 794 of file EVGBAssociationUtil.h.

801  {
802 
803  try{
804  // We need the "product ID" of what is going to become a data product.
805  // The data product ID is unique for the combination of process, producer,
806  // data type and product (instance) label.
807  //
808  art::ProductID first_id = prod.template getProductID< std::vector<T> >();
809  art::ProductID second_id = prod.template getProductID< std::vector<U> >();
810 
811  // we declare here that we want to associate the element first_index of the
812  // (only) data product of type std::vector<T> with other objects.
813  // This is the pointer to that element:
814  art::Ptr<T> first_ptr(first_id, first_index, evt.productGetter(first_id));
815 
816  // we are going to associate that element in a with a number of elements
817  // of the only data product of type std::vector<U>
818  auto const* getter = evt.productGetter(second_id); // auto, spare me the details
819  while (from_second_index != to_second_index) {
820  art::Ptr<U> second_ptr(second_id, *from_second_index, getter);
821  assn.addSingle(first_ptr, second_ptr);
822  ++from_second_index;
823  } // while
824  }
825  catch(cet::exception &e){
826  mf::LogWarning("AssociationUtil")
827  << "unable to create requested art:Assns, exception thrown: " << e;
828  return false;
829  }
830 
831  return true;
832 } // evgb::util::CreateAssn() [08]
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename PRODUCER , typename T , typename U , typename D >
bool evgb::util::CreateAssnD ( PRODUCER const &  prod,
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.

Template Parameters
Ttype of the new object to associate
Utype of the many objects already in the data product or art::Ptr
Dtype of the "metadata" coupled to this pair association
Parameters
prodreference to the producer that will write the vector a
evtreference to the current event
assnreference to association object where the new one will be put
first_indexindex of the object of type T to be associated
second_indexindex of the object of type U to be associated
data"metadata" to be store in this association
Returns
whether the operation was successful (can it ever fail??)

Use this if you want some metadata to travel together with the association. An example may be the order of the second element within a list:

size_t a_index = 2;
std::vector<size_t> b_indices{ 6, 9, 18, 12 };
for (size_t i = 0; i < b_indices.size(); ++i)
  CreateAssn(prod, evt, assn, a_index, b_index[i], i);

In this way, the association between the element #2 of "a" (a vector that is not specified – nor needed – in this snippet of code) and the element #18 will be remembered as being the third (metadata value of 2). In this example metadata is of type size_t the association would be declared as art::Assn<A, B, size_t>. A FindMany query of that association might look like:

art::Handle<std::vector<A>> a_list; // read this from the event

art::FindMany<B, size_t> Query(a_list, event, ModuleLabel);

// search for the last of the objects associated to the third element:
size_t a_index = 2; // this means third element

std::vector<size_t const*> const& metadata = Query.data(a_index);
size_t largest_index = 0, last_item = 0;
for (size_t iB = 0; iB < metadata.size(); ++iB) {
  if (largest_index >= *(metadata[iB])) continue;
  largest_index = *(metadata[iB]);
  last_item = iB;
} // for iB
B const& lastB = Query.at(last_item);

In alternative, the elements and their metadata can be fetched simultaneously with:

std::vector<art::Ptr<B>> const& Bs;
std::vector<size_t const*> const& metadata;

size_t a_index = 2; // this means third element
size_t nMatches = Query.get(a_index, Bs, metadata);

Definition at line 838 of file EVGBAssociationUtil.h.

845  {
846 
847  try{
848  // We need the "product ID" of what is going to become a data product.
849  // The data product ID is unique for the combination of process, producer,
850  // data type and product (instance) label.
851  //
852  // we declare here that we want to associate the element first_index of the
853  // (only) data product of type std::vector<T> with the other object
854  art::ProductID first_id = prod.template getProductID< std::vector<T> >();
855  art::Ptr<T> first_ptr(first_id, first_index, evt.productGetter(first_id));
856 
857  // the same to associate the element second_index of the (only)
858  // data product of type std::vector<U> with the first object.
859  art::ProductID second_id = prod.template getProductID< std::vector<U> >();
860  art::Ptr<U> second_ptr
861  (second_id, second_index, evt.productGetter(second_id));
862 
863  assn.addSingle(first_ptr, second_ptr, std::move(data));
864  }
865  catch(cet::exception &e){
866  mf::LogWarning("AssociationUtil")
867  << "unable to create requested art:Assns, exception thrown: " << e;
868  return false;
869  }
870 
871  return true;
872 } // evgb::util::CreateAssnD() [01a]
const double e
def move(depos, offset)
Definition: depos.py:107
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename PRODUCER , typename T , typename U , typename D >
bool evgb::util::CreateAssnD ( PRODUCER const &  prod,
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 const &  data 
)

Definition at line 875 of file EVGBAssociationUtil.h.

882  {
883 
884  try{
885  // We need the "product ID" of what is going to become a data product.
886  // The data product ID is unique for the combination of process, producer,
887  // data type and product (instance) label.
888  //
889  // we declare here that we want to associate the element first_index of the
890  // (only) data product of type std::vector<T> with the other object
891  art::ProductID first_id = prod.template getProductID< std::vector<T> >();
892  art::Ptr<T> first_ptr(first_id, first_index, evt.productGetter(first_id));
893 
894  // the same to associate the element second_index of the (only)
895  // data product of type std::vector<U> with the first object.
896  art::ProductID second_id = prod.template getProductID< std::vector<U> >();
897  art::Ptr<U> second_ptr
898  (second_id, second_index, evt.productGetter(second_id));
899 
900  assn.addSingle(first_ptr, second_ptr, data);
901  }
902  catch(cet::exception &e){
903  mf::LogWarning("AssociationUtil")
904  << "unable to create requested art:Assns, exception thrown: " << e;
905  return false;
906  }
907 
908  return true;
909 } // evgb::util::CreateAssnD() [01b]
const double e
EDProductGetter const * productGetter(ProductID const pid) const
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class T , class U >
std::vector< const U * > evgb::util::FindUNotAssociatedToT ( art::Handle< U >  b,
art::Event const &  evt,
std::string const &  label 
)
inline

Definition at line 913 of file EVGBAssociationUtil.h.

916 {
917 
918  // Do a FindOne for type T for each object of type U
919  // If the FindOne returns an invalid maybe ref, add the pointer
920  // of object type U to the return vector
921 
922  std::vector<const U*> notAssociated;
923 
924  art::FindOne<T> fa(b, evt, label);
925 
926  for(size_t u = 0; u < b->size(); ++u){
927  cet::maybe_ref<T const> t(fa.at(u));
928  if( !t.isValid() ){
929  art::Ptr<U> ptr(b, u);
930  notAssociated.push_back(ptr.get());
931  }
932  }
933 //
934  return notAssociated;
935 }
TCEvent evt
Definition: DataStructs.cxx:7
Definition: fwd.h:29
template<class T , class U >
std::vector< art::Ptr< U > > evgb::util::FindUNotAssociatedToTP ( art::Handle< U >  b,
art::Event const &  evt,
std::string const &  label 
)
inline

Definition at line 938 of file EVGBAssociationUtil.h.

941 {
942 
943  // Do a FindOneP for type T for each object of type U
944  // If the FindOne returns an invalid maybe ref, add the pointer
945  // of object type U to the return vector
946 
947  std::vector< art::Ptr<U> > notAssociated;
948 
949  art::FindOneP<T> fa(b, evt, label);
950 
951  for(size_t u = 0; u < b->size(); ++u){
952  cet::maybe_ref<T const> t(fa.at(u));
953  if( !t.isValid() ){
954  art::Ptr<U> ptr(b, u);
955  notAssociated.push_back(ptr);
956  }
957  }
958 
959  return notAssociated;
960 }
TCEvent evt
Definition: DataStructs.cxx:7
Definition: fwd.h:29
template<class T , class U >
std::vector< std::vector< size_t > > evgb::util::GetAssociatedVectorManyI ( art::Handle< art::Assns< T, U > >  h,
art::Handle< std::vector< T > >  index_p 
)
inline

Definition at line 982 of file EVGBAssociationUtil.h.

984 {
985  std::vector< std::vector<size_t> > associated_indices(index_p->size());
986  for(auto const& pair : *h)
987  associated_indices.at(pair.first.key()).push_back(pair.second.key());
988  return associated_indices;
989 }
template<class T , class U >
std::vector< std::vector< const U * > > evgb::util::GetAssociatedVectorManyP ( art::Handle< art::Assns< T, U > >  h,
art::Handle< std::vector< T > >  index_p 
)
inline

Definition at line 991 of file EVGBAssociationUtil.h.

993 {
994  std::vector< std::vector<const U*> > associated_pointers(index_p->size());
995  for(auto const& pair : *h)
996  associated_pointers.at(pair.first.key()).push_back( &(*(pair.second)) );
997  return associated_pointers;
998 }
template<class T , class U >
std::vector< size_t > evgb::util::GetAssociatedVectorOneI ( art::Handle< art::Assns< T, U > >  h,
art::Handle< std::vector< T > >  index_p 
)
inline

Definition at line 964 of file EVGBAssociationUtil.h.

966 {
967  std::vector<size_t> associated_index(index_p->size());
968  for(auto const& pair : *h)
969  associated_index.at(pair.first.key()) = pair.second.key();
970  return associated_index;
971 }
template<class T , class U >
std::vector< const U * > evgb::util::GetAssociatedVectorOneP ( art::Handle< art::Assns< T, U > >  h,
art::Handle< std::vector< T > >  index_p 
)
inline

Definition at line 973 of file EVGBAssociationUtil.h.

975 {
976  std::vector<const U*> associated_pointer(index_p->size());
977  for(auto const& pair : *h)
978  associated_pointer.at(pair.first.key()) = &(*(pair.second));
979  return associated_pointer;
980 }