Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15A branch containing and managing a TRefTable for TRef autoloading.
16It loads the TBranch containing a referenced object when requested
17by TRef::GetObject(), so the reference can be resolved. The
18information which branch to load is stored by TRefTable. Once a
19TBranch has read the TBranchRef's current entry it will not be told
20to re-read, in case the use has changed objects read from the
21branch.
22
23### LIMITATION :
24Note that this does NOT allow for autoloading of references spanning
25different entries. The TBranchRef's current entry has to correspond
26to the entry of the TBranch containing the referenced object.
27
28The TRef cannot be stored in a top-level branch which is a
29TBranchObject for the auto-loading to work. E.g. you cannot store
30the TRefs in TObjArray, and create a top-level branch storing this
31TObjArray.
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
46TBranchRef::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{
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();
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) {
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
160{
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{
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
212Int_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
#define b(i)
Definition RSha256.hxx:100
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
A helper class for managing IMT work during TTree:Fill operations.
A branch containing and managing a TRefTable for TRef autoloading.
Definition TBranchRef.h:34
TRefTable * GetRefTable() const
Definition TBranchRef.h:49
void Reset(Option_t *option="") override
virtual ~TBranchRef()
Typical destructor.
TBranchRef()
Default constructor.
Bool_t Notify() override
This function is called by TRefTable::Notify, itself called by TRef::GetObject.
void FillLeavesImpl(TBuffer &b)
This function called by TBranch::Fill overloads TBranch::FillLeaves.
Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *) override
Fill the branch basket with the referenced objects parent numbers.
void Print(Option_t *option="") const override
Print the TRefTable branch.
void Clear(Option_t *option="") override
Clear entries in the TRefTable.
TRefTable * fRefTable
pointer to the TRefTable
Definition TBranchRef.h:39
Long64_t fRequestedEntry
! Cursor indicating which entry is being requested.
Definition TBranchRef.h:36
void ReadLeavesImpl(TBuffer &b)
This function called by TBranch::GetEntry overloads TBranch::ReadLeaves.
void ResetAfterMerge(TFileMergeInfo *) override
Reset a Branch after a Merge operation (drop data but keep customizations) TRefTable is cleared.
virtual Int_t SetParent(const TObject *obj, Int_t branchID)
Set the current parent branch.
A TTree is a list of TBranches.
Definition TBranch.h:89
TString fFileName
Name of file where buffers are stored ("" if in same file as Tree header)
Definition TBranch.h:145
Int_t fMaxBaskets
Maximum number of Baskets so far.
Definition TBranch.h:121
FillLeaves_t fFillLeaves
! Pointer to the FillLeaves implementation to use.
Definition TBranch.h:159
void(TBranch::* ReadLeaves_t)(TBuffer &b)
Definition TBranch.h:156
char * fAddress
! Address of 1st leaf (variable or object)
Definition TBranch.h:143
Long64_t * fBasketEntry
[fMaxBaskets] Table of first entry in each basket
Definition TBranch.h:138
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:1652
Long64_t fReadEntry
! Current entry number when reading
Definition TBranch.h:126
void Print(Option_t *option="") const override
Print TBranch parameters.
Definition TBranch.cxx:2287
ReadLeaves_t fReadLeaves
! Pointer to the ReadLeaves implementation to use.
Definition TBranch.h:157
void(TBranch::* FillLeaves_t)(TBuffer &b)
Definition TBranch.h:158
Long64_t GetReadEntry() const
Definition TBranch.h:233
Int_t * fBasketBytes
[fMaxBaskets] Length of baskets on file
Definition TBranch.h:137
virtual void ResetAfterMerge(TFileMergeInfo *)
Reset a Branch.
Definition TBranch.cxx:2544
TDirectory * fDirectory
! Pointer to directory where this branch buffers are stored
Definition TBranch.h:144
TBranch * fMother
! Pointer to top-level parent branch in the tree.
Definition TBranch.h:141
Long64_t * fBasketSeek
[fMaxBaskets] Addresses of baskets on file
Definition TBranch.h:139
Int_t fBasketSize
Initial Size of Basket Buffer.
Definition TBranch.h:114
virtual void Reset(Option_t *option="")
Reset a Branch.
Definition TBranch.cxx:2503
Int_t fCompress
Compression level and algorithm.
Definition TBranch.h:113
virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *)
Loop on all leaves of this branch to fill Basket buffer.
Definition TBranch.cxx:856
TTree * fTree
! Pointer to Tree header
Definition TBranch.h:140
Buffer base class used for serializing objects.
Definition TBuffer.h:43
A TFriendElement TF describes a TTree object TF in a file.
virtual TTree * GetTree()
Return pointer to friend TTree.
A doubly linked list.
Definition TList.h:38
virtual TObjLink * FirstLink() const
Definition TList.h:102
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition TProcessID.h:74
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition TRefTable.h:35
void Clear(Option_t *="") override
Clear all entries in the table.
virtual Int_t SetParent(const TObject *parent, Int_t branchID)
– Set current parent object, typically a branch of a tree.
UInt_t GetUID() const
Definition TRefTable.h:84
TProcessID * GetUIDContext() const
Definition TRefTable.h:85
virtual void FillBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
TObject * GetParent(Int_t uid, TProcessID *context=nullptr) const
Return object corresponding to uid.
static void SetRefTable(TRefTable *table)
Static function setting the current TRefTable.
virtual void Reset(Option_t *="")
Clear all entries in the table.
virtual void ReadBuffer(TBuffer &b)
Fill buffer b with the fN elements in fParentdIDs.
A TTree represents a columnar dataset.
Definition TTree.h:79
TDirectory * GetDirectory() const
Definition TTree.h:459
virtual TList * GetListOfFriends() const
Definition TTree.h:487
Definition tree.py:1