AliPhysics  master (3d17d9d)
AliEmcalContainerIndexMap< U, V > Class Template Reference

Container or array to index mapping for AliEmcalContainer derived classes. More...

#include <AliEmcalContainerIndexMap.h>

Public Member Functions

 AliEmcalContainerIndexMap ()
 
 AliEmcalContainerIndexMap (const AliEmcalContainerIndexMap &map)
 
AliEmcalContainerIndexMapoperator= (AliEmcalContainerIndexMap map)
 
 AliEmcalContainerIndexMap (AliEmcalContainerIndexMap< U, V > &&other)
 
virtual ~AliEmcalContainerIndexMap ()
 
int RegisterArray (U *inputObject)
 
template<class U2 >
void CopyMappingFrom (const AliEmcalContainerIndexMap< U2, V > &map, U *cont)
 
template<class U2 >
void CopyMappingFrom (const AliEmcalContainerIndexMap< U2, V > &map, TCollection &containers)
 
template<class U2 >
int GetOffset (const U2 *inputObject) const
 
int GlobalIndexFromLocalIndex (const U *inputObject, const int localIndex) const
 
std::pair< int, U * > LocalIndexFromGlobalIndex (const int globalIndex) const
 
V * GetObjectFromGlobalIndex (const int globalIndex) const
 

Protected Member Functions

const TClonesArray * GetObject (const AliEmcalContainer *inputObject) const
 
const TClonesArray * GetObject (const TClonesArray *inputObject) const
 
bool IsUnderlyingInputObjectTypeCompatible (const U *inputObject) const
 

Protected Attributes

std::map< int, U * > fGlobalIndexMap
 ! Map between index and input object More...
 
int fOffset
 Offset between each TClonesArray. More...
 
TClass * fClass
 Used to compare the type of V against the underlying input object type. More...
 

Friends

template<class X , class Y >
void swap (AliEmcalContainerIndexMap< X, Y > &first, AliEmcalContainerIndexMap< X, Y > &second)
 

Detailed Description

template<class U, class V>
class AliEmcalContainerIndexMap< U, V >

Container or array to index mapping for AliEmcalContainer derived classes.

AliEmcalContainerIndexMap contains index mapping for AliEmcalContainer derived classes. The mapping is from a single global linear array to an index in a collection of a container. For example, if there are two containers, then container a would be at offset 0 and container b at offset 1000. Then, the third particle in container b would be indexed as 1002, while the third particle in container a would be indexed as 2.

Below, input object (or inputObject) should be read as a TClonesArray or AliEmcalContainer derived class. An object of interest will usually be what we are trying to retrieve, so usually a AliVCluster or AliVParticle derived class, but could be any type derived from TObject.

Generally, U corresponds to the input object and V corresponds to the object of interest.

Actually using the index mapping requires a few steps. The mapping between the TClonesArrays used by cluster or particle containers and indices is stored in each container class. Thus, the first step is to copy that mapping, adapting it to map between the containers in your task and the indices. To do so, create an instance of AliEmcalContainerIndexMap for your class and then copy the mapping with CopyMappingFrom(). For example:

// This example will focus on particle containers.
// The particle containers are assumed to be stored in fParticleCollArray, which is
// a TObjArray defined in AliAnalysisTaskEmcal (assuming your task inherits from it).
// Define the object to container the container to index mapping.
// It is recommended to call CopyMappingFrom() in ExecOnce().
// At the very least, it must be after the arrays are set in the containers!

Now, we can access the objects as desired. Some example might include:

// We must already have the global index from somewhere, such as the id of a
// track matched to a cluster.
// Get the particle
AliVParticle * particleOne = particleMap.GetObjectFromGlobalIndex(globalIndex);
// Or get the index and the associated container
auto result = particleMap.LocalIndexFromGlobalIndex(globalIndex);
Int_t localIndex = result.first;
AliParticleContainer * partCont = result.second;
// Can use the result to check whether a particle is accepted.
AliVParticle * particleTwo = partCont.GetAcceptParticle(localIndex);

For some additional information, see the framework details in the embedding documentation.

Author
Raymond Ehlers raymo.nosp@m.nd.e.nosp@m.hlers.nosp@m.@cer.nosp@m.n.ch, Yale University
Date
Nov 21, 2016

Definition at line 74 of file AliEmcalContainerIndexMap.h.

