Logo ROOT  
Reference Guide
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/RFieldValue.hxx>
21#include <ROOT/RNTupleUtil.hxx>
22
23#include <algorithm>
24#include <iostream>
25#include <sstream>
26#include <string>
27#include <vector>
28
29namespace ROOT {
30namespace Experimental {
31namespace Detail {
32
33
34// clang-format off
35/**
36\class ROOT::Experimental::Detail::RFieldVisitor
37\ingroup NTuple
38\brief Abstract base class for classes implementing the visitor design pattern.
39
40RFieldVisitor::VisitField() is invoked by RFieldBase::AcceptVisitor(). VisitField() is inherited for instance
41by the RPrintSchemaVisitor class. The RFieldBase class and classes which inherit from it will be visited.
42*/
43// clang-format on
45public:
46 virtual void VisitField(const Detail::RFieldBase &field) = 0;
47 virtual void VisitFieldZero(const RFieldZero &field) { VisitField(field); }
48 virtual void VisitArrayField(const RArrayField &field) { VisitField(field); }
49 virtual void VisitBoolField(const RField<bool> &field) { VisitField(field); }
50 virtual void VisitClassField(const RClassField &field) { VisitField(field); }
51 virtual void VisitRecordField(const RRecordField &field) { VisitField(field); }
52 virtual void VisitClusterSizeField(const RField<ClusterSize_t> &field) { VisitField(field); }
53 virtual void VisitDoubleField(const RField<double> &field) { VisitField(field); }
54 virtual void VisitFloatField(const RField<float> &field) { VisitField(field); }
55 virtual void VisitCharField(const RField<char> &field) { VisitField(field); }
56 virtual void VisitInt8Field(const RField<std::int8_t> &field) { VisitField(field); }
57 virtual void VisitInt16Field(const RField<std::int16_t> &field) { VisitField(field); }
58 virtual void VisitIntField(const RField<int> &field) { VisitField(field); }
59 virtual void VisitInt64Field(const RField<std::int64_t> &field) { VisitField(field); }
60 virtual void VisitStringField(const RField<std::string> &field) { VisitField(field); }
61 virtual void VisitUInt16Field(const RField<std::uint16_t> &field) { VisitField(field); }
62 virtual void VisitUInt32Field(const RField<std::uint32_t> &field) { VisitField(field); }
63 virtual void VisitUInt64Field(const RField<std::uint64_t> &field) { VisitField(field); }
64 virtual void VisitUInt8Field(const RField<std::uint8_t> &field) { VisitField(field); }
65 virtual void VisitVectorField(const RVectorField &field) { VisitField(field); }
66 virtual void VisitVectorBoolField(const RField<std::vector<bool>> &field) { VisitField(field); }
67}; // class RFieldVisitor
68
69} // namespace Detail
70
71
72// clang-format off
73/**
74\class ROOT::Experimental::RPrepareVisitor
75\ingroup NTuple
76\brief Visitor used for a pre-processing run to collect information needed by another visitor class.
77
78 Currently used for RPrintSchemaVisitor in RNTupleReader::Print() to collect information about levels, max depth etc.
79*/
80// clang-format on
82private:
83 unsigned int fDeepestLevel = 1;
84 unsigned int fNumFields = 1;
85
86public:
87 RPrepareVisitor() = default;
88 void VisitField(const Detail::RFieldBase &field) final;
89 void VisitFieldZero(const RFieldZero &field) final;
90
91 unsigned int GetDeepestLevel() const { return fDeepestLevel; }
92 unsigned int GetNumFields() const { return fNumFields; }
93};
94
95
96// clang-format off
97/**
98\class ROOT::Experimental::RPrintSchemaVisitor
99\ingroup NTuple
100\brief Contains settings for printing and prints a summary of an RField instance.
101
102This visitor is used by RNTupleReader::Print()
103*/
104// clang-format on
106private:
107 /// Where to write the printout to
108 std::ostream &fOutput;
109 /// To render the output, use an asterix (*) by default to draw table lines and boundaries
111 /// Indicates maximal number of allowed characters per line
117 int fFieldNo = 1;
118 std::string fTreePrefix;
119 std::string fFieldNoPrefix;
120
121public:
122 RPrintSchemaVisitor(std::ostream &out = std::cout, char frameSymbol = '*', int width = 80, int deepestLevel = 1,
123 int numFields = 1)
124 : fOutput{out}, fFrameSymbol{frameSymbol}, fWidth{width}, fDeepestLevel{deepestLevel}, fNumFields{numFields}
125 {
127 }
128 /// Prints summary of Field
129 void VisitField(const Detail::RFieldBase &field) final;
130 void VisitFieldZero(const RFieldZero &fieldZero) final;
131 void SetFrameSymbol(char s) { fFrameSymbol = s; }
132 void SetWidth(int w) { fWidth = w; }
133 void SetDeepestLevel(int d);
134 void SetNumFields(int n);
135 /// Computes how many characters should be placed between the frame symbol and ':' for left and right side of ':' for
136 /// visually pleasing output.
137 // E.g.
138 // * Field 1 : vpx (std::vector<float>) *
139 // * |__Field 1.1 : vpx/vpx (float) *
140 // int fAvailableSpaceKeyString (num characters on left side between "* " and " : ")
141 // deepestlevel here is 2 (1.1 is deepest and has 2 numbers).
142 // For every additional level an additional "|_" and ".1" (4 characters) is added, so the number of required
143 // additional characters is 4 * fDeepestLevel. For level 1, 8 characters are required ("Field 1 "), so an
144 // additional + 4 is added. To account for cases where the total number of fields is not a single digit number and
145 // more space is required to output big numbers, fNumFields is incorporated into the calculation. To make sure
146 // that there is still enough space for the right side of " : ", an std::min comparision with fWidth - 15 is done.
147 // int fAvailableSpaceValueString(num characters on right side between " : " and '*')
148 // The 6 subtracted characters are "* " (2) in the beginning, " : " (3) and '*' (1) on the far right.
150 {
152 std::min(4 * fDeepestLevel + 4 + static_cast<int>(std::to_string(fNumFields).size()), fWidth - 15);
154 }
155};
156
157
158// clang-format off
159/**
160\class ROOT::Experimental::RPrintValueVisitor
161\ingroup NTuple
162\brief Renders a JSON value corresponding to the field.
163*/
164// clang-format on
166public:
170
172 };
173
174private:
176 /// The output is directed to fOutput which may differ from std::cout.
177 std::ostream &fOutput;
178 unsigned int fLevel;
180
181 void PrintIndent();
182 void PrintName(const Detail::RFieldBase &field);
183 void PrintCollection(const Detail::RFieldBase &field);
184
185public:
187 std::ostream &output,
188 unsigned int level = 0,
189 RPrintOptions options = RPrintOptions())
190 : fValue(value), fOutput{output}, fLevel(level), fPrintOptions(options) {}
191
192 void VisitField(const Detail::RFieldBase &field) final;
193
194 void VisitBoolField(const RField<bool> &field) final;
195 void VisitDoubleField(const RField<double> &field) final;
196 void VisitFloatField(const RField<float> &field) final;
197 void VisitCharField(const RField<char> &field) final;
198 void VisitInt8Field(const RField<std::int8_t> &field) final;
199 void VisitInt16Field(const RField<std::int16_t> &field) final;
200 void VisitIntField(const RField<int> &field) final;
201 void VisitInt64Field(const RField<std::int64_t> &field) final;
202 void VisitStringField(const RField<std::string> &field) final;
203 void VisitUInt8Field(const RField<std::uint8_t> &field) final;
204 void VisitUInt16Field(const RField<std::uint16_t> &field) final;
205 void VisitUInt32Field(const RField<std::uint32_t> &field) final;
206 void VisitUInt64Field(const RField<std::uint64_t> &field) final;
207
208 void VisitArrayField(const RArrayField &field) final;
209 void VisitClassField(const RClassField &field) final;
210 void VisitRecordField(const RRecordField &field) final;
211 void VisitVectorField(const RVectorField &field) final;
212 void VisitVectorBoolField(const RField<std::vector<bool>> &field) final;
213};
214
215
216// clang-format off
217/**
218\class ROOT::Experimental::RNTupleFormatter
219\ingroup NTuple
220\brief Contains helper functions for RNTupleReader::PrintInfo() and RPrintSchemaVisitor::VisitField()
221
222The functions in this class format strings which are displayed by RNTupleReader::PrintInfo() and RNTupleReader::Show().
223*/
224// clang-format on
226public:
227 // Can abbreviate long strings, e.g. ("ExampleString" , space= 8) => "Examp..."
228 static std::string FitString(const std::string &str, int availableSpace);
229};
230
231} // namespace Experimental
232} // namespace ROOT
233
234#endif
#define d(i)
Definition: RSha256.hxx:102
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
Abstract base class for classes implementing the visitor design pattern.
virtual void VisitBoolField(const RField< bool > &field)
virtual void VisitVectorBoolField(const RField< std::vector< bool > > &field)
virtual void VisitFieldZero(const RFieldZero &field)
virtual void VisitInt8Field(const RField< std::int8_t > &field)
virtual void VisitClusterSizeField(const RField< ClusterSize_t > &field)
virtual void VisitField(const Detail::RFieldBase &field)=0
virtual void VisitDoubleField(const RField< double > &field)
virtual void VisitStringField(const RField< std::string > &field)
virtual void VisitUInt32Field(const RField< std::uint32_t > &field)
virtual void VisitUInt64Field(const RField< std::uint64_t > &field)
virtual void VisitInt16Field(const RField< std::int16_t > &field)
virtual void VisitCharField(const RField< char > &field)
virtual void VisitArrayField(const RArrayField &field)
virtual void VisitClassField(const RClassField &field)
virtual void VisitIntField(const RField< int > &field)
virtual void VisitUInt16Field(const RField< std::uint16_t > &field)
virtual void VisitRecordField(const RRecordField &field)
virtual void VisitUInt8Field(const RField< std::uint8_t > &field)
virtual void VisitInt64Field(const RField< std::int64_t > &field)
virtual void VisitVectorField(const RVectorField &field)
virtual void VisitFloatField(const RField< float > &field)
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
The container field for an ntuple model, which itself has no physical representation.
Definition: RField.hxx:271
Template specializations for concrete C++ types.
Definition: RField.hxx:538
Classes with dictionaries that can be inspected by TClass.
Definition: RField.hxx:480
Contains helper functions for RNTupleReader::PrintInfo() and RPrintSchemaVisitor::VisitField()
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
unsigned int GetDeepestLevel() const
void VisitFieldZero(const RFieldZero &field) final
Contains settings for printing and prints a summary of an RField instance.
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 VisitField(const Detail::RFieldBase &field) final
Prints summary of Field.
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
void VisitUInt16Field(const RField< std::uint16_t > &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 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)
RPrintValueVisitor(const Detail::RFieldValue &value, std::ostream &output, unsigned int level=0, RPrintOptions options=RPrintOptions())
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
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static constexpr double s
static void output(int code)
Definition: gifencode.c:226