ROOT
remotes/pull/22321/merge
Reference Guide
Loading...
Searching...
No Matches
TFriendProxy.cxx
Go to the documentation of this file.
1
// @(#)root/base:$Id$
2
// Author: Philippe Canal 13/05/2003
3
4
/*************************************************************************
5
* Copyright (C) 1995-2000, Rene Brun, Fons Rademakers and al. *
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 TFriendProxy
13
Concrete implementation of the proxy around a Friend Tree.
14
*/
15
16
#include "
TChain.h
"
17
#include "
TFriendProxy.h
"
18
#include "
TTree.h
"
19
#include "
TList.h
"
20
#include "
TFriendElement.h
"
21
22
23
namespace
ROOT
{
24
namespace
Internal {
25
26
/////////////////////////////////////////////////////////////////////////////
27
28
TFriendProxy::TFriendProxy
() :
fDirector
(nullptr,-1),
fIndex
(-1)
29
{
30
}
31
32
/////////////////////////////////////////////////////////////////////////////
33
/// Constructor.
34
35
TFriendProxy::TFriendProxy
(
TBranchProxyDirector
*director,
TTree
*
main
,
Int_t
index
) :
36
fDirector
(nullptr,-1),
fIndex
(
index
)
37
{
38
39
auto
getFriendAtIdx = [](
TTree
*dataset,
Int_t
frIdx) ->
TTree
* {
40
if
(!dataset)
41
return
nullptr
;
42
43
auto
*friends = dataset->
GetListOfFriends
();
44
if
(!friends)
45
return
nullptr
;
46
47
auto
*friendAtIdx = friends->
At
(frIdx);
48
if
(!friendAtIdx)
49
return
nullptr
;
50
51
auto
*frEl =
dynamic_cast<
TFriendElement
*
>
(friendAtIdx);
52
if
(!frEl)
53
return
nullptr
;
54
55
return
frEl->
GetTree
();
56
};
57
58
// The list of friends needs to be accessed via GetTree()->GetListOfFriends()
59
// (and not directly GetListOfFriends()), otherwise when `main` is a TChain we
60
// might not recover the list correctly (see #6993 for the TTreeReader issue
61
// and #6741 for a more complete discussion/explanation).
62
if
(
main
) {
63
// But, we do need to get the top-level friend from the dataset (TTree or TChain)
64
// to check if it has an index
65
auto
*topLevelFriendTree = getFriendAtIdx(
main
,
fIndex
);
66
if
(topLevelFriendTree) {
67
fHasIndex
= (topLevelFriendTree->GetTreeIndex() !=
nullptr
);
68
}
69
70
// Then, point the director to the current tree from the friend that is being read
71
auto
*localFriendTree = getFriendAtIdx(
main
->GetTree(),
fIndex
);
72
if
(localFriendTree) {
73
fDirector
.SetTree(localFriendTree);
74
// If we still do not think the friend has a TTreeIndex, retry for good measure
75
if
(!
fHasIndex
)
76
fHasIndex
= (localFriendTree->GetTreeIndex() !=
nullptr
);
77
}
78
}
79
80
director->
Attach
(
this
);
81
}
82
83
/////////////////////////////////////////////////////////////////////////////
84
/// Return the entry number currently being looked at.
85
86
Long64_t
TFriendProxy::GetReadEntry
()
const
87
{
88
return
fDirector
.GetReadEntry();
89
}
90
91
/////////////////////////////////////////////////////////////////////////////
92
/// Refresh the cached read entry number from the original tree.
93
94
void
TFriendProxy::ResetReadEntry
()
95
{
96
// The 2nd call to GetTree is to insure we get the 'local' tree's entry in the case of a
97
// chain.
98
if
(
fDirector
.GetTree())
fDirector
.SetReadEntry(
fDirector
.GetTree()->GetTree()->GetReadEntry());
99
}
100
101
//////////////////////////////////////////////////////////////////////////////
102
/// Update the address of the underlying tree.
103
104
void
TFriendProxy::Update
(
TTree
*newmain)
105
{
106
if
(!newmain)
107
return
;
108
109
if
(
auto
friends = newmain->
GetTree
()->
GetListOfFriends
()) {
110
auto
*element =
dynamic_cast<
TFriendElement
*
>
(friends->At(
fIndex
));
111
fDirector
.SetTree(element ? element->GetTree() :
nullptr
);
112
}
else
{
113
fDirector
.SetTree(
nullptr
);
114
}
115
}
116
117
}
// namespace Internal
118
}
// namespace ROOT
Int_t
int Int_t
Signed integer 4 bytes (int)
Definition
RtypesCore.h:59
Long64_t
long long Long64_t
Portable signed long integer 8 bytes.
Definition
RtypesCore.h:83
TChain.h
TFriendElement.h
TFriendProxy.h
index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Definition
TGWin32VirtualXProxy.cxx:168
TList.h
TTree.h
main
int main(int argc, char *argv[])
Definition
cef_main.cxx:54
ROOT::Internal::TBranchProxyDirector
Definition
TBranchProxyDirector.h:35
ROOT::Internal::TBranchProxyDirector::Attach
void Attach(Detail::TBranchProxy *p)
Attach a TBranchProxy object to this director.
Definition
TBranchProxyDirector.cxx:71
ROOT::Internal::TFriendProxy::fIndex
Int_t fIndex
Index of this tree in the list of friends.
Definition
TFriendProxy.h:25
ROOT::Internal::TFriendProxy::fDirector
TBranchProxyDirector fDirector
Contain pointer to TTree and entry to be read.
Definition
TFriendProxy.h:24
ROOT::Internal::TFriendProxy::GetReadEntry
Long64_t GetReadEntry() const
Return the entry number currently being looked at.
Definition
TFriendProxy.cxx:86
ROOT::Internal::TFriendProxy::TFriendProxy
TFriendProxy()
Definition
TFriendProxy.cxx:28
ROOT::Internal::TFriendProxy::ResetReadEntry
void ResetReadEntry()
Refresh the cached read entry number from the original tree.
Definition
TFriendProxy.cxx:94
ROOT::Internal::TFriendProxy::Update
void Update(TTree *newmain)
Update the address of the underlying tree.
Definition
TFriendProxy.cxx:104
ROOT::Internal::TFriendProxy::fHasIndex
bool fHasIndex
Whether this friend has a TTreeIndex attached.
Definition
TFriendProxy.h:26
TFriendElement
A TFriendElement TF describes a TTree object TF in a file.
Definition
TFriendElement.h:33
TFriendElement::GetTree
virtual TTree * GetTree()
Return pointer to friend TTree.
Definition
TFriendElement.cxx:216
TList::At
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition
TList.cxx:487
TTree
A TTree represents a columnar dataset.
Definition
TTree.h:89
TTree::GetTree
virtual TTree * GetTree() const
Definition
TTree.h:604
TTree::GetListOfFriends
virtual TList * GetListOfFriends() const
Definition
TTree.h:577
ROOT
Definition
EExecutionPolicy.hxx:4
tree
treeplayer
src
TFriendProxy.cxx
ROOTremotes/pull/22321/merge - Reference Guide Generated on Thu Jun 25 2026 10:46:09 (GVA Time) using Doxygen 1.13.2