LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
lar::FindManyInChainP< Target, Intermediate > Class Template Reference

Query object collecting a list of associated objects. More...

#include "FindManyInChainP.h"

Public Types

using Target_t = Target
 Type of the associated objects. More...
 
using TargetPtr_t = art::Ptr< Target_t >
 Pointer to associated objects. More...
 
using TargetPtrCollection_t = std::vector< TargetPtr_t >
 Type returned by at() method. More...
 

Public Member Functions

template<typename Source , typename Event , typename... InputTags>
 FindManyInChainP (Source &&source, Event const &event, InputTags...tags)
 Constructor: extracts target objects associated to all objects under the specified handle. More...
 
std::size_t size () const noexcept
 Returns the number of Source objects we have information about. More...
 
TargetPtrCollection_t const & at (std::size_t i) const
 Returns all the Target objects associated to specified object. More...
 

Static Public Member Functions

template<typename Source , typename Event , typename... InputTags>
static std::vector< TargetPtrCollection_tfind (Source &&source, Event const &event, InputTags...tags)
 Returns target objects associated to all objects contained in the specified source. More...
 

Private Attributes

std::vector< TargetPtrCollection_tresults
 Stored results. More...
 

Detailed Description

template<typename Target, typename... Intermediate>
class lar::FindManyInChainP< Target, Intermediate >

Query object collecting a list of associated objects.

Template Parameters
Targettype of objects to be fetched
Intermediatetypes of objects connecting to Target by association

This query object collects information about all objects of type Target associated to each specified object of type Source. The Source type is implicitly specified in the constructor. For example, each recob::Shower object is expected to be associated to a number of recob::Cluster objects, and each one of these clusters must be associated to recob::Hit objects. To retrieve all the hit objects associated to a shower collection (not recommended):

auto showers = event.getValidHandle<std::vector<recob::Shower>>(showerTag);
(showers, event, showerTag);
for (std::size_t iShower = 0; iShower < showers.size(); ++iShower) {
recob::Shower const& shower = (*showers)[iShower];
decltype(auto) showerHits = showerToHits.at(iShower);
// ...
} // for each shower

In this example, it is explicitly stated that the producer of the shower associations to clusters is the same as the producer of the showers, as the same input tag showerTag is used. It is also implicitly assumed that the same producer which created the associated clusters is also responsible for the creation of the associations between clusters and hits.

The example shows the similarity with art::FindManyP. In fact, this object has a similar interface, and a similar functionality too. Nevertheless, prefer using the static member find() and then using its result directly, as it has a more complete interface:

auto showers = event.getValidHandle<std::vector<recob::Shower>>(showerTag);
std::size_t iShower = 0;
for (auto const& showerHits:
(showers, event, showerTag)
)
{
recob::Shower const& shower = (*showers)[iShower++];
// all associated hits are already in showerHits
// ...
} // for each shower

This is the recommended approach, as long as lar::FindManyInChainP() has to be called only once.

Note
Due to the inability to retrieve provenance information in gallery, this class is not compatible with gallery.

Definition at line 109 of file FindManyInChainP.h.

Member Typedef Documentation

template<typename Target , typename... Intermediate>
using lar::FindManyInChainP< Target, Intermediate >::Target_t = Target

Type of the associated objects.

Definition at line 112 of file FindManyInChainP.h.

template<typename Target , typename... Intermediate>
using lar::FindManyInChainP< Target, Intermediate >::TargetPtr_t = art::Ptr<Target_t>

Pointer to associated objects.

Definition at line 113 of file FindManyInChainP.h.

template<typename Target , typename... Intermediate>
using lar::FindManyInChainP< Target, Intermediate >::TargetPtrCollection_t = std::vector<TargetPtr_t>

Type returned by at() method.

Definition at line 117 of file FindManyInChainP.h.

Constructor & Destructor Documentation

template<typename Target , typename... Intermediate>
template<typename Source , typename Event , typename... InputTags>
lar::FindManyInChainP< Target, Intermediate >::FindManyInChainP ( Source &&  source,
Event const &  event,
InputTags...  tags 
)
inline

