Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

lcrtrel::LCRTRelations Class Reference

Base class that provides run time (user) extensions and relation between objects. More...

#include <LCRTRelations.h>

Inheritance diagram for lcrtrel::LCRTRelations:

EVENT::LCObject EVENT::CalorimeterHit EVENT::Cluster EVENT::LCFloatVec EVENT::LCGenericObject EVENT::LCIntVec EVENT::LCRelation EVENT::LCRunHeader EVENT::LCStrVec EVENT::MCParticle EVENT::ParticleID EVENT::RawCalorimeterHit EVENT::ReconstructedParticle EVENT::SimCalorimeterHit EVENT::SimTrackerHit EVENT::TPCHit EVENT::Track EVENT::TrackerData EVENT::TrackerHit EVENT::TrackerPulse EVENT::TrackerRawData EVENT::Vertex List of all members.

Public Member Functions

template<class V>
V::ext_type ext ()
 Provides access to an extension object - the type and ownership is defined by the class V which should be a subtype of LCExtension, LCOwnedExtension, LCExtensionVector, LCExtensionList,...
template<class V>
V::rel_type rel ()
 Provides read access to relations - the object types and their connectivity are defined by the class V which has to be a subtype of either LC1To1Relation, LC1ToNRelation or LCNToNRelation.

Protected Member Functions

template<class V>
V::ptr & ptr ()
 Returns the reference to the pointer to the extension/relation object.

Friends

template<class R>
void set_relation (typename R::from::obj_ptr f, typename R::to::obj_ptr t)
 Set the 1-to-1 relation between two objects - prexisting inconsistent relations involving the two objects are deleted to enforce a consistent set of from-to relations.
template<class R>
void unset_relation (typename R::from::obj_ptr f)
 Unset the 1-to-1 relation from f.
template<class R>
void add_relation (typename R::from::obj_ptr f, typename R::to::obj_ptr t)
 Add a link from f to t to an N-to-N relation ship.
template<class R>
void remove_relation (typename R::from::obj_ptr f, typename R::to::obj_ptr t)
 Remove the link from from f to t from the N-to-N relation ship.
template<class R>
void remove_relations (typename R::from::obj_ptr f)
 Removes all relations from the given object.
template<class R>
void merge_relations (typename R::from::obj_ptr f1, typename R::from::obj_ptr f2)
 Merge the relations from f2 to f1 - after this call f1 will hold all the relations and f2 will be empty.

Detailed Description

Base class that provides run time (user) extensions and relation between objects.

Every subclass object of LCRTRelations (and thus LCObbject) will automatically have the following functionality:

The described functionality is provided through the two templated member functions:
ext<class V>()
rel<class V>()
the class V is a user defined so called traits class, that uniquely tags the extension/relationship and defines the types of the objects involved.
For extensions users have to subclass one of the following classes:
LCExtension, LCOwnedExtension, LCIntExtension, LCFloatExtension,
LCExtensionVector, LCExtensionList, LCOwnedExtensionVector, LCOwnedExtensionList.
For example the following defines a user extension of a vector of strings that are owned by the object (i.e. deleted when the object is deleted):

struct ParticleIDs : LCOwnedExtensionVector<ParticleIDs, std::string> {};
   (note: the first template parameter has to be the class itself !)

This extension can then be used anywhere in the following code for all LCObjects, e.g.:

MCParticle* mcp = dynamic_cast<MCParticle*>( mcpcol->getElementAt(i) ) ;
mcp->ext<ParticleIDs>()->push_back( new std::string("charged") ) ;
mcp->ext<ParticleIDs>()->push_back( new std::string("hadron") ) ;
mcp->ext<ParticleIDs>()->push_back( new std::string("pion") ) ;

and be read out again:

ParticleIDs::ext_type pidv = mcp->ext<ParticleIDs>() ;
for( ParticleIDs::const_iterator ipid = pidv->begin() ; ipid != pidv->end(); ++ipid){
   std::cout << **ipid << ", " ;
}

Similarily the following defines a one to many relationship between Tracks and Clusters:

struct TrkCluLink : LC1ToNRelation<TrkCluLink,Track,Cluster> {} ;

Relations are allways biderectional, i.e. there is a from and a to side. They can then be set and modified with the following functions:
set_relation(), unset_relation(), add_relation(),
remove_relation(), remove_relations(), merge_relations().
For example:

Track* trk = dynamic_cast<Track*> ( trkcol->getElementAt(j) ) ;
//...
Cluster* clu = dynamic_cast<Cluster*> ( clucol->getElementAt(k) ) ;
add_relation<TrkCluLink>( trk ,clu );

The many side can then be read out with a const_iterator and the one side with a normal pointer:

Track* trk = clu->rel<TrkCluLink::from>() ;
//...
TrkCluLink::to::rel_type clulist = trk->rel<TrkCluLink::to>() ;
for( TrkCluLink::to::const_iterator iclu = clulist->begin() ; iclu != clulist->end() ; ++iclu ){
  Cluster* clu = *iclu ; // iterator is of type pointer to container element
  std::cout << " assigned cluster with E = " << clu->getEnergy() << std::endl ;
}

More examples can be found in $LCIO/src/cpp/src/EXAMPLES/lcrtrelations.cc.


The documentation for this class was generated from the following file:
Generated on Wed Dec 2 17:39:56 2009 for LCIO by  doxygen 1.3.9.1