Constructor & Destructor Documentation

template<class U , class V >
AliEmcalContainerIndexMap< U, V >::AliEmcalContainerIndexMap ( )

Standard constructor

Definition at line 127 of file AliEmcalContainerIndexMap.h.

template<class U , class V >
AliEmcalContainerIndexMap< U, V >::AliEmcalContainerIndexMap ( const AliEmcalContainerIndexMap< U, V > &  map)

Copy Constructor

Definition at line 138 of file AliEmcalContainerIndexMap.h.

template<class U, class V>
AliEmcalContainerIndexMap< U, V >::AliEmcalContainerIndexMap ( AliEmcalContainerIndexMap< U, V > &&  other)

Move constructor

Definition at line 149 of file AliEmcalContainerIndexMap.h.

template<class U, class V>
virtual AliEmcalContainerIndexMap< U, V >::~AliEmcalContainerIndexMap ( )
inlinevirtual

Definition at line 87 of file AliEmcalContainerIndexMap.h.

Member Function Documentation

template<class U, class V>
template<class U2 >
void AliEmcalContainerIndexMap< U, V >::CopyMappingFrom ( const AliEmcalContainerIndexMap< U2, V > &  map,
U *  cont 
)

Copy a given index mapping from one AliEmcalContainerIndexMap object to the current one. The map values which are copied are those corresponding to the input object passed to this function. For a collection of input objects, see the other signature for this function.

Parameters
mapAliEmcalContainerIndexMap object containing the index map that should be copied.
contThe input object whose index value should be copied from the index map.
Returns

