Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldVisitor.cxx
Go to the documentation of this file.
1/// \file RFieldVisitor.cxx
2/// \ingroup NTuple
3/// \author Simon Leisibach <simon.leisibach@gmail.com>
4/// \date 2019-06-11
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#include <ROOT/RField.hxx>
16#include <ROOT/RNTupleTypes.hxx>
17#include <ROOT/RNTupleUtils.hxx>
18#include <ROOT/RNTupleView.hxx>
19
20#include <cassert>
21#include <cstddef>
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.GetConstSubfields();
34 for (auto f : subfields) {
36 f->AcceptVisitor(visitor);
37 fNumFields += visitor.fNumFields;
38 fDeepestLevel = std::max(fDeepestLevel, 1 + visitor.fDeepestLevel);
39 }
40}
41
43{
44 VisitField(field);
45 fNumFields--;
46 fDeepestLevel--;
47}
48
49
50//---------------------------- RPrintSchemaVisitor -----------------------------
51
53{
54 fDeepestLevel = d;
55}
56
58{
59 fNumFields = n;
60 SetAvailableSpaceForStrings();
61}
62
64{
65 std::string key = fTreePrefix;
66 key += "Field " + fFieldNoPrefix + std::to_string(fFieldNo);
67 fOutput << RNTupleFormatter::FitString(key, fAvailableSpaceKeyString);
68 fOutput << " : ";
69
70 std::string value = field.GetFieldName();
71 if (!field.GetTypeName().empty())
72 value += " (" + field.GetTypeName() + ")";
73 fOutput << value << '\n';
74
75 auto subfields = field.GetConstSubfields();
76 auto fieldNo = 1;
77 for (auto iField = subfields.begin(); iField != subfields.end();) {
79 visitor.fFieldNo = fieldNo++;
80 visitor.fFieldNoPrefix += std::to_string(fFieldNo) + ".";
81
82 auto f = *iField;
83 ++iField;
84 // TODO(jblomer): implement tree drawing
85 visitor.fTreePrefix += " ";
86 f->AcceptVisitor(visitor);
87 }
88}
89
91{
92 auto fieldNo = 1;
93 for (auto f : fieldZero.GetConstSubfields()) {
95 visitor.fFieldNo = fieldNo++;
96 f->AcceptVisitor(visitor);
97 }
98}
99
100
101//--------------------------- RPrintValueVisitor -------------------------------
102
104{
105 if (fPrintOptions.fPrintSingleLine)
106 return;
107
108 for (unsigned int i = 0; i < fLevel; ++i)
109 fOutput << " ";
110}
111
113{
114 if (fPrintOptions.fPrintName)
115 fOutput << "\"" << field.GetFieldName() << "\": ";
116}
117
119{
120 PrintIndent();
121 PrintName(field);
122 fOutput << "[";
123 auto elems = field.SplitValue(fValue);
124 for (auto iValue = elems.begin(); iValue != elems.end(); ) {
125 RPrintOptions options;
126 options.fPrintSingleLine = true;
127 options.fPrintName = false;
128 RPrintValueVisitor elemVisitor(*iValue, fOutput, 0 /* level */, options);
129 iValue->GetField().AcceptVisitor(elemVisitor);
130
131 if (++iValue == elems.end())
132 break;
133 else
134 fOutput << ", ";
135 }
136 fOutput << "]";
137}
138
140{
141 PrintIndent();
142 PrintName(field);
143 fOutput << "{";
144 auto elems = field.SplitValue(fValue);
145 for (auto iValue = elems.begin(); iValue != elems.end();) {
146 if (!fPrintOptions.fPrintSingleLine)
147 fOutput << std::endl;
148
149 RPrintOptions options;
150 options.fPrintSingleLine = fPrintOptions.fPrintSingleLine;
151 RPrintValueVisitor visitor(*iValue, fOutput, fLevel + 1, options);
152 iValue->GetField().AcceptVisitor(visitor);
153
154 if (++iValue == elems.end()) {
155 if (!fPrintOptions.fPrintSingleLine)
156 fOutput << std::endl;
157 break;
158 } else {
159 fOutput << ",";
160 if (fPrintOptions.fPrintSingleLine)
161 fOutput << " ";
162 }
163 }
164 PrintIndent();
165 fOutput << "}";
166}
167
169{
170 PrintIndent();
171 PrintName(field);
172 fOutput << "\"<unsupported type: " << field.GetTypeName() << ">\"";
173}
174
176{
177 PrintIndent();
178 PrintName(field);
179 if (fValue.GetRef<bool>())
180 fOutput << "true";
181 else
182 fOutput << "false";
183}
184
186{
187 PrintIndent();
188 PrintName(field);
189 fOutput << fValue.GetRef<double>();
190}
191
193{
194 PrintIndent();
195 PrintName(field);
196 fOutput << fValue.GetRef<float>();
197}
198
200{
201 PrintIndent();
202 PrintName(field);
203 char prev = std::cout.fill();
204 auto value = std::to_integer<unsigned int>(fValue.GetRef<std::byte>());
205 fOutput << "0x" << std::setw(2) << std::setfill('0') << std::hex << value;
206 fOutput << std::resetiosflags(std::ios_base::basefield);
207 std::cout.fill(prev);
208}
209
211{
212 PrintIndent();
213 PrintName(field);
214 fOutput << fValue.GetRef<char>();
215}
216
218{
219 PrintIndent();
220 PrintName(field);
221 fOutput << static_cast<int>(fValue.GetRef<std::int8_t>());
222}
223
225{
226 PrintIndent();
227 PrintName(field);
228 fOutput << fValue.GetRef<std::int16_t>();
229}
230
232{
233 PrintIndent();
234 PrintName(field);
235 fOutput << fValue.GetRef<std::int32_t>();
236}
237
239{
240 PrintIndent();
241 PrintName(field);
242 fOutput << fValue.GetRef<std::int64_t>();
243}
244
246{
247 PrintIndent();
248 PrintName(field);
249 // TODO(jblomer): escape double quotes
250 fOutput << "\"" << fValue.GetRef<std::string>() << "\"";
251}
252
254{
255 PrintIndent();
256 PrintName(field);
257 fOutput << static_cast<int>(fValue.GetRef<std::uint8_t>());
258}
259
261{
262 PrintIndent();
263 PrintName(field);
264 fOutput << fValue.GetRef<std::uint16_t>();
265}
266
268{
269 PrintIndent();
270 PrintName(field);
271 fOutput << fValue.GetRef<std::uint32_t>();
272}
273
275{
276 PrintIndent();
277 PrintName(field);
278 fOutput << fValue.GetRef<std::uint64_t>();
279}
280
282{
283 PrintIndent();
284 PrintName(field);
285 if (field.As32Bit()) {
286 fOutput << fValue.GetRef<std::uint32_t>();
287 return;
288 }
289 if (field.As64Bit()) {
290 fOutput << fValue.GetRef<std::uint64_t>();
291 return;
292 }
293 R__ASSERT(false && "unsupported cardinality size type");
294}
295
297{
298 constexpr auto nBitsULong = sizeof(unsigned long) * 8;
299 const auto *asULongArray = static_cast<unsigned long *>(fValue.GetPtr<void>().get());
300
301 PrintIndent();
302 PrintName(field);
303 fOutput << "\"";
304 std::size_t i = 0;
305 std::string str;
306 for (std::size_t word = 0; word < (field.GetN() + nBitsULong - 1) / nBitsULong; ++word) {
307 for (std::size_t mask = 0; (mask < nBitsULong) && (i < field.GetN()); ++mask, ++i) {
308 bool isSet = (asULongArray[word] & (static_cast<unsigned long>(1) << mask)) != 0;
309 str = std::to_string(isSet) + str;
310 }
311 }
312 fOutput << str << "\"";
313}
314
319
324
329
331{
332 PrintIndent();
333 PrintName(field);
334 fOutput << "<streamer mode>";
335}
336
341
346
351
353{
354 PrintIndent();
355 PrintName(field);
356 auto elems = field.SplitValue(fValue);
357 if (elems.empty()) {
358 fOutput << "null";
359 } else {
360 RPrintOptions options;
361 options.fPrintSingleLine = true;
362 options.fPrintName = false;
363 RPrintValueVisitor visitor(elems[0], fOutput, fLevel, options);
364 elems[0].GetField().AcceptVisitor(visitor);
365 }
366}
367
369{
370 PrintIndent();
371 PrintName(field);
372 auto intValue = field.SplitValue(fValue)[0];
373 RPrintOptions options;
374 options.fPrintSingleLine = true;
375 options.fPrintName = false;
376 RPrintValueVisitor visitor(intValue, fOutput, fLevel, options);
377 intValue.GetField().AcceptVisitor(visitor);
378}
379
381{
382 PrintIndent();
383 PrintName(field);
384 auto itemValue = field.SplitValue(fValue)[0];
385 RPrintOptions options;
386 options.fPrintSingleLine = true;
387 options.fPrintName = false;
388 RPrintValueVisitor visitor(itemValue, fOutput, fLevel, options);
389 itemValue.GetField().AcceptVisitor(visitor);
390}
391
396
401
403{
404 PrintCollection(field);
405}
406
411
412//---------------------------- RNTupleFormatter --------------------------------
413
414std::string ROOT::Internal::RNTupleFormatter::FitString(const std::string &str, int availableSpace)
415{
416 int strSize{static_cast<int>(str.size())};
417 if (strSize <= availableSpace)
418 return str + std::string(availableSpace - strSize, ' ');
419 else if (availableSpace < 3)
420 return std::string(availableSpace, '.');
421 return std::string(str, 0, availableSpace - 3) + "...";
422}
#define d(i)
Definition RSha256.hxx:102
#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.
#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
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 VisitFieldZero(const ROOT::RFieldZero &field) final
void VisitField(const ROOT::RFieldBase &field) final
Contains settings for printing and prints a summary of an RField instance.
void VisitFieldZero(const ROOT::RFieldZero &fieldZero) final
void VisitField(const ROOT::RFieldBase &field) final
Prints summary of Field.
Renders a JSON value corresponding to the field.
void VisitVectorField(const ROOT::RVectorField &field) final
void VisitEnumField(const ROOT::REnumField &field) final
void VisitRVecField(const ROOT::RRVecField &field) final
void VisitUInt16Field(const ROOT::RIntegralField< std::uint16_t > &field) final
void VisitCardinalityField(const ROOT::RCardinalityField &field) final
void VisitCharField(const ROOT::RField< char > &field) final
void PrintRecord(const ROOT::RFieldBase &field)
void VisitAtomicField(const ROOT::RAtomicField &field) final
void VisitClassField(const ROOT::RClassField &field) final
void VisitTObjectField(const ROOT::RField< TObject > &field) final
void VisitInt64Field(const ROOT::RIntegralField< std::int64_t > &field) final
void VisitInt32Field(const ROOT::RIntegralField< std::int32_t > &field) final
void PrintName(const ROOT::RFieldBase &field)
void VisitByteField(const ROOT::RField< std::byte > &field) final
void VisitArrayAsVectorField(const ROOT::RArrayAsVectorField &field) final
void VisitStringField(const ROOT::RField< std::string > &field) final
void VisitArrayField(const ROOT::RArrayField &field) final
void VisitFloatField(const ROOT::RField< float > &field) final
void VisitRecordField(const ROOT::RRecordField &field) final
void VisitBitsetField(const ROOT::RBitsetField &field) final
void VisitUInt32Field(const ROOT::RIntegralField< std::uint32_t > &field) final
void VisitBoolField(const ROOT::RField< bool > &field) final
void VisitVectorBoolField(const ROOT::RField< std::vector< bool > > &field) final
void VisitInt16Field(const ROOT::RIntegralField< std::int16_t > &field) final
void VisitNullableField(const ROOT::RNullableField &field) final
void VisitDoubleField(const ROOT::RField< double > &field) final
void VisitArrayAsRVecField(const ROOT::RArrayAsRVecField &field) final
void VisitField(const ROOT::RFieldBase &field) final
void VisitProxiedCollectionField(const ROOT::RProxiedCollectionField &field) final
void VisitStreamerField(const ROOT::RStreamerField &field) final
void PrintCollection(const ROOT::RFieldBase &field)
void VisitInt8Field(const ROOT::RIntegralField< std::int8_t > &field) final
void VisitUInt64Field(const ROOT::RIntegralField< std::uint64_t > &field) final
void VisitUInt8Field(const ROOT::RIntegralField< std::uint8_t > &field) final
Additional classes related to sequence containers.
A field for fixed-size arrays that are represented as std::vector in memory.
Template specializations for C++ std::array and C-style arrays.
Template specializations for C++ std::atomic.
Template specializations for C++ std::bitset.
An artificial field that transforms an RNTuple column that contains the offset of collections into co...
Definition RField.hxx:348
The field for a class with dictionary.
Definition RField.hxx:136
The field for an unscoped or scoped enum with dictionary.
Definition RField.hxx:291
A field translates read and write calls from/to underlying columns to/from tree values.
The container field for an ntuple model, which itself has no physical representation.
Definition RField.hxx:59
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:321
Template specializations for C++ std::optional and std::unique_ptr.
The field for a class representing a collection of elements via TVirtualCollectionProxy.
Template specializations for ROOT's RVec.
const_iterator begin() const
const_iterator end() const
The field for an untyped record.
The field for a class using ROOT standard streaming.
Definition RField.hxx:236
Template specializations for C++ std::vector.
const Int_t n
Definition legend1.C:16