ROOT logo
// @(#)root/tree:$Id$
// Author: Rene Brun   19/01/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TBasket
#define ROOT_TBasket


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TBasket                                                              //
//                                                                      //
// The TBasket objects are created at run time to collect TTree entries //
// in buffers. When a Basket is full, it is written to the file.        //
// The Basket is kept in memory if there is enough space.               //
//  (see the fMaxVirtualsize of TTree).                                 //
//                                                                      //
// The Basket class derives from TKey.                                  //
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TKey
#include "TKey.h"
#endif


class TFile;
class TTree;
class TBranch;

class TBasket : public TKey {

private:
   TBasket(const TBasket&);            // TBasket objects are not copiable.
   TBasket& operator=(const TBasket&); // TBasket objects are not copiable.

   // Internal corner cases for ReadBasketBuffers
   Int_t ReadBasketBuffersUnzip(char*, Int_t, Bool_t, TFile*);
   Int_t ReadBasketBuffersUncompressedCase();

   // Helper for managing the compressed buffer.
   void InitializeCompressedBuffer(Int_t len, TFile* file);
 
protected:
   Int_t       fBufferSize;      //fBuffer length in bytes
   Int_t       fNevBufSize;      //Length in Int_t of fEntryOffset OR fixed length of each entry if fEntryOffset is null!
   Int_t       fNevBuf;          //Number of entries in basket
   Int_t       fLast;            //Pointer to last used byte in basket
   Bool_t      fHeaderOnly;      //True when only the basket header must be read/written
   Int_t      *fDisplacement;    //![fNevBuf] Displacement of entries in fBuffer(TKey)
   Int_t      *fEntryOffset;     //[fNevBuf] Offset of entries in fBuffer(TKey)
   TBranch    *fBranch;          //Pointer to the basket support branch
   TBuffer    *fCompressedBufferRef; //! Compressed buffer.
   Bool_t      fOwnsCompressedBuffer; //! Whether or not we own the compressed buffer.
   Int_t       fLastWriteBufferSize; //! Size of the buffer last time we wrote it to disk

public:
   
   TBasket();
   TBasket(TDirectory *motherDir);
   TBasket(const char *name, const char *title, TBranch *branch);
   virtual ~TBasket();
   
   virtual void    AdjustSize(Int_t newsize);
   virtual void    DeleteEntryOffset();
   virtual Int_t   DropBuffers();
   TBranch        *GetBranch() const {return fBranch;}
           Int_t   GetBufferSize() const {return fBufferSize;}
           Int_t  *GetDisplacement() const {return fDisplacement;}
           Int_t  *GetEntryOffset() const {return fEntryOffset;}
           Int_t   GetEntryPointer(Int_t Entry);
           Int_t   GetNevBuf() const {return fNevBuf;}
           Int_t   GetNevBufSize() const {return fNevBufSize;}
           Int_t   GetLast() const {return fLast;}
   virtual void    MoveEntries(Int_t dentries);
   virtual void    PrepareBasket(Long64_t /* entry */) {};
           Int_t   ReadBasketBuffers(Long64_t pos, Int_t len, TFile *file);
           Int_t   ReadBasketBytes(Long64_t pos, TFile *file);
   virtual void    Reset();

           Int_t   LoadBasketBuffers(Long64_t pos, Int_t len, TFile *file, TTree *tree = 0);
   Long64_t        CopyTo(TFile *to);

           void    SetBranch(TBranch *branch) { fBranch = branch; }
           void    SetNevBufSize(Int_t n) { fNevBufSize=n; }
   virtual void    SetReadMode();
   virtual void    SetWriteMode();
   inline  void    Update(Int_t newlast) { Update(newlast,newlast); }; 
   virtual void    Update(Int_t newlast, Int_t skipped);
   virtual Int_t   WriteBuffer();

   ClassDef(TBasket,2);  //the TBranch buffers
};

#endif
 TBasket.h:1
 TBasket.h:2
 TBasket.h:3
 TBasket.h:4
 TBasket.h:5
 TBasket.h:6
 TBasket.h:7
 TBasket.h:8
 TBasket.h:9
 TBasket.h:10
 TBasket.h:11
 TBasket.h:12
 TBasket.h:13
 TBasket.h:14
 TBasket.h:15
 TBasket.h:16
 TBasket.h:17
 TBasket.h:18
 TBasket.h:19
 TBasket.h:20
 TBasket.h:21
 TBasket.h:22
 TBasket.h:23
 TBasket.h:24
 TBasket.h:25
 TBasket.h:26
 TBasket.h:27
 TBasket.h:28
 TBasket.h:29
 TBasket.h:30
 TBasket.h:31
 TBasket.h:32
 TBasket.h:33
 TBasket.h:34
 TBasket.h:35
 TBasket.h:36
 TBasket.h:37
 TBasket.h:38
 TBasket.h:39
 TBasket.h:40
 TBasket.h:41
 TBasket.h:42
 TBasket.h:43
 TBasket.h:44
 TBasket.h:45
 TBasket.h:46
 TBasket.h:47
 TBasket.h:48
 TBasket.h:49
 TBasket.h:50
 TBasket.h:51
 TBasket.h:52
 TBasket.h:53
 TBasket.h:54
 TBasket.h:55
 TBasket.h:56
 TBasket.h:57
 TBasket.h:58
 TBasket.h:59
 TBasket.h:60
 TBasket.h:61
 TBasket.h:62
 TBasket.h:63
 TBasket.h:64
 TBasket.h:65
 TBasket.h:66
 TBasket.h:67
 TBasket.h:68
 TBasket.h:69
 TBasket.h:70
 TBasket.h:71
 TBasket.h:72
 TBasket.h:73
 TBasket.h:74
 TBasket.h:75
 TBasket.h:76
 TBasket.h:77
 TBasket.h:78
 TBasket.h:79
 TBasket.h:80
 TBasket.h:81
 TBasket.h:82
 TBasket.h:83
 TBasket.h:84
 TBasket.h:85
 TBasket.h:86
 TBasket.h:87
 TBasket.h:88
 TBasket.h:89
 TBasket.h:90
 TBasket.h:91
 TBasket.h:92
 TBasket.h:93
 TBasket.h:94
 TBasket.h:95
 TBasket.h:96
 TBasket.h:97
 TBasket.h:98
 TBasket.h:99
 TBasket.h:100
 TBasket.h:101
 TBasket.h:102