class TGenericTable::iterator


TGenericTable

This is the class to represent the array of C-struct
defined at run-time

Example: see $ROOTSYS/tutorials/tree/staff.C

 !{
 !//   example of macro to read data from an ascii file and
 !//   create a root file with an histogram and an ntuple.
 !//   A'la the famous ROOT/PAW staff data example
 !//   ( see PAW - Long write up, CERN, page33. )
 !
 !   gROOT->Reset();
 !   gSystem->Load("libRootKernel");
 !
 !   struct staff_t {
 !                Int_t cat;
 !                Int_t division;
 !                Int_t flag;
 !                Int_t age;
 !                Int_t service;
 !                Int_t children;
 !                Int_t grade;
 !                Int_t step;
 !                Int_t nation;
 !                Int_t hrweek;
 !                Int_t cost;
 !    };
 !
 !   staff_t staff;
 !
 !   // open ASCII data file
 !   FILE *fp = fopen("staff.dat","r");
 !
 !   char line[81];
 !
 !   // Create the generic table for 1000 rows (it may grow then)
 !   TGenericTable *allStaff = new TGenericTable("staff_t","Staff-data",1000);
 !
 !   // Fill the memory resident table
 !   while (fgets(&line,80,fp)) {
 !      sscanf(&line[0] ,"%d%d%d%d", &staff.cat,&staff.division,&staff.flag,&staff.age);
 !      sscanf(&line[13],"%d%d%d%d", &staff.service,&staff.children,&staff.grade,&staff.step);
 !      sscanf(&line[24],"%d%d%d",   &staff.nation,&staff.hrweek,&staff.cost);
 !      allStaff->AddAt(&staff);
 !   }
 !   fclose(fp);
 !   // Delete unused space;
 !   allStaff->Purge();
 !
 !   allStaff->Print(0,10);
 !
 !//  Create ROOT file
 !   TFile *f = new TFile("aptuple.root","RECREATE");
 !          allStaff->Write();
 !   f->Write();
 !
 !   // We should close  TFile otherwise all histograms we create below
 !   // may be written to the file too occasionaly
 !   f->Close();
 !
 !//  Create ROOT Browser
 !   new TBrowser("staff",allStaff);
 !
 !//  Create couple of the histograms
 !   TCanvas *canva = new TCanvas("Staff","CERN Population",600,600);
 !   canva->Divide(1,2);
 !
 !
 !// one can use 2 meta variable:
 !//  n$ - the total number of the rows in the table
 !//  i$ - stands for the current row index i = [0 -> (n$-1)]
 !
 !   gStyle->SetHistFillColor(10);
 !   gStyle->SetHistFillStyle(3013);
 !   canva->cd(1);
 !   allStaff->Draw("age");
 !   canva->Update();
 !   canva->cd(2);
 !   allStaff->Draw("cost");
 !   canva->Update();
 !}


Function Members (Methods)

public:
~iterator()
TGenericTable::iteratoriterator(const TTable& t)
TGenericTable::iteratoriterator(const TGenericTable::iterator& iter)
TGenericTable::iteratoriterator(UInt_t size, char& rowPtr)
TGenericTable::iteratoriterator(const TTable& t, char& rowPtr)
Bool_toperator!=(const TGenericTable::iterator& t) const
char*operator*()
TGenericTable::iterator&operator+(Int_t idx)
TGenericTable::iterator&operator++()
voidoperator++(int)
TGenericTable::iterator&operator-(Int_t idx)
Int_toperator-(const TGenericTable::iterator& it) const
TGenericTable::iterator&operator--()
voidoperator--(int)
TGenericTable::iterator&operator=(const TGenericTable::iterator& iter)
Bool_toperator==(const TGenericTable::iterator& t) const
protected:
TGenericTable::iteratoriterator()

Data Members

protected:
char*fCurrentRow
UInt_tfRowSize

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

iterator()
{}
iterator(UInt_t size, char &rowPtr)
{}
iterator(const TTable &t, char &rowPtr)
{}
iterator(const TTable &t)
{}
iterator(const iterator& iter)
{}
iterator & operator=(const TGenericTable::iterator& iter)
{ fRowSize = iter.fRowSize; fCurrentRow = iter.fCurrentRow; return *this;}
iterator & operator++(int )
{ if (fCurrentRow) fCurrentRow+=fRowSize; return *this;}
void operator++(int )
{ if (fCurrentRow) fCurrentRow+=fRowSize;}
iterator & operator--(int )
{ if (fCurrentRow) fCurrentRow-=fRowSize; return *this;}
void operator--(int )
{ if (fCurrentRow) fCurrentRow-=fRowSize;}
iterator & operator+(Int_t idx)
{ if (fCurrentRow) fCurrentRow+=idx*fRowSize; return *this;}
iterator & operator-(Int_t idx)
{ if (fCurrentRow) fCurrentRow-=idx*fRowSize; return *this;}
Int_t operator-(const iterator &it)
{ return (fCurrentRow-it.fCurrentRow)/fRowSize; }
Bool_t operator==(const TGenericTable::iterator& t) const
{ return (fCurrentRow == t.fCurrentRow); }
Bool_t operator!=(const TGenericTable::iterator& t) const
{ return !operator==(t); }

Author: Valery Fine(fine@bnl.gov) 30/06/2001
Last change: root/table:$Id: TGenericTable.h 20882 2007-11-19 11:31:26Z rdm $
Last generated: 2008-06-25 08:44

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.