Logo ROOT   6.12/07
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 #include "TFileCacheRead.h"
25 #include "TObjArray.h"
26 
27 class TTree;
28 class TBranch;
29 
30 class TTreeCache : public TFileCacheRead {
31 
32 public:
34 
35 protected:
36  Long64_t fEntryMin; ///<! first entry in the cache
37  Long64_t fEntryMax; ///<! last entry in the cache
38  Long64_t fEntryCurrent; ///<! current lowest entry number in the cache
39  Long64_t fEntryNext; ///<! next entry number where cache must be filled
40  Int_t fNbranches; ///<! Number of branches in the cache
41  Int_t fNReadOk; ///< Number of blocks read and found in the cache
42  Int_t fNReadMiss; ///< Number of blocks read and not found in the cache
43  Int_t fNReadPref; ///< Number of blocks that were prefetched
44  TObjArray *fBranches; ///<! List of branches to be stored in the cache
45  TList *fBrNames; ///<! list of branch names in the cache
46  TTree *fTree; ///<! pointer to the current Tree
47  Bool_t fIsLearning; ///<! true if cache is in learning mode
48  Bool_t fIsManual; ///<! true if cache is StopLearningPhase was used
49  Bool_t fFirstBuffer; ///<! true if first buffer is used for prefetching
50  Bool_t fOneTime; ///<! used in the learning phase
51  Bool_t fReverseRead; ///<! reading in reverse mode
52  Int_t fFillTimes; ///<! how many times we can fill the current buffer
53  Bool_t fFirstTime; ///<! save the fact that we processes the first entry
54  Long64_t fFirstEntry; ///<! save the value of the first entry
55  Bool_t fReadDirectionSet; ///<! read direction established
56  Bool_t fEnabled; ///<! cache enabled for cached reading
57  EPrefillType fPrefillType; ///< Whether a pre-filling is enabled (and if applicable which type)
58  static Int_t fgLearnEntries; ///< number of entries used for learning mode
59  Bool_t fAutoCreated; ///<! true if cache was automatically created
60 
61 private:
62  TTreeCache(const TTreeCache &); //this class cannot be copied
64 
65 public:
66 
67  TTreeCache();
68  TTreeCache(TTree *tree, Int_t buffersize=0);
69  virtual ~TTreeCache();
70  virtual Int_t AddBranch(TBranch *b, Bool_t subgbranches = kFALSE);
71  virtual Int_t AddBranch(const char *branch, Bool_t subbranches = kFALSE);
72  virtual Int_t DropBranch(TBranch *b, Bool_t subbranches = kFALSE);
73  virtual Int_t DropBranch(const char *branch, Bool_t subbranches = kFALSE);
74  virtual void Disable() {fEnabled = kFALSE;}
75  virtual void Enable() {fEnabled = kTRUE;}
76  const TObjArray *GetCachedBranches() const { return fBranches; }
78  Double_t GetEfficiency() const;
79  Double_t GetEfficiencyRel() const;
80  virtual Int_t GetEntryMin() const {return fEntryMin;}
81  virtual Int_t GetEntryMax() const {return fEntryMax;}
82  static Int_t GetLearnEntries();
83  virtual EPrefillType GetLearnPrefill() const {return fPrefillType;}
84  TTree *GetTree() const {return fTree;}
85  Bool_t IsAutoCreated() const {return fAutoCreated;}
86  virtual Bool_t IsEnabled() const {return fEnabled;}
87  virtual Bool_t IsLearning() const {return fIsLearning;}
88 
89  virtual Bool_t FillBuffer();
90  virtual void LearnPrefill();
91 
92  virtual void Print(Option_t *option="") const;
93  virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
94  virtual Int_t ReadBufferNormal(char *buf, Long64_t pos, Int_t len);
95  virtual Int_t ReadBufferPrefetch(char *buf, Long64_t pos, Int_t len);
96  virtual void ResetCache();
97  void SetAutoCreated(Bool_t val) {fAutoCreated = val;}
98  virtual Int_t SetBufferSize(Int_t buffersize);
99  virtual void SetEntryRange(Long64_t emin, Long64_t emax);
102  static void SetLearnEntries(Int_t n = 10);
103  void StartLearningPhase();
104  virtual void StopLearningPhase();
105  virtual void UpdateBranches(TTree *tree);
106 
107  ClassDef(TTreeCache,2) //Specialization of TFileCacheRead for a TTree
108 };
109 
110 #endif
Long64_t fEntryMax
! last entry in the cache
Definition: TTreeCache.h:37
An array of TObjects.
Definition: TObjArray.h:37
Int_t fNReadOk
Number of blocks read and found in the cache.
Definition: TTreeCache.h:41
long long Long64_t
Definition: RtypesCore.h:69
const TObjArray * GetCachedBranches() const
Definition: TTreeCache.h:76
TObjArray * fBranches
! List of branches to be stored in the cache
Definition: TTreeCache.h:44
A cache when reading files over the network.
const char Option_t
Definition: RtypesCore.h:62
Bool_t fOneTime
! used in the learning phase
Definition: TTreeCache.h:50
virtual EPrefillType GetLearnPrefill() const
Definition: TTreeCache.h:83
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:30
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
Long64_t fEntryMin
! first entry in the cache
Definition: TTreeCache.h:36
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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...
void SetAutoCreated(Bool_t val)
Definition: TTreeCache.h:97
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:332
Bool_t fAutoCreated
! true if cache was automatically created
Definition: TTreeCache.h:59
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:320
Bool_t IsAutoCreated() const
Definition: TTreeCache.h:85
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
! cache enabled for cached reading
Definition: TTreeCache.h:56
virtual void Enable()
Definition: TTreeCache.h:75
Double_t GetEfficiencyRel() const
This will indicate a sort of relative efficiency...
Definition: TTreeCache.cxx:988
A doubly linked list.
Definition: TList.h:44
TTree * fTree
! pointer to the current Tree
Definition: TTreeCache.h:46
EPrefillType GetConfiguredPrefillType() const
Return the desired prefill type from the environment or resource variable.
Definition: TTreeCache.cxx:953
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:484
virtual Bool_t IsEnabled() const
Definition: TTreeCache.h:86
TTree * GetTree() const
Definition: TTreeCache.h:84
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:315
Bool_t fReadDirectionSet
! read direction established
Definition: TTreeCache.h:55
TTreeCache & operator=(const TTreeCache &)
Int_t fNReadMiss
Number of blocks read and not found in the cache.
Definition: TTreeCache.h:42
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:619
Int_t fNReadPref
Number of blocks that were prefetched.
Definition: TTreeCache.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t fReverseRead
! reading in reverse mode
Definition: TTreeCache.h:51
Bool_t fFirstTime
! save the fact that we processes the first entry
Definition: TTreeCache.h:53
Long64_t fEntryCurrent
! current lowest entry number in the cache
Definition: TTreeCache.h:38
TTreeCache()
Default Constructor.
Definition: TTreeCache.cxx:252
virtual void Print(Option_t *option="") const
Print cache statistics.
double Double_t
Definition: RtypesCore.h:55
Bool_t fIsLearning
! true if cache is in learning mode
Definition: TTreeCache.h:47
virtual Int_t GetEntryMax() const
Definition: TTreeCache.h:81
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
Whether a pre-filling is enabled (and if applicable which type)
Definition: TTreeCache.h:57
Int_t fFillTimes
! how many times we can fill the current buffer
Definition: TTreeCache.h:52
virtual Int_t SetBufferSize(Int_t buffersize)
Change the underlying buffer size of the cache.
virtual Bool_t IsLearning() const
Definition: TTreeCache.h:87
Int_t fNbranches
! Number of branches in the cache
Definition: TTreeCache.h:40
Long64_t fFirstEntry
! save the value of the first entry
Definition: TTreeCache.h:54
Definition: file.py:1
TList * fBrNames
! list of branch names in the cache
Definition: TTreeCache.h:45
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Bool_t fFirstBuffer
! true if first buffer is used for prefetching
Definition: TTreeCache.h:49
static Int_t fgLearnEntries
number of entries used for learning mode
Definition: TTreeCache.h:58
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:70
Bool_t fIsManual
! true if cache is StopLearningPhase was used
Definition: TTreeCache.h:48
A TTree is a list of TBranches.
Definition: TBranch.h:59
Long64_t fEntryNext
! next entry number where cache must be filled
Definition: TTreeCache.h:39
virtual Int_t GetEntryMin() const
Definition: TTreeCache.h:80
virtual void UpdateBranches(TTree *tree)
Update pointer to current Tree and recompute pointers to the branches in the cache.
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
Double_t GetEfficiency() const
Give the total efficiency of the cache...
Definition: TTreeCache.cxx:976
static Int_t GetLearnEntries()
Static function returning the number of entries used to train the cache see SetLearnEntries.
virtual void Disable()
Definition: TTreeCache.h:74
ECacheAction
TTreeCache flushing semantics.
Definition: TFile.h:63