Logo ROOT  
Reference Guide
TFileCacheRead.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Rene Brun 19/05/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_TFileCacheRead
13 #define ROOT_TFileCacheRead
14 
15 #include "TObject.h"
16 
17 #include "TFile.h"
18 
19 class TBranch;
20 class TFilePrefetch;
21 
22 class TFileCacheRead : public TObject {
23 
24 protected:
25  TFilePrefetch *fPrefetch; ///<! Object that does the asynchronous reading in another thread
26  Int_t fBufferSizeMin; ///< Original size of fBuffer
27  Int_t fBufferSize; ///< Allocated size of fBuffer (at a given time)
28  Int_t fBufferLen; ///< Current buffer length (<= fBufferSize)
29 
30  Long64_t fBytesRead; ///< Number of bytes read for this cache
31  Long64_t fBytesReadExtra; ///< Number of extra bytes (overhead) read by the readahead buffer
32  Int_t fReadCalls; ///< Number of read calls for this cache
33  Long64_t fNoCacheBytesRead; ///< Number of bytes read by basket to fill cached tree
34  Int_t fNoCacheReadCalls; ///< Number of read calls by basket to fill cached tree
35 
37  Bool_t fEnablePrefetching;///< reading by prefetching asynchronously
38 
39  Int_t fNseek; ///< Number of blocks to be prefetched
40  Int_t fNtot; ///< Total size of prefetched blocks
41  Int_t fNb; ///< Number of long buffers
42  Int_t fSeekSize; ///< Allocated size of fSeek
43  Long64_t *fSeek; ///<[fNseek] Position on file of buffers to be prefetched
44  Long64_t *fSeekSort; ///<[fNseek] Position on file of buffers to be prefetched (sorted)
45  Int_t *fSeekIndex; ///<[fNseek] sorted index table of fSeek
46  Long64_t *fPos; ///<[fNb] start of long buffers
47  Int_t *fSeekLen; ///<[fNseek] Length of buffers to be prefetched
48  Int_t *fSeekSortLen; ///<[fNseek] Length of buffers to be prefetched (sorted)
49  Int_t *fSeekPos; ///<[fNseek] Position of sorted blocks in fBuffer
50  Int_t *fLen; ///<[fNb] Length of long buffers
51  TFile *fFile; ///< Pointer to file
52  char *fBuffer; ///<[fBufferSize] buffer of contiguous prefetched blocks
53  Bool_t fIsSorted; ///< True if fSeek array is sorted
54  Bool_t fIsTransferred; ///< True when fBuffer contains something valid
55  Long64_t fPrefetchedBlocks; ///< Number of blocks prefetched.
56 
57  //variables for the second block prefetched with the same semantics as for the first one
62  Long64_t *fBSeek; ///<[fBNseek]
63  Long64_t *fBSeekSort; ///<[fBNseek]
64  Int_t *fBSeekIndex; ///<[fBNseek]
65  Long64_t *fBPos; ///<[fBNb]
66  Int_t *fBSeekLen; ///<[fBNseek]
67  Int_t *fBSeekSortLen; ///<[fBNseek]
68  Int_t *fBSeekPos; ///<[fBNseek]
69  Int_t *fBLen; ///<[fBNb]
72 
73  void SetEnablePrefetchingImpl(Bool_t setPrefetching = kFALSE); // Can not be virtual as it is called from the constructor.
74 
75 private:
76  TFileCacheRead(const TFileCacheRead &) = delete; //cannot be copied
77  TFileCacheRead& operator=(const TFileCacheRead &) = delete;
78 
79 public:
81  TFileCacheRead(TFile *file, Int_t buffersize, TObject *tree = nullptr);
82  virtual ~TFileCacheRead();
83  virtual Int_t AddBranch(TBranch * /*b*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
84  virtual Int_t AddBranch(const char * /*branch*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
85  virtual void AddNoCacheBytesRead(Long64_t len) { fNoCacheBytesRead += len; }
86  virtual void AddNoCacheReadCalls(Int_t reads) { fNoCacheReadCalls += reads; }
87  virtual void Close(Option_t *option="");
88  virtual Int_t GetBufferSize() const { return fBufferSize; };
89  virtual Long64_t GetBytesRead() const { return fBytesRead; }
90  virtual Long64_t GetNoCacheBytesRead() const { return fNoCacheBytesRead; }
91  virtual Long64_t GetBytesReadExtra() const { return fBytesReadExtra; }
92  TFile *GetFile() const { return fFile; } // Return the TFile being cached.
93  Int_t GetNseek() const { return fNseek; } // Return the number of blocks in the current cache.
94  Int_t GetNtot() const { return fNtot; } // Return the total size of the prefetched blocks.
95  virtual Int_t GetReadCalls() const { return fReadCalls; }
96  virtual Int_t GetNoCacheReadCalls() const { return fNoCacheReadCalls; }
97  virtual Int_t GetUnzipBuffer(char ** /*buf*/, Long64_t /*pos*/, Int_t /*len*/, Bool_t * /*free*/) { return -1; }
99  virtual Bool_t IsAsyncReading() const { return fAsyncReading; };
100  virtual void SetEnablePrefetching(Bool_t setPrefetching = kFALSE);
101  virtual Bool_t IsEnablePrefetching() const { return fEnablePrefetching; };
102  virtual Bool_t IsLearning() const {return kFALSE;}
103  virtual Int_t LearnBranch(TBranch * /*b*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
104  virtual void Prefetch(Long64_t pos, Int_t len);
105  virtual void Print(Option_t *option="") const;
106  virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
107  virtual Int_t ReadBufferExtNormal(char *buf, Long64_t pos, Int_t len, Int_t &loc);
108  virtual Int_t ReadBufferExtPrefetch(char *buf, Long64_t pos, Int_t len, Int_t &loc);
109  virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
110  virtual Int_t SetBufferSize(Int_t buffersize);
111  virtual void SetFile(TFile *file, TFile::ECacheAction action = TFile::kDisconnect);
112  virtual void SetSkipZip(Bool_t /*skip*/ = kTRUE) {} // This function is only used by TTreeCacheUnzip (ignore it)
113  virtual void Sort();
114  virtual void SecondSort(); //Method used to sort and merge the chunks in the second block
115  virtual void SecondPrefetch(Long64_t, Int_t); //Used to add chunks to the second block
116  virtual TFilePrefetch* GetPrefetchObj();
117  virtual void WaitFinishPrefetch(); //Gracefully join the prefetching thread
118 
119  ClassDef(TFileCacheRead,2) //TFile cache when reading
120 };
121 
122 #endif
TFileCacheRead::Prefetch
virtual void Prefetch(Long64_t pos, Int_t len)
Add block of length len at position pos in the list of blocks to be prefetched.
Definition: TFileCacheRead.cxx:201
TFileCacheRead::fLen
Int_t * fLen
[fNb] Length of long buffers
Definition: TFileCacheRead.h:50
TFileCacheRead::fNoCacheBytesRead
Long64_t fNoCacheBytesRead
Number of bytes read by basket to fill cached tree.
Definition: TFileCacheRead.h:33
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TFileCacheRead::GetNoCacheBytesRead
virtual Long64_t GetNoCacheBytesRead() const
Definition: TFileCacheRead.h:90
TFileCacheRead::fSeek
Long64_t * fSeek
[fNseek] Position on file of buffers to be prefetched
Definition: TFileCacheRead.h:43
TFileCacheRead::fBSeekSize
Int_t fBSeekSize
Definition: TFileCacheRead.h:61
TFileCacheRead::fPrefetch
TFilePrefetch * fPrefetch
! Object that does the asynchronous reading in another thread
Definition: TFileCacheRead.h:25
TFileCacheRead::AddNoCacheReadCalls
virtual void AddNoCacheReadCalls(Int_t reads)
Definition: TFileCacheRead.h:86
TFileCacheRead::GetNoCacheReadCalls
virtual Int_t GetNoCacheReadCalls() const
Definition: TFileCacheRead.h:96
TFileCacheRead::~TFileCacheRead
virtual ~TFileCacheRead()
Destructor.
Definition: TFileCacheRead.cxx:159
TFileCacheRead::fBNseek
Int_t fBNseek
Definition: TFileCacheRead.h:58
TFileCacheRead::GetBufferSize
virtual Int_t GetBufferSize() const
Definition: TFileCacheRead.h:88
TFileCacheRead::TFileCacheRead
TFileCacheRead()
Default Constructor.
Definition: TFileCacheRead.cxx:40
TFile::ECacheAction
ECacheAction
TTreeCache flushing semantics.
Definition: TFile.h:71
TFileCacheRead::fBufferLen
Int_t fBufferLen
Current buffer length (<= fBufferSize)
Definition: TFileCacheRead.h:28
tree
Definition: tree.py:1
TFileCacheRead::ReadBufferExtNormal
virtual Int_t ReadBufferExtNormal(char *buf, Long64_t pos, Int_t len, Int_t &loc)
Base function for ReadBuffer.
Definition: TFileCacheRead.cxx:453
TFileCacheRead::fNb
Int_t fNb
Number of long buffers.
Definition: TFileCacheRead.h:41
TFileCacheRead::fPos
Long64_t * fPos
[fNb] start of long buffers
Definition: TFileCacheRead.h:46
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TFileCacheRead::operator=
TFileCacheRead & operator=(const TFileCacheRead &)=delete
Int_t
int Int_t
Definition: RtypesCore.h:45
TFileCacheRead::ReadBufferExtPrefetch
virtual Int_t ReadBufferExtPrefetch(char *buf, Long64_t pos, Int_t len, Int_t &loc)
prefetch the first block
Definition: TFileCacheRead.cxx:393
TFileCacheRead::SecondPrefetch
virtual void SecondPrefetch(Long64_t, Int_t)
Definition: TFileCacheRead.cxx:258
TFileCacheRead::fBufferSize
Int_t fBufferSize
Allocated size of fBuffer (at a given time)
Definition: TFileCacheRead.h:27
TFileCacheRead::fBNb
Int_t fBNb
Definition: TFileCacheRead.h:60
TFileCacheRead::SetEnablePrefetching
virtual void SetEnablePrefetching(Bool_t setPrefetching=kFALSE)
Set the prefetching mode of this file.
Definition: TFileCacheRead.cxx:771
TFileCacheRead::GetUnzipBuffer
virtual Int_t GetUnzipBuffer(char **, Long64_t, Int_t, Bool_t *)
Definition: TFileCacheRead.h:97
TFileCacheRead::fBytesRead
Long64_t fBytesRead
Number of bytes read for this cache.
Definition: TFileCacheRead.h:30
TFileCacheRead::GetFile
TFile * GetFile() const
Definition: TFileCacheRead.h:92
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFileCacheRead::IsEnablePrefetching
virtual Bool_t IsEnablePrefetching() const
Definition: TFileCacheRead.h:101
TFile.h
TFileCacheRead::fBSeekIndex
Int_t * fBSeekIndex
[fBNseek]
Definition: TFileCacheRead.h:64
bool
TFileCacheRead::fBSeekSortLen
Int_t * fBSeekSortLen
[fBNseek]
Definition: TFileCacheRead.h:67
TFileCacheRead::fBPos
Long64_t * fBPos
[fBNb]
Definition: TFileCacheRead.h:65
TFile::kDisconnect
@ kDisconnect
Definition: TFile.h:71
TBranch
Definition: TBranch.h:89
TFileCacheRead::GetReadCalls
virtual Int_t GetReadCalls() const
Definition: TFileCacheRead.h:95
TFileCacheRead::fBSeekLen
Int_t * fBSeekLen
[fBNseek]
Definition: TFileCacheRead.h:66
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TFileCacheRead::fSeekIndex
Int_t * fSeekIndex
[fNseek] sorted index table of fSeek
Definition: TFileCacheRead.h:45
TFileCacheRead::fSeekSize
Int_t fSeekSize
Allocated size of fSeek.
Definition: TFileCacheRead.h:42
TFileCacheRead::ReadBuffer
virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len)
Read buffer at position pos.
Definition: TFileCacheRead.cxx:363
TFileCacheRead::fBIsTransferred
Bool_t fBIsTransferred
Definition: TFileCacheRead.h:71
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TFileCacheRead::fBLen
Int_t * fBLen
[fBNb]
Definition: TFileCacheRead.h:69
TFileCacheRead::GetNseek
Int_t GetNseek() const
Definition: TFileCacheRead.h:93
TFileCacheRead::fBuffer
char * fBuffer
[fBufferSize] buffer of contiguous prefetched blocks
Definition: TFileCacheRead.h:52
TFileCacheRead::SetBufferSize
virtual Int_t SetBufferSize(Int_t buffersize)
Sets the buffer size.
Definition: TFileCacheRead.cxx:709
TFileCacheRead::fReadCalls
Int_t fReadCalls
Number of read calls for this cache.
Definition: TFileCacheRead.h:32
TFileCacheRead::fBytesReadExtra
Long64_t fBytesReadExtra
Number of extra bytes (overhead) read by the readahead buffer.
Definition: TFileCacheRead.h:31
TFileCacheRead::AddNoCacheBytesRead
virtual void AddNoCacheBytesRead(Long64_t len)
Definition: TFileCacheRead.h:85
TFileCacheRead::fIsSorted
Bool_t fIsSorted
True if fSeek array is sorted.
Definition: TFileCacheRead.h:53
TFileCacheRead::Close
virtual void Close(Option_t *option="")
Close out any threads or asynchronous fetches used by the underlying implementation.
Definition: TFileCacheRead.cxx:188
TFileCacheRead::SecondSort
virtual void SecondSort()
Sort buffers to be prefetched in increasing order of positions.
Definition: TFileCacheRead.cxx:629
TFileCacheRead::GetBytesRead
virtual Long64_t GetBytesRead() const
Definition: TFileCacheRead.h:89
TFileCacheRead::fAsyncReading
Bool_t fAsyncReading
Definition: TFileCacheRead.h:36
TFileCacheRead::fSeekLen
Int_t * fSeekLen
[fNseek] Length of buffers to be prefetched
Definition: TFileCacheRead.h:47
TFile
Definition: TFile.h:54
TFileCacheRead::fBNtot
Int_t fBNtot
Definition: TFileCacheRead.h:59
TFileCacheRead
Definition: TFileCacheRead.h:22
TFileCacheRead::Sort
virtual void Sort()
Sort buffers to be prefetched in increasing order of positions.
Definition: TFileCacheRead.cxx:571
TFileCacheRead::Print
virtual void Print(Option_t *option="") const
Print cache statistics.
Definition: TFileCacheRead.cxx:325
TFileCacheRead::fNtot
Int_t fNtot
Total size of prefetched blocks.
Definition: TFileCacheRead.h:40
TFileCacheRead::fBSeekSort
Long64_t * fBSeekSort
[fBNseek]
Definition: TFileCacheRead.h:63
TFilePrefetch
Definition: TFilePrefetch.h:33
TFileCacheRead::AddBranch
virtual Int_t AddBranch(TBranch *, Bool_t=kFALSE)
Definition: TFileCacheRead.h:83
TFileCacheRead::ReadBufferExt
virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc)
Definition: TFileCacheRead.cxx:381
TFileCacheRead::GetPrefetchObj
virtual TFilePrefetch * GetPrefetchObj()
Definition: TFileCacheRead.cxx:683
TFileCacheRead::fSeekPos
Int_t * fSeekPos
[fNseek] Position of sorted blocks in fBuffer
Definition: TFileCacheRead.h:49
TFileCacheRead::fNoCacheReadCalls
Int_t fNoCacheReadCalls
Number of read calls by basket to fill cached tree.
Definition: TFileCacheRead.h:34
TFileCacheRead::SetSkipZip
virtual void SetSkipZip(Bool_t=kTRUE)
Definition: TFileCacheRead.h:112
TObject.h
TFileCacheRead::fPrefetchedBlocks
Long64_t fPrefetchedBlocks
Number of blocks prefetched.
Definition: TFileCacheRead.h:55
TFileCacheRead::GetBytesReadExtra
virtual Long64_t GetBytesReadExtra() const
Definition: TFileCacheRead.h:91
file
Definition: file.py:1
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TFileCacheRead::fSeekSortLen
Int_t * fSeekSortLen
[fNseek] Length of buffers to be prefetched (sorted)
Definition: TFileCacheRead.h:48
TFileCacheRead::fBSeek
Long64_t * fBSeek
[fBNseek]
Definition: TFileCacheRead.h:62
TFileCacheRead::SetEnablePrefetchingImpl
void SetEnablePrefetchingImpl(Bool_t setPrefetching=kFALSE)
TFileCacheRead implementation of SetEnablePrefetching.
Definition: TFileCacheRead.cxx:781
TFileCacheRead::fBIsSorted
Bool_t fBIsSorted
Definition: TFileCacheRead.h:70
TFileCacheRead::IsLearning
virtual Bool_t IsLearning() const
Definition: TFileCacheRead.h:102
TFileCacheRead::fSeekSort
Long64_t * fSeekSort
[fNseek] Position on file of buffers to be prefetched (sorted)
Definition: TFileCacheRead.h:44
TFileCacheRead::fEnablePrefetching
Bool_t fEnablePrefetching
reading by prefetching asynchronously
Definition: TFileCacheRead.h:37
TFileCacheRead::SetFile
virtual void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect)
Set the file using this cache and reset the current blocks (if any).
Definition: TFileCacheRead.cxx:544
TFileCacheRead::fNseek
Int_t fNseek
Number of blocks to be prefetched.
Definition: TFileCacheRead.h:39
TFileCacheRead::GetPrefetchedBlocks
Long64_t GetPrefetchedBlocks() const
Definition: TFileCacheRead.h:98
TFileCacheRead::fFile
TFile * fFile
Pointer to file.
Definition: TFileCacheRead.h:51
TFileCacheRead::WaitFinishPrefetch
virtual void WaitFinishPrefetch()
Definition: TFileCacheRead.cxx:690
TFileCacheRead::LearnBranch
virtual Int_t LearnBranch(TBranch *, Bool_t=kFALSE)
Definition: TFileCacheRead.h:103
TFileCacheRead::fBSeekPos
Int_t * fBSeekPos
[fBNseek]
Definition: TFileCacheRead.h:68
TFileCacheRead::GetNtot
Int_t GetNtot() const
Definition: TFileCacheRead.h:94
TFileCacheRead::IsAsyncReading
virtual Bool_t IsAsyncReading() const
Definition: TFileCacheRead.h:99
TFileCacheRead::fBufferSizeMin
Int_t fBufferSizeMin
Original size of fBuffer.
Definition: TFileCacheRead.h:26
TFileCacheRead::AddBranch
virtual Int_t AddBranch(const char *, Bool_t=kFALSE)
Definition: TFileCacheRead.h:84
TFileCacheRead::fIsTransferred
Bool_t fIsTransferred
True when fBuffer contains something valid.
Definition: TFileCacheRead.h:54
int