Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleBrowseProvider.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2025, 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
14
18
19#include "TClass.h"
20#include "RFieldHolder.hxx"
21
23
24namespace ROOT::Experimental {
25class TObjectDrawable;
26}
27using namespace std::string_literals;
28using namespace ROOT::Browsable;
29
30// ==============================================================================================
31/** \class RTreeMapElement
32\ingroup rbrowser
33\brief Browsing element representing TreeMap visualization for RNTuple
34\author Patryk Pilichowski
35\date 2025
36\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
37welcome!
38*/
39
40class RTreeMapElement : public RElement {
41protected:
42 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
43 std::string fFileName;
44
45public:
46 RTreeMapElement(std::shared_ptr<ROOT::RNTupleReader> ntplReader, const std::string &fileName = "")
48 {
49 }
50
51 ~RTreeMapElement() override = default;
52
53 /** Name of TreeMap visualization */
54 std::string GetName() const override { return "TreeMap"; }
55
56 /** Title of TreeMap visualization */
57 std::string GetTitle() const override { return "TreeMap visualization of RNTuple structure and disk usage"; }
58
59 /** No children for TreeMap visualization */
60 std::unique_ptr<RLevelIter> GetChildsIter() override { return nullptr; }
61
62 /** Return class of RNTuple for consistency */
63 const TClass *GetClass() const { return TClass::GetClass<ROOT::RNTuple>(); }
64
65 /** Return holder with visualization data */
66 std::unique_ptr<RHolder> GetObject() override
67 {
68 return std::make_unique<RVisualizationHolder>(fNtplReader, fFileName, fNtplReader->GetDescriptor().GetName());
69 }
70
71 /** Default action is to draw the treemap */
72 EActionKind GetDefaultAction() const override { return kActDraw7; }
73
74 /** Check if visualization is capable of being drawn */
75 bool IsCapable(EActionKind kind) const override { return kind == kActDraw6 || kind == kActDraw7; }
76
77 /** Create item with TreeMap icon */
78 std::unique_ptr<RItem> CreateItem() const override
79 {
80 auto item = std::make_unique<RNTupleItem>(GetName(), 0, "sap-icon://Chart-Tree-Map");
81 item->SetTitle(GetTitle());
82 return item;
83 }
84
85 /** Not expandable by default */
86 bool IsFolder() const override { return false; }
87
88 /** Set filename for treemap creation */
89 void SetFileName(const std::string &fileName) { fFileName = fileName; }
90};
91
92// ==============================================================================================
93/** \class RVisualizationElement
94\ingroup rbrowser
95\brief Browsing element representing visualization folder for RNTuple
96\author Patryk Pilichowski
97\date 2025
98\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
99welcome!
100*/
101
103protected:
104 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
105 std::string fFileName;
106
107public:
108 RVisualizationElement(std::shared_ptr<ROOT::RNTupleReader> ntplReader, const std::string &fileName = "")
110 {
111 }
112
113 ~RVisualizationElement() override = default;
114
115 /** Name of visualization folder */
116 std::string GetName() const override { return "Visualization"; }
117
118 /** Title of visualization folder */
119 std::string GetTitle() const override { return "Visualization tools and options for RNTuple data"; }
120
121 /** Create iterator for visualization children */
122 std::unique_ptr<RLevelIter> GetChildsIter() override;
123
124 /** Return class of RNTuple for consistency */
125 const TClass *GetClass() const { return TClass::GetClass<ROOT::RNTuple>(); }
126
127 /** No direct object for folder */
128 std::unique_ptr<RHolder> GetObject() override { return nullptr; }
129
130 /** Default action is none for folder */
131 EActionKind GetDefaultAction() const override { return kActNone; }
132
133 /** Create item with visualization folder icon */
134 std::unique_ptr<RItem> CreateItem() const override
135 {
136 auto item =
137 std::make_unique<RNTupleItem>(GetName(), 1, "sap-icon://show", RNTupleItem::ECategory::kVisualization);
138 item->SetTitle(GetTitle());
139 return item;
140 }
141
142 /** This is a folder */
143 bool IsFolder() const override { return true; }
144
145 /** Set filename for child elements */
146 void SetFileName(const std::string &fileName) { fFileName = fileName; }
147};
148
149// ==============================================================================================
150/** \class RVisualizationIterator
151\ingroup rbrowser
152\brief Iterator over visualization options
153\author Patryk Pilichowski
154\date 2025
155\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
156welcome!
157*/
158
160 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
161 std::string fFileName;
162 int fCounter{-1};
164
165public:
166 RVisualizationIterator(std::shared_ptr<ROOT::RNTupleReader> ntplReader, const std::string &fileName = "")
167 : fNtplReader(ntplReader), fFileName(fileName)
168 {
169 }
170
171 ~RVisualizationIterator() override = default;
172
173 bool Next() override { return ++fCounter < fTotalItems; }
174
175 std::string GetItemName() const override
176 {
177 if (fCounter == 0) {
178 return "TreeMap";
179 }
180 return "";
181 }
182
183 bool CanItemHaveChilds() const override { return false; }
184
185 /** Create item for the browser */
186 std::unique_ptr<RItem> CreateItem() override
187 {
188 if (fCounter == 0) {
189 auto item = std::make_unique<RNTupleItem>("TreeMap", 0, "sap-icon://Chart-Tree-Map");
190 item->SetTitle("TreeMap visualization of RNTuple structure and disk usage");
191 return item;
192 }
193 return nullptr;
194 }
195
196 std::shared_ptr<RElement> GetElement() override
197 {
198 if (fCounter == 0) {
199 return std::make_shared<RTreeMapElement>(fNtplReader, fFileName);
200 }
201 return nullptr;
202 }
203};
204
205std::unique_ptr<RLevelIter> RVisualizationElement::GetChildsIter()
206{
207 return std::make_unique<RVisualizationIterator>(fNtplReader, fFileName);
208}
209
210// ==============================================================================================
211
212class RFieldElement : public RElement {
213protected:
214 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
215 std::string fParentName;
217 std::string fDisplayName;
218
219public:
220 RFieldElement(std::shared_ptr<ROOT::RNTupleReader> ntplReader, const std::string &parent_name,
221 const ROOT::DescriptorId_t id, const std::string &displayName)
223 {
224 }
225
226 ~RFieldElement() override = default;
227
228 /** Name of RField */
229 std::string GetName() const override
230 {
231 return fNtplReader->GetDescriptor().GetFieldDescriptor(fFieldId).GetFieldName();
232 }
233
234 /** Title of RField */
235 std::string GetTitle() const override
236 {
237 auto &fld = fNtplReader->GetDescriptor().GetFieldDescriptor(fFieldId);
238 return "RField name "s + fld.GetFieldName() + " type "s + fld.GetTypeName();
239 }
240
241 std::unique_ptr<RLevelIter> GetChildsIter() override;
242
243 /** Return class of field - for a moment using RNTuple class as dummy */
244 const TClass *GetClass() const { return TClass::GetClass<ROOT::RNTuple>(); }
245
246 std::unique_ptr<RHolder> GetObject() override
247 {
248 return std::make_unique<RFieldHolder>(fNtplReader, fParentName, fFieldId, fDisplayName);
249 }
250
252 {
253 auto range = fNtplReader->GetDescriptor().GetFieldIterable(fFieldId);
254 if (range.begin() != range.end())
255 return kActNone;
256 return kActDraw7;
257 }
258
259 bool IsCapable(EActionKind kind) const override
260 {
261 if ((kind == kActDraw6) || (kind == kActDraw7))
262 return GetDefaultAction() == kActDraw7;
263
264 return false;
265 }
266};
267
268// ==============================================================================================
269
270/** \class RNTupleElement
271\ingroup rbrowser
272\brief Browsing element representing of RNTuple
273\author Sergey Linev <S.Linev@gsi.de>
274\date 2021-03-08
275\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
276welcome!
277*/
278
279class RNTupleElement : public RElement {
280protected:
281 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
282 std::string fFileName;
283
284public:
285 RNTupleElement(const std::string &ntplName, const std::string &filename) : fFileName(filename)
286 {
288 }
289
290 ~RNTupleElement() override = default;
291
292 /** Returns true if no ntuple found */
293 bool IsNull() const { return !fNtplReader; }
294
295 /** Name of NTuple */
296 std::string GetName() const override { return fNtplReader->GetDescriptor().GetName(); }
297
298 /** Title of NTuple */
299 std::string GetTitle() const override { return "RNTuple title"s; }
300
301 /** Get the filename */
302 const std::string &GetFileName() const { return fFileName; }
303
304 /** Create iterator for childs elements if any */
305 std::unique_ptr<RLevelIter> GetChildsIter() override;
306
307 const TClass *GetClass() const { return TClass::GetClass<ROOT::RNTuple>(); }
308
309 std::unique_ptr<RItem> CreateItem() const override
310 {
311 auto item = std::make_unique<RNTupleItem>(GetName(), -1, "sap-icon://table-chart");
312 item->SetTitle(GetTitle());
313 return item;
314 }
315};
316
317// ==============================================================================================
318
319/** \class RNTupleIterator
320\ingroup rbrowser
321\brief Iterator over RNTuple fields & visualization entry
322\author Sergey Linev <S.Linev@gsi.de>
323\date 2021-03-08
324\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
325welcome!
326*/
327
329 std::shared_ptr<ROOT::RNTupleReader> fNtplReader;
330 std::vector<ROOT::DescriptorId_t> fProvidedFieldIds;
331 std::vector<ROOT::DescriptorId_t> fActualFieldIds;
332 std::string fParentName;
333 std::string fFileName;
334 int fCounter{-1};
335 bool fHasVisualization{false};
337
338public:
339 RNTupleIterator(std::shared_ptr<ROOT::RNTupleReader> ntplReader, std::vector<ROOT::DescriptorId_t> &&ids,
340 const std::string &parent_name = "", bool includeVisualization = false,
341 const std::string &fileName = "")
345 fFileName(fileName),
347 {
348 const auto &desc = fNtplReader->GetDescriptor();
349 fActualFieldIds.reserve(fProvidedFieldIds.size());
350 for (auto fid : fProvidedFieldIds) {
352 }
353
355 if (fHasVisualization) {
356 fTotalItems++;
357 }
358 }
359
360 ~RNTupleIterator() override = default;
361
362 bool Next() override { return ++fCounter < fTotalItems; }
363
364 std::string GetItemName() const override
365 {
366 if (fHasVisualization && fCounter == 0) {
367 return "Visualization";
368 }
370 return fNtplReader->GetDescriptor().GetFieldDescriptor(fProvidedFieldIds[fieldIndex]).GetFieldName();
371 }
372
373 bool CanItemHaveChilds() const override
374 {
375 if (fHasVisualization && fCounter == 0) {
376 return true;
377 }
379 auto subrange = fNtplReader->GetDescriptor().GetFieldIterable(fActualFieldIds[fieldIndex]);
380 return subrange.begin() != subrange.end();
381 }
382
383 /** Create element for the browser */
384 std::unique_ptr<RItem> CreateItem() override
385 {
386 if (fHasVisualization && fCounter == 0) {
387 auto item = std::make_unique<RNTupleItem>("Visualization", 1, "sap-icon://show",
388 RNTupleItem::ECategory::kVisualization);
389 item->SetTitle("Visualization tools and options for RNTuple data");
390 return item;
391 }
392
394 int nchilds = 0;
395 for (auto &sub : fNtplReader->GetDescriptor().GetFieldIterable(fActualFieldIds[fieldIndex])) {
396 (void)sub;
397 nchilds++;
398 }
399
400 const auto &field = fNtplReader->GetDescriptor().GetFieldDescriptor(fProvidedFieldIds[fieldIndex]);
401
402 auto item = std::make_unique<RNTupleItem>(field.GetFieldName(), nchilds,
403 nchilds > 0 ? "sap-icon://split" : "sap-icon://e-care");
404
405 item->SetTitle("RField name "s + field.GetFieldName() + " type "s + field.GetTypeName());
406 return item;
407 }
408
409 std::shared_ptr<RElement> GetElement() override
410 {
411 if (fHasVisualization && fCounter == 0) {
412 return std::make_shared<RVisualizationElement>(fNtplReader, fFileName);
413 }
414
416 const auto name = fNtplReader->GetDescriptor().GetFieldDescriptor(fProvidedFieldIds[fieldIndex]).GetFieldName();
417 return std::make_shared<RFieldElement>(fNtplReader, fParentName, fActualFieldIds[fieldIndex], name);
418 }
419};
420
421std::unique_ptr<RLevelIter> RFieldElement::GetChildsIter()
422{
423 std::vector<ROOT::DescriptorId_t> ids;
424 std::string prefix;
425
426 const auto &desc = fNtplReader->GetDescriptor();
427 for (auto &f : fNtplReader->GetDescriptor().GetFieldIterable(ROOT::Internal::GetNextBrowsableField(fFieldId, desc)))
428 ids.emplace_back(f.GetId());
429
430 if (ids.size() == 0)
431 return nullptr;
432
433 prefix = fParentName;
434 const auto &fld = desc.GetFieldDescriptor(fFieldId);
435 prefix.append(fld.GetFieldName());
436 prefix.append(".");
437
438 return std::make_unique<RNTupleIterator>(fNtplReader, std::move(ids), prefix);
439}
440
441std::unique_ptr<RLevelIter> RNTupleElement::GetChildsIter()
442{
443 std::vector<ROOT::DescriptorId_t> ids;
444
445 for (auto &f : fNtplReader->GetDescriptor().GetTopLevelFields())
446 ids.emplace_back(f.GetId());
447
448 if (ids.size() == 0)
449 return nullptr;
450
451 return std::make_unique<RNTupleIterator>(fNtplReader, std::move(ids), "", true, fFileName);
452}
453
454// ==============================================================================================
455
456/** \class RNTupleBrowseProvider
457\ingroup rbrowser
458\brief Provider for browsing RNTuple classes
459\author Sergey Linev <S.Linev@gsi.de>
460\date 2021-03-08
461\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is
462welcome!
463*/
464
466
467public:
469 {
470 RegisterNTupleFunc([](const std::string &tuple_name, const std::string &filename) -> std::shared_ptr<RElement> {
471 auto elem = std::make_shared<RNTupleElement>(tuple_name, filename);
472 return elem->IsNull() ? nullptr : elem;
473 });
474 }
475
477
RNTupleBrowseProvider newRNTupleBrowseProvider
#define f(i)
Definition RSha256.hxx:104
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
char name[80]
Definition TGX11.cxx:110
EActionKind GetDefaultAction() const override
Get default action.
bool IsCapable(EActionKind kind) const override
Check if want to perform action.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
RFieldElement(std::shared_ptr< ROOT::RNTupleReader > ntplReader, const std::string &parent_name, const ROOT::DescriptorId_t id, const std::string &displayName)
std::unique_ptr< RHolder > GetObject() override
Access object.
std::string GetTitle() const override
Title of RField.
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for childs elements if any.
const TClass * GetClass() const
Return class of field - for a moment using RNTuple class as dummy.
std::string GetName() const override
Name of RField.
ROOT::DescriptorId_t fFieldId
~RFieldElement() override=default
Provider for browsing RNTuple classes.
Browsing element representing of RNTuple.
std::string GetName() const override
Name of NTuple.
~RNTupleElement() override=default
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for childs elements if any.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
const std::string & GetFileName() const
Get the filename.
bool IsNull() const
Returns true if no ntuple found.
std::unique_ptr< RItem > CreateItem() const override
Returns item with element description.
RNTupleElement(const std::string &ntplName, const std::string &filename)
std::string GetTitle() const override
Title of NTuple.
const TClass * GetClass() const
Iterator over RNTuple fields & visualization entry.
std::unique_ptr< RItem > CreateItem() override
Create element for the browser.
std::vector< ROOT::DescriptorId_t > fProvidedFieldIds
~RNTupleIterator() override=default
RNTupleIterator(std::shared_ptr< ROOT::RNTupleReader > ntplReader, std::vector< ROOT::DescriptorId_t > &&ids, const std::string &parent_name="", bool includeVisualization=false, const std::string &fileName="")
std::string GetItemName() const override
Returns current entry name
bool Next() override
Shift to next entry.
bool CanItemHaveChilds() const override
Returns true if current item can have childs.
std::vector< ROOT::DescriptorId_t > fActualFieldIds
std::shared_ptr< RElement > GetElement() override
Create RElement for current entry - may take much time to load object or open file.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
Basic element of browsable hierarchy.
Definition RElement.hxx:34
EActionKind
Possible actions on double-click.
Definition RElement.hxx:50
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:55
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:56
Iterator over single level hierarchy like any array, keys list, ...
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:37
void RegisterNTupleFunc(BrowseNTupleFunc_t func)
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
const_iterator begin() const
const_iterator end() const
Browsing element representing TreeMap visualization for RNTuple.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
~RTreeMapElement() override=default
bool IsCapable(EActionKind kind) const override
Check if visualization is capable of being drawn.
std::string GetTitle() const override
Title of TreeMap visualization.
void SetFileName(const std::string &fileName)
Set filename for treemap creation.
std::unique_ptr< RLevelIter > GetChildsIter() override
No children for TreeMap visualization.
std::string GetName() const override
Name of TreeMap visualization.
std::unique_ptr< RItem > CreateItem() const override
Create item with TreeMap icon.
EActionKind GetDefaultAction() const override
Default action is to draw the treemap.
RTreeMapElement(std::shared_ptr< ROOT::RNTupleReader > ntplReader, const std::string &fileName="")
const TClass * GetClass() const
Return class of RNTuple for consistency.
std::unique_ptr< RHolder > GetObject() override
Return holder with visualization data.
bool IsFolder() const override
Not expandable by default.
Browsing element representing visualization folder for RNTuple.
std::unique_ptr< RItem > CreateItem() const override
Create item with visualization folder icon.
bool IsFolder() const override
This is a folder.
~RVisualizationElement() override=default
std::string GetName() const override
Name of visualization folder.
void SetFileName(const std::string &fileName)
Set filename for child elements.
RVisualizationElement(std::shared_ptr< ROOT::RNTupleReader > ntplReader, const std::string &fileName="")
EActionKind GetDefaultAction() const override
Default action is none for folder.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
std::string GetTitle() const override
Title of visualization folder.
std::unique_ptr< RHolder > GetObject() override
No direct object for folder.
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for visualization children.
const TClass * GetClass() const
Return class of RNTuple for consistency.
Iterator over visualization options.
std::shared_ptr< RElement > GetElement() override
Create RElement for current entry - may take much time to load object or open file.
bool Next() override
Shift to next entry.
bool CanItemHaveChilds() const override
Returns true if current item can have childs.
std::shared_ptr< ROOT::RNTupleReader > fNtplReader
std::string GetItemName() const override
Returns current entry name
RVisualizationIterator(std::shared_ptr< ROOT::RNTupleReader > ntplReader, const std::string &fileName="")
std::unique_ptr< RItem > CreateItem() override
Create item for the browser.
~RVisualizationIterator() override=default
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
DescriptorId_t GetNextBrowsableField(DescriptorId_t fieldId, const RNTupleDescriptor &desc)
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.