12 #ifndef ROOT_TTreeCache
13 #define ROOT_TTreeCache
35 class TTreeCache :
public TFileCacheRead {
38 enum EPrefillType { kNoPrefill, kAllBranches };
41 Long64_t fEntryMin{0};
42 Long64_t fEntryMax{1};
43 Long64_t fEntryCurrent{-1};
44 Long64_t fEntryNext{-1};
45 Long64_t fCurrentClusterStart{-1};
46 Long64_t fNextClusterStart{-1};
49 Int_t fNMissReadOk{0};
51 Int_t fNMissReadMiss{0};
53 Int_t fNMissReadPref{0};
54 TObjArray *fBranches{
nullptr};
55 TList *fBrNames{
nullptr};
56 TTree *fTree{
nullptr};
57 Bool_t fIsLearning{kTRUE};
58 Bool_t fIsManual{kFALSE};
59 Bool_t fFirstBuffer{kTRUE};
60 Bool_t fOneTime{kFALSE};
61 Bool_t fReverseRead{kFALSE};
63 Bool_t fFirstTime{kTRUE};
64 Long64_t fFirstEntry{-1};
65 Bool_t fReadDirectionSet{kFALSE};
66 Bool_t fEnabled{kTRUE};
67 EPrefillType fPrefillType;
68 static Int_t fgLearnEntries;
69 Bool_t fAutoCreated{kFALSE};
71 Bool_t fLearnPrefilling{kFALSE};
75 Bool_t fOptimizeMisses{kFALSE};
76 Long64_t fFirstMiss{-1};
77 Long64_t fLastMiss{-1};
82 IOPos(Long64_t pos, Int_t len) : fPos(pos), fLen(len) {}
90 Entry(IOPos io) : fIO(io) {}
94 friend bool operator<(
const Entry &a,
const Entry &b) {
return a.fIO.fPos < b.fIO.fPos; }
96 std::vector<Entry> fEntries;
97 std::vector<TBranch *> fBranches;
98 std::vector<char> fData;
108 std::unique_ptr<MissCache> fMissCache;
111 TTreeCache(
const TTreeCache &) =
delete;
112 TTreeCache &operator=(
const TTreeCache &) =
delete;
121 Bool_t CheckMissCache(
char *buf, Long64_t pos,
123 Bool_t FillMissCache();
124 Bool_t CalculateMissCache();
125 IOPos FindBranchBasketPos(TBranch &, Long64_t entry);
127 TBranch *CalculateMissEntries(Long64_t,
int,
bool);
128 Bool_t ProcessMiss(Long64_t pos,
int len);
133 TTreeCache(TTree *tree, Int_t buffersize=0);
134 virtual ~TTreeCache();
135 virtual Int_t AddBranch(TBranch *b, Bool_t subgbranches = kFALSE);
136 virtual Int_t AddBranch(
const char *branch, Bool_t subbranches = kFALSE);
137 virtual Int_t DropBranch(TBranch *b, Bool_t subbranches = kFALSE);
138 virtual Int_t DropBranch(
const char *branch, Bool_t subbranches = kFALSE);
139 virtual void Disable() {fEnabled = kFALSE;}
140 virtual void Enable() {fEnabled = kTRUE;}
141 Bool_t GetOptimizeMisses()
const {
return fOptimizeMisses; }
142 const TObjArray *GetCachedBranches()
const {
return fBranches; }
143 EPrefillType GetConfiguredPrefillType()
const;
144 Double_t GetEfficiency()
const;
145 Double_t GetEfficiencyRel()
const;
146 virtual Int_t GetEntryMin()
const {
return fEntryMin;}
147 virtual Int_t GetEntryMax()
const {
return fEntryMax;}
148 static Int_t GetLearnEntries();
149 virtual EPrefillType GetLearnPrefill()
const {
return fPrefillType;}
150 Double_t GetMissEfficiency()
const;
151 Double_t GetMissEfficiencyRel()
const;
152 TTree *GetTree()
const {
return fTree;}
153 Bool_t IsAutoCreated()
const {
return fAutoCreated;}
154 virtual Bool_t IsEnabled()
const {
return fEnabled;}
155 virtual Bool_t IsLearning()
const {
return fIsLearning;}
157 virtual Bool_t FillBuffer();
158 virtual Int_t LearnBranch(TBranch *b, Bool_t subgbranches = kFALSE);
159 virtual void LearnPrefill();
161 virtual void Print(Option_t *option=
"")
const;
162 virtual Int_t ReadBuffer(
char *buf, Long64_t pos, Int_t len);
163 virtual Int_t ReadBufferNormal(
char *buf, Long64_t pos, Int_t len);
164 virtual Int_t ReadBufferPrefetch(
char *buf, Long64_t pos, Int_t len);
165 virtual void ResetCache();
166 void ResetMissCache();
167 void SetAutoCreated(Bool_t val) {fAutoCreated = val;}
168 virtual Int_t SetBufferSize(Int_t buffersize);
169 virtual void SetEntryRange(Long64_t emin, Long64_t emax);
170 virtual void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect);
171 virtual void SetLearnPrefill(EPrefillType type = kNoPrefill);
172 static void SetLearnEntries(Int_t n = 10);
173 void SetOptimizeMisses(Bool_t opt);
174 void StartLearningPhase();
175 virtual void StopLearningPhase();
176 virtual void UpdateBranches(TTree *tree);
178 ClassDef(TTreeCache,3)