Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFieldVisitor.hxx
Go to the documentation of this file.
1/// \file ROOT/RFieldVisitor.hxx
2/// \ingroup NTuple ROOT7
3/// \author Simon Leisibach <simon.satoshi.rene.leisibach@cern.ch>
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#ifndef ROOT7_RFieldVisitor
17#define ROOT7_RFieldVisitor
18
19#include <ROOT/RField.hxx>
20#include <ROOT/RNTupleUtil.hxx>
21
22#include <algorithm>
23#include <iostream>
24#include <sstream>
25#include <string>
26#include <vector>
27
28namespace ROOT {
29namespace Experimental {
30namespace Detail {
31
32
33// clang-format off
34/**
35\class ROOT::Experimental::Detail::RFieldVisitor
36\ingroup NTuple
37\brief Abstract base class for classes implementing the visitor design pattern.
38
39RFieldVisitor::VisitField() is invoked by RFieldBase::AcceptVisitor(). VisitField() is inherited for instance
40by the RPrintSchemaVisitor class. The RFieldBase class and classes which inherit from it will be visited.
41*/
42// clang-format on
44public:
45 virtual void VisitField(const RFieldBase &field) = 0;
46 virtual void VisitFieldZero(const RFieldZero &field) { VisitField(field); }
47 virtual void VisitArrayField(const RArrayField &field) { VisitField(field); }
48 virtual void VisitArrayAsRVecField(const RArrayAsRVecField &field) { VisitField(field); }
49 virtual void VisitAtomicField(const RAtomicField &field) { VisitField(field); }
50 virtual void VisitBitsetField(const RBitsetField &field) { VisitField(field); }
51 virtual void VisitBoolField(const RField<bool> &field) { VisitField(field); }
52 virtual void VisitClassField(const RClassField &field) { VisitField(field); }
53 virtual void VisitTObjectField(const RField<TObject> &field) { VisitField(field); }
54 virtual void VisitStreamerField(const RStreamerField &field) { VisitField(field); }
55 virtual void VisitProxiedCollectionField(const RProxiedCollectionField &field) { VisitField(field); }
56 virtual void VisitRecordField(const RRecordField &field) { VisitField(field); }
57 virtual void VisitCardinalityField(const RCardinalityField &field) { VisitField(field); }
58 virtual void VisitDoubleField(const RField<double> &field) { VisitField(field); }
59 virtual void VisitEnumField(const REnumField &field) { VisitField(field); }
60 virtual void VisitFloatField(const RField<float> &field) { VisitField(field); }
61 virtual void VisitByteField(const RField<std::byte> &field) { VisitField(field); }
62 virtual void VisitCharField(const RField<char> &field) { VisitField(field); }
63 // We have to accept RIntegralField here because there can be multiple basic types that map to the same fixed-width
64 // integer type; for example on 64-bit Unix systems, both long and long long map to std::int64_t.
65 virtual void VisitInt8Field(const RIntegralField<std::int8_t> &field) { VisitField(field); }
66 virtual void VisitInt16Field(const RIntegralField<std::int16_t> &field) { VisitField(field); }
67 virtual void VisitInt32Field(const RIntegralField<std::int32_t> &field) { VisitField(field); }
68 virtual void VisitInt64Field(const RIntegralField<std::int64_t> &field) { VisitField(field); }
69 virtual void VisitNullableField(const RNullableField &field) { VisitField(field); }
70 virtual void VisitStringField(const RField<std::string> &field) { VisitField(field); }
71 virtual void VisitUInt8Field(const RIntegralField<std::uint8_t> &field) { VisitField(field); }
72 virtual void VisitUInt16Field(const RIntegralField<std::uint16_t> &field) { VisitField(field); }
73 virtual void VisitUInt32Field(const RIntegralField<std::uint32_t> &field) { VisitField(field); }
74 virtual void VisitUInt64Field(const RIntegralField<std::uint64_t> &field) { VisitField(field); }
75 virtual void VisitVectorField(const RVectorField &field) { VisitField(field); }
76 virtual void VisitVectorBoolField(const RField<std::vector<bool>> &field) { VisitField(field); }
77 virtual void VisitRVecField(const RRVecField &field) { VisitField(field); }
78}; // class RFieldVisitor
79
80} // namespace Detail
81
82
83// clang-format off
84/**
85\class ROOT::Experimental::RPrepareVisitor
86\ingroup NTuple
87\brief Visitor used for a pre-processing run to collect information needed by another visitor class.
88
89 Currently used for RPrintSchemaVisitor in RNTupleReader::Print() to collect information about levels, max depth etc.
90*/
91// clang-format on
93private:
94 unsigned int fDeepestLevel = 1;
95 unsigned int fNumFields = 1;
96
97public:
98 RPrepareVisitor() = default;
99 void VisitField(const RFieldBase &field) final;
100 void VisitFieldZero(const RFieldZero &field) final;
101
102 unsigned int GetDeepestLevel() const { return fDeepestLevel; }
103 unsigned int GetNumFields() const { return fNumFields; }
104};
105
106
107// clang-format off
108/**
109\class ROOT::Experimental::RPrintSchemaVisitor
110\ingroup NTuple
111\brief Contains settings for printing and prints a summary of an RField instance.
112
113This visitor is used by RNTupleReader::Print()
114*/
115// clang-format on
117private:
118 /// Where to write the printout to
119 std::ostream &fOutput;
120 /// To render the output, use an asterix (*) by default to draw table lines and boundaries
122 /// Indicates maximal number of allowed characters per line
128 int fFieldNo = 1;
129 std::string fTreePrefix;
130 std::string fFieldNoPrefix;
131
132public:
133 RPrintSchemaVisitor(std::ostream &out = std::cout, char frameSymbol = '*', int width = 80, int deepestLevel = 1,
134 int numFields = 1)
135 : fOutput{out}, fFrameSymbol{frameSymbol}, fWidth{width}, fDeepestLevel{deepestLevel}, fNumFields{numFields}
136 {
138 }
139 /// Prints summary of Field
140 void VisitField(const RFieldBase &field) final;
141 void VisitFieldZero(const RFieldZero &fieldZero) final;
142 void SetFrameSymbol(char s) { fFrameSymbol = s; }
143 void SetWidth(int w) { fWidth = w; }
144 void SetDeepestLevel(int d);
145 void SetNumFields(int n);
146 /// Computes how many characters should be placed between the frame symbol and ':' for left and right side of ':' for
147 /// visually pleasing output.
148 // E.g.
149 // * Field 1 : vpx (std::vector<float>) *
150 // * |__Field 1.1 : vpx/vpx (float) *
151 // int fAvailableSpaceKeyString (num characters on left side between "* " and " : ")
152 // deepestlevel here is 2 (1.1 is deepest and has 2 numbers).
153 // For every additional level an additional "|_" and ".1" (4 characters) is added, so the number of required
154 // additional characters is 4 * fDeepestLevel. For level 1, 8 characters are required ("Field 1 "), so an
155 // additional + 4 is added. To account for cases where the total number of fields is not a single digit number and
156 // more space is required to output big numbers, fNumFields is incorporated into the calculation. To make sure
157 // that there is still enough space for the right side of " : ", an std::min comparision with fWidth - 15 is done.
158 // int fAvailableSpaceValueString(num characters on right side between " : " and '*')
159 // The 6 subtracted characters are "* " (2) in the beginning, " : " (3) and '*' (1) on the far right.
161 {
163 std::min(4 * fDeepestLevel + 4 + static_cast<int>(std::to_string(fNumFields).size()), fWidth - 15);
165 }
166};
167
168
169// clang-format off
170/**
171\class ROOT::Experimental::RPrintValueVisitor
172\ingroup NTuple
173\brief Renders a JSON value corresponding to the field.
174*/
175// clang-format on
177public:
181
183 };
184
185private:
187 /// The output is directed to fOutput which may differ from std::cout.
188 std::ostream &fOutput;
189 unsigned int fLevel;
191
192 void PrintIndent();
193 void PrintName(const RFieldBase &field);
194 void PrintCollection(const RFieldBase &field);
195 void PrintRecord(const RFieldBase &field);
196
197public:
198 RPrintValueVisitor(RFieldBase::RValue value, std::ostream &output, unsigned int level = 0,
199 RPrintOptions options = RPrintOptions())
200 : fValue(value), fOutput{output}, fLevel(level), fPrintOptions(options)
201 {
202 }
203
204 void VisitField(const RFieldBase &field) final;
205
206 void VisitBoolField(const RField<bool> &field) final;
207 void VisitDoubleField(const RField<double> &field) final;
208 void VisitFloatField(const RField<float> &field) final;
209 void VisitByteField(const RField<std::byte> &field) final;
210 void VisitCharField(const RField<char> &field) final;
211 void VisitInt8Field(const RIntegralField<std::int8_t> &field) final;
212 void VisitInt16Field(const RIntegralField<std::int16_t> &field) final;
213 void VisitInt32Field(const RIntegralField<std::int32_t> &field) final;
214 void VisitInt64Field(const RIntegralField<std::int64_t> &field) final;
215 void VisitStringField(const RField<std::string> &field) final;
216 void VisitUInt8Field(const RIntegralField<std::uint8_t> &field) final;
217 void VisitUInt16Field(const RIntegralField<std::uint16_t> &field) final;
218 void VisitUInt32Field(const RIntegralField<std::uint32_t> &field) final;
219 void VisitUInt64Field(const RIntegralField<std::uint64_t> &field) final;
220
221 void VisitCardinalityField(const RCardinalityField &field) final;
222 void VisitArrayField(const RArrayField &field) final;
223 void VisitArrayAsRVecField(const RArrayAsRVecField &field) final;
224 void VisitClassField(const RClassField &field) final;
225 void VisitTObjectField(const RField<TObject> &field) final;
226 void VisitStreamerField(const RStreamerField &field) final;
227 void VisitRecordField(const RRecordField &field) final;
229 void VisitVectorField(const RVectorField &field) final;
230 void VisitVectorBoolField(const RField<std::vector<bool>> &field) final;
231 void VisitRVecField(const RRVecField &field) final;
232 void VisitBitsetField(const RBitsetField &field) final;
233 void VisitNullableField(const RNullableField &field) final;
234 void VisitEnumField(const REnumField &field) final;
235 void VisitAtomicField(const RAtomicField &field) final;
236};
237
238
239// clang-format off
240/**
241\class ROOT::Experimental::RNTupleFormatter
242\ingroup NTuple
243\brief Contains helper functions for RNTupleReader::PrintInfo() and RPrintSchemaVisitor::VisitField()
244
245The functions in this class format strings which are displayed by RNTupleReader::PrintInfo() and RNTupleReader::Show().
246*/
247// clang-format on
249public:
250 // Can abbreviate long strings, e.g. ("ExampleString" , space= 8) => "Examp..."
251 static std::string FitString(const std::string &str, int availableSpace);
252};
253
254} // namespace Experimental
255} // namespace ROOT
256
257#endif
#define d(i)
Definition RSha256.hxx:102
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t width
Abstract base class for classes implementing the visitor design pattern.
virtual void VisitProxiedCollectionField(const RProxiedCollectionField &field)
virtual void VisitBoolField(const RField< bool > &field)
virtual void VisitBitsetField(const RBitsetField &field)
virtual void VisitNullableField(const RNullableField &field)
virtual void VisitStreamerField(const RStreamerField &field)
virtual void VisitVectorBoolField(const RField< std::vector< bool > > &field)
virtual void VisitUInt16Field(const RIntegralField< std::uint16_t > &field)
virtual void VisitUInt64Field(const RIntegralField< std::uint64_t > &field)
virtual void VisitFieldZero(const RFieldZero &field)
virtual void VisitRVecField(const RRVecField &field)
virtual void VisitByteField(const RField< std::byte > &field)
virtual void VisitCardinalityField(const RCardinalityField &field)
virtual void VisitTObjectField(const RField< TObject > &field)
virtual void VisitEnumField(const REnumField &field)
virtual void VisitInt16Field(const RIntegralField< std::int16_t > &field)
virtual void VisitArrayAsRVecField(const RArrayAsRVecField &field)
virtual void VisitUInt32Field(const RIntegralField< std::uint32_t > &field)
virtual void VisitDoubleField(const RField< double > &field)
virtual void VisitStringField(const RField< std::string > &field)
virtual void VisitInt32Field(const RIntegralField< std::int32_t > &field)
virtual void VisitField(const RFieldBase &field)=0
virtual void VisitCharField(const RField< char > &field)
virtual void VisitArrayField(const RArrayField &field)
virtual void VisitClassField(const RClassField &field)
virtual void VisitInt8Field(const RIntegralField< std::int8_t > &field)
virtual void VisitInt64Field(const RIntegralField< std::int64_t > &field)
virtual void VisitRecordField(const RRecordField &field)
virtual void VisitVectorField(const RVectorField &field)
virtual void VisitUInt8Field(const RIntegralField< std::uint8_t > &field)
virtual void VisitFloatField(const RField< float > &field)
virtual void VisitAtomicField(const RAtomicField &field)
Additional classes related to sequence containers.
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:268
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
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
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:58
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:241
Contains helper functions for RNTupleReader::PrintInfo() and RPrintSchemaVisitor::VisitField()
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.
std::ostream & fOutput
Where to write the printout to.
int fWidth
Indicates maximal number of allowed characters per line.
RPrintSchemaVisitor(std::ostream &out=std::cout, char frameSymbol=' *', int width=80, int deepestLevel=1, int numFields=1)
void SetAvailableSpaceForStrings()
Computes how many characters should be placed between the frame symbol and ':' for left and right sid...
char fFrameSymbol
To render the output, use an asterix (*) by default to draw table lines and boundaries.
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
std::ostream & fOutput
The output is directed to fOutput which may differ from std::cout.
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
RPrintValueVisitor(RFieldBase::RValue value, std::ostream &output, unsigned int level=0, RPrintOptions options=RPrintOptions())
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static void output()