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->GetSharedDescriptorGuard()->GetFieldDescriptor(fFieldId).GetFieldName();
58 }
59
60 /** Title of RField */
61 std::string GetTitle() const override
62 {
63 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
64 auto &fld = descriptorGuard->GetFieldDescriptor(fFieldId);
65 return "RField name "s + fld.GetFieldName() + " type "s + fld.GetTypeName();
66 }
67
68 std::unique_ptr<RLevelIter> GetChildsIter() override;
69
70 /** Return class of field - for a moment using RNTuple class as dummy */
71 const TClass *GetClass() const { return TClass::GetClass<ROOT::Experimental::RNTuple>(); }
72
73 std::unique_ptr<RHolder> GetObject() override
74 {
75 return std::make_unique<RFieldHolder>(fNtplSource, fParentName, fFieldId);
76 }
77
79 {
80 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
81 auto range = descriptorGuard->GetFieldIterable(fFieldId);
82 if (range.begin() != range.end()) return kActNone;
83 return kActDraw7;
84 }
85
86 bool IsCapable(EActionKind kind) const override
87 {
88 if ((kind == kActDraw6) || (kind == kActDraw7))
89 return GetDefaultAction() == kActDraw7;
90
91 return false;
92 }
93
94};
95
96// ==============================================================================================
97
98/** \class RNTupleElement
99\ingroup rbrowser
100\brief Browsing element representing of RNTuple
101\author Sergey Linev <S.Linev@gsi.de>
102\date 2021-03-08
103\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
104*/
105
106class RNTupleElement : public RElement {
107protected:
108 std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fNtplSource;
109
110public:
111 RNTupleElement(const std::string &ntplName, const std::string &filename)
112 {
115 fNtplSource->Attach();
116 }
117
118 virtual ~RNTupleElement() = default;
119
120 /** Returns true if no ntuple found */
121 bool IsNull() const { return !fNtplSource; }
122
123 /** Name of NTuple */
124 std::string GetName() const override { return fNtplSource->GetSharedDescriptorGuard()->GetName(); }
125
126 /** Title of NTuple */
127 std::string GetTitle() const override { return "RNTuple title"s; }
128
129 /** Create iterator for childs elements if any */
130 std::unique_ptr<RLevelIter> GetChildsIter() override;
131
132 const TClass *GetClass() const { return TClass::GetClass<ROOT::Experimental::RNTuple>(); }
133
134 std::unique_ptr<RItem> CreateItem() const override
135 {
136 auto item = std::make_unique<RItem>(GetName(), -1, "sap-icon://table-chart");
137 item->SetTitle(GetTitle());
138 return item;
139 }
140
141 //EActionKind GetDefaultAction() const override;
142
143 //bool IsCapable(EActionKind) const override;
144};
145
146
147// ==============================================================================================
148
149/** \class RFieldsIterator
150\ingroup rbrowser
151\brief Iterator over RNTuple fields
152\author Sergey Linev <S.Linev@gsi.de>
153\date 2021-03-08
154\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
155*/
156
157
159
160 std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fNtplSource;
161 std::vector<ROOT::Experimental::DescriptorId_t> fFieldIds;
162 std::string fParentName;
163 int fCounter{-1};
164
165public:
166 RFieldsIterator(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> ntplSource,
167 std::vector<ROOT::Experimental::DescriptorId_t> &&ids,
168 const std::string &parent_name = ""s)
169 : fNtplSource(ntplSource), fFieldIds(ids), fParentName(parent_name)
170 {
171 }
172
173 virtual ~RFieldsIterator() = default;
174
175 bool Next() override
176 {
177 return ++fCounter < (int) fFieldIds.size();
178 }
179
180 std::string GetItemName() const override
181 {
182 return fNtplSource->GetSharedDescriptorGuard()->GetFieldDescriptor(fFieldIds[fCounter]).GetFieldName();
183 }
184
185 bool CanItemHaveChilds() const override
186 {
187 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
188 auto subrange = descriptorGuard->GetFieldIterable(fFieldIds[fCounter]);
189 return subrange.begin() != subrange.end();
190 }
191
192 /** Create element for the browser */
193 std::unique_ptr<RItem> CreateItem() override
194 {
195
196 int nchilds = 0;
197 std::string fieldName;
198 std::string typeName;
199
200 {
201 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
202 for (auto &sub : descriptorGuard->GetFieldIterable(fFieldIds[fCounter])) {
203 (void)sub;
204 nchilds++;
205 }
206
207 auto &field = descriptorGuard->GetFieldDescriptor(fFieldIds[fCounter]);
208 fieldName = field.GetFieldName();
209 typeName = field.GetTypeName();
210 }
211
212 auto item = std::make_unique<RItem>(fieldName, nchilds, nchilds > 0 ? "sap-icon://split" : "sap-icon://e-care");
213
214 item->SetTitle("RField name "s + fieldName + " type "s + typeName);
215
216 return item;
217 }
218
219 std::shared_ptr<RElement> GetElement() override
220 {
221 return std::make_shared<RFieldElement>(fNtplSource, fParentName, fFieldIds[fCounter]);
222 }
223};
224
225
226std::unique_ptr<RLevelIter> RFieldElement::GetChildsIter()
227{
228 std::vector<ROOT::Experimental::DescriptorId_t> ids;
229 std::string prefix;
230
231 {
232 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
233
234 for (auto &f : descriptorGuard->GetFieldIterable(fFieldId))
235 ids.emplace_back(f.GetId());
236
237 if (ids.size() == 0)
238 return nullptr;
239
240 prefix = fParentName;
241 auto &fld = descriptorGuard->GetFieldDescriptor(fFieldId);
242 prefix.append(fld.GetFieldName());
243 }
244 prefix.append(".");
245
246 return std::make_unique<RFieldsIterator>(fNtplSource, std::move(ids), prefix);
247}
248
249std::unique_ptr<RLevelIter> RNTupleElement::GetChildsIter()
250{
251 std::vector<ROOT::Experimental::DescriptorId_t> ids;
252
253 {
254 auto descriptorGuard = fNtplSource->GetSharedDescriptorGuard();
255 for (auto &f : descriptorGuard->GetTopLevelFields())
256 ids.emplace_back(f.GetId());
257 }
258
259 if (ids.size() == 0) return nullptr;
260 return std::make_unique<RFieldsIterator>(fNtplSource, std::move(ids));
261}
262
263
264// ==============================================================================================
265
266/** \class RNTupleBrowseProvider
267\ingroup rbrowser
268\brief Provider for browsing RNTuple classes
269\author Sergey Linev <S.Linev@gsi.de>
270\date 2021-03-08
271\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
272*/
273
275
276public:
277
279 {
280 RegisterNTupleFunc([](const std::string &tuple_name, const std::string &filename) -> std::shared_ptr<RElement> {
281 auto elem = std::make_shared<RNTupleElement>(tuple_name, filename);
282 return elem->IsNull() ? nullptr : elem;
283 });
284 }
285
287 {
288 RegisterNTupleFunc(nullptr);
289 }
290
292
RNTupleBrowseProvider newRNTupleBrowseProvider
#define f(i)
Definition RSha256.hxx:104
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
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.
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
Basic element of browsable hierarchy.
Definition RElement.hxx:35
EActionKind
Possible actions on double-click.
Definition RElement.hxx:51
@ kActDraw7
can be drawn inside ROOT7 canvas
Definition RElement.hxx:57
@ kActDraw6
can be drawn inside ROOT6 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: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:81
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.