ROOT logo
// @(#)root/tree:$Id: TBranch.h 25980 2008-10-27 18:17:39Z pcanal $
// Author: Rene Brun   12/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_TBranch
#define ROOT_TBranch


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TBranch                                                              //
//                                                                      //
// A TTree object is a list of TBranchs.                                //
//   A TBranch describes the branch data structure and supports :       //
//     the list of TBaskets (branch buffers) associated to this branch. //
//     the list of TLeaves (branch description)                         //
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TNamed
#include "TNamed.h"
#endif

#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif

#ifndef ROOT_TAttFill
#include "TAttFill.h"
#endif

class TTree;
class TBasket;
class TLeaf;
class TBrowser;
class TDirectory;
class TFile;
class TClonesArray;

   const Int_t kDoNotProcess = BIT(10); // Active bit for branches
   const Int_t kIsClone      = BIT(11); // to indicate a TBranchClones
   const Int_t kBranchObject = BIT(12); // branch is a TObject*
   const Int_t kBranchAny    = BIT(17); // branch is an object*
   const Int_t kMapObject    = kBranchObject | kBranchAny;

class TBranch : public TNamed , public TAttFill {

protected:
   // TBranch status bits
   enum { kAutoDelete = BIT(15) };

   static Int_t fgCount;          //! branch counter
   Int_t       fCompress;        //  (=1 branch is compressed, 0 otherwise)
   Int_t       fBasketSize;      //  Initial Size of  Basket Buffer
   Int_t       fEntryOffsetLen;  //  Initial Length of fEntryOffset table in the basket buffers
   Int_t       fWriteBasket;     //  Last basket number written
   Long64_t    fEntryNumber;     //  Current entry number (last one filled in this branch)
   Int_t       fOffset;          //  Offset of this branch
   Int_t       fMaxBaskets;      //  Maximum number of Baskets so far
   Int_t       fSplitLevel;      //  Branch split level
   Int_t       fNleaves;         //! Number of leaves
   Int_t       fReadBasket;      //! Current basket number when reading
   Long64_t    fReadEntry;       //! Current entry number when reading
   Long64_t    fEntries;         //  Number of entries
   Long64_t    fFirstEntry;      //  Number of the first entry in this branch
   Long64_t    fTotBytes;        //  Total number of bytes in all leaves before compression
   Long64_t    fZipBytes;        //  Total number of bytes in all leaves after compression
   TObjArray   fBranches;        //-> List of Branches of this branch
   TObjArray   fLeaves;          //-> List of leaves of this branch
   TObjArray   fBaskets;         //-> List of baskets of this branch
   Int_t       fNBasketRAM;      //! Number of baskets in fBasketRAM
   Int_t      *fBasketRAM;       //! [fNBasketRAM] table of basket numbers in memory
   Int_t      *fBasketBytes;     //[fMaxBaskets] Lenght of baskets on file
   Long64_t   *fBasketEntry;     //[fMaxBaskets] Table of first entry in eack basket
   Long64_t   *fBasketSeek;      //[fMaxBaskets] Addresses of baskets on file
   TTree      *fTree;            //! Pointer to Tree header
   TBranch    *fMother;          //! Pointer to top-level parent branch in the tree.
   TBranch    *fParent;          //! Pointer to parent branch.
   char       *fAddress;         //! Address of 1st leaf (variable or object)
   TDirectory *fDirectory;       //! Pointer to directory where this branch buffers are stored
   TString     fFileName;        //  Name of file where buffers are stored ("" if in same file as Tree header)
   TBuffer    *fEntryBuffer;     //! Buffer used to directly pass the content without streaming
   TList      *fBrowsables;      //! List of TVirtualBranchBrowsables used for Browse()

   Bool_t      fSkipZip;         //!After being read, the buffer will not be unziped.

   void     SetSkipZip(Bool_t skip = kTRUE) { fSkipZip = skip; }
   void     Init(const char *name, const char *leaflist, Int_t compress);

   Int_t    WriteBasket(TBasket* basket, Int_t where);
   
   TString  GetRealFileName() const;

private:
   TBranch(const TBranch&);             // not implemented
   TBranch& operator=(const TBranch&);  // not implemented

public:
   TBranch();
   TBranch(TTree *tree, const char *name, void *address, const char *leaflist, Int_t basketsize=32000, Int_t compress=-1);
   TBranch(TBranch *parent, const char *name, void *address, const char *leaflist, Int_t basketsize=32000, Int_t compress=-1);
   virtual ~TBranch();

