ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 A branch containing and managing a TRefTable for TRef autoloading.
14 It loads the TBranch containing a referenced object when requested
15 by TRef::GetObject(), so the reference can be resolved. The
16 information which branch to load is stored by TRefTable. Once a
17 TBranch has read the TBranchRef's current entry it will not be told
18 to re-read, in case the use has changed objects read from the
19 branch.
20 
21 *** LIMITATION ***
22 Note that this does NOT allow for autoloading of references spanning
23 different entries. The TBranchRef's current entry has to correspond
24 to the entry of the TBranch containing the referenced object.
25 
26 The TRef cannot be stored in a top-level branch which is a
27 TBranchObject for the auto-loading to work. E.g. you cannot store
28 the TRefs in TObjArray, and create a top-level branch storing this
29 TObjArray.
30 */
31 
32 #include "TBranchRef.h"
33 #include "TBuffer.h"
34 #include "TTree.h"
35 #include "TBasket.h"
36 #include "TFile.h"
37 #include "TFriendElement.h"
38 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Default constructor.
43 
44 TBranchRef::TBranchRef(): TBranch(), fRequestedEntry(-1), fRefTable(0)
45 {
46  fReadLeaves = (ReadLeaves_t)&TBranchRef::ReadLeavesImpl;
47  fFillLeaves = (FillLeaves_t)&TBranchRef::FillLeavesImpl;
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Main constructor called by TTree::BranchRef.
52 
54  : TBranch(), fRequestedEntry(-1), fRefTable(0)
55 {
56  if (!tree) return;
57  SetName("TRefTable");
58  SetTitle("List of branch numbers with referenced objects");
59  fRefTable = new TRefTable(this,100);
60 
61  fCompress = 1;
62  fBasketSize = 32000;
63  fAddress = 0;
67 
68  for (Int_t i=0;i<fMaxBaskets;i++) {
69  fBasketBytes[i] = 0;
70  fBasketEntry[i] = 0;
71  fBasketSeek[i] = 0;
72  }
73 
74  fTree = tree;
75  fMother = this;
77  fFileName = "";
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Typical destructor.
84 
86 {
87  delete fRefTable;
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Clear entries in the TRefTable.
92 
94 {
95  if (fRefTable) fRefTable->Clear(option);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Fill the branch basket with the referenced objects parent numbers.
100 
102 {
103  Int_t nbytes = TBranch::Fill();
104  return nbytes;
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// This function is called by TRefTable::Notify, itself called by
109 /// TRef::GetObject.
110 /// The function reads the branch containing the object referenced
111 /// by the TRef.
112 
114 {
115  if (!fRefTable) fRefTable = new TRefTable(this,100);
116  UInt_t uid = fRefTable->GetUID();
117  TProcessID* context = fRefTable->GetUIDContext();
118  if (fReadEntry != fRequestedEntry) {
119  // Load the RefTable if we need to.
121  }
122  TBranch *branch = (TBranch*)fRefTable->GetParent(uid, context);
123  if (branch) {
124  // don't re-read, the user might have changed some object
125  if (branch->GetReadEntry() != fRequestedEntry)
126  branch->GetEntry(fRequestedEntry);
127  } else {
128  //scan the TRefTable of possible friend Trees
129  TList *friends = fTree->GetListOfFriends();
130  if (!friends) return kTRUE;
131  TObjLink *lnk = friends->FirstLink();
132  while (lnk) {
133  TFriendElement* elem = (TFriendElement*)lnk->GetObject();
134  TTree *tree = elem->GetTree();
135  TBranchRef *bref = tree->GetBranchRef();
136  if (bref) {
137  if (bref->GetReadEntry() != fRequestedEntry) {
138  bref->GetEntry(fRequestedEntry);
139  }
140  branch = (TBranch*)bref->GetRefTable()->GetParent(uid, context);
141  if (branch) {
142  // don't re-read, the user might have changed some object
143  if (branch->GetReadEntry() != fRequestedEntry)
144  branch->GetEntry(fRequestedEntry);
145  return kTRUE;
146  }
147  }
148  lnk = lnk->Next();
149  }
150  }
151  return kTRUE;
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Print the TRefTable branch.
156 
157 void TBranchRef::Print(Option_t *option) const
158 {
159  TBranch::Print(option);
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// This function called by TBranch::GetEntry overloads TBranch::ReadLeaves.
164 
166 {
167  if (!fRefTable) fRefTable = new TRefTable(this,100);
168  fRefTable->ReadBuffer(b);
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// This function called by TBranch::Fill overloads TBranch::FillLeaves.
173 
175 {
176  if (!fRefTable) fRefTable = new TRefTable(this,100);
177  fRefTable->FillBuffer(b);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// - Existing buffers are deleted
182 /// - Entries, max and min are reset
183 /// - TRefTable is cleared.
184 
186 {
187  TBranch::Reset(option);
188  if (!fRefTable) fRefTable = new TRefTable(this,100);
189  fRefTable->Reset();
190 }
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Reset a Branch after a Merge operation (drop data but keep customizations)
194 /// TRefTable is cleared.
195 
197 {
199  if (!fRefTable) fRefTable = new TRefTable(this,100);
200  fRefTable->Reset();
201 }
202 
203 ////////////////////////////////////////////////////////////////////////////////
204 /// Set the current parent branch.
205 ///
206 /// This function is called by TBranchElement::GetEntry()
207 /// and TBranchElement::Fill() when reading or writing
208 /// branches that may contain referenced objects.
209 
210 Int_t TBranchRef::SetParent(const TObject* object, Int_t branchID)
211 {
212  if (!fRefTable) {
213  fRefTable = new TRefTable(this, 100);
214  }
216  return fRefTable->SetParent(object, branchID);
217 }
218 
Long64_t GetReadEntry() const
Definition: TBranch.h:169
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch after a Merge operation (drop data but keep customizations) TRefTable is cleared...
Definition: TBranchRef.cxx:196
virtual TTree * GetTree()
Return pointer to friend TTree.
long long Long64_t
Definition: RtypesCore.h:69
const char Option_t
Definition: RtypesCore.h:62
TObject * GetParent(Int_t uid, TProcessID *context=0) const
Return object corresponding to uid.
Definition: TRefTable.cxx:249
void ReadLeavesImpl(TBuffer &b)
This function called by TBranch::GetEntry overloads TBranch::ReadLeaves.
Definition: TBranchRef.cxx:165
ReadLeaves_t fReadLeaves
Definition: TBranch.h:106
TProcessID * GetUIDContext() const
Definition: TRefTable.h:83
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
void(TBranch::* ReadLeaves_t)(TBuffer &b)
After being read, the buffer will not be unziped.
Definition: TBranch.h:105
virtual void Print(Option_t *option="") const
Print TBranch parameters.
Definition: TBranch.cxx:1727
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TRefTable * GetRefTable() const
Definition: TBranchRef.h:49
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t Notify()
This function is called by TRefTable::Notify, itself called by TRef::GetObject.
Definition: TBranchRef.cxx:113
Long64_t * fBasketSeek
Definition: TBranch.h:93
virtual ~TBranchRef()
Typical destructor.
Definition: TBranchRef.cxx:85
virtual void Clear(Option_t *="")
Clear all entries in the table.
Definition: TRefTable.cxx:145
virtual void Reset(Option_t *option="")
Definition: TBranchRef.cxx:185
Int_t * fBasketBytes
Definition: TBranch.h:91
static void SetRefTable(TRefTable *table)
Static function setting the current TRefTable.
Definition: TRefTable.cxx:383
virtual TList * GetListOfFriends() const
Definition: TTree.h:411
Int_t fMaxBaskets
Definition: TBranch.h:75
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:34
A branch containing and managing a TRefTable for TRef autoloading.
Definition: TBranchRef.h:33
A doubly linked list.
Definition: TList.h:47
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch.
Definition: TBranch.cxx:1965
virtual Int_t Fill()
Loop on all leaves of this branch to fill Basket buffer.
Definition: TBranch.cxx:724
virtual void Reset(Option_t *="")
Clear all entries in the table.
Definition: TRefTable.cxx:345
Int_t fBasketSize
Definition: TBranch.h:70
void FillLeavesImpl(TBuffer &b)
This function called by TBranch::Fill overloads TBranch::FillLeaves.
Definition: TBranchRef.cxx:174
TDirectory * GetDirectory() const
Definition: TTree.h:385
virtual void ReadBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
Definition: TRefTable.cxx:308
FillLeaves_t fFillLeaves
Definition: TBranch.h:108
unsigned int UInt_t
Definition: RtypesCore.h:42
Long64_t fRequestedEntry
Definition: TBranchRef.h:35
virtual TBranchRef * GetBranchRef() const
Definition: TTree.h:374
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:1199
virtual TObjLink * FirstLink() const
Definition: TList.h:101
virtual Int_t Fill()
Fill the branch basket with the referenced objects parent numbers.
Definition: TBranchRef.cxx:101
tuple tree
Definition: tree.py:24
TRefTable * fRefTable
Cursor indicating which entry is being requested.
Definition: TBranchRef.h:38
virtual void Clear(Option_t *option="")
Clear entries in the TRefTable.
Definition: TBranchRef.cxx:93
void(TBranch::* FillLeaves_t)(TBuffer &b)
Pointer to the ReadLeaves implementation to use.
Definition: TBranch.h:107
virtual Int_t SetParent(const TObject *parent, Int_t branchID)
– Set current parent object, typically a branch of a tree.
Definition: TRefTable.cxx:357
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition: TRefTable.h:37
virtual Int_t SetParent(const TObject *obj, Int_t branchID)
Set the current parent branch.
Definition: TBranchRef.cxx:210
TTree * fTree
Definition: TBranch.h:94
TDirectory * fDirectory
Address of 1st leaf (variable or object)
Definition: TBranch.h:98
virtual void FillBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
Definition: TRefTable.cxx:225
Mother of all ROOT objects.
Definition: TObject.h:58
ClassImp(TBranchRef) TBranchRef
Default constructor.
Definition: TBranchRef.cxx:39
Long64_t * fBasketEntry
Definition: TBranch.h:92
virtual void Reset(Option_t *option="")
Reset a Branch.
Definition: TBranch.cxx:1924
A TFriendElement TF describes a TTree object TF in a file.
Long64_t fReadEntry
Current basket number when reading.
Definition: TBranch.h:80
TBranch * fMother
Pointer to Tree header.
Definition: TBranch.h:95
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
UInt_t GetUID() const
Definition: TRefTable.h:82
Int_t fCompress
branch counter
Definition: TBranch.h:69
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TString fFileName
Pointer to directory where this branch buffers are stored.
Definition: TBranch.h:99
virtual void Print(Option_t *option="") const
Print the TRefTable branch.
Definition: TBranchRef.cxx:157
char * fAddress
Pointer to parent branch.
Definition: TBranch.h:97