Definition at line 400 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalCorrectionClusterHadronicCorrection::ExecOnce(), AliEmcalCorrectionClusterTrackMatcher::ExecOnce(), AliEmcalJetTask::ExecOnce(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U, class V>
template<class U2 >
void AliEmcalContainerIndexMap< U, V >::CopyMappingFrom ( const AliEmcalContainerIndexMap< U2, V > &  map,
TCollection containers 
)

Copy a given index mapping from one AliEmcalContainerIndexMap object to the current one. The map values which are copied are those corresponding to the input objects collection passed to this function. For a single input object, see the other signature for this function.

Parameters
mapAliEmcalContainerIndexMap object containing the index map that should be copied.
containersThe collection of input objects whose index values should be copied from the index map.
Returns

Definition at line 372 of file AliEmcalContainerIndexMap.h.

template<class U , class V >
const TClonesArray * AliEmcalContainerIndexMap< U, V >::GetObject ( const AliEmcalContainer inputObject) const
inlineprotected

Get the proper object to use in comparison. This function handles AliEmcalContainer derived classes.

Note: If we use enable_if<> in the future, we should check that it is an AliEmcalContainer derived class with std::is_conertible<>.

Parameters
inputObjectAliEmcalContainer derived class.
Returns
TClonesArray to be mapped.

Definition at line 190 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalContainerIndexMap< U, V >::GetOffset(), AliEmcalContainerIndexMap< U, V >::RegisterArray(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U , class V >
const TClonesArray * AliEmcalContainerIndexMap< U, V >::GetObject ( const TClonesArray *  inputObject) const
inlineprotected

Get the proper object to use in comparison. This function handles a TClonesArray. It is really just a dummy function, but is needed so that AliEmcalContainer derived classes work correctly.

Parameters
inputObjectThe TClonesArray to be mapped.
Returns
TClonesArray to be mapped.

Definition at line 204 of file AliEmcalContainerIndexMap.h.

template<class U , class V >
V * AliEmcalContainerIndexMap< U, V >::GetObjectFromGlobalIndex ( const int  globalIndex) const

Gets the object of interest at the global index. Leverages LocalIndexFromGlobalIndex() to get the array location of the object, as well as the input object.

Parameters
globalIndex
Returns
The object of interest, cast to the proper type.

Definition at line 352 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalCorrectionClusterHadronicCorrection::ApplyHadCorrAllTracks(), AliEmcalCorrectionClusterHadronicCorrection::ApplyHadCorrOneTrack(), AliEmcalJet::Cluster(), AliEmcalCorrectionClusterHadronicCorrection::DoMatchedTracksLoop(), AliEmcalJet::Track(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U , class V >
template<class U2 >
int AliEmcalContainerIndexMap< U, V >::GetOffset ( const U2 *  inputObject) const

Get the offset assigned to a particular input object.

Parameters
inputObjectInput object which we want to get the offset of in the map.
Returns
Global index corresponding to the offset of the input object in the map.

Definition at line 309 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalContainerIndexMap< U, V >::CopyMappingFrom(), AliEmcalContainerIndexMap< U, V >::GlobalIndexFromLocalIndex(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U, class V >
int AliEmcalContainerIndexMap< U, V >::GlobalIndexFromLocalIndex ( const U *  inputObject,
const int  localIndex 
) const

Get the global index from the local index of an object of interest in the input object. The input object is needed to determine the offset.

Parameters
inputObjectInput object where the object of interest resides.
localIndexLocal index of the object of interest in the input object.
Returns
globalIndex The global index of the object of interest.

Definition at line 285 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalJetTask::FillJetConstituents(), AliEmcalCorrectionClusterTrackMatcher::GenerateEmcalParticles(), AliEmcalCorrectionClusterHadronicCorrection::Run(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U, class V >
bool AliEmcalContainerIndexMap< U, V >::IsUnderlyingInputObjectTypeCompatible ( const U *  inputObject) const
inlineprotected

Check if the type to cast the object of interest (ie V) is compatible with the underlying object type of the input object. Note that the input object must implement GetClass() (which for AliEmcalContainer derived classes, it passes through the GetClass() of the underlying TClonesArray) in order to check the type.

If the types are incompatible (ie returns false), then an AliError is thrown!

Parameters
inputObjectInput object to be checked.
Returns
True if the underlying type is compatible.

Definition at line 221 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalContainerIndexMap< U, V >::CopyMappingFrom(), AliEmcalContainerIndexMap< U, V >::RegisterArray(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U , class V >
std::pair< int, U * > AliEmcalContainerIndexMap< U, V >::LocalIndexFromGlobalIndex ( const int  globalIndex) const

Get the local index of an object of interest from the global index.

Parameters
globalIndexGlobal index of the object of interest
Returns
std::pair of the local index and the associated input object (could be TClonesArray * or AliEmcalContainer *). The input object can be used to retrieve the object of interest.

Definition at line 332 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalCorrectionClusterHadronicCorrection::ApplyHadCorrAllTracks(), AliEmcalCorrectionClusterHadronicCorrection::ApplyHadCorrOneTrack(), AliEmcalJet::ClusterAt(), AliEmcalCorrectionClusterHadronicCorrection::DoMatchedTracksLoop(), AliEmcalContainerIndexMap< U, V >::GetObjectFromGlobalIndex(), AliEmcalJet::TrackAt(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

template<class U , class V >
AliEmcalContainerIndexMap< U, V > & AliEmcalContainerIndexMap< U, V >::operator= ( AliEmcalContainerIndexMap< U, V >  map)

Assignment operator. Note that we pass by value, so a copy is created and it is fine to swap the values with the created object!

Definition at line 160 of file AliEmcalContainerIndexMap.h.

template<class U, class V >
int AliEmcalContainerIndexMap< U, V >::RegisterArray ( U *  inputObject)

Add arrays to the map. We are just comparing the address that the TClonesArray points to. Given that we should be in control of everyting, this should always be a fine way to make the comparison, and much faster than comparing the entire object.

Parameters
inputObjectInput object to be registered in the map. Can be either AliEmcalContainer or TClonesArray
Returns
Index where the input object is registered.

Definition at line 242 of file AliEmcalContainerIndexMap.h.

Referenced by AliParticleContainer::SetArray(), AliClusterContainer::SetArray(), and AliEmcalContainerIndexMap< AliClusterContainer, AliVCluster >::~AliEmcalContainerIndexMap().

Friends And Related Function Documentation

template<class U, class V>
template<class X , class Y >
void swap ( AliEmcalContainerIndexMap< X, Y > &  first,
AliEmcalContainerIndexMap< X, Y > &  second 
)
friend

Member Data Documentation

template<class U, class V>
TClass* AliEmcalContainerIndexMap< U, V >::fClass
protected

Used to compare the type of V against the underlying input object type.

Definition at line 120 of file AliEmcalContainerIndexMap.h.

Referenced by AliEmcalContainerIndexMap< U, V >::IsUnderlyingInputObjectTypeCompatible(), and swap().

template<class U, class V>
int AliEmcalContainerIndexMap< U, V >::fOffset
protected

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