ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TTreeCache
29 #include "TTreeCache.h"
30 #endif
31 
32 #include <queue>
33 
34 class TTree;
35 class TBranch;
36 class TThread;
37 class TCondition;
38 class TBasket;
39 class TMutex;
40 
41 class TTreeCacheUnzip : public TTreeCache {
42 public:
43  // We have three possibilities for the unzipping mode:
44  // enable, disable and force
46 
47 protected:
48 
49  // Members for paral. managing
51  Bool_t fActiveThread; // Used to terminate gracefully the unzippers
52  TCondition *fUnzipStartCondition; // Used to signal the threads to start.
53  TCondition *fUnzipDoneCondition; // Used to wait for an unzip tour to finish. Gives the Async feel.
54  Bool_t fParallel; // Indicate if we want to activate the parallelism (for this instance)
56  TMutex *fMutexList; // Mutex to protect the various lists. Used by the condvars.
58 
60  static TTreeCacheUnzip::EParUnzipMode fgParallel; // Indicate if we want to activate the parallelism
61 
64 
65  // Unzipping related members
66  Int_t *fUnzipLen; //! [fNseek] Length of the unzipped buffers
67  char **fUnzipChunks; //! [fNseek] Individual unzipped chunks. Their summed size is kept under control.
68  Byte_t *fUnzipStatus; //! [fNSeek] For each blk, tells us if it's unzipped or pending
69  Long64_t fTotalUnzipBytes; //! The total sum of the currently unzipped blks
70 
71  Int_t fNseekMax; //! fNseek can change so we need to know its max size
72  Long64_t fUnzipBufferSize; //! Max Size for the ready unzipped blocks (default is 2*fBufferSize)
73 
74  static Double_t fgRelBuffSize; // This is the percentage of the TTreeCacheUnzip that will be used
75 
76  // Members use to keep statistics
77  Int_t fNUnzip; //! number of blocks that were unzipped
78  Int_t fNFound; //! number of blocks that were found in the cache
79  Int_t fNStalls; //! number of hits which caused a stall
80  Int_t fNMissed; //! number of blocks that were not found in the cache and were unzipped
81 
82  std::queue<Int_t> fActiveBlks; // The blocks which are active now
83 
84 private:
85  TTreeCacheUnzip(const TTreeCacheUnzip &); //this class cannot be copied
87 
88  char *fCompBuffer;
90 
91  // Private methods
92  void Init();
93  Int_t StartThreadUnzip(Int_t nthreads);
95 
96 public:
98  TTreeCacheUnzip(TTree *tree, Int_t buffersize=0);
99  virtual ~TTreeCacheUnzip();
100  virtual Int_t AddBranch(TBranch *b, Bool_t subbranches = kFALSE);
101  virtual Int_t AddBranch(const char *branch, Bool_t subbranches = kFALSE);
102  Bool_t FillBuffer();
103  virtual Int_t ReadBufferExt(char *buf, Long64_t pos, Int_t len, Int_t &loc);
104  void SetEntryRange(Long64_t emin, Long64_t emax);
105  virtual void StopLearningPhase();
106  void UpdateBranches(TTree *tree);
107 
108  // Methods related to the thread
110  static Bool_t IsParallelUnzip();
112 
115 
116  void WaitUnzipStartSignal();
117  void SendUnzipStartSignal(Bool_t broadcast);
118 
119  // Unzipping related methods
120  Int_t GetRecordHeader(char *buf, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen);
121  virtual void ResetCache();
122  virtual Int_t GetUnzipBuffer(char **buf, Long64_t pos, Int_t len, Bool_t *free);
123  virtual Int_t SetBufferSize(Int_t buffersize);
124  void SetUnzipBufferSize(Long64_t bufferSize);
125  static void SetUnzipRelBufferSize(Float_t relbufferSize);
126  Int_t UnzipBuffer(char **dest, char *src);
127  Int_t UnzipCache(Int_t &startindex, Int_t &locbuffsz, char *&locbuff);
128 
129  // Methods to get stats
130  Int_t GetNUnzip() { return fNUnzip; }
131  Int_t GetNFound() { return fNFound; }
132  Int_t GetNMissed(){ return fNMissed; }
133 
134  void Print(Option_t* option = "") const;
135 
136  // static members
137  static void* UnzipLoop(void *arg);
138  ClassDef(TTreeCacheUnzip,0) //Specialization of TTreeCache for parallel unzipping
139 };
140 
141 #endif
TCondition * fUnzipStartCondition
void Print(Option_t *option="") const
Print cache statistics.
Definition: TMutex.h:34
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 blocks that were found in the cache
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's the same as TTreeCache::StopLearningPhase but we guarantee that we start the unzipping just afte...
A specialized TFileCacheRead object for a TTree.
Definition: TTreeCache.h:34
static Int_t SetParallelUnzip(TTreeCacheUnzip::EParUnzipMode option=TTreeCacheUnzip::kEnable)
Static function that (de)activates multithreading unzipping.
Byte_t * fUnzipStatus
[fNseek] Individual unzipped chunks. Their summed size is kept under control.
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
const Bool_t kFALSE
Definition: Rtypes.h:92
TThread * fUnzipThread[10]
void SetUnzipBufferSize(Long64_t bufferSize)
Sets the size for the unzipping cache...
Int_t fNFound
number of blocks that were unzipped
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
number of blocks that were not found in the cache and were unzipped
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:254
unsigned char Byte_t
Definition: RtypesCore.h:60
Int_t fNMissed
number of hits which caused a stall
Specialization of TTreeCache for parallel Unzipping.
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
Max Size for the ready unzipped blocks (default is 2*fBufferSize)
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
The total sum of the currently unzipped blks.
Manages buffers for branches of a Tree.
Definition: TBasket.h:38
static EParUnzipMode GetParallelUnzip()
Static function that returns the parallel option (to indicate an additional thread) ...
tuple free
Definition: fildir.py:30
TTreeCacheUnzip & operator=(const TTreeCacheUnzip &)
tuple tree
Definition: tree.py:24
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
fNseek can change so we need to know its max size
TCondition * fUnzipDoneCondition
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
char ** fUnzipChunks
[fNseek] Length of the unzipped buffers
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
A TTree object has a header with a name and a title.
Definition: TTree.h:98
A TTree is a list of TBranches.
Definition: TBranch.h:58
Long64_t fTotalUnzipBytes
[fNSeek] For each blk, tells us if it's unzipped or pending
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...