Logo ROOT  
Reference Guide
TTreeCacheUnzip.h
Go to the documentation of this file.
1// Authors: Rene Brun 04/06/2006
2// Leandro Franco 10/04/2008
3// Fabrizio Furano (CERN) Aug 2009
4
5/*************************************************************************
6 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_TTreeCacheUnzip
14#define ROOT_TTreeCacheUnzip
15
16#include "Bytes.h"
17#include "TTreeCache.h"
18#include <atomic>
19#include <memory>
20#include <vector>
21
22class TBasket;
23class TBranch;
24class TMutex;
25class TTree;
26
27#ifdef R__USE_IMT
28namespace ROOT {
29namespace Experimental {
30class TTaskGroup;
31}
32}
33#endif
34
36
37public:
38 // We have three possibilities for the unzipping mode:
39 // enable, disable and force
41
42 // Unzipping states for a basket:
44
45protected:
46 // Unzipping state for baskets
47 struct UnzipState {
48 // Note: we cannot use std::unique_ptr<std::unique_ptr<char[]>[]> or vector of unique_ptr
49 // for fUnzipChunks since std::unique_ptr is not copy constructable.
50 // However, in future upgrade we cannot use make_vector in C++14.
51 std::unique_ptr<char[]> *fUnzipChunks; ///<! [fNseek] Individual unzipped chunks. Their summed size is kept under control.
52 std::vector<Int_t> fUnzipLen; ///<! [fNseek] Length of the unzipped buffers
53 std::atomic<Byte_t> *fUnzipStatus; ///<! [fNSeek]
54
56 fUnzipChunks = nullptr;
57 fUnzipStatus = nullptr;
58 }
60 if (fUnzipChunks) delete [] fUnzipChunks;
61 if (fUnzipStatus) delete [] fUnzipStatus;
62 }
63 void Clear(Int_t size);
68 void Reset(Int_t oldSize, Int_t newSize);
72 void SetMissed(Int_t index);
73 void SetUnzipped(Int_t index, char* buf, Int_t len);
75 };
76
77 typedef struct UnzipState UnzipState_t;
79
80 // Members for paral. managing
84 Bool_t fParallel; ///< Indicate if we want to activate the parallelism (for this instance)
85
86 std::unique_ptr<TMutex> fIOMutex;
87
88 static TTreeCacheUnzip::EParUnzipMode fgParallel; ///< Indicate if we want to activate the parallelism
89
90 // IMT TTaskGroup Manager
91#ifdef R__USE_IMT
92 std::unique_ptr<ROOT::Experimental::TTaskGroup> fUnzipTaskGroup;
93#endif
94
95 // Unzipping related members
96 Int_t fNseekMax; ///<! fNseek can change so we need to know its max size
97 Int_t fUnzipGroupSize; ///<! Min accumulated size of a group of baskets ready to be unzipped by a IMT task
98 Long64_t fUnzipBufferSize; ///<! Max Size for the ready unzipped blocks (default is 2*fBufferSize)
99
100 static Double_t fgRelBuffSize; ///< This is the percentage of the TTreeCacheUnzip that will be used
101
102 // Members use to keep statistics
103 Int_t fNFound; ///<! number of blocks that were found in the cache
104 Int_t fNMissed; ///<! number of blocks that were not found in the cache and were unzipped
105 Int_t fNStalls; ///<! number of hits which caused a stall
106 Int_t fNUnzip; ///<! number of blocks that were unzipped
107
108private:
111
114
115 // Private methods
116 void Init();
117
118public:
120 TTreeCacheUnzip(TTree *tree, Int_t buffersize=0);
121 virtual ~TTreeCacheUnzip();
122
123 Int_t AddBranch(TBranch *b, Bool_t subbranches = kFALSE) override;
124 Int_t AddBranch(const char *branch, Bool_t subbranches = kFALSE) override;
125 Bool_t FillBuffer() override;
126 Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc) override;
127 void SetEntryRange(Long64_t emin, Long64_t emax) override;
128 void StopLearningPhase() override;
129 void UpdateBranches(TTree *tree) override;
130
131 // Methods related to the thread
133 static Bool_t IsParallelUnzip();
135
136 // Unzipping related methods
137#ifdef R__USE_IMT
139#endif
140 Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen);
141 Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free) override;
143 void ResetCache() override;
144 Int_t SetBufferSize(Int_t buffersize) override;
146 void SetUnzipGroupSize(Int_t groupSize) { fUnzipGroupSize = groupSize; }
147 static void SetUnzipRelBufferSize(Float_t relbufferSize);
148 Int_t UnzipBuffer(char **dest, char *src);
150
151 // Methods to get stats
152 Int_t GetNUnzip() { return fNUnzip; }
154 Int_t GetNFound() { return fNFound; }
155
156 void Print(Option_t* option = "") const override;
157
158 // static members
159 ClassDefOverride(TTreeCacheUnzip,0) //Specialization of TTreeCache for parallel unzipping
160};
161
162#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:80
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
#define free
Definition: civetweb.c:1539
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
A TTree is a list of TBranches.
Definition: TBranch.h:89
Definition: TMutex.h:30
A TTreeCache which exploits parallelized decompression of its own content.
UnzipState_t fUnzipState
void SetUnzipGroupSize(Int_t groupSize)
void Init()
Initialization procedure common to all the constructors.
Int_t UnzipCache(Int_t index)
This inflates a basket in the cache.
Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free) override
We try to read a buffer that has already been unzipped Returns -1 in case of read failure,...
Int_t fNMissed
! number of blocks that were not found in the cache and were unzipped
void UpdateBranches(TTree *tree) override
update pointer to current Tree and recompute pointers to the branches in the cache
Int_t SetBufferSize(Int_t buffersize) override
Change the underlying buffer size of the cache.
Int_t GetUnzipGroupSize()
TTreeCacheUnzip(const TTreeCacheUnzip &)=delete
Bool_t FillBuffer() override
Fill the cache buffer with the branches in the cache.
TTreeCacheUnzip & operator=(const TTreeCacheUnzip &)=delete
void ResetCache() override
This will delete the list of buffers that are in the unzipping cache and will reset certain values in...
void SetEntryRange(Long64_t emin, Long64_t emax) override
Set the minimum and maximum entry number to be processed this information helps to optimize the numbe...
Int_t fNseekMax
! fNseek can change so we need to know its max size
virtual ~TTreeCacheUnzip()
Destructor. (in general called by the TFile destructor)
Int_t AddBranch(TBranch *b, Bool_t subbranches=kFALSE) override
Add a branch to the list of branches to be stored in the cache this function is called by TBranch::Ge...
Int_t fNStalls
! number of hits which caused a stall
static TTreeCacheUnzip::EParUnzipMode fgParallel
Indicate if we want to activate the parallelism.
std::unique_ptr< ROOT::Experimental::TTaskGroup > fUnzipTaskGroup
static Int_t SetParallelUnzip(TTreeCacheUnzip::EParUnzipMode option=TTreeCacheUnzip::kEnable)
Static function that (de)activates multithreading unzipping.
Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc) override
Int_t UnzipBuffer(char **dest, char *src)
Unzips a ROOT specific buffer... by reading the header at the beginning.
Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen)
Read the logical record header from the buffer buf.
static void SetUnzipRelBufferSize(Float_t relbufferSize)
static function: Sets the unzip relative buffer size
std::unique_ptr< TMutex > fIOMutex
Int_t fNUnzip
! number of blocks that were unzipped
Int_t CreateTasks()
We create a TTaskGroup and asynchronously maps each group of baskets(> 100 kB in total) to a task.
Bool_t fParallel
Indicate if we want to activate the parallelism (for this instance)
Long64_t fUnzipBufferSize
! Max Size for the ready unzipped blocks (default is 2*fBufferSize)
static Bool_t IsParallelUnzip()
Static function that tells wether the multithreading unzipping is activated.
void SetUnzipBufferSize(Long64_t bufferSize)
Sets the size for the unzipping cache... by default it should be two times the size of the prefetchin...
Int_t fUnzipGroupSize
! Min accumulated size of a group of baskets ready to be unzipped by a IMT task
void StopLearningPhase() override
It's the same as TTreeCache::StopLearningPhase but we guarantee that we start the unzipping just afte...
void Print(Option_t *option="") const override
Print cache statistics.
Int_t fNFound
! number of blocks that were found in the cache
static Double_t fgRelBuffSize
This is the percentage of the TTreeCacheUnzip that will be used.
static EParUnzipMode GetParallelUnzip()
Static function that returns the parallel option (to indicate an additional thread)
A cache to speed-up the reading of ROOT datasets.
Definition: TTreeCache.h:32
A TTree represents a columnar dataset.
Definition: TTree.h:79
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
constexpr uint16_t bufferSize
Definition: Batches.h:38
Definition: tree.py:1
Bool_t IsFinished(Int_t index) const
void Reset(Int_t oldSize, Int_t newSize)
Reset all baskets' state arrays.
void Clear(Int_t size)
Clear all baskets' state arrays.
Bool_t IsProgress(Int_t index) const
std::atomic< Byte_t > * fUnzipStatus
! [fNSeek]
void SetUnzipped(Int_t index, char *buf, Int_t len)
std::vector< Int_t > fUnzipLen
! [fNseek] Length of the unzipped buffers
Bool_t TryUnzipping(Int_t index)
Start unzipping the basket if it is untouched yet.
void SetProgress(Int_t index)
void SetUntouched(Int_t index)
Bool_t IsUnzipped(Int_t index) const
Check if the basket is unzipped already.
Bool_t IsUntouched(Int_t index) const
void SetFinished(Int_t index)
Set cache as finished.
std::unique_ptr< char[]> * fUnzipChunks
! [fNseek] Individual unzipped chunks. Their summed size is kept under control.