   virtual void      AddBasket(TBasket &b, Bool_t ondisk, Long64_t startEntry);
   virtual void      AddLastBasket(Long64_t startEntry);
   virtual void      Browse(TBrowser *b);
   virtual void      DeleteBaskets(Option_t* option="");
   virtual void      DropBaskets(Option_t *option = "");
           void      ExpandBasketArrays();
   virtual Int_t     Fill();
   virtual void      FillLeaves(TBuffer &b);
   virtual TBranch  *FindBranch(const char *name);
   virtual TLeaf    *FindLeaf(const char *name);
           Int_t     FlushBaskets();
           Int_t     FlushOneBasket(UInt_t which);

   virtual char     *GetAddress() const {return fAddress;}
   virtual Int_t     GetBasketSize() const {return fBasketSize;}
   virtual const char* GetClassName() const { return ""; }
   virtual Int_t     GetCompressionLevel() const {return fCompress;}
   virtual Int_t     GetEntry(Long64_t entry=0, Int_t getall = 0);
   virtual Int_t     GetEntryExport(Long64_t entry, Int_t getall, TClonesArray *list, Int_t n);
           Int_t     GetEvent(Long64_t entry=0) {return GetEntry(entry);}
           Int_t     GetEntryOffsetLen() const {return fEntryOffsetLen;}
   const char       *GetIconName() const;
   virtual TLeaf    *GetLeaf(const char *name) const;
           TBasket  *GetBasket(Int_t basket);
           Int_t    *GetBasketBytes() const {return fBasketBytes;}
           Long64_t *GetBasketEntry() const {return fBasketEntry;}
   virtual Long64_t  GetBasketSeek(Int_t basket) const;
   virtual TList    *GetBrowsables();
   TDirectory       *GetDirectory() const {return fDirectory;}
   virtual TFile    *GetFile(Int_t mode=0);
   const char       *GetFileName()    const {return fFileName.Data();}
           Int_t     GetOffset()      const {return fOffset;}
           Int_t     GetReadBasket()  const {return fReadBasket;}
           Long64_t  GetReadEntry()   const {return fReadEntry;}
           Int_t     GetWriteBasket() const {return fWriteBasket;}
           Long64_t  GetTotalSize(Option_t *option="")   const;
           Long64_t  GetTotBytes(Option_t *option="")    const;
           Long64_t  GetZipBytes(Option_t *option="")    const;
           Long64_t  GetEntryNumber() const {return fEntryNumber;}
           Long64_t  GetFirstEntry()  const {return fFirstEntry; }
         TObjArray  *GetListOfBaskets()  {return &fBaskets;}
         TObjArray  *GetListOfBranches() {return &fBranches;}
         TObjArray  *GetListOfLeaves()   {return &fLeaves;}
           Int_t     GetMaxBaskets()  const  {return fMaxBaskets;}
           Int_t     GetNleaves()     const {return fNleaves;}
           Int_t     GetSplitLevel()  const {return fSplitLevel;}
           Long64_t  GetEntries()     const {return fEntries;}
           TTree    *GetTree()        const {return fTree;}
   virtual Int_t     GetRow(Int_t row);
   TBranch          *GetMother() const;
   TBranch          *GetSubBranch(const TBranch *br) const;
   Bool_t            IsAutoDelete() const;
   Bool_t            IsFolder() const;
   virtual void      KeepCircular(Long64_t maxEntries);
   virtual Int_t     LoadBaskets();
   virtual void      Print(Option_t *option="") const;
   virtual void      ReadBasket(TBuffer &b);
   virtual void      ReadLeaves(TBuffer &b);
   virtual void      Refresh(TBranch *b);
   virtual void      Reset(Option_t *option="");
   virtual void      ResetAddress();
   virtual void      ResetReadEntry() {fReadEntry = -1;}
   virtual void      SetAddress(void *add);
   virtual void      SetObject(void *objadd);
   virtual void      SetAutoDelete(Bool_t autodel=kTRUE);
   virtual void      SetBasketSize(Int_t buffsize);
   virtual void      SetBufferAddress(TBuffer *entryBuffer);
   virtual void      SetCompressionLevel(Int_t level=1);
   virtual void      SetEntryOffsetLen(Int_t len) {fEntryOffsetLen = len;}
   virtual void      SetEntries(Long64_t entries);
   virtual void      SetFirstEntry( Long64_t entry );
   virtual void      SetFile(TFile *file=0);
   virtual void      SetFile(const char *filename);
   virtual void      SetOffset(Int_t offset=0) {fOffset=offset;}
   virtual void      SetTree(TTree *tree) { fTree = tree;}
   virtual void      UpdateAddress() {;}

   static  void      ResetCount();

   ClassDef(TBranch,11);  //Branch descriptor
};

