File indexing completed on 2025-01-18 10:12:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT_TTreeCacheUnzip
0014 #define ROOT_TTreeCacheUnzip
0015
0016 #include "Bytes.h"
0017 #include "TTreeCache.h"
0018 #include <atomic>
0019 #include <memory>
0020 #include <vector>
0021
0022 class TBasket;
0023 class TBranch;
0024 class TMutex;
0025 class TTree;
0026
0027 #ifdef R__USE_IMT
0028 namespace ROOT {
0029 namespace Experimental {
0030 class TTaskGroup;
0031 }
0032 }
0033 #endif
0034
0035 class TTreeCacheUnzip : public TTreeCache {
0036
0037 public:
0038
0039
0040 enum EParUnzipMode { kEnable, kDisable, kForce };
0041
0042
0043 enum EUnzipState { kUntouched, kProgress, kFinished };
0044
0045 protected:
0046
0047 struct UnzipState {
0048
0049
0050
0051 std::unique_ptr<char[]> *fUnzipChunks;
0052 std::vector<Int_t> fUnzipLen;
0053 std::atomic<Byte_t> *fUnzipStatus;
0054
0055 UnzipState() {
0056 fUnzipChunks = nullptr;
0057 fUnzipStatus = nullptr;
0058 }
0059 ~UnzipState() {
0060 if (fUnzipChunks) delete [] fUnzipChunks;
0061 if (fUnzipStatus) delete [] fUnzipStatus;
0062 }
0063 void Clear(Int_t size);
0064 bool IsUntouched(Int_t index) const;
0065 bool IsProgress(Int_t index) const;
0066 bool IsFinished(Int_t index) const;
0067 bool IsUnzipped(Int_t index) const;
0068 void Reset(Int_t oldSize, Int_t newSize);
0069 void SetUntouched(Int_t index);
0070 void SetProgress(Int_t index);
0071 void SetFinished(Int_t index);
0072 void SetMissed(Int_t index);
0073 void SetUnzipped(Int_t index, char* buf, Int_t len);
0074 bool TryUnzipping(Int_t index);
0075 };
0076
0077 typedef struct UnzipState UnzipState_t;
0078 UnzipState_t fUnzipState;
0079
0080
0081 bool fAsyncReading;
0082 bool fEmpty;
0083 Int_t fCycle;
0084 bool fParallel;
0085
0086 std::unique_ptr<TMutex> fIOMutex;
0087
0088 static TTreeCacheUnzip::EParUnzipMode fgParallel;
0089
0090
0091 #ifdef R__USE_IMT
0092 std::unique_ptr<ROOT::Experimental::TTaskGroup> fUnzipTaskGroup;
0093 #endif
0094
0095
0096 Int_t fNseekMax;
0097 Int_t fUnzipGroupSize;
0098 Long64_t fUnzipBufferSize;
0099
0100 static Double_t fgRelBuffSize;
0101
0102
0103 Int_t fNFound;
0104 Int_t fNMissed;
0105 Int_t fNStalls;
0106 Int_t fNUnzip;
0107
0108 private:
0109 TTreeCacheUnzip(const TTreeCacheUnzip &) = delete;
0110 TTreeCacheUnzip& operator=(const TTreeCacheUnzip &) = delete;
0111
0112 char *fCompBuffer;
0113 Int_t fCompBufferSize;
0114
0115
0116 void Init();
0117
0118 public:
0119 TTreeCacheUnzip();
0120 TTreeCacheUnzip(TTree *tree, Int_t buffersize=0);
0121 ~TTreeCacheUnzip() override;
0122
0123 Int_t AddBranch(TBranch *b, bool subbranches = false) override;
0124 Int_t AddBranch(const char *branch, bool subbranches = false) override;
0125 bool FillBuffer() override;
0126 Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc) override;
0127 void SetEntryRange(Long64_t emin, Long64_t emax) override;
0128 void StopLearningPhase() override;
0129 void UpdateBranches(TTree *tree) override;
0130
0131
0132 static EParUnzipMode GetParallelUnzip();
0133 static bool IsParallelUnzip();
0134 static Int_t SetParallelUnzip(TTreeCacheUnzip::EParUnzipMode option = TTreeCacheUnzip::kEnable);
0135
0136
0137 #ifdef R__USE_IMT
0138 Int_t CreateTasks();
0139 #endif
0140 Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen);
0141 Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, bool *free) override;
0142 Int_t GetUnzipGroupSize() { return fUnzipGroupSize; }
0143 void ResetCache() override;
0144 Int_t SetBufferSize(Int_t buffersize) override;
0145 void SetUnzipBufferSize(Long64_t bufferSize);
0146 void SetUnzipGroupSize(Int_t groupSize) { fUnzipGroupSize = groupSize; }
0147 static void SetUnzipRelBufferSize(Float_t relbufferSize);
0148 Int_t UnzipBuffer(char **dest, char *src);
0149 Int_t UnzipCache(Int_t index);
0150
0151
0152 Int_t GetNUnzip() { return fNUnzip; }
0153 Int_t GetNMissed(){ return fNMissed; }
0154 Int_t GetNFound() { return fNFound; }
0155
0156 void Print(Option_t* option = "") const override;
0157
0158
0159 ClassDefOverride(TTreeCacheUnzip,0)
0160 };
0161
0162 #endif