LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
UTIL::LCIterator< T > Class Template Reference

Simple convenient iterator class for LCCollections that saves some boiler plate code. More...

#include <LCIterator.h>

Public Member Functions

 LCIterator (EVENT::LCEvent *evt, const std::string &name)
 Constructor that reads the collection with the given name from the event - note: no exception is thrown if the collection is not in the event, this will behave the same as an empty collection - use operator() to test, if the collection exists. More...
 
 LCIterator (const EVENT::LCCollection *col)
 Constructor for the given collection. More...
 
T * next ()
 Returns the next element as long as there is one, otherwise 0 is returned. More...
 
int size ()
 Size of the collection. More...
 
const EVENT::LCCollectionoperator-> ()
 Serves as a handle to the LCCollection itself, to provide access to the collection parameters etc. More...
 
const EVENT::LCCollectionoperator() ()
 Return pointer to LCCollection, e.g. More...
 

Private Member Functions

 LCIterator ()
 

Private Attributes

int _n {0}
 
int _i
 
const EVENT::LCCollection_col
 

Detailed Description

template<class T>
class UTIL::LCIterator< T >

Simple convenient iterator class for LCCollections that saves some boiler plate code.

LCIterators can be constructed either form an LCCollection or from the LCEvent and and a collection name.

Examples:

 // ------ use with while():
 LCIterator<TrackerHit> it( evt, "VXDCollection" ) ;
 while( TrackerHit* hit = it.next()  ){
    hitMap[ hit->getCellID0() ] = hit ;
 }
 // --- with for() :
 for(  LCIterator<Track> it( col ) ;  Track* trk = it.next()  ; ) {
    std::cout << trk->getTrackState( TrackState::AtIP ) << std::endl  ;
 }
Author
F.Gaede, DESY
Version
$Id:$

Definition at line 39 of file LCIterator.h.

Constructor & Destructor Documentation

template<class T >
UTIL::LCIterator< T >::LCIterator ( )
inlineprivate

Definition at line 41 of file LCIterator.h.

template<class T >
UTIL::LCIterator< T >::LCIterator ( EVENT::LCEvent evt,
const std::string name 
)
inline

Constructor that reads the collection with the given name from the event - note: no exception is thrown if the collection is not in the event, this will behave the same as an empty collection - use operator() to test, if the collection exists.

Definition at line 50 of file LCIterator.h.

References UTIL::LCIterator< T >::_col, UTIL::LCIterator< T >::_n, std::endl(), EVENT::LCCollection::getElementAt(), EVENT::LCCollection::getNumberOfElements(), and std::stringstream::str().

template<class T >
UTIL::LCIterator< T >::LCIterator ( const EVENT::LCCollection col)
inline

Member Function Documentation

template<class T >
T* UTIL::LCIterator< T >::next ( )
inline

Returns the next element as long as there is one, otherwise 0 is returned.

Definition at line 96 of file LCIterator.h.

References UTIL::LCIterator< T >::_col, UTIL::LCIterator< T >::_i, UTIL::LCIterator< T >::_n, and EVENT::LCCollection::getElementAt().

template<class T >
const EVENT::LCCollection* UTIL::LCIterator< T >::operator() ( )
inline

Return pointer to LCCollection, e.g.

for testing whether the collections was in the event.

Definition at line 116 of file LCIterator.h.

References UTIL::LCIterator< T >::_col.

template<class T >
const EVENT::LCCollection* UTIL::LCIterator< T >::operator-> ( )
inline

Serves as a handle to the LCCollection itself, to provide access to the collection parameters etc.

Definition at line 112 of file LCIterator.h.

References UTIL::LCIterator< T >::_col.

template<class T >
int UTIL::LCIterator< T >::size ( )
inline

Size of the collection.

Definition at line 107 of file LCIterator.h.

References UTIL::LCIterator< T >::_n.

Member Data Documentation

template<class T >
const EVENT::LCCollection* UTIL::LCIterator< T >::_col
private
template<class T >
int UTIL::LCIterator< T >::_i
private

Definition at line 119 of file LCIterator.h.

Referenced by UTIL::LCIterator< T >::next().

template<class T >
int UTIL::LCIterator< T >::_n {0}
private

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