Constructor: extracts target objects associated to all objects under the specified handle.

Template Parameters
Sourcetype of source: art Handle or collection of art pointers
Eventtype of event to be used (either art or gallery Event)
InputTagsa variable number of art::InputTag objects
Parameters
sourceart Handle or collection of art pointers to source objects
eventthe event to read associations and objects from
tagsinput tags for each one of the required associations
See also
find()

This constructor finds the associated objects as in find(), and stored the result. Access to it will be performed e.g. by the at() method.

Definition at line 135 of file FindManyInChainP.h.

136  : results(find(std::forward<Source>(source), event, tags...))
137  {}
static std::vector< TargetPtrCollection_t > find(Source &&source, Event const &event, InputTags...tags)
Returns target objects associated to all objects contained in the specified source.
std::vector< TargetPtrCollection_t > results
Stored results.
Event finding and building.

Member Function Documentation

template<typename Target , typename... Intermediate>
TargetPtrCollection_t const& lar::FindManyInChainP< Target, Intermediate >::at ( std::size_t  i) const

Returns all the Target objects associated to specified object.

Parameters
iindex of the source object to query
Returns
a sequence of art pointers to the associated Target objects
Exceptions
std::out_of_rangeif the specified index is not valid

The specified index matches the index of the element in the collection this query object was constructed with. For example:

auto showers
= event.getValidHandle<std::vector<recob::Shower>>(showerTag);
(shower, event, showerTag);
for (std::size_t iShower = 0; iShower < showers.size(); ++iShower) {
recob::Shower const& shower = (*showers)[iShower];
decltype(auto) showerHits = showerToHits.at(iShower);
// ...
} // for each shower

the showerHits will pertain the iShower-th recob::Shower (shower) on each iteration of the loop.

The returned sequence points to objects convertible to art pointers to Target (e.g., art::Ptr<Target>). The order of the objects in this sequence is not defined. The same Target object may appear more than once if two intermediate objects are associated to the same target (or intermediate object of tier closer to the target). This sequence is of an unspecified type, guaranteed to support std::begin(), std::end(), size() method and to be iterable in a range-for loop. For example, it may be a STL vector returned by constant reference.

template<typename Target , typename... Intermediate>
template<typename Source , typename Event , typename... InputTags>
static std::vector<TargetPtrCollection_t> lar::FindManyInChainP< Target, Intermediate >::find ( Source &&  source,
Event const &  event,
InputTags...  tags 
)
static

Returns target objects associated to all objects contained in the specified source.

Template Parameters
Sourcetype of source: art Handle or collection of art pointers
Eventtype of event to be used (either art or gallery Event)
InputTagsa variable number of art::InputTag objects
Parameters
sourceart Handle or collection of art pointers to source objects
eventthe event to read associations and objects from
tagsinput tags for each one of the required associations
Returns
collection of lists of pointers to associated objects, one for each source element, in the same order

This methods returns a collection with an entry for each of the elements pointed by the specified handle, in the same order as they are extracted from the source collection.

The input tag arguments must be convertible to art::InputTag type. The first tag identifies the data product containing the associations between the Source collection (the same pointed by source) and the first Intermediate class. The second tag likewise points to the data product containing the associations between the first and the second Intermediate classes. The last tag, finally, points to the data product containing the associations between the last Intermediate class and the Target class. If one tag is not specified, it is assumed that the same class that produced the Intermediate (or Source) data product also produced the association to the next Intermediate (or Target) data product. Note that:

  • if the tag is specified, all associations are expected to come from that same tag; if the tag is not specified, elements from different data products will be assumed to have different association data products too
  • it is possible to "omit" the explicit specification of a tag by using the lar::SameAsData tag
template<typename Target , typename... Intermediate>
std::size_t lar::FindManyInChainP< Target, Intermediate >::size ( ) const
noexcept

Returns the number of Source objects we have information about.

Member Data Documentation

template<typename Target , typename... Intermediate>
std::vector<TargetPtrCollection_t> lar::FindManyInChainP< Target, Intermediate >::results
private

Stored results.

Definition at line 225 of file FindManyInChainP.h.


The documentation for this class was generated from the following file: