TTreeCacheUnzip.h

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TTreeCacheUnzip.h 31469 2009-11-30 17:25:19Z brun $
00002 // Author: Rene Brun   04/06/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TTreeCacheUnzip
00013 #define ROOT_TTreeCacheUnzip
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TTreeCacheUnzip                                                      //
00019 //                                                                      //
00020 // Specialization of TTreeCache for parallel Unzipping                  //
00021 //                                                                      //
00022 // Fabrizio Furano (CERN) Aug 2009                                      //
00023 // Core TTree-related code borrowed from the previous version           //
00024 //  by Leandro Franco and Rene Brun                                     //
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    // We have three possibilities for the unzipping mode:
00044    // enable, disable and force
00045    enum EParUnzipMode { kEnable, kDisable, kForce };
00046 
00047 protected:
00048 
00049    // Members for paral. managing
00050    TThread    *fUnzipThread[10];
00051    Bool_t      fActiveThread;          // Used to terminate gracefully the unzippers
00052    TCondition *fUnzipStartCondition;   // Used to signal the threads to start.
00053    TCondition *fUnzipDoneCondition;    // Used to wait for an unzip tour to finish. Gives the Async feel.
00054    Bool_t      fParallel;              // Indicate if we want to activate the parallelism (for this instance)
00055    Bool_t      fAsyncReading;
00056    TMutex     *fMutexList;             // Mutex to protect the various lists. Used by the condvars.
00057    TMutex     *fIOMutex;
00058 
00059    Int_t       fCycle;
00060    static TTreeCacheUnzip::EParUnzipMode fgParallel;  // Indicate if we want to activate the parallelism
00061 
00062    Int_t       fLastReadPos;
00063    Int_t       fBlocksToGo;
00064 
00065    // Unzipping related members
00066    Int_t      *fUnzipLen;         //! [fNseek] Length of the unzipped buffers
00067    char      **fUnzipChunks;      //! [fNseek] Individual unzipped chunks. Their summed size is kept under control.
00068    Byte_t     *fUnzipStatus;      //! [fNSeek] For each blk, tells us if it's unzipped or pending
00069    Long64_t    fTotalUnzipBytes;  //! The total sum of the currently unzipped blks
00070 
00071    Int_t       fNseekMax;         //!  fNseek can change so we need to know its max size
00072    Long64_t    fUnzipBufferSize;  //!  Max Size for the ready unzipped blocks (default is 2*fBufferSize)
00073 
00074    static Double_t fgRelBuffSize; // This is the percentage of the TTreeCacheUnzip that will be used
00075 
00076    // Members use to keep statistics
00077    Int_t       fNUnzip;           //! number of blocks that were unzipped
00078    Int_t       fNFound;           //! number of blocks that were found in the cache
00079    Int_t       fNStalls;          //! number of hits which caused a stall
00080    Int_t       fNMissed;          //! number of blocks that were not found in the cache and were unzipped
00081 
00082    std::queue<Int_t>       fActiveBlks; // The blocks which are active now
00083 
00084 private:
00085    TTreeCacheUnzip(const TTreeCacheUnzip &);            //this class cannot be copied
00086    TTreeCacheUnzip& operator=(const TTreeCacheUnzip &);
00087 
00088    char *fCompBuffer;
00089    Int_t fCompBufferSize;
00090 
00091    // Private methods
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    // Methods related to the thread
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    // Unzipping related methods
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    // Methods to get stats
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    // static members
00136    static void* UnzipLoop(void *arg);
00137    ClassDef(TTreeCacheUnzip,0)  //Specialization of TTreeCache for parallel unzipping
00138 };
00139 
00140 #endif

Generated on Tue Jul 5 14:28:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1