LCIO
02.17
|
Base class that provides run time (user) extensions and relation between objects. More...
#include <LCRTRelations.h>
Public Types | |
typedef std::type_index | ext_index |
typedef std::shared_ptr< void > | ext_type |
typedef std::map< ext_index, ext_type > | ext_map |
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,... More... | |
template<class V > | |
const V::ext_type | ext () const |
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,... More... | |
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. More... | |
Private Member Functions | |
template<class V > | |
V::ptr & | ptr () const |
Returns the reference to the pointer to the extension/relation object. More... | |
Private Attributes | |
ext_map | _extensionMap {} |
The user extension map. More... | |
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. More... | |
template<class R > | |
void | unset_relation (typename R::from::obj_ptr f) |
Unset the 1-to-1 relation from f. More... | |
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. More... | |
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. More... | |
template<class R > | |
void | remove_relations (typename R::from::obj_ptr f) |
Removes all relations from the given object. More... | |
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. More... | |
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.
Definition at line 470 of file LCRTRelations.h.
Definition at line 494 of file LCRTRelations.h.
Definition at line 496 of file LCRTRelations.h.
typedef std::shared_ptr<void> lcrtrel::LCRTRelations::ext_type |
Definition at line 495 of file LCRTRelations.h.
|
inline |
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,...
Definition at line 504 of file LCRTRelations.h.
|
inline |
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,...
Definition at line 514 of file LCRTRelations.h.
|
inlineprivate |
Returns the reference to the pointer to the extension/relation object.
Definition at line 532 of file LCRTRelations.h.
References std::static_pointer_cast().
|
inline |
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.
Definition at line 524 of file LCRTRelations.h.
|
friend |
Add a link from f to t to an N-to-N relation ship.
|
friend |
Merge the relations from f2 to f1 - after this call f1 will hold all the relations and f2 will be empty.
|
friend |
Remove the link from from f to t from the N-to-N relation ship.
|
friend |
Removes all relations from the given object.
|
friend |
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.
|
friend |
Unset the 1-to-1 relation from f.
|
mutableprivate |
The user extension map.
Definition at line 558 of file LCRTRelations.h.