ROOT logo
// @(#)root/proofplayer:$Id: TEventIter.h 29126 2009-06-22 09:05:46Z brun $
// Author: Maarten Ballintijn   07/01/02
// Modified: Long Tran-Thanh    04/09/07  (Addition of TEventIterUnit)

 * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *

#ifndef ROOT_TEventIter
#define ROOT_TEventIter

//                                                                      //
// TEventIter                                                           //
//                                                                      //
// Special iterator class used in TProofPlayer to iterate over events   //
// or objects in the packets.                                           //
//                                                                      //

#ifndef ROOT_TNamed
#include "TNamed.h"
#ifndef ROOT_TString
#include "TString.h"

class TDSet;
class TDSetElement;
class TFile;
class TDirectory;
class TSelector;
class TList;
class TIter;
class TTree;
class TTreeCache;
class TEventList;
class TEntryList;


class TEventIter : public TObject {

   TDSet         *fDSet;         // data set over which to iterate

   TDSetElement  *fElem;         // Current Element

   TString        fFilename;     // Name of the current file
   TFile         *fFile;         // Current file
   Long64_t       fOldBytesRead; // last reported number of bytes read
   TString        fPath;         // Path to current TDirectory
   TDirectory    *fDir;          // directory containing the objects or the TTree
   Long64_t       fElemFirst;    // first entry to process for this element
   Long64_t       fElemNum;      // number of entries to process for this element
   Long64_t       fElemCur;      // current entry for this element

   TSelector     *fSel;          // selector to be used
   Long64_t       fFirst;        // first entry to process
   Long64_t       fNum;          // number of entries to process
   Long64_t       fCur;          // current entry
   Bool_t         fStop;         // termination of run requested
   TEventList    *fEventList;    //! eventList for processing
   Int_t          fEventListPos; //! current position in the eventList
   TEntryList    *fEntryList;    //! entry list for processing
   Long64_t       fEntryListPos; //! current position in the entrylist

   Int_t          LoadDir();     // Load the directory pointed to by fElem

   TEventIter(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
   virtual ~TEventIter();

   virtual Long64_t  GetNextEvent() = 0;
   virtual void      StopProcess(Bool_t abort);

   static TEventIter *Create(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);

   ClassDef(TEventIter,0)  // Event iterator used by TProofPlayer's


class TEventIterUnit : public TEventIter {

 Long64_t fNum;
 Long64_t fCurrent;

   TEventIterUnit(TDSet *dset, TSelector *sel, Long64_t num);
   ~TEventIterUnit() { }

   Long64_t GetNextEvent();

   ClassDef(TEventIterUnit,0)  // Event iterator for objects


class TEventIterObj : public TEventIter {

   TString  fClassName;    // class name of objects to iterate over
   TList   *fKeys;         // list of keys
   TIter   *fNextKey;      // next key in directory
   TObject *fObj;          // object found

   TEventIterObj(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);

   Long64_t GetNextEvent();

   ClassDef(TEventIterObj,0)  // Event iterator for objects

class TEventIterTree : public TEventIter {

   TString     fTreeName;     // name of the tree object to iterate over
   TTree      *fTree;         // tree we are iterating over
   TTreeCache *fTreeCache;    // instance of the tree cache for the tree
   Bool_t      fUseTreeCache; // Control usage of the tree cache
   Long64_t    fCacheSize;    // Cache size
   TList      *fFileTrees;    // Files && Trees currently open

   // Auxilliary class to keep track open files and loaded trees
   class TFileTree : public TNamed {
      Bool_t    fUsed;
      Bool_t    fIsLocal;
      TFile    *fFile;
      TList    *fTrees;
      TFileTree(const char *name, TFile *f, Bool_t islocal);
      virtual ~TFileTree();

   TTree* Load(TDSetElement *elem, Bool_t &localfile);
   TTree* GetTrees(TDSetElement *elem);
   TEventIterTree(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);

   Long64_t GetNextEvent();

   ClassDef(TEventIterTree,0)  // Event iterator for Trees