00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TCache
00013 #define ROOT_TCache
00014
00015
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00043
00044 #ifndef ROOT_THashList
00045 #include "THashList.h"
00046 #endif
00047
00048 class TSortedList;
00049 class TFile;
00050
00051
00052 class TCache : public TObject {
00053
00054 friend class TFile;
00055
00056 private:
00057
00058 class TPage : public TObject {
00059 friend class TCache;
00060 private:
00061 Seek_t fOffset;
00062 char *fData;
00063 Int_t fSize;
00064 public:
00065 enum { kDirty = BIT(14), kLocked = BIT(15) };
00066 TPage(Seek_t offset, char *page, Int_t size)
00067 { fOffset = offset; fData = page; fSize = size; }
00068 ~TPage() { delete [] fData; }
00069 ULong_t Hash() const { return fOffset; }
00070 Bool_t IsEqual(const TObject *obj) const
00071 { return fOffset == ((const TPage*)obj)->fOffset; }
00072 Bool_t IsSortable() const { return kTRUE; }
00073 Int_t Compare(const TObject *obj) const
00074 { return fOffset > ((const TPage*)obj)->fOffset ? 1 :
00075 fOffset < ((const TPage*)obj)->fOffset ? -1 : 0; }
00076 Seek_t Offset() const { return fOffset; }
00077 char *Data() const { return fData; }
00078 Int_t Size() const { return fSize; }
00079 };
00080
00081 class TCacheList : public THashList {
00082 public:
00083 TCacheList(Int_t capacity = 1000) : THashList(capacity, 3) { }
00084 void PageUsed(TObject *page) { TList::Remove(page); TList::AddLast(page); }
00085 };
00086
00087 TCacheList *fCache;
00088 TSortedList *fNew;
00089 TList *fFree;
00090 TFile *fFile;
00091 Seek_t fEOF;
00092 ULong_t fHighWater;
00093 ULong_t fLowWater;
00094 Int_t fPageSize;
00095 Int_t fLowLevel;
00096 Int_t fDiv;
00097 Bool_t fRecursive;
00098
00099 void SetPageSize(Int_t size);
00100 TPage *ReadPage(Seek_t offset);
00101 Int_t WritePage(TPage *page);
00102 Int_t FlushList(TList *list);
00103 Int_t FlushNew();
00104 Int_t Free(ULong_t upto);
00105
00106 public:
00107 enum {
00108 kDfltPageSize = 0x80000,
00109 kDfltLowLevel = 70
00110 };
00111
00112 TCache(Int_t maxCacheSize, TFile *file, Int_t pageSize = kDfltPageSize);
00113 virtual ~TCache();
00114
00115 Int_t GetMaxCacheSize() const { return Int_t(fHighWater / 1024 / 1024); }
00116 Int_t GetActiveCacheSize() const;
00117 Int_t GetPageSize() const { return fPageSize; }
00118 Int_t GetLowLevel() const { return fLowLevel; }
00119 Int_t Resize(Int_t maxCacheSize);
00120 void SetLowLevel(Int_t percentOfHigh);
00121
00122 Int_t ReadBuffer(Seek_t offset, char *buf, Int_t len);
00123 Int_t WriteBuffer(Seek_t offset, const char *buf, Int_t len);
00124 Int_t Flush();
00125
00126 ClassDef(TCache,0)
00127 };
00128
00129 #endif