Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TFileCacheRead.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/io:$Id$
0002 // Author: Rene Brun   19/05/2006
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TFileCacheRead
0013 #define ROOT_TFileCacheRead
0014 
0015 #include "TObject.h"
0016 
0017 #include "TFile.h"
0018 
0019 class TBranch;
0020 class TFilePrefetch;
0021 
0022 class TFileCacheRead : public TObject {
0023 
0024 protected:
0025    TFilePrefetch *fPrefetch;         ///<! Object that does the asynchronous reading in another thread
0026    Int_t          fBufferSizeMin;    ///< Original size of fBuffer
0027    Int_t          fBufferSize;       ///< Allocated size of fBuffer (at a given time)
0028    Int_t          fBufferLen;        ///< Current buffer length (<= fBufferSize)
0029 
0030    Long64_t       fBytesRead;        ///< Number of bytes read for this cache
0031    Long64_t       fBytesReadExtra;   ///< Number of extra bytes (overhead) read by the readahead buffer
0032    Int_t          fReadCalls;        ///< Number of read calls for this cache
0033    Long64_t       fNoCacheBytesRead; ///< Number of bytes read by basket to fill cached tree
0034    Int_t          fNoCacheReadCalls; ///< Number of read calls by basket to fill cached tree
0035 
0036    Bool_t         fAsyncReading;
0037    Bool_t         fEnablePrefetching;///< reading by prefetching asynchronously
0038 
0039    Int_t          fNseek;            ///< Number of blocks to be prefetched
0040    Int_t          fNtot;             ///< Total size of prefetched blocks
0041    Int_t          fNb;               ///< Number of long buffers
0042    Int_t          fSeekSize;         ///< Allocated size of fSeek
0043    Long64_t      *fSeek;             ///<[fNseek] Position on file of buffers to be prefetched
0044    Long64_t      *fSeekSort;         ///<[fNseek] Position on file of buffers to be prefetched (sorted)
0045    Int_t         *fSeekIndex;        ///<[fNseek] sorted index table of fSeek
0046    Long64_t      *fPos;              ///<[fNb] start of long buffers
0047    Int_t         *fSeekLen;          ///<[fNseek] Length of buffers to be prefetched
0048    Int_t         *fSeekSortLen;      ///<[fNseek] Length of buffers to be prefetched (sorted)
0049    Int_t         *fSeekPos;          ///<[fNseek] Position of sorted blocks in fBuffer
0050    Int_t         *fLen;              ///<[fNb] Length of long buffers
0051    TFile         *fFile;             ///< Pointer to file
0052    char          *fBuffer;           ///<[fBufferSize] buffer of contiguous prefetched blocks
0053    Bool_t         fIsSorted;         ///< True if fSeek array is sorted
0054    Bool_t         fIsTransferred;    ///< True when fBuffer contains something valid
0055    Long64_t       fPrefetchedBlocks; ///< Number of blocks prefetched.
0056 
0057    //variables for the second block prefetched with the same semantics as for the first one
0058    Int_t          fBNseek;
0059    Int_t          fBNtot;
0060    Int_t          fBNb;
0061    Int_t          fBSeekSize;
0062    Long64_t      *fBSeek;        ///<[fBNseek]
0063    Long64_t      *fBSeekSort;    ///<[fBNseek]
0064    Int_t         *fBSeekIndex;   ///<[fBNseek]
0065    Long64_t      *fBPos;         ///<[fBNb]
0066    Int_t         *fBSeekLen;     ///<[fBNseek]
0067    Int_t         *fBSeekSortLen; ///<[fBNseek]
0068    Int_t         *fBSeekPos;     ///<[fBNseek]
0069    Int_t         *fBLen;         ///<[fBNb]
0070    Bool_t         fBIsSorted;
0071    Bool_t         fBIsTransferred;
0072 
0073    void SetEnablePrefetchingImpl(Bool_t setPrefetching = kFALSE); // Can not be virtual as it is called from the constructor.
0074 
0075 private:
0076    TFileCacheRead(const TFileCacheRead &) = delete;            //cannot be copied
0077    TFileCacheRead& operator=(const TFileCacheRead &) = delete;
0078 
0079 public:
0080    TFileCacheRead();
0081    TFileCacheRead(TFile *file, Int_t buffersize, TObject *tree = nullptr);
0082    ~TFileCacheRead() override;
0083    virtual Int_t       AddBranch(TBranch * /*b*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
0084    virtual Int_t       AddBranch(const char * /*branch*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
0085    virtual void        AddNoCacheBytesRead(Long64_t len) { fNoCacheBytesRead += len; }
0086    virtual void        AddNoCacheReadCalls(Int_t reads) { fNoCacheReadCalls += reads; }
0087    virtual void        Close(Option_t *option="");
0088    virtual Int_t       GetBufferSize() const { return fBufferSize; };
0089    virtual Long64_t    GetBytesRead() const { return fBytesRead; }
0090    virtual Long64_t    GetNoCacheBytesRead() const { return fNoCacheBytesRead; }
0091    virtual Long64_t    GetBytesReadExtra() const { return fBytesReadExtra; }
0092            TFile      *GetFile() const { return fFile; }   // Return the TFile being cached.
0093            Int_t       GetNseek() const { return fNseek; } // Return the number of blocks in the current cache.
0094            Int_t       GetNtot() const { return fNtot; }   // Return the total size of the prefetched blocks.
0095    virtual Int_t       GetReadCalls() const { return fReadCalls; }
0096    virtual Int_t       GetNoCacheReadCalls() const { return fNoCacheReadCalls; }
0097    virtual Int_t       GetUnzipBuffer(char ** /*buf*/, Long64_t /*pos*/, Int_t /*len*/, Bool_t * /*free*/) { return -1; }
0098            Long64_t    GetPrefetchedBlocks() const { return fPrefetchedBlocks; }
0099    virtual Bool_t      IsAsyncReading() const { return fAsyncReading; };
0100    virtual void        SetEnablePrefetching(Bool_t setPrefetching = kFALSE);
0101    virtual Bool_t      IsEnablePrefetching() const { return fEnablePrefetching; };
0102    virtual Bool_t      IsLearning() const {return kFALSE;}
0103    virtual Int_t       LearnBranch(TBranch * /*b*/, Bool_t /*subbranches*/ = kFALSE) { return 0; }
0104    virtual void        Prefetch(Long64_t pos, Int_t len);
0105            void        Print(Option_t *option="") const override;
0106    virtual Int_t       ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
0107    virtual Int_t       ReadBufferExtNormal(char *buf, Long64_t pos, Int_t len, Int_t &loc);
0108    virtual Int_t       ReadBufferExtPrefetch(char *buf, Long64_t pos, Int_t len, Int_t &loc);
0109    virtual Int_t       ReadBuffer(char *buf, Long64_t pos, Int_t len);
0110    virtual Int_t       SetBufferSize(Int_t buffersize);
0111    virtual void        SetFile(TFile *file, TFile::ECacheAction action = TFile::kDisconnect);
0112    virtual void        SetSkipZip(Bool_t /*skip*/ = kTRUE) {} // This function is only used by TTreeCacheUnzip (ignore it)
0113    virtual void        Sort();
0114    virtual void        SecondSort();                          //Method used to sort and merge the chunks in the second block
0115    virtual void        SecondPrefetch(Long64_t, Int_t);       //Used to add chunks to the second block
0116    virtual TFilePrefetch* GetPrefetchObj();
0117    virtual void        WaitFinishPrefetch();                  //Gracefully join the prefetching thread
0118 
0119    ClassDefOverride(TFileCacheRead,2)  //TFile cache when reading
0120 };
0121 
0122 #endif