Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTreePerfStats.h
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Rene Brun 29/10/09
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2009, 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_TTreePerfStats
13 #define ROOT_TTreePerfStats
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TTreePerfStats //
18 // //
19 // TTree I/O performance measurement //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 
24 #include "TVirtualPerfStats.h"
25 #include "TString.h"
26 #include <vector>
27 #include <unordered_map>
28 
29 class TBrowser;
30 class TFile;
31 class TTree;
32 class TStopwatch;
33 class TPaveText;
34 class TGraphErrors;
35 class TGaxis;
36 class TText;
37 
38 class TTreePerfStats : public TVirtualPerfStats {
39 
40 public:
41  struct BasketInfo {
42  UInt_t fUsed = {0}; // Number of times the basket was requested from the disk.
43  UInt_t fLoaded = {0}; // Number of times the basket was put in the primary TTreeCache
44  UInt_t fLoadedMiss = {0}; // Number of times the basket was put in the secondary cache
45  UInt_t fMissed = {0}; // Number of times the basket was read directly from the file.
46  };
47 
48  using BasketList_t = std::vector<std::pair<TBranch*, std::vector<size_t>>>;
49 
50 protected:
51  Int_t fTreeCacheSize; //TTreeCache buffer size
52  Int_t fNleaves; //Number of leaves in the tree
53  Int_t fReadCalls; //Number of read calls
54  Int_t fReadaheadSize; //Readahead cache size
55  Long64_t fBytesRead; //Number of bytes read
56  Long64_t fBytesReadExtra;//Number of bytes (overhead) of the readahead cache
57  Double_t fRealNorm; //Real time scale factor for fGraphTime
58  Double_t fRealTime; //Real time
59  Double_t fCpuTime; //Cpu time
60  Double_t fDiskTime; //Time spent in pure raw disk IO
61  Double_t fUnzipTime; //Time spent uncompressing the data.
62  Double_t fCompress; //Tree compression factor
63  TString fName; //name of this TTreePerfStats
64  TString fHostInfo; //name of the host system, ROOT version and date
65  TFile *fFile; //!pointer to the file containing the Tree
66  TTree *fTree; //!pointer to the Tree being monitored
67  TGraphErrors *fGraphIO ; //pointer to the graph with IO data
68  TGraphErrors *fGraphTime ; //pointer to the graph with timestamp info
69  TPaveText *fPave; //pointer to annotation pavetext
70  TStopwatch *fWatch; //TStopwatch pointer
71  TGaxis *fRealTimeAxis; //pointer to TGaxis object showing real-time
72  TText *fHostInfoText; //Graphics Text object with the fHostInfo data
73 
74  std::unordered_map<TBranch*, size_t> fBranchIndexCache; // Cache the index of the branch in the cache's array.
75  std::vector<std::vector<BasketInfo> > fBasketsInfo; // Details on which baskets was used, cached, 'miss-cached' or read uncached.Browse
76 
77  BasketInfo &GetBasketInfo(TBranch *b, size_t basketNumber);
78  BasketInfo &GetBasketInfo(size_t bi, size_t basketNumber);
79 
80 public:
81  TTreePerfStats();
82  TTreePerfStats(const char *name, TTree *T);
83  virtual ~TTreePerfStats();
84  virtual void Browse(TBrowser *b);
85  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
86  virtual void Draw(Option_t *option="");
87  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
88  virtual void Finish();
89  virtual Long64_t GetBytesRead() const {return fBytesRead;}
90  virtual Long64_t GetBytesReadExtra() const {return fBytesReadExtra;}
91  virtual Double_t GetCpuTime() const {return fCpuTime;}
92  virtual Double_t GetDiskTime() const {return fDiskTime;}
93  TGraphErrors *GetGraphIO() {return fGraphIO;}
94  TGraphErrors *GetGraphTime() {return fGraphTime;}
95  const char *GetHostInfo() const{return fHostInfo.Data();}
96  const char *GetName() const{return fName.Data();}
97  virtual Int_t GetNleaves() const {return fNleaves;}
98  virtual Long64_t GetNumEvents() const {return 0;}
99  TPaveText *GetPave() {return fPave;}
100  virtual Int_t GetReadaheadSize() const {return fReadaheadSize;}
101  virtual Int_t GetReadCalls() const {return fReadCalls;}
102  virtual Double_t GetRealTime() const {return fRealTime;}
103  TStopwatch *GetStopwatch() const {return fWatch;}
104  virtual Int_t GetTreeCacheSize() const {return fTreeCacheSize;}
105  virtual Double_t GetUnzipTime() const {return fUnzipTime; }
106  virtual void Paint(Option_t *chopt="");
107  virtual void Print(Option_t *option="") const;
108 
109  virtual void SimpleEvent(EEventType) {}
110  virtual void PacketEvent(const char *, const char *, const char *,
111  Long64_t , Double_t ,Double_t , Double_t ,Long64_t ) {}
112  virtual void FileEvent(const char *, const char *, const char *, const char *, Bool_t) {}
113  virtual void FileOpenEvent(TFile *, const char *, Double_t) {}
114  virtual void FileReadEvent(TFile *file, Int_t len, Double_t start);
115  virtual void UnzipEvent(TObject *tree, Long64_t pos, Double_t start, Int_t complen, Int_t objlen);
116  virtual void RateEvent(Double_t , Double_t , Long64_t , Long64_t) {}
117 
118  virtual void SaveAs(const char *filename="",Option_t *option="") const;
119  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
120  virtual void SetBytesRead(Long64_t nbytes) {fBytesRead = nbytes;}
121  virtual void SetBytesReadExtra(Long64_t nbytes) {fBytesReadExtra = nbytes;}
122  virtual void SetCompress(Double_t cx) {fCompress = cx;}
123  virtual void SetDiskTime(Double_t t) {fDiskTime = t;}
124  virtual void SetNumEvents(Long64_t) {}
125  virtual void SetCpuTime(Double_t cptime) {fCpuTime = cptime;}
126  virtual void SetGraphIO(TGraphErrors *gr) {fGraphIO = gr;}
127  virtual void SetGraphTime(TGraphErrors *gr) {fGraphTime = gr;}
128  virtual void SetHostInfo(const char *info) {fHostInfo = info;}
129  virtual void SetName(const char *name) {fName = name;}
130  virtual void SetNleaves(Int_t nleaves) {fNleaves = nleaves;}
131  virtual void SetReadaheadSize(Int_t nbytes) {fReadaheadSize = nbytes;}
132  virtual void SetReadCalls(Int_t ncalls) {fReadCalls = ncalls;}
133  virtual void SetRealNorm(Double_t rnorm) {fRealNorm = rnorm;}
134  virtual void SetRealTime(Double_t rtime) {fRealTime = rtime;}
135  virtual void SetTreeCacheSize(Int_t nbytes) {fTreeCacheSize = nbytes;}
136  virtual void SetUnzipTime(Double_t uztime) {fUnzipTime = uztime;}
137 
138  virtual void PrintBasketInfo(Option_t *option = "") const;
139  virtual void SetLoaded(TBranch *b, size_t basketNumber) { ++GetBasketInfo(b, basketNumber).fLoaded; }
140  virtual void SetLoaded(size_t bi, size_t basketNumber) { ++GetBasketInfo(bi, basketNumber).fLoaded; }
141  virtual void SetLoadedMiss(TBranch *b, size_t basketNumber) { ++GetBasketInfo(b, basketNumber).fLoadedMiss; }
142  virtual void SetLoadedMiss(size_t bi, size_t basketNumber) { ++GetBasketInfo(bi, basketNumber).fLoadedMiss; }
143  virtual void SetMissed(TBranch *b, size_t basketNumber) { ++GetBasketInfo(b, basketNumber).fMissed; }
144  virtual void SetMissed(size_t bi, size_t basketNumber) { ++GetBasketInfo(bi, basketNumber).fMissed; }
145  virtual void SetUsed(TBranch *b, size_t basketNumber) { ++GetBasketInfo(b, basketNumber).fUsed; }
146  virtual void SetUsed(size_t bi, size_t basketNumber) { ++GetBasketInfo(bi, basketNumber).fUsed; }
147  virtual void UpdateBranchIndices(TObjArray *branchNames);
148 
149  BasketList_t GetDuplicateBasketCache() const;
150 
151  ClassDef(TTreePerfStats, 7) // TTree I/O performance measurement
152 };
153 
154 #endif