Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleBrowseProvider.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
13
16#include <ROOT/RPageStorage.hxx>
17
18#include "TClass.h"
19#include "RFieldHolder.hxx"
20
21
22using namespace std::string_literals;
23
24using namespace ROOT::Experimental::Browsable;
25
26
27// ==============================================================================================
28
29/** \class RFieldElement
30\ingroup rbrowser
31\brief Browsing element representing of RField
32\author Sergey Linev <S.Linev@gsi.de>
33\date 2021-03-08
34\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
35*/
36
37class RFieldElement : public RElement {
38protected:
39 std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fNtplSource;
40
41 std::string fParentName;
42
44
45public:
46
47 RFieldElement(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> ntplSource,
48 const std::string &parent_name,
50 : RElement(), fNtplSource(ntplSource), fParentName(parent_name), fFieldId(id) {}
51
52 virtual ~RFieldElement() = default;
53
54 /** Name of RField */
55 std::string GetName() const override
56 {
57 return fNtplSource->GetDescriptor().GetFieldDescriptor(fFieldId).GetFieldName();
58 }
59
60 /** Title of RField */
61 std::string GetTitle() const override
62 {
63 auto &fld = fNtplSource->GetDescriptor().GetFieldDescriptor(fFieldId);
64 return "RField name "s + fld.GetFieldName() + " type "s + fld.GetTypeName();
65 }
66
67 std::unique_ptr<RLevelIter> GetChildsIter() override;
68
69 /** Return class of field - for a moment using RNTuple class as dummy */
70 const TClass *GetClass() const { return TClass::GetClass<ROOT::Experimental::RNTuple>(); }
71
72 std::unique_ptr<RHolder> GetObject() override
73 {
74 return std::make_unique<RFieldHolder>(fNtplSource, fParentName, fFieldId);
75 }
76
78 {
79 auto range = fNtplSource->GetDescriptor().GetFieldIterable(fFieldId);
80 if (range.begin() != range.end()) return kActNone;
81 return kActDraw7;
82 }
83
84 bool IsCapable(EActionKind kind) const override
85 {
86 if ((kind == kActDraw6) || (kind == kActDraw7))
87 return GetDefaultAction() == kActDraw7;
88
89 return false;
90 }
91
92};
93
94// ==============================================================================================
95
96/** \class RNTupleElement
97\ingroup rbrowser
98\brief Browsing element representing of RNTuple
99\author Sergey Linev <S.Linev@gsi.de>
100\date 2021-03-08
101\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
102*/
103
104class RNTupleElement : public RElement {
105protected:
106 std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fNtplSource;
107
108public:
109 RNTupleElement(const std::string &ntplName, const std::string &filename)
110 {
113 fNtplSource->Attach();
114 }
115
116 virtual ~RNTupleElement() = default;
117
118 /** Returns true if no ntuple found */
119 bool IsNull() const { return !fNtplSource; }
120
121 /** Name of NTuple */
122 std::string GetName() const override { return fNtplSource->GetDescriptor().GetName(); }
123
124 /** Title of NTuple */
125 std::string GetTitle() const override { return "RNTuple title"s; }
126
127 /** Create iterator for childs elements if any */
128 std::unique_ptr<RLevelIter> GetChildsIter() override;
129
130 const TClass *GetClass() const { return TClass::GetClass<ROOT::Experimental::RNTuple>(); }
131
132 //EActionKind GetDefaultAction() const override;
133
134 //bool IsCapable(EActionKind) const override;
135};
136
137
138// ==============================================================================================
139
140/** \class RFieldsIterator
141\ingroup rbrowser
142\brief Iterator over RNTuple fields
143\author Sergey Linev <S.Linev@gsi.de>
144\date 2021-03-08
145\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
146*/
147
148
150
151 std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fNtplSource;
152 std::vector<ROOT::Experimental::DescriptorId_t> fFieldIds;
153 std::string fParentName;
154 int fCounter{-1};
155
156public:
157 RFieldsIterator(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> ntplSource,
158 std::vector<ROOT::Experimental::DescriptorId_t> &&ids,
159 const std::string &parent_name = ""s)
160 : fNtplSource(ntplSource), fFieldIds(ids), fParentName(parent_name)
161 {
162 }
163
164 virtual ~RFieldsIterator() = default;
165
166 bool Next() override
167 {
168 return ++fCounter < (int) fFieldIds.size();
169 }
170
171 std::string GetItemName() const override
172 {
173 return fNtplSource->GetDescriptor().GetFieldDescriptor(fFieldIds[fCounter]).GetFieldName();
174 }
175
176 bool CanItemHaveChilds() const override
177 {
178 auto subrange = fNtplSource->GetDescriptor().GetFieldIterable(fFieldIds[fCounter]);
179 return subrange.begin() != subrange.end();
180 }
181
182 /** Create element for the browser */
183 std::unique_ptr<RItem> CreateItem() override
184 {
185
186 int nchilds = 0;
187 for (auto &sub: fNtplSource->GetDescriptor().GetFieldIterable(fFieldIds[fCounter])) { (void) sub; nchilds++; }
188
189 auto &field = fNtplSource->GetDescriptor().GetFieldDescriptor(fFieldIds[fCounter]);
190
191 auto item = std::make_unique<RItem>(field.GetFieldName(), nchilds, nchilds > 0 ? "sap-icon://split" : "sap-icon://e-care");
192
193 item->SetTitle("RField name "s + field.GetFieldName() + " type "s + field.GetTypeName());
194
195 return item;
196 }
197
198 std::shared_ptr<RElement> GetElement() override
199 {
200 return std::make_shared<RFieldElement>(fNtplSource, fParentName, fFieldIds[fCounter]);
201 }
202};
203
204
205std::unique_ptr<RLevelIter> RFieldElement::GetChildsIter()
206{
207 std::vector<ROOT::Experimental::DescriptorId_t> ids;
208
209 for (auto &f : fNtplSource->GetDescriptor().GetFieldIterable(fFieldId))
210 ids.emplace_back(f.GetId());
211
212 if (ids.size() == 0) return nullptr;
213
214 std::string prefix = fParentName;
215 auto &fld = fNtplSource->GetDescriptor().GetFieldDescriptor(fFieldId);
216 prefix.append(fld.GetFieldName());
217 prefix.append(".");
218
219 return std::make_unique<RFieldsIterator>(fNtplSource, std::move(ids), prefix);
220}
221
222std::unique_ptr<RLevelIter> RNTupleElement::GetChildsIter()
223{
224 std::vector<ROOT::Experimental::DescriptorId_t> ids;
225
226 for (auto &f : fNtplSource->GetDescriptor().GetTopLevelFields())
227 ids.emplace_back(f.GetId());
228
229 if (ids.size() == 0) return nullptr;
230 return std::make_unique<RFieldsIterator>(fNtplSource, std::move(ids));
231}
232
233
234// ==============================================================================================
235
236/** \class RNTupleBrowseProvider
237\ingroup rbrowser
238\brief Provider for browsing RNTuple classes
239\author Sergey Linev <S.Linev@gsi.de>
240\date 2021-03-08
241\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
242*/
243
245
246public:
247
249 {
250 RegisterNTupleFunc([](const std::string &tuple_name, const std::string &filename) -> std::shared_ptr<RElement> {
251 auto elem = std::make_shared<RNTupleElement>(tuple_name, filename);
252 return elem->IsNull() ? nullptr : elem;
253 });
254 }
255
257 {
258 RegisterNTupleFunc(nullptr);
259 }
260
262
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
RNTupleBrowseProvider newRNTupleBrowseProvider
#define f(i)
Definition RSha256.hxx:104
XFontStruct * id
Definition TGX11.cxx:109
Browsing element representing of RField.
EActionKind GetDefaultAction() const override
Get default action.
bool IsCapable(EActionKind kind) const override
Check if want to perform action.
ROOT::Experimental::DescriptorId_t fFieldId
virtual ~RFieldElement()=default
std::shared_ptr< ROOT::Experimental::Detail::RPageSource > fNtplSource
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.
RFieldElement(std::shared_ptr< ROOT::Experimental::Detail::RPageSource > ntplSource, const std::string &parent_name, const ROOT::Experimental::DescriptorId_t id)
Iterator over RNTuple fields.
std::unique_ptr< RItem > CreateItem() override
Create element for the browser.
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::Experimental::Detail::RPageSource > fNtplSource
bool Next() override
Shift to next entry.
virtual ~RFieldsIterator()=default
RFieldsIterator(std::shared_ptr< ROOT::Experimental::Detail::RPageSource > ntplSource, std::vector< ROOT::Experimental::DescriptorId_t > &&ids, const std::string &parent_name=""s)
std::vector< ROOT::Experimental::DescriptorId_t > fFieldIds
std::string GetItemName() const override
Returns current entry name
bool CanItemHaveChilds() const override
Returns true if current item can have childs.
Provider for browsing RNTuple classes.
Browsing element representing of RNTuple.
std::string GetName() const override
Name of NTuple.
std::unique_ptr< RLevelIter > GetChildsIter() override
Create iterator for childs elements if any.
std::shared_ptr< ROOT::Experimental::Detail::RPageSource > fNtplSource
virtual ~RNTupleElement()=default
bool IsNull() const
Returns true if no ntuple found.
RNTupleElement(const std::string &ntplName, const std::string &filename)
std::string GetTitle() const override
Title of NTuple.
const TClass * GetClass() const
Basic element of browsable hierarchy.
Definition RElement.hxx:33
EActionKind
Possible actions on double-click.
Definition RElement.hxx:49
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:55
@ kActDraw6
can be drawn inside ROOT6 canvas
Definition RElement.hxx:54
Iterator over single level hierarchy like any array, keys list, ...
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:36
void RegisterNTupleFunc(BrowseNTupleFunc_t func)
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const RNTupleReadOptions &options=RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
Common user-tunable settings for reading ntuples.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.