Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEventIter.h
Go to the documentation of this file.
1 // @(#)root/proofplayer:$Id$
2 // Author: Maarten Ballintijn 07/01/02
3 // Modified: Long Tran-Thanh 04/09/07 (Addition of TEventIterUnit)
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TEventIter
14 #define ROOT_TEventIter
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TEventIter //
19 // //
20 // Special iterator class used in TProofPlayer to iterate over events //
21 // or objects in the packets. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TNamed.h"
26 #include "TString.h"
27 
28 class TDSet;
29 class TDSetElement;
30 class TFile;
31 class TDirectory;
32 class TSelector;
33 class TList;
34 class TIter;
35 class TTree;
36 class TTreeCache;
37 class TEventList;
38 class TEntryList;
39 
40 //------------------------------------------------------------------------
41 
42 class TEventIter : public TObject {
43 
44 public:
45  enum EIterType { kData = 15}; // True if iterating over data
46 
47 protected:
48  TDSet *fDSet; // data set over which to iterate
49 
50  TDSetElement *fElem; // Current Element
51 
52  TString fFilename; // Name of the current file
53  TFile *fFile; // Current file
54  Long64_t fOldBytesRead; // last reported number of bytes read
55  TString fPath; // Path to current TDirectory
56  TDirectory *fDir; // directory containing the objects or the TTree
57  Long64_t fElemFirst; // first entry to process for this element
58  Long64_t fElemNum; // number of entries to process for this element
59  Long64_t fElemCur; // current entry for this element
60 
61  TSelector *fSel; // selector to be used
62  Long64_t fFirst; // first entry to process
63  Long64_t fNum; // number of entries to process
64  Long64_t fCur; // current entry
65  Bool_t fStop; // termination of run requested
66  TEventList *fEventList; //! eventList for processing
67  Int_t fEventListPos; //! current position in the eventList
68  TEntryList *fEntryList; //! entry list for processing
69  Long64_t fEntryListPos; //! current position in the entrylist
70 
71  TList *fPackets; // list of packets processed packets
72 
73  Int_t LoadDir(); // Load the directory pointed to by fElem
74  virtual void PreProcessEvent(Long64_t) { }
75 
76 public:
77  TEventIter();
78  TEventIter(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
79  virtual ~TEventIter();
80 
81  virtual Long64_t GetCacheSize() = 0;
82  virtual Int_t GetLearnEntries() = 0;
83  virtual Long64_t GetNextEvent() = 0;
84  virtual Int_t GetNextPacket(Long64_t &first, Long64_t &num) = 0;
85  virtual void InvalidatePacket();
86  virtual Long64_t GetEntryNumber(Long64_t);
87  virtual void StopProcess(Bool_t abort);
88 
89  TList *GetPackets() { return fPackets; }
90 
91  static TEventIter *Create(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
92 
93  ClassDef(TEventIter,0) // Event iterator used by TProofPlayer's
94 };
95 
96 
97 //------------------------------------------------------------------------
98 
99 class TEventIterUnit : public TEventIter {
100 
101 private:
102  Long64_t fNum;
103  Long64_t fCurrent;
104 
105 
106 public:
107  TEventIterUnit();
108  TEventIterUnit(TDSet *dset, TSelector *sel, Long64_t num);
109  ~TEventIterUnit() { }
110 
111  Long64_t GetCacheSize() {return -1;}
112  Int_t GetLearnEntries() {return -1;}
113  Long64_t GetNextEvent();
114  Int_t GetNextPacket(Long64_t &first, Long64_t &num);
115 
116  ClassDef(TEventIterUnit,0) // Event iterator for objects
117 };
118 
119 
120 //------------------------------------------------------------------------
121 
122 class TEventIterObj : public TEventIter {
123 
124 private:
125  TString fClassName; // class name of objects to iterate over
126  TList *fKeys; // list of keys
127  TIter *fNextKey; // next key in directory
128  TObject *fObj; // object found
129 
130 protected:
131  void PreProcessEvent(Long64_t);
132 
133 public:
134  TEventIterObj();
135  TEventIterObj(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
136  ~TEventIterObj();
137 
138  Long64_t GetCacheSize() {return -1;}
139  Int_t GetLearnEntries() {return -1;}
140  Long64_t GetNextEvent();
141  Int_t GetNextPacket(Long64_t &first, Long64_t &num);
142 
143  ClassDef(TEventIterObj,0) // Event iterator for objects
144 };
145 
146 
147 //------------------------------------------------------------------------
148 class TEventIterTree : public TEventIter {
149 
150 private:
151  TString fTreeName; // name of the tree object to iterate over
152  TTree *fTree; // tree we are iterating over
153  TTreeCache *fTreeCache; // instance of the tree cache for the tree
154  Bool_t fTreeCacheIsLearning; // Whether cache is in learning phase
155  Bool_t fUseTreeCache; // Control usage of the tree cache
156  Long64_t fCacheSize; // Cache size
157  Bool_t fUseParallelUnzip; // Control usage of parallel unzip
158  Bool_t fDontCacheFiles; // Control OS caching of read files (Mac Os X only)
159  TList *fFileTrees; // Files && Trees currently open
160 
161  // Auxilliary class to keep track open files and loaded trees
162  class TFileTree : public TNamed {
163  public:
164  Bool_t fUsed;
165  Bool_t fIsLocal;
166  TFile *fFile;
167  TList *fTrees;
168  TFileTree(const char *name, TFile *f, Bool_t islocal);
169  virtual ~TFileTree();
170  };
171 
172  TTree* Load(TDSetElement *elem, Bool_t &localfile, const char *objname = 0);
173  TTree* GetTrees(TDSetElement *elem);
174 
175 protected:
176  void PreProcessEvent(Long64_t ent);
177 
178 public:
179  TEventIterTree();
180  TEventIterTree(TDSet *dset, TSelector *sel, Long64_t first, Long64_t num);
181  ~TEventIterTree();
182 
183  Long64_t GetCacheSize();
184  Int_t GetLearnEntries();
185  Long64_t GetNextEvent();
186  Int_t GetNextPacket(Long64_t &first, Long64_t &num);
187 
188  ClassDef(TEventIterTree,0) // Event iterator for Trees
189 };
190 
191 #endif