// @(#)root/proofplayer:$Id$
// 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"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif

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 {

public:
   enum EIterType { kData = 15};  // True if iterating over data
  
protected:
   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

   TList         *fPackets;      // list of packets processed packets

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

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

   virtual Long64_t  GetCacheSize() = 0;
   virtual Int_t     GetLearnEntries() = 0;
   virtual Long64_t  GetNextEvent() = 0;
   virtual Int_t     GetNextPacket(Long64_t &first, Long64_t &num,
                                   TEntryList **enl = 0, TEventList **evl = 0) = 0;
   virtual void      InvalidatePacket();
   virtual void      PreProcessEvent(Long64_t) = 0;
   virtual void      StopProcess(Bool_t abort);

   TList            *GetPackets() { return fPackets; }

   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 {

private:
 Long64_t fNum;
 Long64_t fCurrent;


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

   Long64_t GetCacheSize() {return -1;}
   Int_t    GetLearnEntries() {return -1;}
   Long64_t GetNextEvent();
   Int_t    GetNextPacket(Long64_t &first, Long64_t &num,
                          TEntryList **enl = 0, TEventList **evl = 0);
   inline void PreProcessEvent(Long64_t) { };

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


//------------------------------------------------------------------------

class TEventIterObj : public TEventIter {

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

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

   Long64_t GetCacheSize() {return -1;}
   Int_t    GetLearnEntries() {return -1;}
   Long64_t GetNextEvent();
   Int_t    GetNextPacket(Long64_t &first, Long64_t &num,
                          TEntryList **enl = 0, TEventList **evl = 0);
   void PreProcessEvent(Long64_t);

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


//------------------------------------------------------------------------
class TEventIterTree : public TEventIter {

private:
   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      fTreeCacheIsLearning; // Whether cache is in learning phase
   Bool_t      fUseTreeCache; // Control usage of the tree cache
   Long64_t    fCacheSize;    // Cache size
   Bool_t      fUseParallelUnzip; // Control usage of parallel unzip
   Bool_t      fDontCacheFiles; // Control OS caching of read files (Mac Os X only)
   TList      *fFileTrees;    // Files && Trees currently open

   // Auxilliary class to keep track open files and loaded trees
   class TFileTree : public TNamed {
   public:
      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, const char *objname = 0);
   TTree* GetTrees(TDSetElement *elem);
public:
   TEventIterTree();
   TEventIterTree(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
   ~TEventIterTree();

   Long64_t GetCacheSize();
   Int_t    GetLearnEntries();
   Long64_t GetNextEvent();
   Int_t    GetNextPacket(Long64_t &first, Long64_t &num,
                          TEntryList **enl = 0, TEventList **evl = 0);
   void PreProcessEvent(Long64_t ent);

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

#endif
 TEventIter.h:1
 TEventIter.h:2
 TEventIter.h:3
 TEventIter.h:4
 TEventIter.h:5
 TEventIter.h:6
 TEventIter.h:7
 TEventIter.h:8
 TEventIter.h:9
 TEventIter.h:10
 TEventIter.h:11
 TEventIter.h:12
 TEventIter.h:13
 TEventIter.h:14
 TEventIter.h:15
 TEventIter.h:16
 TEventIter.h:17
 TEventIter.h:18
 TEventIter.h:19
 TEventIter.h:20
 TEventIter.h:21
 TEventIter.h:22
 TEventIter.h:23
 TEventIter.h:24
 TEventIter.h:25
 TEventIter.h:26
 TEventIter.h:27
 TEventIter.h:28
 TEventIter.h:29
 TEventIter.h:30
 TEventIter.h:31
 TEventIter.h:32
 TEventIter.h:33
 TEventIter.h:34
 TEventIter.h:35
 TEventIter.h:36
 TEventIter.h:37
 TEventIter.h:38
 TEventIter.h:39
 TEventIter.h:40
 TEventIter.h:41
 TEventIter.h:42
 TEventIter.h:43
 TEventIter.h:44
 TEventIter.h:45
 TEventIter.h:46
 TEventIter.h:47
 TEventIter.h:48
 TEventIter.h:49
 TEventIter.h:50
 TEventIter.h:51
 TEventIter.h:52
 TEventIter.h:53
 TEventIter.h:54
 TEventIter.h:55
 TEventIter.h:56
 TEventIter.h:57
 TEventIter.h:58
 TEventIter.h:59
 TEventIter.h:60
 TEventIter.h:61
 TEventIter.h:62
 TEventIter.h:63
 TEventIter.h:64
 TEventIter.h:65
 TEventIter.h:66
 TEventIter.h:67
 TEventIter.h:68
 TEventIter.h:69
 TEventIter.h:70
 TEventIter.h:71
 TEventIter.h:72
 TEventIter.h:73
 TEventIter.h:74
 TEventIter.h:75
 TEventIter.h:76
 TEventIter.h:77
 TEventIter.h:78
 TEventIter.h:79
 TEventIter.h:80
 TEventIter.h:81
 TEventIter.h:82
 TEventIter.h:83
 TEventIter.h:84
 TEventIter.h:85
 TEventIter.h:86
 TEventIter.h:87
 TEventIter.h:88
 TEventIter.h:89
 TEventIter.h:90
 TEventIter.h:91
 TEventIter.h:92
 TEventIter.h:93
 TEventIter.h:94
 TEventIter.h:95
 TEventIter.h:96
 TEventIter.h:97
 TEventIter.h:98
 TEventIter.h:99
 TEventIter.h:100
 TEventIter.h:101
 TEventIter.h:102
 TEventIter.h:103
 TEventIter.h:104
 TEventIter.h:105
 TEventIter.h:106
 TEventIter.h:107
 TEventIter.h:108
 TEventIter.h:109
 TEventIter.h:110
 TEventIter.h:111
 TEventIter.h:112
 TEventIter.h:113
 TEventIter.h:114
 TEventIter.h:115
 TEventIter.h:116
 TEventIter.h:117
 TEventIter.h:118
 TEventIter.h:119
 TEventIter.h:120
 TEventIter.h:121
 TEventIter.h:122
 TEventIter.h:123
 TEventIter.h:124
 TEventIter.h:125
 TEventIter.h:126
 TEventIter.h:127
 TEventIter.h:128
 TEventIter.h:129
 TEventIter.h:130
 TEventIter.h:131
 TEventIter.h:132
 TEventIter.h:133
 TEventIter.h:134
 TEventIter.h:135
 TEventIter.h:136
 TEventIter.h:137
 TEventIter.h:138
 TEventIter.h:139
 TEventIter.h:140
 TEventIter.h:141
 TEventIter.h:142
 TEventIter.h:143
 TEventIter.h:144
 TEventIter.h:145
 TEventIter.h:146
 TEventIter.h:147
 TEventIter.h:148
 TEventIter.h:149
 TEventIter.h:150
 TEventIter.h:151
 TEventIter.h:152
 TEventIter.h:153
 TEventIter.h:154
 TEventIter.h:155
 TEventIter.h:156
 TEventIter.h:157
 TEventIter.h:158
 TEventIter.h:159
 TEventIter.h:160
 TEventIter.h:161
 TEventIter.h:162
 TEventIter.h:163
 TEventIter.h:164
 TEventIter.h:165
 TEventIter.h:166
 TEventIter.h:167
 TEventIter.h:168
 TEventIter.h:169
 TEventIter.h:170
 TEventIter.h:171
 TEventIter.h:172
 TEventIter.h:173
 TEventIter.h:174
 TEventIter.h:175
 TEventIter.h:176
 TEventIter.h:177
 TEventIter.h:178
 TEventIter.h:179
 TEventIter.h:180
 TEventIter.h:181
 TEventIter.h:182
 TEventIter.h:183
 TEventIter.h:184
 TEventIter.h:185
 TEventIter.h:186
 TEventIter.h:187
 TEventIter.h:188
 TEventIter.h:189
 TEventIter.h:190
 TEventIter.h:191
 TEventIter.h:192
 TEventIter.h:193
 TEventIter.h:194