Logo ROOT  
Reference Guide
TBranchRef.cxx
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 19/08/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 /** \class TBranchRef
13 \ingroup tree
14 
15 A branch containing and managing a TRefTable for TRef autoloading.
16 It loads the TBranch containing a referenced object when requested
17 by TRef::GetObject(), so the reference can be resolved. The
18 information which branch to load is stored by TRefTable. Once a
19 TBranch has read the TBranchRef's current entry it will not be told
20 to re-read, in case the use has changed objects read from the
21 branch.
22 
23 ### LIMITATION :
24 Note that this does NOT allow for autoloading of references spanning
25 different entries. The TBranchRef's current entry has to correspond
26 to the entry of the TBranch containing the referenced object.
27 
28 The TRef cannot be stored in a top-level branch which is a
29 TBranchObject for the auto-loading to work. E.g. you cannot store
30 the TRefs in TObjArray, and create a top-level branch storing this
31 TObjArray.
32 */
33 
34 #include "TBranchRef.h"
35 #include "TTree.h"
36 #include "TBasket.h"
37 #include "TRefTable.h"
38 #include "TFile.h"
39 #include "TFriendElement.h"
40 
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 /// Default constructor.
45 
46 TBranchRef::TBranchRef(): TBranch(), fRequestedEntry(-1), fRefTable(0)
47 {
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Main constructor called by TTree::BranchRef.
54 
56  : TBranch(), fRequestedEntry(-1), fRefTable(0)
57 {
58  if (!tree) return;
59  SetName("TRefTable");
60  SetTitle("List of branch numbers with referenced objects");
61  fRefTable = new TRefTable(this,100);
62 
63  fCompress = 1;
64  fBasketSize = 32000;
65  fAddress = 0;
69 
70  for (Int_t i=0;i<fMaxBaskets;i++) {
71  fBasketBytes[i] = 0;
72  fBasketEntry[i] = 0;
73  fBasketSeek[i] = 0;
74  }
75 
76  fTree = tree;
77  fMother = this;
79  fFileName = "";
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Typical destructor.
86 
88 {
89  delete fRefTable;
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Clear entries in the TRefTable.
94 
96 {
97  if (fRefTable) fRefTable->Clear(option);
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Fill the branch basket with the referenced objects parent numbers.
102 
104 {
105  Int_t nbytes = TBranch::FillImpl(imtHelper);
106  return nbytes;
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// This function is called by TRefTable::Notify, itself called by
111 /// TRef::GetObject.
112 /// The function reads the branch containing the object referenced
113 /// by the TRef.
114 
116 {
117  if (!fRefTable) fRefTable = new TRefTable(this,100);
118  UInt_t uid = fRefTable->GetUID();
119  TProcessID* context = fRefTable->GetUIDContext();
120  if (fReadEntry != fRequestedEntry) {
121  // Load the RefTable if we need to.
123  }
124  TBranch *branch = (TBranch*)fRefTable->GetParent(uid, context);
125  if (branch) {
126  // don't re-read, the user might have changed some object
127  if (branch->GetReadEntry() != fRequestedEntry)
128  branch->GetEntry(fRequestedEntry);
129  } else {
130  //scan the TRefTable of possible friend Trees
131  TList *friends = fTree->GetListOfFriends();
132  if (!friends) return kTRUE;
133  TObjLink *lnk = friends->FirstLink();
134  while (lnk) {
135  TFriendElement* elem = (TFriendElement*)lnk->GetObject();
136  TTree *tree = elem->GetTree();
137  TBranchRef *bref = tree->GetBranchRef();
138  if (bref) {
139  if (bref->GetReadEntry() != fRequestedEntry) {
140  bref->GetEntry(fRequestedEntry);
141  }
142  branch = (TBranch*)bref->GetRefTable()->GetParent(uid, context);
143  if (branch) {
144  // don't re-read, the user might have changed some object
145  if (branch->GetReadEntry() != fRequestedEntry)
146  branch->GetEntry(fRequestedEntry);
147  return kTRUE;
148  }
149  }
150  lnk = lnk->Next();
151  }
152  }
153  return kTRUE;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Print the TRefTable branch.
158 
159 void TBranchRef::Print(Option_t *option) const
160 {
161  TBranch::Print(option);
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// This function called by TBranch::GetEntry overloads TBranch::ReadLeaves.
166 
168 {
169  if (!fRefTable) fRefTable = new TRefTable(this,100);
171 }
172 
173 ////////////////////////////////////////////////////////////////////////////////
174 /// This function called by TBranch::Fill overloads TBranch::FillLeaves.
175 
177 {
178  if (!fRefTable) fRefTable = new TRefTable(this,100);
180 }
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 /// - Existing buffers are deleted
184 /// - Entries, max and min are reset
185 /// - TRefTable is cleared.
186 
188 {
189  TBranch::Reset(option);
190  if (!fRefTable) fRefTable = new TRefTable(this,100);
191  fRefTable->Reset();
192 }
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Reset a Branch after a Merge operation (drop data but keep customizations)
196 /// TRefTable is cleared.
197 
199 {
201  if (!fRefTable) fRefTable = new TRefTable(this,100);
202  fRefTable->Reset();
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Set the current parent branch.
207 ///
208 /// This function is called by TBranchElement::GetEntry()
209 /// and TBranchElement::Fill() when reading or writing
210 /// branches that may contain referenced objects.
211 
212 Int_t TBranchRef::SetParent(const TObject* object, Int_t branchID)
213 {
214  if (!fRefTable) {
215  fRefTable = new TRefTable(this, 100);
216  }
218  return fRefTable->SetParent(object, branchID);
219 }
220 
TFileMergeInfo
Definition: TFileMergeInfo.h:42
TBranch::fBasketSize
Int_t fBasketSize
Initial Size of Basket Buffer.
Definition: TBranch.h:114
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
TBranchRef::FillLeavesImpl
void FillLeavesImpl(TBuffer &b)
This function called by TBranch::Fill overloads TBranch::FillLeaves.
Definition: TBranchRef.cxx:176
TBranchRef.h
TRefTable::Clear
virtual void Clear(Option_t *="")
Clear all entries in the table.
Definition: TRefTable.cxx:145
TTree::GetListOfFriends
virtual TList * GetListOfFriends() const
Definition: TTree.h:485
TRefTable::Reset
virtual void Reset(Option_t *="")
Clear all entries in the table.
Definition: TRefTable.cxx:345
TBranchRef::fRequestedEntry
Long64_t fRequestedEntry
! Cursor indicating which entry is being requested.
Definition: TBranchRef.h:36
tree
Definition: tree.py:1
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TBranch::fReadEntry
Long64_t fReadEntry
! Current entry number when reading
Definition: TBranch.h:126
TBranch::fReadLeaves
ReadLeaves_t fReadLeaves
! Pointer to the ReadLeaves implementation to use.
Definition: TBranch.h:157
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TBranch::GetReadEntry
Long64_t GetReadEntry() const
Definition: TBranch.h:233
TTree
Definition: TTree.h:79
TBranchRef::SetParent
virtual Int_t SetParent(const TObject *obj, Int_t branchID)
Set the current parent branch.
Definition: TBranchRef.cxx:212
TProcessID
Definition: TProcessID.h:74
TBranchRef::fRefTable
TRefTable * fRefTable
pointer to the TRefTable
Definition: TBranchRef.h:39
TBranchRef::Clear
virtual void Clear(Option_t *option="")
Clear entries in the TRefTable.
Definition: TBranchRef.cxx:95
TFriendElement
Definition: TFriendElement.h:33
TBuffer
Definition: TBuffer.h:43
TFriendElement.h
TTree.h
b
#define b(i)
Definition: RSha256.hxx:118
TFile.h
TBranch::fFileName
TString fFileName
Name of file where buffers are stored ("" if in same file as Tree header)
Definition: TBranch.h:145
bool
TRefTable::GetParent
TObject * GetParent(Int_t uid, TProcessID *context=0) const
Return object corresponding to uid.
Definition: TRefTable.cxx:249
TRefTable::GetUIDContext
TProcessID * GetUIDContext() const
Definition: TRefTable.h:81
TBranch::fCompress
Int_t fCompress
Compression level and algorithm.
Definition: TBranch.h:113
TBranch
Definition: TBranch.h:89
TRefTable.h
TBranchRef::GetRefTable
TRefTable * GetRefTable() const
Definition: TBranchRef.h:49
TRefTable::SetRefTable
static void SetRefTable(TRefTable *table)
Static function setting the current TRefTable.
Definition: TRefTable.cxx:383
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TBranch::fFillLeaves
FillLeaves_t fFillLeaves
! Pointer to the FillLeaves implementation to use.
Definition: TBranch.h:159
TBranchRef::ResetAfterMerge
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch after a Merge operation (drop data but keep customizations) TRefTable is cleared.
Definition: TBranchRef.cxx:198
TBranch::fMaxBaskets
Int_t fMaxBaskets
Maximum number of Baskets so far.
Definition: TBranch.h:121
TBranchRef::ReadLeavesImpl
void ReadLeavesImpl(TBuffer &b)
This function called by TBranch::GetEntry overloads TBranch::ReadLeaves.
Definition: TBranchRef.cxx:167
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TBranch::fTree
TTree * fTree
! Pointer to Tree header
Definition: TBranch.h:140
TFriendElement::GetTree
virtual TTree * GetTree()
Return pointer to friend TTree.
Definition: TFriendElement.cxx:209
TBranch::GetEntry
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
Definition: TBranch.cxx:1582
TBranch::fBasketSeek
Long64_t * fBasketSeek
[fMaxBaskets] Addresses of baskets on file
Definition: TBranch.h:139
TBranchRef::FillImpl
virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *)
Fill the branch basket with the referenced objects parent numbers.
Definition: TBranchRef.cxx:103
TRefTable::GetUID
UInt_t GetUID() const
Definition: TRefTable.h:80
TBranch::fDirectory
TDirectory * fDirectory
! Pointer to directory where this branch buffers are stored
Definition: TBranch.h:144
TRefTable::ReadBuffer
virtual void ReadBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
Definition: TRefTable.cxx:308
TBranch::FillImpl
virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *)
Loop on all leaves of this branch to fill Basket buffer.
Definition: TBranch.cxx:835
TBranch::ResetAfterMerge
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch.
Definition: TBranch.cxx:2430
TBranch::Print
virtual void Print(Option_t *option="") const
Print TBranch parameters.
Definition: TBranch.cxx:2173
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TBranchRef::Reset
virtual void Reset(Option_t *option="")
Definition: TBranchRef.cxx:187
TBranch::fAddress
char * fAddress
! Address of 1st leaf (variable or object)
Definition: TBranch.h:143
unsigned int
TTree::GetDirectory
TDirectory * GetDirectory() const
Definition: TTree.h:457
TRefTable
Definition: TRefTable.h:35
TBranch::Reset
virtual void Reset(Option_t *option="")
Reset a Branch.
Definition: TBranch.cxx:2389
TBranchRef::Print
virtual void Print(Option_t *option="") const
Print the TRefTable branch.
Definition: TBranchRef.cxx:159
TRefTable::SetParent
virtual Int_t SetParent(const TObject *parent, Int_t branchID)
– Set current parent object, typically a branch of a tree.
Definition: TRefTable.cxx:357
TBranchRef::Notify
virtual Bool_t Notify()
This function is called by TRefTable::Notify, itself called by TRef::GetObject.
Definition: TBranchRef.cxx:115
TBranchRef::TBranchRef
TBranchRef()
Default constructor.
Definition: TBranchRef.cxx:46
ROOT::Internal::TBranchIMTHelper
Definition: TBranchIMTHelper.h:38
TObject
Definition: TObject.h:37
TBranch::FillLeaves_t
void(TBranch::* FillLeaves_t)(TBuffer &b)
Definition: TBranch.h:158
TRefTable::FillBuffer
virtual void FillBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
Definition: TRefTable.cxx:225
TBranch::fBasketBytes
Int_t * fBasketBytes
[fMaxBaskets] Length of baskets on file
Definition: TBranch.h:137
TBranch::ReadLeaves_t
void(TBranch::* ReadLeaves_t)(TBuffer &b)
Definition: TBranch.h:156
TBranch::fBasketEntry
Long64_t * fBasketEntry
[fMaxBaskets] Table of first entry in each basket
Definition: TBranch.h:138
TBranchRef::~TBranchRef
virtual ~TBranchRef()
Typical destructor.
Definition: TBranchRef.cxx:87
TBranch::fMother
TBranch * fMother
! Pointer to top-level parent branch in the tree.
Definition: TBranch.h:141
TBasket.h
TList
Definition: TList.h:44
TBranchRef
Definition: TBranchRef.h:34
int