Logo ROOT  
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
13Concrete 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
23
24namespace ROOT {
25namespace Internal {
26
27/////////////////////////////////////////////////////////////////////////////
28
29TFriendProxy::TFriendProxy() : fDirector(nullptr,-1), fIndex(-1)
30{
31}
32
33 /////////////////////////////////////////////////////////////////////////////
34 /// Constructor.
35
37 fDirector(nullptr,-1), fIndex(index)
38 {
39
40 auto getFriendAtIdx = [](TTree *dataset, Int_t frIdx) -> TTree * {
41 if (!dataset)
42 return nullptr;
43
44 auto *friends = dataset->GetListOfFriends();
45 if (!friends)
46 return nullptr;
47
48 auto *friendAtIdx = friends->At(frIdx);
49 if (!friendAtIdx)
50 return nullptr;
51
52 auto *frEl = dynamic_cast<TFriendElement *>(friendAtIdx);
53 if (!frEl)
54 return nullptr;
55
56 return frEl->GetTree();
57 };
58
59 // The list of friends needs to be accessed via GetTree()->GetListOfFriends()
60 // (and not directly GetListOfFriends()), otherwise when `main` is a TChain we
61 // might not recover the list correctly (see #6993 for the TTreeReader issue
62 // and #6741 for a more complete discussion/explanation).
63 if (main) {
64 // But, we do need to get the top-level friend from the dataset (TTree or TChain)
65 // to check if it has an index
66 auto *topLevelFriendTree = getFriendAtIdx(main, fIndex);
67 if (topLevelFriendTree) {
68 fHasIndex = (topLevelFriendTree->GetTreeIndex() != nullptr);
69 }
70
71 // Then, point the director to the current tree from the friend that is being read
72 auto *localFriendTree = getFriendAtIdx(main->GetTree(), fIndex);
73 if (localFriendTree) {
74 fDirector.SetTree(localFriendTree);
75 // If we still do not think the friend has a TTreeIndex, retry for good measure
76 if (!fHasIndex)
77 fHasIndex = (localFriendTree->GetTreeIndex() != nullptr);
78 }
79 }
80
81 director->Attach(this);
82 }
83
84 /////////////////////////////////////////////////////////////////////////////
85 /// Return the entry number currently being looked at.
86
88 {
89 return fDirector.GetReadEntry();
90 }
91
92 /////////////////////////////////////////////////////////////////////////////
93 /// Refresh the cached read entry number from the original tree.
94
96 {
97 // The 2nd call to GetTree is to insure we get the 'local' tree's entry in the case of a
98 // chain.
100 }
101
102 //////////////////////////////////////////////////////////////////////////////
103 /// Update the address of the underlying tree.
104
106 {
107 if (!newmain)
108 return;
109
110 if (auto friends = newmain->GetTree()->GetListOfFriends()) {
111 auto *element = dynamic_cast<TFriendElement *>(friends->At(fIndex));
112 fDirector.SetTree(element ? element->GetTree() : nullptr);
113 } else {
114 fDirector.SetTree(nullptr);
115 }
116 }
117
118} // namespace Internal
119} // namespace ROOT
int main()
Definition Prototype.cxx:12
long long Long64_t
Definition RtypesCore.h:69
#define ClassImp(name)
Definition Rtypes.h:382
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
Long64_t GetReadEntry() const
Return the current 'local' entry number; i.e.
void SetReadEntry(Long64_t entry)
Move to a new entry to read entry is the 'local' entry number; i.e.
TTree * SetTree(TTree *newtree)
Set the BranchProxy to be looking at a new tree.
void Attach(Detail::TBranchProxy *p)
Attach a TBranchProxy object to this director.
Int_t fIndex
Index of this tree in the list of friends.
TBranchProxyDirector fDirector
Contain pointer to TTree and entry to be read.
Long64_t GetReadEntry() const
Return the entry number currently being looked at.
void ResetReadEntry()
Refresh the cached read entry number from the original tree.
void Update(TTree *newmain)
Update the address of the underlying tree.
bool fHasIndex
Whether this friend has a TTreeIndex attached.
A TFriendElement TF describes a TTree object TF in a file.
virtual TTree * GetTree()
Return pointer to friend TTree.
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual Long64_t GetReadEntry() const
Definition TTree.h:549
virtual TTree * GetTree() const
Definition TTree.h:557
virtual TList * GetListOfFriends() const
Definition TTree.h:530
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...