ROOT  6.06/09
Reference Guide
TTreeCache.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 04/06/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TTreeCache
13 #define ROOT_TTreeCache
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TTreeCache //
19 // //
20 // Specialization of TFileCacheRead for a TTree //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TFileCacheRead
25 #include "TFileCacheRead.h"
26 #endif
27 #ifndef ROOT_TObjArray
28 #include "TObjArray.h"
29 #endif
30 
31 class TTree;
32 class TBranch;
33 
34 class TTreeCache : public TFileCacheRead {
35 
36 public:
38 
39 protected:
40  Long64_t fEntryMin; //! first entry in the cache
41  Long64_t fEntryMax; //! last entry in the cache
42  Long64_t fEntryCurrent;//! current lowest entry number in the cache
43  Long64_t fEntryNext; //! next entry number where cache must be filled
44  Int_t fNbranches; //! Number of branches in the cache
45  Int_t fNReadOk; //Number of blocks read and found in the cache
46  Int_t fNReadMiss; //Number of blocks read and not found in the chache
47  Int_t fNReadPref; //Number of blocks that were prefetched
48  TObjArray *fBranches; //! List of branches to be stored in the cache
49  TList *fBrNames; //! list of branch names in the cache
50  TTree *fTree; //! pointer to the current Tree
51  Bool_t fIsLearning; //! true if cache is in learning mode
52  Bool_t fIsManual; //! true if cache is StopLearningPhase was used
53  Bool_t fFirstBuffer; //! true if first buffer is used for prefetching
54  Bool_t fOneTime; //! used in the learning phase
55  Bool_t fReverseRead; //! reading in reverse mode
56  Int_t fFillTimes; //! how many times we can fill the current buffer
57  Bool_t fFirstTime; //! save the fact that we processes the first entry
58  Long64_t fFirstEntry; //! save the value of the first entry
59  Bool_t fReadDirectionSet; //! read direction established
60  Bool_t fEnabled; //! cache enabled for cached reading
61  EPrefillType fPrefillType; // Whether a prefilling is enabled (and if applicable which type)
62  static Int_t fgLearnEntries; // number of entries used for learning mode
63  Bool_t fAutoCreated; //! true if cache was automatically created
64 
65 private:
66  TTreeCache(const TTreeCache &); //this class cannot be copied
68 
69 public:
70 
71  TTreeCache();
72  TTreeCache(TTree *tree, Int_t buffersize=0);
73  virtual ~TTreeCache();
74  virtual Int_t AddBranch(TBranch *b, Bool_t subgbranches = kFALSE);
75  virtual Int_t AddBranch(const char *branch, Bool_t subbranches = kFALSE);
76  virtual Int_t DropBranch(TBranch *b, Bool_t subbranches = kFALSE);
77  virtual Int_t DropBranch(const char *branch, Bool_t subbranches = kFALSE);
78  virtual void Disable() {fEnabled = kFALSE;}
79  virtual void Enable() {fEnabled = kTRUE;}
80  const TObjArray *GetCachedBranches() const { return fBranches; }
82  Double_t GetEfficiency() const;
83  Double_t GetEfficiencyRel() const;
84  virtual Int_t GetEntryMin() const {return fEntryMin;}
85  virtual Int_t GetEntryMax() const {return fEntryMax;}
86  static Int_t GetLearnEntries();
87  virtual EPrefillType GetLearnPrefill() const {return fPrefillType;}
88  TTree *GetTree() const {return fTree;}
89  Bool_t IsAutoCreated() const {return fAutoCreated;}
90  virtual Bool_t IsEnabled() const {return fEnabled;}
91  virtual Bool_t IsLearning() const {return fIsLearning;}
92 
93  virtual Bool_t FillBuffer();
94  virtual void LearnPrefill();
95 
96  virtual void Print(Option_t *option="") const;
97  virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
98  virtual Int_t ReadBufferNormal(char *buf, Long64_t pos, Int_t len);
99  virtual Int_t ReadBufferPrefetch(char *buf, Long64_t pos, Int_t len);
100  virtual void ResetCache();
101  void SetAutoCreated(Bool_t val) {fAutoCreated = val;}
102  virtual Int_t SetBufferSize(Int_t buffersize);
103  virtual void SetEntryRange(Long64_t emin, Long64_t emax);
104  virtual void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect);
106  static void SetLearnEntries(Int_t n = 10);
107  void StartLearningPhase();
108  virtual void StopLearningPhase();
109  virtual void UpdateBranches(TTree *tree);
110 
111  ClassDef(TTreeCache,2) //Specialization of TFileCacheRead for a TTree
112 };
113 
114 #endif
Long64_t fEntryMax
first entry in the cache
Definition: TTreeCache.h:41
An array of TObjects.
Definition: TObjArray.h:39
Bool_t IsAutoCreated() const
Definition: TTreeCache.h:89
Int_t fNReadOk
Number of branches in the cache.
Definition: TTreeCache.h:45
long long Long64_t
Definition: RtypesCore.h:69
const TObjArray * GetCachedBranches() const
Definition: TTreeCache.h:80
TObjArray * fBranches
Definition: TTreeCache.h:48
A cache when reading files over the network.
const char Option_t
Definition: RtypesCore.h:62
Bool_t fOneTime
true if first buffer is used for prefetching
Definition: TTreeCache.h:54
virtual void SetLearnPrefill(EPrefillType type=kNoPrefill)
Set whether the learning period is started with a prefilling of the cache and which type of prefillin...
A specialized TFileCacheRead object for a TTree.
Definition: TTreeCache.h:34
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Long64_t fEntryMin
Definition: TTreeCache.h:40
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void StopLearningPhase()
This is the counterpart of StartLearningPhase() and can be used to stop the learning phase...
virtual void LearnPrefill()
Perform an initial prefetch, attempting to read as much of the learning phase baskets for all branche...
TTree * GetTree() const
Definition: TTreeCache.h:88
void SetAutoCreated(Bool_t val)
Definition: TTreeCache.h:101
void StartLearningPhase()
The name should be enough to explain the method.
virtual Int_t AddBranch(TBranch *b, Bool_t subgbranches=kFALSE)
Add a branch to the list of branches to be stored in the cache this function is called by TBranch::Ge...
Definition: TTreeCache.cxx:330
Bool_t fAutoCreated
Definition: TTreeCache.h:63
virtual void Print(Option_t *option="") const
Print cache statistics.
Definition: TTreeCache.cxx:994
virtual Int_t ReadBufferNormal(char *buf, Long64_t pos, Int_t len)
Old method ReadBuffer before the addition of the prefetch mechanism.
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual EPrefillType GetLearnPrefill() const
Definition: TTreeCache.h:87
virtual Bool_t IsEnabled() const
Definition: TTreeCache.h:90
EPrefillType GetConfiguredPrefillType() const
Return the desired prefill type from the environment or resource variable.
Definition: TTreeCache.cxx:922
virtual Bool_t IsLearning() const
Definition: TTreeCache.h:91
virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len)
Read buffer at position pos if the request is in the list of prefetched blocks read from fBuffer...
virtual void ResetCache()
This will simply clear the cache.
Bool_t fEnabled
read direction established
Definition: TTreeCache.h:60
virtual void Enable()
Definition: TTreeCache.h:79
A doubly linked list.
Definition: TList.h:47
TTree * fTree
list of branch names in the cache
Definition: TTreeCache.h:50
Double_t GetEfficiency() const
Give the total efficiency of the cache...
Definition: TTreeCache.cxx:945
virtual void SetEntryRange(Long64_t emin, Long64_t emax)
Set the minimum and maximum entry number to be processed this information helps to optimize the numbe...
virtual Int_t DropBranch(TBranch *b, Bool_t subbranches=kFALSE)
Remove a branch to the list of branches to be stored in the cache this function is called by TBranch:...
Definition: TTreeCache.cxx:482
virtual Int_t ReadBufferPrefetch(char *buf, Long64_t pos, Int_t len)
Used to read a chunk from a block previously fetched.
virtual ~TTreeCache()
Destructor. (in general called by the TFile destructor)
Definition: TTreeCache.cxx:313
Bool_t fReadDirectionSet
save the value of the first entry
Definition: TTreeCache.h:59
TTreeCache & operator=(const TTreeCache &)
Int_t fNReadMiss
Definition: TTreeCache.h:46
static void SetLearnEntries(Int_t n=10)
Static function to set the number of entries to be used in learning mode The default value for n is 1...
virtual Bool_t FillBuffer()
Fill the cache buffer with the branches in the cache.
Definition: TTreeCache.cxx:617
Int_t fNReadPref
Definition: TTreeCache.h:47
Bool_t fReverseRead
used in the learning phase
Definition: TTreeCache.h:55
Bool_t fFirstTime
how many times we can fill the current buffer
Definition: TTreeCache.h:57
Long64_t fEntryCurrent
last entry in the cache
Definition: TTreeCache.h:42
double Double_t
Definition: RtypesCore.h:55
Bool_t fIsLearning
pointer to the current Tree
Definition: TTreeCache.h:51
int type
Definition: TGX11.cxx:120
virtual void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect)
Overload to make sure that the object specific.
EPrefillType fPrefillType
cache enabled for cached reading
Definition: TTreeCache.h:61
Int_t fFillTimes
reading in reverse mode
Definition: TTreeCache.h:56
virtual Int_t GetEntryMin() const
Definition: TTreeCache.h:84
virtual Int_t SetBufferSize(Int_t buffersize)
Change the underlying buffer size of the cache.
Int_t fNbranches
next entry number where cache must be filled
Definition: TTreeCache.h:44
Long64_t fFirstEntry
save the fact that we processes the first entry
Definition: TTreeCache.h:58
TList * fBrNames
List of branches to be stored in the cache.
Definition: TTreeCache.h:49
Bool_t fFirstBuffer
true if cache is StopLearningPhase was used
Definition: TTreeCache.h:53
static Int_t fgLearnEntries
Definition: TTreeCache.h:62
A TTree object has a header with a name and a title.
Definition: TTree.h:94
Bool_t fIsManual
true if cache is in learning mode
Definition: TTreeCache.h:52
A TTree is a list of TBranches.
Definition: TBranch.h:58
Long64_t fEntryNext
current lowest entry number in the cache
Definition: TTreeCache.h:43
Double_t GetEfficiencyRel() const
This will indicate a sort of relative efficiency...
Definition: TTreeCache.cxx:957
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void UpdateBranches(TTree *tree)
Update pointer to current Tree and recompute pointers to the branches in the cache.
const Int_t n
Definition: legend1.C:16
virtual Int_t GetEntryMax() const
Definition: TTreeCache.h:85
static Int_t GetLearnEntries()
Static function returning the number of entries used to train the cache see SetLearnEntries.
Definition: TTreeCache.cxx:969
virtual void Disable()
Definition: TTreeCache.h:78
ECacheAction
TTreeCache flushing semantics.
Definition: TFile.h:57