ROOT » MISC » TABLE » TTable::iterator

class TTable::iterator


 Wraps the array of the plain C-structures (one C-structure per element)

class TTable provides the automatic schema evolution for
the derived "table" classes saved with ROOT format.

"Automatic Schema evolution" provides:
-  skipping data-member if it is not present for the current
implementation of the "table" but was present at the time the
table was written;
-  assign a default value ZERO for the brand-new data-members,
those were not in the structure when the object was written but
present now;
-  trace propely any change in the order of the data-members

To enjoy this class one has to derive one's own custom class:


#ifndef STAF_St_dst_track_Table
#define STAF_St_dst_track_Table

#include "TTable.h"

 #include "dst_track.h"  the C-structure defintion may be kept
typedef struct dst_track_st {
     float r0;             /* radius at start (cm). See also comments*
     float phi0;           /* azimuthal angle at start (deg)         *
     float z0;             /* z-coord. at start (cm)                 *
     float psi;            /* azimuthal angle of pT vector (deg)     *
     float tanl;           /* tan(dip) =pz/pt at start               *
     float invpt;          /* 1/pt at start (GeV/c)^(-1)             *
     float curvature;      /* Track curvature (1/cm)                 *
     float covar[15];      /* full covariance matrix                 *
     float chisq[2];       /* Chi-square per degree of freedom       *
     float x_first[3];     /* coord. of first measured point (cm)    *
     float x_last[3];      /* coord. of last measured point (cm)     *
     float length;         /* from first to last point (cm)          *
     float impact;         /* primary vertex (cm)                    *
     unsigned long map[2]; /* extrap. info. (see preceding comments)*
     int id;               /* Primary key (see comments)             *
     int iflag;            /* bitmask quality info. (see comments)   *
     int det_id;           /* Detector id information                *
     int method;           /* Track finding/fitting method, packed   *
     int pid;              /* Geant particle ID for assumed mass     *
     int n_point;          /* SVT, TPC, FTPC component #s are packed *
     int n_max_point;      /* SVT, TPC, FTPC component #s are packed *
     int n_fit_point;      /* SVT, TPC, FTPC component #s are packed *
     int icharge;          /* Particle charge in units of |e|        *
     int id_start_vertex;  /* final fit and primary track candidates *

class St_dst_track : public TTable
ClassDef(St_dst_track,2) //C++ wrapper for <dst_track> StAF table

where the CPP macro defines several convinient methods for the
"table" class (see: $ROOTSYS/table/inc/Ttypes.h for details:

  #define ClassDefTable(className,structName)
       static TTableDescriptor *fgColDescriptors;
       virtual TTableDescriptor *GetDescriptorPointer() const { return fgColDescriptors;}
       virtual void SetDescriptorPointer(TTableDescriptor *list) const { fgColDescriptors = list;}
      typedef structName* iterator;
      className() : TTable(_QUOTE_(className),sizeof(structName))    {SetType(_QUOTE_(structName));}
      className(const char *name) : TTable(name,sizeof(structName)) {SetType(_QUOTE_(structName));}
      className(Int_t n) : TTable(_QUOTE_(className),n,sizeof(structName)) {SetType(_QUOTE_(structName));}
      className(const char *name,Int_t n) : TTable(name,n,sizeof(structName)) {SetType(_QUOTE_(structName));}
      structName *GetTable(Int_t i=0) const { return ((structName *)GetArray())+i;}
      structName &operator[](Int_t i){ assert(i>=0 && i < GetNRows()); return *GetTable(i); }
      const structName &operator[](Int_t i) const { assert(i>=0 && i < GetNRows()); return *((const structName *)(GetTable(i))); }
      structName *begin() const  {                      return GetNRows()? GetTable(0):0;}
      structName *end()   const  {Int_t i = GetNRows(); return          i? GetTable(i):0;}

The class implementation file may 2 lines and look as follows:
(for the example above):


#include "St_dst_track_Table.h"
TableClassImpl(St_dst_track, dst_track_st)


To provide ROOT I/O for this class TWO CINT dictonary entries
should be defined with your custom LinkDef.h file
1. First entry (as usually) for the class derived from TTable
for example:
#pragma C++ class St_dst_track
2. Second entry for the C-structure wrapped into the class.
Since C-structuire is not derived from TObject it must be
properly defined as "foreign" ROOT class
#pragma C++ class dst_track_st+;

meta-variables i$ and n$ introduced
where "i$" stands for the current row index
"n$" stands for the total number of rows
meta-variable can be used along the normal
table column names in the expressions (see for example
method TTable::Draw

Function Members (Methods)

TTable::iteratoriterator(const TTable::iterator& iter)
TTable::iteratoriterator(const TTable& table, TTable::iterator::vec_iterator& arowPtr)
TTable::iteratoriterator(const TTable& table, TTable::iterator::vec_const_iterator& arowPtr)
void*operator void *() const
Bool_toperator!=(const TTable::iterator& t) const
Long_toperator*() const
TTable::iteratoroperator+(Int_t idx)
voidoperator+=(Int_t idx)
TTable::iteratoroperator-(Int_t idx)
Int_toperator-(const TTable::iterator& it) const
voidoperator-=(Int_t idx)
TTable::iterator&operator=(const TTable::iterator& iter)
Bool_toperator==(const TTable::iterator& t) const
const vector<long>::iterator&Row() const
void*rowPtr() const
const Long_t&RowSize() const
const TTable&Table() const

Data Members

const TTable*fThisTable

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TTable & operator=(const TTable::iterator& iter)
iterator(const TTable &table, vec_iterator &arowPtr)
iterator(const TTable &table, vec_const_iterator &arowPtr)
fCurrentRow(* const_cast<std::vector<Long_t>::iterator *>(&arowPtr) ) {;}
iterator(const TTable::iterator& iter)
void operator++()
void operator++(int )
void operator--()
void operator--(int )
iterator operator+(Int_t idx)
{ std::vector<Long_t>::iterator addition = fCurrentRow+idx; return iterator(*fThisTable,addition); }
iterator operator-(Int_t idx)
{ std::vector<Long_t>::iterator subtraction = fCurrentRow-idx; return iterator(*fThisTable,subtraction); }
void operator+=(Int_t idx)
{ fCurrentRow+=idx; }
void operator-=(Int_t idx)
{ fCurrentRow-=idx; }
void * rowPtr() const
{ return (void *)(((const char *)fThisTable->GetArray()) + (*fCurrentRow)*fRowSize ); }
operator void *() const
{ return rowPtr(); }
Int_t operator-(const TTable::iterator& it) const
{ return (*fCurrentRow)-(*(it.fCurrentRow)); }
Bool_t operator==(const TTable::iterator& t) const
{ return ( (fCurrentRow == t.fCurrentRow) && (fThisTable == t.fThisTable) ); }
Bool_t operator!=(const TTable::iterator& t) const
{ return !operator==(t); }
const Long_t & RowSize() const
{ return fRowSize;}
const std::vector<Long_t>::iterator & Row() const
{ return fCurrentRow;}