Logo ROOT   6.12/07
Reference Guide
TTreeCacheUnzip.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 04/06/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TTreeCacheUnzip
13 #define ROOT_TTreeCacheUnzip
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TTreeCacheUnzip //
19 // //
20 // Specialization of TTreeCache for parallel Unzipping //
21 // //
22 // Fabrizio Furano (CERN) Aug 2009 //
23 // Core TTree-related code borrowed from the previous version //
24 // by Leandro Franco and Rene Brun //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TTreeCache.h"
29 
30 #include <queue>
31 
32 class TTree;
33 class TBranch;
34 class TThread;
35 class TCondition;
36 class TBasket;
37 class TMutex;
38 
39 class TTreeCacheUnzip : public TTreeCache {
40 public:
41  // We have three possibilities for the unzipping mode:
42  // enable, disable and force
44 
45 protected:
46 
47  // Members for paral. managing
49  Bool_t fActiveThread; ///< Used to terminate gracefully the unzippers
50  TCondition *fUnzipStartCondition; ///< Used to signal the threads to start.
51  TCondition *fUnzipDoneCondition; ///< Used to wait for an unzip tour to finish. Gives the Async feel.
52  Bool_t fParallel; ///< Indicate if we want to activate the parallelism (for this instance)
54  TMutex *fMutexList; ///< Mutex to protect the various lists. Used by the condvars.
56 
58  static TTreeCacheUnzip::EParUnzipMode fgParallel; ///< Indicate if we want to activate the parallelism
59 
62 
63  // Unzipping related members
64  Int_t *fUnzipLen; ///<! [fNseek] Length of the unzipped buffers
65  char **fUnzipChunks; ///<! [fNseek] Individual unzipped chunks. Their summed size is kept under control.
66  Byte_t *fUnzipStatus; ///<! [fNSeek] For each blk, tells us if it's unzipped or pending
67  Long64_t fTotalUnzipBytes; ///<! The total sum of the currently unzipped blks
68 
69  Int_t fNseekMax; ///<! fNseek can change so we need to know its max size
70  Long64_t fUnzipBufferSize; ///<! Max Size for the ready unzipped blocks (default is 2*fBufferSize)
71 
72  static Double_t fgRelBuffSize; ///< This is the percentage of the TTreeCacheUnzip that will be used
73 
74  // Members use to keep statistics
75  Int_t fNUnzip; ///<! number of blocks that were unzipped
76  Int_t fNFound; ///<! number of blocks that were found in the cache
77  Int_t fNStalls; ///<! number of hits which caused a stall
78  Int_t fNMissed; ///<! number of blocks that were not found in the cache and were unzipped
79 
80  std::queue<Int_t> fActiveBlks; ///< The blocks which are active now
81 
82 private:
83  TTreeCacheUnzip(const TTreeCacheUnzip &); //this class cannot be copied
85 
86  char *fCompBuffer;
88 
89  // Private methods
90  void Init();
91  Int_t StartThreadUnzip(Int_t nthreads);
93 
94 public:
96  TTreeCacheUnzip(TTree *tree, Int_t buffersize=0);
97  virtual ~TTreeCacheUnzip();
98  virtual Int_t AddBranch(TBranch *b, Bool_t subbranches = kFALSE);
99  virtual Int_t AddBranch(const char *branch, Bool_t subbranches = kFALSE);
100  Bool_t FillBuffer();
101  virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
102  void SetEntryRange(Long64_t emin, Long64_t emax);
103  virtual void StopLearningPhase();
104  void UpdateBranches(TTree *tree);
105 
106  // Methods related to the thread
108  static Bool_t IsParallelUnzip();
110 
113 
114  void WaitUnzipStartSignal();
115  void SendUnzipStartSignal(Bool_t broadcast);
116 
117  // Unzipping related methods
118  Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen);
119  virtual void ResetCache();
120  virtual Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free);
121  virtual Int_t SetBufferSize(Int_t buffersize);
122  void SetUnzipBufferSize(Long64_t bufferSize);
123  static void SetUnzipRelBufferSize(Float_t relbufferSize);
124  Int_t UnzipBuffer(char **dest, char *src);
125  Int_t UnzipCache(Int_t &startindex, Int_t &locbuffsz, char *&locbuff);
126 
127  // Methods to get stats
128  Int_t GetNUnzip() { return fNUnzip; }
129  Int_t GetNFound() { return fNFound; }
130  Int_t GetNMissed(){ return fNMissed; }
131 
132  void Print(Option_t* option = "") const;
133 
134  // static members
135  static void* UnzipLoop(void *arg);
136  ClassDef(TTreeCacheUnzip,0) //Specialization of TTreeCache for parallel unzipping
137 };
138 
139 #endif
TCondition * fUnzipStartCondition
Used to signal the threads to start.
Definition: TMutex.h:30
Int_t fNUnzip
! number of blocks that were unzipped
long long Long64_t
Definition: RtypesCore.h:69
Int_t StopThreadUnzip()
To stop the thread we only need to change the value of the variable fActiveThread to false and the lo...
void UpdateBranches(TTree *tree)
update pointer to current Tree and recompute pointers to the branches in the cache ...
virtual void ResetCache()
This will delete the list of buffers that are in the unzipping cache and will reset certain values in...
float Float_t
Definition: RtypesCore.h:53
Int_t fNStalls
! number of hits which caused a stall
const char Option_t
Definition: RtypesCore.h:62
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.
virtual void StopLearningPhase()
It&#39;s the same as TTreeCache::StopLearningPhase but we guarantee that we start the unzipping just afte...
TMutex * fMutexList
Mutex to protect the various lists. Used by the condvars.
A specialized TFileCacheRead object for a TTree.
Definition: TTreeCache.h:30
static Int_t SetParallelUnzip(TTreeCacheUnzip::EParUnzipMode option=TTreeCacheUnzip::kEnable)
Static function that (de)activates multithreading unzipping.
Byte_t * fUnzipStatus
! [fNSeek] For each blk, tells us if it&#39;s unzipped or pending
virtual Int_t SetBufferSize(Int_t buffersize)
Change the underlying buffer size of the cache.
Bool_t FillBuffer()
Fill the cache buffer with the branches in the cache.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t * fUnzipLen
! [fNseek] Length of the unzipped buffers
TThread * fUnzipThread[10]
void SetUnzipBufferSize(Long64_t bufferSize)
Sets the size for the unzipping cache...
Bool_t fActiveThread
Used to terminate gracefully the unzippers.
Int_t fNFound
! number of blocks that were found in the cache
static Bool_t IsParallelUnzip()
Static function that tells wether the multithreading unzipping is activated.
Int_t UnzipBuffer(char **dest, char *src)
Unzips a ROOT specific buffer...
virtual Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free)
We try to read a buffer that has already been unzipped Returns -1 in case of read failure...
std::queue< Int_t > fActiveBlks
The blocks which are active now.
virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc)
static void * UnzipLoop(void *arg)
This is a static function.
#define ClassDef(name, id)
Definition: Rtypes.h:320
unsigned char Byte_t
Definition: RtypesCore.h:60
Int_t fNMissed
! number of blocks that were not found in the cache and were unzipped
void Print(Option_t *option="") const
Print cache statistics.
Specialization of TTreeCache for parallel Unzipping.
Bool_t fParallel
Indicate if we want to activate the parallelism (for this instance)
virtual Int_t AddBranch(TBranch *b, Bool_t subbranches=kFALSE)
Add a branch to the list of branches to be stored in the cache this function is called by TBranch::Ge...
static Double_t fgRelBuffSize
This is the percentage of the TTreeCacheUnzip that will be used.
void SendUnzipStartSignal(Bool_t broadcast)
This will send the signal corresponfing to the queue...
virtual ~TTreeCacheUnzip()
Destructor. (in general called by the TFile destructor)
Int_t fNseekMax
! fNseek can change so we need to know its max size
Manages buffers for branches of a Tree.
Definition: TBasket.h:34
static EParUnzipMode GetParallelUnzip()
Static function that returns the parallel option (to indicate an additional thread) ...
const Bool_t kFALSE
Definition: RtypesCore.h:88
TTreeCacheUnzip & operator=(const TTreeCacheUnzip &)
Bool_t IsQueueEmpty()
It says if the queue is empty... useful to see if we have to process it.
double Double_t
Definition: RtypesCore.h:55
Long64_t fUnzipBufferSize
! Max Size for the ready unzipped blocks (default is 2*fBufferSize)
TCondition * fUnzipDoneCondition
Used to wait for an unzip tour to finish. Gives the Async feel.
#define free
Definition: civetweb.c:821
void Init()
Initialization procedure common to all the constructors.
static void SetUnzipRelBufferSize(Float_t relbufferSize)
static function: Sets the unzip relatibe buffer size
static TTreeCacheUnzip::EParUnzipMode fgParallel
Indicate if we want to activate the parallelism.
char ** fUnzipChunks
! [fNseek] Individual unzipped chunks. Their summed size is kept under control.
Bool_t IsActiveThread()
This indicates if the thread is active in this moment...
Int_t StartThreadUnzip(Int_t nthreads)
The Thread is only a part of the TTreeCache but it is the part that waits for info in the queue and p...
#define dest(otri, vertexptr)
Definition: triangle.c:1040
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Definition: tree.py:1
A TTree object has a header with a name and a title.
Definition: TTree.h:70
A TTree is a list of TBranches.
Definition: TBranch.h:59
Long64_t fTotalUnzipBytes
! The total sum of the currently unzipped blks
Int_t UnzipCache(Int_t &startindex, Int_t &locbuffsz, char *&locbuff)
This inflates all the buffers in the cache.
void SetEntryRange(Long64_t emin, Long64_t emax)
Set the minimum and maximum entry number to be processed this information helps to optimize the numbe...