Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldVisitor.cxx
Go to the documentation of this file.
1/// \file RFieldVisitor.cxx
2/// \ingroup NTuple ROOT7
3/// \author Simon Leisibach <simon.leisibach@gmail.com>
4/// \date 2019-06-11
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RField.hxx>
17#include <ROOT/RFieldValue.hxx>
19#include <ROOT/RNTuple.hxx>
20#include <ROOT/RNTupleUtil.hxx>
21#include <ROOT/RNTupleView.hxx>
22
23#include <cassert>
24#include <iostream>
25#include <sstream>
26#include <string>
27#include <vector>
28
29
30//----------------------------- RPrepareVisitor --------------------------------
31
32
34{
35 auto subFields = field.GetSubFields();
36 for (auto f : subFields) {
37 RPrepareVisitor visitor;
38 f->AcceptVisitor(visitor);
39 fNumFields += visitor.fNumFields;
40 fDeepestLevel = std::max(fDeepestLevel, 1 + visitor.fDeepestLevel);
41 }
42}
43
44
46{
47 VisitField(field);
48 fNumFields--;
49 fDeepestLevel--;
50}
51
52
53//---------------------------- RPrintSchemaVisitor -----------------------------
54
55
57{
58 fDeepestLevel = d;
59}
60
62{
63 fNumFields = n;
64 SetAvailableSpaceForStrings();
65}
66
68{
69 fOutput << fFrameSymbol << ' ';
70
71 std::string key = fTreePrefix;
72 key += "Field " + fFieldNoPrefix + std::to_string(fFieldNo);
73 fOutput << RNTupleFormatter::FitString(key, fAvailableSpaceKeyString);
74 fOutput << " : ";
75
76 std::string value = field.GetName();
77 if (!field.GetType().empty())
78 value += " (" + field.GetType() + ")";
79 fOutput << RNTupleFormatter::FitString(value, fAvailableSpaceValueString);
80 fOutput << fFrameSymbol << std::endl;
81
82 auto subFields = field.GetSubFields();
83 auto fieldNo = 1;
84 for (auto iField = subFields.begin(); iField != subFields.end(); ) {
85 RPrintSchemaVisitor visitor(*this);
86 visitor.fFieldNo = fieldNo++;
87 visitor.fFieldNoPrefix += std::to_string(fFieldNo) + ".";
88
89 auto f = *iField;
90 ++iField;
91 // TODO(jblomer): implement tree drawing
92 visitor.fTreePrefix += " ";
93 f->AcceptVisitor(visitor);
94 }
95}
96
97
99{
100 auto fieldNo = 1;
101 for (auto f : fieldZero.GetSubFields()) {
102 RPrintSchemaVisitor visitor(*this);
103 visitor.fFieldNo = fieldNo++;
104 f->AcceptVisitor(visitor);
105 }
106}
107
108
109//--------------------------- RPrintValueVisitor -------------------------------
110
112{
113 if (fPrintOptions.fPrintSingleLine)
114 return;
115
116 for (unsigned int i = 0; i < fLevel; ++i)
117 fOutput << " ";
118}
119
120
122{
123 if (fPrintOptions.fPrintName)
124 fOutput << "\"" << field.GetName() << "\": ";
125}
126
127
129{
130 PrintIndent();
131 PrintName(field);
132 fOutput << "[";
133 auto elems = field.SplitValue(fValue);
134 for (auto iValue = elems.begin(); iValue != elems.end(); ) {
135 RPrintOptions options;
136 options.fPrintSingleLine = true;
137 options.fPrintName = false;
138 RPrintValueVisitor elemVisitor(*iValue, fOutput, 0 /* level */, options);
139 iValue->GetField()->AcceptVisitor(elemVisitor);
140
141 if (++iValue == elems.end())
142 break;
143 else
144 fOutput << ", ";
145 }
146 fOutput << "]";
147}
148
149
151{
152 PrintIndent();
153 PrintName(field);
154 fOutput << "\"<unsupported type: " << field.GetType() << ">\"";
155}
156
157
159{
160 PrintIndent();
161 PrintName(field);
162 if (*fValue.Get<bool>())
163 fOutput << "true";
164 else
165 fOutput << "false";
166}
167
168
170{
171 PrintIndent();
172 PrintName(field);
173 fOutput << *fValue.Get<double>();
174}
175
176
178{
179 PrintIndent();
180 PrintName(field);
181 fOutput << *fValue.Get<float>();
182}
183
185{
186 PrintIndent();
187 PrintName(field);
188 fOutput << *fValue.Get<char>();
189}
190
192{
193 PrintIndent();
194 PrintName(field);
195 fOutput << *fValue.Get<std::int8_t>();
196}
197
199{
200 PrintIndent();
201 PrintName(field);
202 fOutput << *fValue.Get<std::int16_t>();
203}
204
206{
207 PrintIndent();
208 PrintName(field);
209 fOutput << *fValue.Get<int>();
210}
211
213{
214 PrintIndent();
215 PrintName(field);
216 fOutput << *fValue.Get<std::int64_t>();
217}
218
220{
221 PrintIndent();
222 PrintName(field);
223 // TODO(jblomer): escape double quotes
224 fOutput << "\"" << *fValue.Get<std::string>() << "\"";
225}
226
227
229{
230 PrintIndent();
231 PrintName(field);
232 fOutput << static_cast<int>(*fValue.Get<std::uint8_t>());
233}
234
236{
237 PrintIndent();
238 PrintName(field);
239 fOutput << *fValue.Get<std::uint16_t>();
240}
241
243{
244 PrintIndent();
245 PrintName(field);
246 fOutput << *fValue.Get<std::uint32_t>();
247}
248
249
251{
252 PrintIndent();
253 PrintName(field);
254 fOutput << *fValue.Get<std::uint64_t>();
255}
256
257
259{
260 PrintCollection(field);
261}
262
263
265{
266 PrintIndent();
267 PrintName(field);
268 fOutput << "{";
269 auto elems = field.SplitValue(fValue);
270 for (auto iValue = elems.begin(); iValue != elems.end(); ) {
271 if (!fPrintOptions.fPrintSingleLine)
272 fOutput << std::endl;
273
274 RPrintOptions options;
275 options.fPrintSingleLine = fPrintOptions.fPrintSingleLine;
276 RPrintValueVisitor visitor(*iValue, fOutput, fLevel + 1, options);
277 iValue->GetField()->AcceptVisitor(visitor);
278
279 if (++iValue == elems.end()) {
280 if (!fPrintOptions.fPrintSingleLine)
281 fOutput << std::endl;
282 break;
283 } else {
284 fOutput << ",";
285 if (fPrintOptions.fPrintSingleLine)
286 fOutput << " ";
287 }
288 }
289 PrintIndent();
290 fOutput << "}";
291}
292
293
295{
296 PrintIndent();
297 PrintName(field);
298 fOutput << "{";
299 auto elems = field.SplitValue(fValue);
300 for (auto iValue = elems.begin(); iValue != elems.end(); ) {
301 if (!fPrintOptions.fPrintSingleLine)
302 fOutput << std::endl;
303
304 RPrintOptions options;
305 options.fPrintSingleLine = fPrintOptions.fPrintSingleLine;
306 RPrintValueVisitor visitor(*iValue, fOutput, fLevel + 1, options);
307 iValue->GetField()->AcceptVisitor(visitor);
308
309 if (++iValue == elems.end()) {
310 if (!fPrintOptions.fPrintSingleLine)
311 fOutput << std::endl;
312 break;
313 } else {
314 fOutput << ",";
315 if (fPrintOptions.fPrintSingleLine)
316 fOutput << " ";
317 }
318 }
319 PrintIndent();
320 fOutput << "}";
321}
322
323
325{
326 PrintCollection(field);
327}
328
329
331{
332 PrintCollection(field);
333}
334
335
336//---------------------------- RNTupleFormatter --------------------------------
337
338
339std::string ROOT::Experimental::RNTupleFormatter::FitString(const std::string &str, int availableSpace)
340{
341 int strSize{static_cast<int>(str.size())};
342 if (strSize <= availableSpace)
343 return str + std::string(availableSpace - strSize, ' ');
344 else if (availableSpace < 3)
345 return std::string(availableSpace, '.');
346 return std::string(str, 0, availableSpace - 3) + "...";
347}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
virtual std::vector< RFieldValue > SplitValue(const RFieldValue &value) const
Creates the list of direct child values given a value for this field.
Definition RField.cxx:278
std::vector< RFieldBase * > GetSubFields() const
Definition RField.cxx:291
The generic field for fixed size arrays, which do not need an offset column.
Definition RField.hxx:408
The field for a class with dictionary.
Definition RField.hxx:291
std::vector< Detail::RFieldValue > SplitValue(const Detail::RFieldValue &value) const final
Creates the list of direct child values given a value for this field.
Definition RField.cxx:868
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:271
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:480
static std::string FitString(const std::string &str, int availableSpace)
Visitor used for a pre-processing run to collect information needed by another visitor class.
void VisitField(const Detail::RFieldBase &field) final
void VisitFieldZero(const RFieldZero &field) final
Contains settings for printing and prints a summary of an RField instance.
void VisitField(const Detail::RFieldBase &field) final
Prints summary of Field.
void VisitFieldZero(const RFieldZero &fieldZero) final
Renders a JSON value corresponding to the field.
void VisitVectorBoolField(const RField< std::vector< bool > > &field) final
void VisitDoubleField(const RField< double > &field) final
void VisitUInt16Field(const RField< std::uint16_t > &field) final
void VisitArrayField(const RArrayField &field) final
void VisitFloatField(const RField< float > &field) final
void VisitRecordField(const RRecordField &field) final
void VisitStringField(const RField< std::string > &field) final
void VisitInt8Field(const RField< std::int8_t > &field) final
void PrintName(const Detail::RFieldBase &field)
void VisitUInt8Field(const RField< std::uint8_t > &field) final
void VisitField(const Detail::RFieldBase &field) final
void PrintCollection(const Detail::RFieldBase &field)
void VisitUInt64Field(const RField< std::uint64_t > &field) final
void VisitBoolField(const RField< bool > &field) final
void VisitInt16Field(const RField< std::int16_t > &field) final
void VisitVectorField(const RVectorField &field) final
void VisitCharField(const RField< char > &field) final
void VisitInt64Field(const RField< std::int64_t > &field) final
void VisitClassField(const RClassField &field) final
void VisitIntField(const RField< int > &field) final
void VisitUInt32Field(const RField< std::uint32_t > &field) final
The field for an untyped record.
Definition RField.hxx:339
std::vector< Detail::RFieldValue > SplitValue(const Detail::RFieldValue &value) const final
Creates the list of direct child values given a value for this field.
Definition RField.cxx:983
The generic field for a (nested) std::vector<Type> except for std::vector<bool>
Definition RField.hxx:371
const Int_t n
Definition legend1.C:16