#endif
 TBranch.h:1
 TBranch.h:2
 TBranch.h:3
 TBranch.h:4
 TBranch.h:5
 TBranch.h:6
 TBranch.h:7
 TBranch.h:8
 TBranch.h:9
 TBranch.h:10
 TBranch.h:11
 TBranch.h:12
 TBranch.h:13
 TBranch.h:14
 TBranch.h:15
 TBranch.h:16
 TBranch.h:17
 TBranch.h:18
 TBranch.h:19
 TBranch.h:20
 TBranch.h:21
 TBranch.h:22
 TBranch.h:23
 TBranch.h:24
 TBranch.h:25
 TBranch.h:26
 TBranch.h:27
 TBranch.h:28
 TBranch.h:29
 TBranch.h:30
 TBranch.h:31
 TBranch.h:32
 TBranch.h:33
 TBranch.h:34
 TBranch.h:35
 TBranch.h:36
 TBranch.h:37
 TBranch.h:38
 TBranch.h:39
 TBranch.h:40
 TBranch.h:41
 TBranch.h:42
 TBranch.h:43
 TBranch.h:44
 TBranch.h:45
 TBranch.h:46
 TBranch.h:47
 TBranch.h:48
 TBranch.h:49
 TBranch.h:50
 TBranch.h:51
 TBranch.h:52
 TBranch.h:53
 TBranch.h:54
 TBranch.h:55
 TBranch.h:56
 TBranch.h:57
 TBranch.h:58
 TBranch.h:59
 TBranch.h:60
 TBranch.h:61
 TBranch.h:62
 TBranch.h:63
 TBranch.h:64
 TBranch.h:65
 TBranch.h:66
 TBranch.h:67
 TBranch.h:68
 TBranch.h:69
 TBranch.h:70
 TBranch.h:71
 TBranch.h:72
 TBranch.h:73
 TBranch.h:74
 TBranch.h:75
 TBranch.h:76
 TBranch.h:77
 TBranch.h:78
 TBranch.h:79
 TBranch.h:80
 TBranch.h:81
 TBranch.h:82
 TBranch.h:83
 TBranch.h:84
 TBranch.h:85
 TBranch.h:86
 TBranch.h:87
 TBranch.h:88
 TBranch.h:89
 TBranch.h:90
 TBranch.h:91
 TBranch.h:92
 TBranch.h:93
 TBranch.h:94
 TBranch.h:95
 TBranch.h:96
 TBranch.h:97
 TBranch.h:98
 TBranch.h:99
 TBranch.h:100
 TBranch.h:101
 TBranch.h:102
 TBranch.h:103
 TBranch.h:104
 TBranch.h:105
 TBranch.h:106
 TBranch.h:107
 TBranch.h:108
 TBranch.h:109
 TBranch.h:110
 TBranch.h:111
 TBranch.h:112
 TBranch.h:113
 TBranch.h:114
 TBranch.h:115
 TBranch.h:116
 TBranch.h:117
 TBranch.h:118
 TBranch.h:119
 TBranch.h:120
 TBranch.h:121
 TBranch.h:122
 TBranch.h:123
 TBranch.h:124
 TBranch.h:125
 TBranch.h:126
 TBranch.h:127
 TBranch.h:128
 TBranch.h:129
 TBranch.h:130
 TBranch.h:131
 TBranch.h:132
 TBranch.h:133
 TBranch.h:134
 TBranch.h:135
 TBranch.h:136
 TBranch.h:137
 TBranch.h:138
 TBranch.h:139
 TBranch.h:140
 TBranch.h:141
 TBranch.h:142
 TBranch.h:143
 TBranch.h:144
 TBranch.h:145
 TBranch.h:146
 TBranch.h:147
 TBranch.h:148
 TBranch.h:149
 TBranch.h:150
 TBranch.h:151
 TBranch.h:152
 TBranch.h:153
 TBranch.h:154
 TBranch.h:155
 TBranch.h:156
 TBranch.h:157
 TBranch.h:158
 TBranch.h:159
 TBranch.h:160
 TBranch.h:161
 TBranch.h:162
 TBranch.h:163
 TBranch.h:164
 TBranch.h:165
 TBranch.h:166
 TBranch.h:167
 TBranch.h:168
 TBranch.h:169
 TBranch.h:170
 TBranch.h:171
 TBranch.h:172
 TBranch.h:173
 TBranch.h:174
 TBranch.h:175
 TBranch.h:176
 TBranch.h:177
 TBranch.h:178
 TBranch.h:179
 TBranch.h:180
 TBranch.h:181
 TBranch.h:182
 TBranch.h:183
 TBranch.h:184
 TBranch.h:185
 TBranch.h:186
 TBranch.h:187
 TBranch.h:188
 TBranch.h:189
 TBranch.h:190
 TBranch.h:191
 TBranch.h:192
 TBranch.h:193