ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TObject
16 #include "TObject.h"
17 #endif
18 
19 #ifndef ROOT_TFile
20 #include "TFile.h"
21 #endif
22 
23 class TBranch;
24 class TFilePrefetch;
25 
26 class TFileCacheRead : public TObject {
27 
28 protected:
29  TFilePrefetch *fPrefetch; ///<! Object that does the asynchronous reading in another thread
30  Int_t fBufferSizeMin; ///< Original size of fBuffer
31  Int_t fBufferSize; ///< Allocated size of fBuffer (at a given time)
32  Int_t fBufferLen; ///< Current buffer length (<= fBufferSize)
33 
34  Long64_t fBytesRead; ///< Number of bytes read for this cache
35  Long64_t fBytesReadExtra; ///< Number of extra bytes (overhead) read by the readahead buffer
36  Int_t fReadCalls; ///< Number of read calls for this cache
37  Long64_t fNoCacheBytesRead; ///< Number of bytes read by basket to fill cached tree
38  Int_t fNoCacheReadCalls; ///< Number of read calls by basket to fill cached tree
39 
41  Bool_t fEnablePrefetching;///< reading by prefetching asynchronously
42 
43  Int_t fNseek; ///< Number of blocks to be prefetched
44  Int_t fNtot; ///< Total size of prefetched blocks
45  Int_t fNb; ///< Number of long buffers
46  Int_t fSeekSize; ///< Allocated size of fSeek
47  Long64_t *fSeek; ///<[fNseek] Position on file of buffers to be prefetched
48  Long64_t *fSeekSort; ///<[fNseek] Position on file of buffers to be prefetched (sorted)
49  Int_t *fSeekIndex; ///<[fNseek] sorted index table of fSeek
50  Long64_t *fPos; ///<[fNb] start of long buffers
51  Int_t *fSeekLen; ///<[fNseek] Length of buffers to be prefetched
52  Int_t *fSeekSortLen; ///<[fNseek] Length of buffers to be prefetched (sorted)
53  Int_t *fSeekPos; ///<[fNseek] Position of sorted blocks in fBuffer
54  Int_t *fLen; ///<[fNb] Length of long buffers
55  TFile *fFile; ///< Pointer to file
56  char *fBuffer; ///<[fBufferSize] buffer of contiguous prefetched blocks
57  Bool_t fIsSorted; ///< True if fSeek array is sorted
58  Bool_t fIsTransferred; ///< True when fBuffer contains something valid
59  Long64_t fPrefetchedBlocks; ///< Number of blocks prefetched.
60 
61  //variables for the second block prefetched with the same semantics as for the first one
66  Long64_t *fBSeek; ///<[fBNseek]
67  Long64_t *fBSeekSort; ///<[fBNseek]
68  Int_t *fBSeekIndex; ///<[fBNseek]
69  Long64_t *fBPos; ///<[fBNb]
70  Int_t *fBSeekLen; ///<[fBNseek]
71  Int_t *fBSeekSortLen; ///<[fBNseek]
72  Int_t *fBSeekPos; ///<[fBNseek]
73  Int_t *fBLen; ///<[fBNb]
76 
77  void SetEnablePrefetchingImpl(Bool_t setPrefetching = kFALSE); // Can not be virtual as it is called from the constructor.
78 
79 private:
80  TFileCacheRead(const TFileCacheRead &); //cannot be copied
82 
83 public:
85  TFileCacheRead(TFile *file, Int_t buffersize, TObject *tree = 0);
86  virtual ~TFileCacheRead();
87  virtual Int_t AddBranch(TBranch * /*b*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
88  virtual Int_t AddBranch(const char * /*branch*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
89  virtual void AddNoCacheBytesRead(Long64_t len) { fNoCacheBytesRead += len; }
91  virtual void Close(Option_t *option="");
92  virtual Int_t GetBufferSize() const { return fBufferSize; };
93  virtual Long64_t GetBytesRead() const { return fBytesRead; }
94  virtual Long64_t GetNoCacheBytesRead() const { return fNoCacheBytesRead; }
95  virtual Long64_t GetBytesReadExtra() const { return fBytesReadExtra; }
96  TFile *GetFile() const { return fFile; } // Return the TFile being cached.
97  Int_t GetNseek() const { return fNseek; } // Return the number of blocks in the current cache.
98  Int_t GetNtot() const { return fNtot; } // Return the total size of the prefetched blocks.
99  virtual Int_t GetReadCalls() const { return fReadCalls; }
100  virtual Int_t GetNoCacheReadCalls() const { return fNoCacheReadCalls; }
101  virtual Int_t GetUnzipBuffer(char ** /*buf*/, Long64_t /*pos*/, Int_t /*len*/, Bool_t * /*free*/) { return -1; }
103  virtual Bool_t IsAsyncReading() const { return fAsyncReading; };
104  virtual void SetEnablePrefetching(Bool_t setPrefetching = kFALSE);
105  virtual Bool_t IsEnablePrefetching() const { return fEnablePrefetching; };
106  virtual Bool_t IsLearning() const {return kFALSE;}
107  virtual void Prefetch(Long64_t pos, Int_t len);
108  virtual void Print(Option_t *option="") const;
109  virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
110  virtual Int_t ReadBufferExtNormal(char *buf, Long64_t pos, Int_t len, Int_t &loc);
111  virtual Int_t ReadBufferExtPrefetch(char *buf, Long64_t pos, Int_t len, Int_t &loc);
112  virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
113  virtual Int_t SetBufferSize(Int_t buffersize);
114  virtual void SetFile(TFile *file, TFile::ECacheAction action = TFile::kDisconnect);
115  virtual void SetSkipZip(Bool_t /*skip*/ = kTRUE) {} // This function is only used by TTreeCacheUnzip (ignore it)
116  virtual void Sort();
117  virtual void SecondSort(); //Method used to sort and merge the chunks in the second block
118  virtual void SecondPrefetch(Long64_t, Int_t); //Used to add chunks to the second block
119  virtual TFilePrefetch* GetPrefetchObj();
120  virtual void WaitFinishPrefetch(); //Gracefully join the prefetching thread
121 
122  ClassDef(TFileCacheRead,2) //TFile cache when reading
123 };
124 
125 #endif
Int_t fNtot
Total size of prefetched blocks.
Long64_t * fBSeek
[fBNseek]
TFile * fFile
Pointer to file.
long long Long64_t
Definition: RtypesCore.h:69
char * fBuffer
[fBufferSize] buffer of contiguous prefetched blocks
virtual Long64_t GetBytesRead() const
virtual void SetEnablePrefetching(Bool_t setPrefetching=kFALSE)
Set the prefetching mode of this file.
A cache when reading files over the network.
const char Option_t
Definition: RtypesCore.h:62
virtual void SecondSort()
Sort buffers to be prefetched in increasing order of positions.
void SetEnablePrefetchingImpl(Bool_t setPrefetching=kFALSE)
TFileCacheRead implementation of SetEnablePrefetching.
Int_t fBufferSize
Allocated size of fBuffer (at a given time)
virtual Int_t AddBranch(TBranch *, Bool_t=kFALSE)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Long64_t fPrefetchedBlocks
Number of blocks prefetched.
virtual Bool_t IsEnablePrefetching() const
virtual Int_t GetReadCalls() const
virtual void Sort()
Sort buffers to be prefetched in increasing order of positions.
Bool_t fIsSorted
True if fSeek array is sorted.
virtual Bool_t IsLearning() const
TFile * GetFile() const
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.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Bool_t IsAsyncReading() const
Int_t fReadCalls
Number of read calls for this cache.
virtual ~TFileCacheRead()
Destructor.
virtual TFilePrefetch * GetPrefetchObj()
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void SecondPrefetch(Long64_t, Int_t)
Int_t * fBSeekPos
[fBNseek]
Long64_t * fBSeekSort
[fBNseek]
Int_t * fSeekLen
[fNseek] Length of buffers to be prefetched
Bool_t fIsTransferred
True when fBuffer contains something valid.
Int_t fBufferLen
Current buffer length (<= fBufferSize)
virtual Int_t GetBufferSize() const
Long64_t fBytesRead
Number of bytes read for this cache.
Int_t GetNtot() const
virtual Long64_t GetNoCacheBytesRead() const
Int_t * fBSeekSortLen
[fBNseek]
TFileCacheRead & operator=(const TFileCacheRead &)
virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc)
Int_t * fBSeekIndex
[fBNseek]
virtual Int_t ReadBufferExtNormal(char *buf, Long64_t pos, Int_t len, Int_t &loc)
Base function for ReadBuffer.
Int_t fSeekSize
Allocated size of fSeek.
Int_t GetNseek() const
virtual void AddNoCacheReadCalls(Int_t reads)
Int_t * fSeekIndex
[fNseek] sorted index table of fSeek
virtual void Print(Option_t *option="") const
Print cache statistics.
virtual void SetFile(TFile *file, TFile::ECacheAction action=TFile::kDisconnect)
Set the file using this cache and reset the current blocks (if any).
virtual Int_t GetNoCacheReadCalls() const
Long64_t fBytesReadExtra
Number of extra bytes (overhead) read by the readahead buffer.
Long64_t fNoCacheBytesRead
Number of bytes read by basket to fill cached tree.
Bool_t fAsyncReading
virtual Int_t SetBufferSize(Int_t buffersize)
Sets the buffer size.
Long64_t * fPos
[fNb] start of long buffers
Long64_t GetPrefetchedBlocks() const
Int_t * fBSeekLen
[fBNseek]
Int_t fNb
Number of long buffers.
Int_t fBufferSizeMin
Original size of fBuffer.
tuple tree
Definition: tree.py:24
tuple file
Definition: fildir.py:20
virtual void WaitFinishPrefetch()
The prefetching mechanism uses two classes (TFilePrefetch and TFPBlock) to prefetch in advance a bloc...
Definition: TFilePrefetch.h:51
Int_t * fSeekPos
[fNseek] Position of sorted blocks in fBuffer
Mother of all ROOT objects.
Definition: TObject.h:58
virtual Int_t GetUnzipBuffer(char **, Long64_t, Int_t, Bool_t *)
Long64_t * fSeekSort
[fNseek] Position on file of buffers to be prefetched (sorted)
virtual Int_t ReadBufferExtPrefetch(char *buf, Long64_t pos, Int_t len, Int_t &loc)
prefetch the first block
Bool_t fEnablePrefetching
reading by prefetching asynchronously
virtual Int_t AddBranch(const char *, Bool_t=kFALSE)
virtual void SetSkipZip(Bool_t=kTRUE)
TFilePrefetch * fPrefetch
! Object that does the asynchronous reading in another thread
virtual Long64_t GetBytesReadExtra() const
Int_t * fLen
[fNb] Length of long buffers
Long64_t * fSeek
[fNseek] Position on file of buffers to be prefetched
Long64_t * fBPos
[fBNb]
void reads()
virtual Int_t ReadBuffer(char *buf, Long64_t pos, Int_t len)
Read buffer at position pos.
Int_t * fBLen
[fBNb]
virtual void Close(Option_t *option="")
Close out any threads or asynchronous fetches used by the underlying implementation.
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t * fSeekSortLen
[fNseek] Length of buffers to be prefetched (sorted)
Bool_t fBIsTransferred
Int_t fNoCacheReadCalls
Number of read calls by basket to fill cached tree.
Int_t fNseek
Number of blocks to be prefetched.
virtual void AddNoCacheBytesRead(Long64_t len)
ECacheAction
TTreeCache flushing semantics.
Definition: TFile.h:57