Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBranchBrowseProvider.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
12
13#include "TLeafProvider.hxx"
14
15#include "TTree.h"
16#include "TNtuple.h"
17#include "TBranch.h"
18#include "TLeaf.h"
19#include "TBranchElement.h"
20#include "TBranchBrowsable.h"
21
22using namespace ROOT::Browsable;
23using namespace std::string_literals;
24
25
27public:
28 TTreeBrowsingElement(std::unique_ptr<RHolder> &obj) : TObjectElement(obj) {}
29
30 /** Check if want to perform action */
31 bool IsCapable(EActionKind action) const override
32 {
33 return (action == kActTree) || (action == kActDraw6) || (action == kActDraw7);
34 }
35
36 /** Get default action */
38 {
39 return GetDrawExpr().empty() ? kActTree : kActDraw6;
40 }
41
42 virtual std::string GetDrawExpr() const { return ""s; }
43
44 std::string GetContent(const std::string &kind) override
45 {
46 if (kind == "tree"s)
47 return GetDrawExpr();
48
49 return TObjectElement::GetContent(kind);
50 }
51
52};
53
54
55////////////////////////////////////////////////////////////
56/// Representing TLeaf in browsables
57
59
60public:
61 TBrLeafElement(std::unique_ptr<RHolder> &leaf) : TTreeBrowsingElement(leaf) {}
62
63 Long64_t GetSize() const override
64 {
65 auto leaf = fObject->Get<TLeaf>();
66 if (!leaf)
67 return -1;
68
69 if (!leaf->GetBranch())
70 return -1;
71
72 return leaf->GetBranch()->GetTotalSize();
73 }
74
75 std::string GetDrawExpr() const override
76 {
77 auto leaf = fObject->Get<TLeaf>();
78
79 TLeafProvider provider;
80 TString expr, name;
81
82 if (provider.GetDrawExpr(leaf, expr, name))
83 return expr.Data();
84
85 return ""s;
86 }
87
88};
89
90////////////////////////////////////////////////////////////
91/// Representing TBranch in browsables
92
94
95public:
96 TBrElement(std::unique_ptr<RHolder> &br) : TTreeBrowsingElement(br) {}
97
98 Long64_t GetSize() const override
99 {
100 auto br = fObject->Get<TBranch>();
101 return br ? br->GetTotalSize() : -1;
102 }
103
104 std::string GetDrawExpr() const override
105 {
106 auto br = fObject->Get<TBranch>();
107 auto elem = fObject->Get<TBranchElement>();
108
109 TLeafProvider provider;
110 TString expr, name;
111
112 if (provider.GetDrawExpr(elem, expr, name))
113 return expr.Data();
114
115 if (provider.GetDrawExpr(br, expr, name))
116 return expr.Data();
117
118 return ""s;
119 }
120
121};
122
123////////////////////////////////////////////////////////////
124/// Representing TVirtualBranchBrowsable in browsables
125
127
128public:
129 TBrBrowsableElement(std::unique_ptr<RHolder> &br) : TTreeBrowsingElement(br) {}
130
131 virtual ~TBrBrowsableElement() = default;
132
133 int GetNumChilds() override
134 {
135 auto br = fObject->Get<TVirtualBranchBrowsable>();
136 return br && br->GetLeaves() ? br->GetLeaves()->GetSize() : 0;
137 }
138
139 /** Create iterator for childs elements if any */
140 std::unique_ptr<RLevelIter> GetChildsIter() override
141 {
142 auto br = fObject->Get<TVirtualBranchBrowsable>();
143 if (br && br->GetLeaves())
144 return GetCollectionIter(br->GetLeaves());
145 return nullptr;
146 }
147
148 std::string GetDrawExpr() const override
149 {
150 auto browsable = fObject->Get<TVirtualBranchBrowsable>();
151
152 TLeafProvider provider;
153 TString expr, name;
154
155 if (provider.GetDrawExpr(browsable, expr, name))
156 return expr.Data();
157
158 return ""s;
159 }
160
161};
162
163// ==============================================================================================
164
165////////////////////////////////////////////////////////////
166/// Representing TTree in browsables
167
169
170public:
171 TTreeElement(std::unique_ptr<RHolder> &br) : TObjectElement(br) {}
172
173 Long64_t GetSize() const override
174 {
175 auto tr = dynamic_cast<const TTree *>(CheckObject());
176 return tr ? tr->GetTotBytes() : -1;
177 }
178
179 /** Get default action */
181 {
182 return kActTree;
183 }
184
185 /** Check if want to perform action */
186 bool IsCapable(EActionKind action) const override
187 {
188 return action == kActTree;
189 }
190
191};
192
193// ==============================================================================================
194
196
197public:
199 {
200 RegisterBrowse(TLeaf::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
201 return std::make_shared<TBrLeafElement>(object);
202 });
203 RegisterBrowse(TBranch::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
204 return std::make_shared<TBrElement>(object);
205 });
206 RegisterBrowse(TBranchElement::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
207 return std::make_shared<TBrElement>(object);
208 });
209 RegisterBrowse(TVirtualBranchBrowsable::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
210 return std::make_shared<TBrBrowsableElement>(object);
211 });
212 RegisterBrowse(TTree::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
213 return std::make_shared<TTreeElement>(object);
214 });
215 RegisterBrowse(TNtuple::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
216 return std::make_shared<TTreeElement>(object);
217 });
218 }
219
long long Long64_t
Definition RtypesCore.h:69
TBranchBrowseProvider newTBranchBrowseProvider
char name[80]
Definition TGX11.cxx:110
EActionKind
Possible actions on double-click.
Definition RElement.hxx:50
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:55
@ kActTree
can be shown in tree viewer
Definition RElement.hxx:58
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:56
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:37
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
Access to TObject basic properties for RBrowsable.
static std::unique_ptr< RLevelIter > GetCollectionIter(const TCollection *)
Creates iterator for TCollection object.
std::unique_ptr< RHolder > fObject
virtual const TObject * CheckObject() const
Check if object still exists.
Representing TVirtualBranchBrowsable in browsables.
std::string GetDrawExpr() const override
TBrBrowsableElement(std::unique_ptr< RHolder > &br)
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for childs elements if any.
int GetNumChilds() override
Returns number of childs By default creates iterator and iterates over all items.
virtual ~TBrBrowsableElement()=default
Representing TBranch in browsables.
Long64_t GetSize() const override
TBrElement(std::unique_ptr< RHolder > &br)
std::string GetDrawExpr() const override
Representing TLeaf in browsables.
Long64_t GetSize() const override
std::string GetDrawExpr() const override
TBrLeafElement(std::unique_ptr< RHolder > &leaf)
A Branch for the case of an object.
static TClass * Class()
A TTree is a list of TBranches.
Definition TBranch.h:93
static TClass * Class()
Long64_t GetTotalSize(Option_t *option="") const
Return total number of bytes in the branch (including current buffer)
Definition TBranch.cxx:2201
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Provider for drawing of branches / leafs in the TTree.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
TBranch * GetBranch() const
Definition TLeaf.h:116
static TClass * Class()
static TClass * Class()
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
bool IsCapable(EActionKind action) const override
Check if want to perform action.
virtual std::string GetDrawExpr() const
EActionKind GetDefaultAction() const override
Get default action.
std::string GetContent(const std::string &kind) override
Returns element content, depends from kind.
TTreeBrowsingElement(std::unique_ptr< RHolder > &obj)
Representing TTree in browsables.
EActionKind GetDefaultAction() const override
Get default action.
Long64_t GetSize() const override
TTreeElement(std::unique_ptr< RHolder > &br)
bool IsCapable(EActionKind action) const override
Check if want to perform action.
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual Long64_t GetTotBytes() const
Definition TTree.h:556
static TClass * Class()
TVirtualBranchBrowsable is a base class (not really abstract, but useless by itself) for helper objec...
TList * GetLeaves() const
Return list of leaves. If not set up yet we'll create them.
static TClass * Class()