00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TTreeCacheUnzip
00013 #define ROOT_TTreeCacheUnzip
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROOT_TTreeCache
00029 #include "TTreeCache.h"
00030 #endif
00031
00032 #include <queue>
00033
00034 class TTree;
00035 class TBranch;
00036 class TThread;
00037 class TCondition;
00038 class TBasket;
00039 class TMutex;
00040
00041 class TTreeCacheUnzip : public TTreeCache {
00042 public:
00043
00044
00045 enum EParUnzipMode { kEnable, kDisable, kForce };
00046
00047 protected:
00048
00049
00050 TThread *fUnzipThread[10];
00051 Bool_t fActiveThread;
00052 TCondition *fUnzipStartCondition;
00053 TCondition *fUnzipDoneCondition;
00054 Bool_t fParallel;
00055 Bool_t fAsyncReading;
00056 TMutex *fMutexList;
00057 TMutex *fIOMutex;
00058
00059 Int_t fCycle;
00060 static TTreeCacheUnzip::EParUnzipMode fgParallel;
00061
00062 Int_t fLastReadPos;
00063 Int_t fBlocksToGo;
00064
00065
00066 Int_t *fUnzipLen;
00067 char **fUnzipChunks;
00068 Byte_t *fUnzipStatus;
00069 Long64_t fTotalUnzipBytes;
00070
00071 Int_t fNseekMax;
00072 Long64_t fUnzipBufferSize;
00073
00074 static Double_t fgRelBuffSize;
00075
00076
00077 Int_t fNUnzip;
00078 Int_t fNFound;
00079 Int_t fNStalls;
00080 Int_t fNMissed;
00081
00082 std::queue<Int_t> fActiveBlks;
00083
00084 private:
00085 TTreeCacheUnzip(const TTreeCacheUnzip &);
00086 TTreeCacheUnzip& operator=(const TTreeCacheUnzip &);
00087
00088 char *fCompBuffer;
00089 Int_t fCompBufferSize;
00090
00091
00092 void Init();
00093 Int_t StartThreadUnzip(Int_t nthreads);
00094 Int_t StopThreadUnzip();
00095
00096 public:
00097 TTreeCacheUnzip();
00098 TTreeCacheUnzip(TTree *tree, Int_t buffersize=0);
00099 virtual ~TTreeCacheUnzip();
00100 virtual void AddBranch(TBranch *b, Bool_t subbranches = kFALSE);
00101 virtual void AddBranch(const char *branch, Bool_t subbranches = kFALSE);
00102 Bool_t FillBuffer();
00103 virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
00104 void SetEntryRange(Long64_t emin, Long64_t emax);
00105 virtual void StopLearningPhase();
00106 void UpdateBranches(TTree *tree, Bool_t owner = kFALSE);
00107
00108
00109 static EParUnzipMode GetParallelUnzip();
00110 static Bool_t IsParallelUnzip();
00111 static Int_t SetParallelUnzip(TTreeCacheUnzip::EParUnzipMode option = TTreeCacheUnzip::kEnable);
00112
00113 Bool_t IsActiveThread();
00114 Bool_t IsQueueEmpty();
00115
00116 void WaitUnzipStartSignal();
00117 void SendUnzipStartSignal(Bool_t broadcast);
00118
00119
00120 Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen);
00121 virtual void ResetCache();
00122 virtual Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free);
00123 void SetUnzipBufferSize(Long64_t bufferSize);
00124 static void SetUnzipRelBufferSize(Float_t relbufferSize);
00125 Int_t UnzipBuffer(char **dest, char *src);
00126 Int_t UnzipCache(Int_t &startindex, Int_t &locbuffsz, char *&locbuff);
00127
00128
00129 Int_t GetNUnzip() { return fNUnzip; }
00130 Int_t GetNFound() { return fNFound; }
00131 Int_t GetNMissed(){ return fNMissed; }
00132
00133 void Print(Option_t* option = "") const;
00134
00135
00136 static void* UnzipLoop(void *arg);
00137 ClassDef(TTreeCacheUnzip,0)
00138 };
00139
00140 #endif