File indexing completed on 2025-01-18 10:12:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TTreeCache
0013 #define ROOT_TTreeCache
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TFileCacheRead.h"
0025
0026 #include <vector>
0027
0028 class TTree;
0029 class TBranch;
0030 class TObjArray;
0031
0032 class TTreeCache : public TFileCacheRead {
0033
0034 public:
0035 enum EPrefillType { kNoPrefill, kAllBranches };
0036
0037 protected:
0038 Long64_t fEntryMin{0};
0039 Long64_t fEntryMax{1};
0040 Long64_t fEntryCurrent{-1};
0041 Long64_t fEntryNext{-1};
0042 Long64_t fCurrentClusterStart{-1};
0043 Long64_t fNextClusterStart{-1};
0044 Int_t fNbranches{0};
0045 Int_t fNReadOk{0};
0046 Int_t fNMissReadOk{0};
0047 Int_t fNReadMiss{0};
0048 Int_t fNMissReadMiss{0};
0049 Int_t fNReadPref{0};
0050 Int_t fNMissReadPref{0};
0051 TObjArray *fBranches{nullptr};
0052 TList *fBrNames{nullptr};
0053 TTree *fTree{nullptr};
0054 bool fIsLearning{true};
0055 bool fIsManual{false};
0056 bool fFirstBuffer{true};
0057 bool fOneTime{false};
0058 bool fReverseRead{false};
0059 Int_t fFillTimes{0};
0060 bool fFirstTime{true};
0061 Long64_t fFirstEntry{-1};
0062 bool fReadDirectionSet{false};
0063 bool fEnabled{true};
0064 EPrefillType fPrefillType;
0065 static Int_t fgLearnEntries;
0066 bool fAutoCreated{false};
0067
0068 bool fLearnPrefilling{false};
0069
0070
0071
0072 bool fOptimizeMisses{false};
0073 Long64_t fFirstMiss{-1};
0074 Long64_t fLastMiss{-1};
0075
0076
0077
0078 struct IOPos {
0079 IOPos(Long64_t pos, Int_t len) : fPos(pos), fLen(len) {}
0080
0081 Long64_t fPos{0};
0082 Int_t fLen{0};
0083 };
0084
0085 struct MissCache {
0086 struct Entry {
0087 Entry(IOPos io) : fIO(io) {}
0088
0089 IOPos fIO;
0090 ULong64_t fIndex{0};
0091 friend bool operator<(const Entry &a, const Entry &b) { return a.fIO.fPos < b.fIO.fPos; }
0092 };
0093 std::vector<Entry> fEntries;
0094 std::vector<TBranch *> fBranches;
0095 std::vector<char> fData;
0096
0097 void clear()
0098 {
0099 fEntries.clear();
0100 fBranches.clear();
0101 fData.clear();
0102 }
0103 };
0104
0105 std::unique_ptr<MissCache> fMissCache;
0106
0107 private:
0108 TTreeCache(const TTreeCache &) = delete;
0109 TTreeCache &operator=(const TTreeCache &) = delete;
0110
0111
0112
0113
0114
0115
0116
0117
0118 bool CheckMissCache(char *buf, Long64_t pos,
0119 int len);
0120 bool FillMissCache();
0121 bool CalculateMissCache();
0122 IOPos FindBranchBasketPos(TBranch &, Long64_t entry);
0123
0124 TBranch *CalculateMissEntries(Long64_t, int, bool);
0125 bool ProcessMiss(Long64_t pos, int len);
0126
0127 public:
0128
0129 TTreeCache();
0130 TTreeCache(TTree *tree, Int_t buffersize=0);
0131 ~TTreeCache() override;
0132 Int_t AddBranch(TBranch *b, bool subgbranches = false) override;
0133 Int_t AddBranch(const char *branch, bool subbranches = false) override;
0134 virtual Int_t DropBranch(TBranch *b, bool subbranches = false);
0135 virtual Int_t DropBranch(const char *branch, bool subbranches = false);
0136 virtual void Disable() {fEnabled = false;}
0137 virtual void Enable() {fEnabled = true;}
0138 bool GetOptimizeMisses() const { return fOptimizeMisses; }
0139 const TObjArray *GetCachedBranches() const { return fBranches; }
0140 EPrefillType GetConfiguredPrefillType() const;
0141 Double_t GetEfficiency() const;
0142 Double_t GetEfficiencyRel() const;
0143 virtual Int_t GetEntryMin() const {return fEntryMin;}
0144 virtual Int_t GetEntryMax() const {return fEntryMax;}
0145 static Int_t GetLearnEntries();
0146 virtual EPrefillType GetLearnPrefill() const {return fPrefillType;}
0147 Double_t GetMissEfficiency() const;
0148 Double_t GetMissEfficiencyRel() const;
0149 TTree *GetTree() const {return fTree;}
0150 bool IsAutoCreated() const {return fAutoCreated;}
0151 virtual bool IsEnabled() const {return fEnabled;}
0152 bool IsLearning() const override {return fIsLearning;}
0153
0154 virtual bool FillBuffer();
0155 Int_t LearnBranch(TBranch *b, bool subgbranches = false) override;
0156 virtual void LearnPrefill();
0157
0158 void Print(Option_t *option="") const override;
0159 Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len) override;
0160 virtual Int_t ReadBufferNormal(char *buf, Long64_t pos, Int_t len);
0161 virtual Int_t ReadBufferPrefetch(char *buf, Long64_t pos, Int_t len);
0162 virtual void ResetCache();
0163 void ResetMissCache();
0164 void SetAutoCreated(bool val) {fAutoCreated = val;}
0165 Int_t SetBufferSize(Int_t buffersize) override;
0166 virtual void SetEntryRange(Long64_t emin, Long64_t emax);
0167 void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect) override;
0168 virtual void SetLearnPrefill(EPrefillType type = kNoPrefill);
0169 static void SetLearnEntries(Int_t n = 10);
0170 void SetOptimizeMisses(bool opt);
0171 void StartLearningPhase();
0172 virtual void StopLearningPhase();
0173 virtual void UpdateBranches(TTree *tree);
0174
0175 ClassDefOverride(TTreeCache,3)
0176 };
0177
0178 #endif