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>
18#include <ROOT/RNTupleUtil.hxx>
19#include <ROOT/RNTupleView.hxx>
20
21#include <cassert>
22#include <iomanip>
23#include <iostream>
24#include <sstream>
25#include <string>
26#include <vector>
27
28
29//----------------------------- RPrepareVisitor --------------------------------
30
32{
33 auto subFields = field.GetSubFields();
34 for (auto f : subFields) {
35 RPrepareVisitor visitor;
36 f->AcceptVisitor(visitor);
37 fNumFields += visitor.fNumFields;
38 fDeepestLevel = std::max(fDeepestLevel, 1 + visitor.fDeepestLevel);
39 }
40}
41
42
44{
45 VisitField(field);
46 fNumFields--;
47 fDeepestLevel--;
48}
49
50
51//---------------------------- RPrintSchemaVisitor -----------------------------
52
53
55{
56 fDeepestLevel = d;
57}
58
60{
61 fNumFields = n;
62 SetAvailableSpaceForStrings();
63}
64
66{
67 fOutput << fFrameSymbol << ' ';
68
69 std::string key = fTreePrefix;
70 key += "Field " + fFieldNoPrefix + std::to_string(fFieldNo);
71 fOutput << RNTupleFormatter::FitString(key, fAvailableSpaceKeyString);
72 fOutput << " : ";
73
74 std::string value = field.GetFieldName();
75 if (!field.GetTypeName().empty())
76 value += " (" + field.GetTypeName() + ")";
77 fOutput << RNTupleFormatter::FitString(value, fAvailableSpaceValueString);
78 fOutput << fFrameSymbol << std::endl;
79
80 auto subFields = field.GetSubFields();
81 auto fieldNo = 1;
82 for (auto iField = subFields.begin(); iField != subFields.end(); ) {
83 RPrintSchemaVisitor visitor(*this);
84 visitor.fFieldNo = fieldNo++;
85 visitor.fFieldNoPrefix += std::to_string(fFieldNo) + ".";
86
87 auto f = *iField;
88 ++iField;
89 // TODO(jblomer): implement tree drawing
90 visitor.fTreePrefix += " ";
91 f->AcceptVisitor(visitor);
92 }
93}
94
95
97{
98 auto fieldNo = 1;
99 for (auto f : fieldZero.GetSubFields()) {
100 RPrintSchemaVisitor visitor(*this);
101 visitor.fFieldNo = fieldNo++;
102 f->AcceptVisitor(visitor);
103 }
104}
105
106
107//--------------------------- RPrintValueVisitor -------------------------------
108
110{
111 if (fPrintOptions.fPrintSingleLine)
112 return;
113
114 for (unsigned int i = 0; i < fLevel; ++i)
115 fOutput << " ";
116}
117
119{
120 if (fPrintOptions.fPrintName)
121 fOutput << "\"" << field.GetFieldName() << "\": ";
122}
123
125{
126 PrintIndent();
127 PrintName(field);
128 fOutput << "[";
129 auto elems = field.SplitValue(fValue);
130 for (auto iValue = elems.begin(); iValue != elems.end(); ) {
131 RPrintOptions options;
132 options.fPrintSingleLine = true;
133 options.fPrintName = false;
134 RPrintValueVisitor elemVisitor(*iValue, fOutput, 0 /* level */, options);
135 iValue->GetField().AcceptVisitor(elemVisitor);
136
137 if (++iValue == elems.end())
138 break;
139 else
140 fOutput << ", ";
141 }
142 fOutput << "]";
143}
144
146{
147 PrintIndent();
148 PrintName(field);
149 fOutput << "{";
150 auto elems = field.SplitValue(fValue);
151 for (auto iValue = elems.begin(); iValue != elems.end();) {
152 if (!fPrintOptions.fPrintSingleLine)
153 fOutput << std::endl;
154
155 RPrintOptions options;
156 options.fPrintSingleLine = fPrintOptions.fPrintSingleLine;
157 RPrintValueVisitor visitor(*iValue, fOutput, fLevel + 1, options);
158 iValue->GetField().AcceptVisitor(visitor);
159
160 if (++iValue == elems.end()) {
161 if (!fPrintOptions.fPrintSingleLine)
162 fOutput << std::endl;
163 break;
164 } else {
165 fOutput << ",";
166 if (fPrintOptions.fPrintSingleLine)
167 fOutput << " ";
168 }
169 }
170 PrintIndent();
171 fOutput << "}";
172}
173
175{
176 PrintIndent();
177 PrintName(field);
178 fOutput << "\"<unsupported type: " << field.GetTypeName() << ">\"";
179}
180
181
183{
184 PrintIndent();
185 PrintName(field);
186 if (fValue.GetRef<bool>())
187 fOutput << "true";
188 else
189 fOutput << "false";
190}
191
192
194{
195 PrintIndent();
196 PrintName(field);
197 fOutput << fValue.GetRef<double>();
198}
199
200
202{
203 PrintIndent();
204 PrintName(field);
205 fOutput << fValue.GetRef<float>();
206}
207
209{
210 PrintIndent();
211 PrintName(field);
212 char prev = std::cout.fill();
213 fOutput << "0x" << std::setw(2) << std::setfill('0') << std::hex << (fValue.GetRef<unsigned char>() & 0xff);
214 fOutput << std::resetiosflags(std::ios_base::basefield);
215 std::cout.fill(prev);
216}
217
219{
220 PrintIndent();
221 PrintName(field);
222 fOutput << fValue.GetRef<char>();
223}
224
226{
227 PrintIndent();
228 PrintName(field);
229 fOutput << fValue.GetRef<std::int8_t>();
230}
231
233{
234 PrintIndent();
235 PrintName(field);
236 fOutput << fValue.GetRef<std::int16_t>();
237}
238
240{
241 PrintIndent();
242 PrintName(field);
243 fOutput << fValue.GetRef<std::int32_t>();
244}
245
247{
248 PrintIndent();
249 PrintName(field);
250 fOutput << fValue.GetRef<std::int64_t>();
251}
252
254{
255 PrintIndent();
256 PrintName(field);
257 // TODO(jblomer): escape double quotes
258 fOutput << "\"" << fValue.GetRef<std::string>() << "\"";
259}
260
262{
263 PrintIndent();
264 PrintName(field);
265 fOutput << static_cast<int>(fValue.GetRef<std::uint8_t>());
266}
267
269{
270 PrintIndent();
271 PrintName(field);
272 fOutput << fValue.GetRef<std::uint16_t>();
273}
274
276{
277 PrintIndent();
278 PrintName(field);
279 fOutput << fValue.GetRef<std::uint32_t>();
280}
281
283{
284 PrintIndent();
285 PrintName(field);
286 fOutput << fValue.GetRef<std::uint64_t>();
287}
288
290{
291 PrintIndent();
292 PrintName(field);
293 if (field.As32Bit()) {
294 fOutput << fValue.GetRef<std::uint32_t>();
295 return;
296 }
297 if (field.As64Bit()) {
298 fOutput << fValue.GetRef<std::uint64_t>();
299 return;
300 }
301 R__ASSERT(false && "unsupported cardinality size type");
302}
303
305{
306 constexpr auto nBitsULong = sizeof(unsigned long) * 8;
307 const auto *asULongArray = fValue.GetPtr<unsigned long>().get();
308
309 PrintIndent();
310 PrintName(field);
311 fOutput << "\"";
312 std::size_t i = 0;
313 std::string str;
314 for (std::size_t word = 0; word < (field.GetN() + nBitsULong - 1) / nBitsULong; ++word) {
315 for (std::size_t mask = 0; (mask < nBitsULong) && (i < field.GetN()); ++mask, ++i) {
316 bool isSet = (asULongArray[word] & (static_cast<unsigned long>(1) << mask)) != 0;
317 str = std::to_string(isSet) + str;
318 }
319 }
320 fOutput << str << "\"";
321}
322
324{
325 PrintCollection(field);
326}
327
329{
330 PrintCollection(field);
331}
332
334{
335 PrintIndent();
336 PrintName(field);
337 fOutput << "<streamer mode>";
338}
339
341{
342 PrintRecord(field);
343}
344
346{
347 PrintRecord(field);
348}
349
351{
352 PrintRecord(field);
353}
354
356{
357 PrintIndent();
358 PrintName(field);
359 auto elems = field.SplitValue(fValue);
360 if (elems.empty()) {
361 fOutput << "null";
362 } else {
363 RPrintOptions options;
364 options.fPrintSingleLine = true;
365 options.fPrintName = false;
366 RPrintValueVisitor visitor(elems[0], fOutput, fLevel, options);
367 elems[0].GetField().AcceptVisitor(visitor);
368 }
369}
370
372{
373 PrintIndent();
374 PrintName(field);
375 auto intValue = field.SplitValue(fValue)[0];
376 RPrintOptions options;
377 options.fPrintSingleLine = true;
378 options.fPrintName = false;
379 RPrintValueVisitor visitor(intValue, fOutput, fLevel, options);
380 intValue.GetField().AcceptVisitor(visitor);
381}
382
384{
385 PrintIndent();
386 PrintName(field);
387 auto itemValue = field.SplitValue(fValue)[0];
388 RPrintOptions options;
389 options.fPrintSingleLine = true;
390 options.fPrintName = false;
391 RPrintValueVisitor visitor(itemValue, fOutput, fLevel, options);
392 itemValue.GetField().AcceptVisitor(visitor);
393}
394
396{
397 PrintCollection(field);
398}
399
401{
402 PrintCollection(field);
403}
404
406{
407 PrintCollection(field);
408}
409
411{
412 PrintCollection(field);
413}
414
415//---------------------------- RNTupleFormatter --------------------------------
416
417
418std::string ROOT::Experimental::RNTupleFormatter::FitString(const std::string &str, int availableSpace)
419{
420 int strSize{static_cast<int>(str.size())};
421 if (strSize <= availableSpace)
422 return str + std::string(availableSpace - strSize, ' ');
423 else if (availableSpace < 3)
424 return std::string(availableSpace, '.');
425 return std::string(str, 0, availableSpace - 3) + "...";
426}
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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 mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Additional classes related to sequence containers.
Template specializations for C++ std::array and C-style arrays.
Template specializations for C++ std::atomic.
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given a value for this field.
Definition RField.cxx:962
Template specializations for C++ std::bitset.
std::size_t GetN() const
Get the number of bits in the bitset, i.e. the N in std::bitset<N>
An artificial field that transforms an RNTuple column that contains the offset of collections into co...
Definition RField.hxx:268
const RField< RNTupleCardinality< std::uint32_t > > * As32Bit() const
Definition RField.cxx:70
const RField< RNTupleCardinality< std::uint64_t > > * As64Bit() const
Definition RField.cxx:76
The field for a class with dictionary.
Definition RField.hxx:99
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:213
std::vector< RValue > SplitValue(const RValue &value) const final
Creates the list of direct child values given a value for this field.
A field translates read and write calls from/to underlying columns to/from tree values.
std::vector< RFieldBase * > GetSubFields()
const std::string & GetFieldName() const
const std::string & GetTypeName() const
virtual std::vector< RValue > SplitValue(const RValue &value) const
Creates the list of direct child values given a value for this field.
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:58
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:241
static std::string FitString(const std::string &str, int availableSpace)
Template specializations for C++ std::optional and std::unique_ptr.
Visitor used for a pre-processing run to collect information needed by another visitor class.
void VisitField(const RFieldBase &field) final
void VisitFieldZero(const RFieldZero &field) final
Contains settings for printing and prints a summary of an RField instance.
void VisitField(const 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 VisitArrayField(const RArrayField &field) final
void VisitFloatField(const RField< float > &field) final
void VisitInt8Field(const RIntegralField< std::int8_t > &field) final
void VisitRecordField(const RRecordField &field) final
void VisitStringField(const RField< std::string > &field) final
void VisitUInt64Field(const RIntegralField< std::uint64_t > &field) final
void VisitUInt8Field(const RIntegralField< std::uint8_t > &field) final
void VisitUInt16Field(const RIntegralField< std::uint16_t > &field) final
void PrintName(const RFieldBase &field)
void VisitNullableField(const RNullableField &field) final
void VisitBitsetField(const RBitsetField &field) final
void VisitCardinalityField(const RCardinalityField &field) final
void VisitTObjectField(const RField< TObject > &field) final
void VisitAtomicField(const RAtomicField &field) final
void VisitRVecField(const RRVecField &field) final
void VisitUInt32Field(const RIntegralField< std::uint32_t > &field) final
void VisitInt64Field(const RIntegralField< std::int64_t > &field) final
void VisitEnumField(const REnumField &field) final
void VisitBoolField(const RField< bool > &field) final
void VisitInt32Field(const RIntegralField< std::int32_t > &field) final
void VisitField(const RFieldBase &field) final
void VisitInt16Field(const RIntegralField< std::int16_t > &field) final
void VisitProxiedCollectionField(const RProxiedCollectionField &field) final
void VisitArrayAsRVecField(const RArrayAsRVecField &field) final
void VisitByteField(const RField< std::byte > &field) final
void VisitStreamerField(const RStreamerField &field) final
void PrintCollection(const RFieldBase &field)
void VisitVectorField(const RVectorField &field) final
void VisitCharField(const RField< char > &field) final
void VisitClassField(const RClassField &field) final
void PrintRecord(const RFieldBase &field)
The field for a class representing a collection of elements via TVirtualCollectionProxy.
Template specializations for ROOT's RVec.
The field for an untyped record.
The field for a class using ROOT standard streaming.
Definition RField.hxx:160
Template specializations for C++ std::vector.
const Int_t n
Definition legend1.C:16