Logo ROOT  
Reference Guide
RFieldVisitor.cxx
Go to the documentation of this file.
1/// \file RFieldVisitor.cxx
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#include <algorithm>
17#include <iomanip>
18#include <iostream>
19#include <sstream>
20#include <string>
21#include <vector>
22
23#include "ROOT/RField.hxx"
25#include "ROOT/RNTuple.hxx"
26
27
28//---------------------------- RPrintVisitor ------------------------------------
29
32 fFlagForVerticalLines.resize(d - 1);
33}
34
36 fNumFields = n;
37 SetAvailableSpaceForStrings();
38}
39
41{
42 std::string result{""};
43 if (level==1) {
44 result += "Field ";
45 result += std::to_string(field.GetLevelInfo().GetOrder());
46 } else {
47 if (field.GetLevelInfo().GetOrder() == field.GetLevelInfo().GetNumSiblings()) { fFlagForVerticalLines.at(level-2) = false;
48 } else {
49 fFlagForVerticalLines.at(level-2) = true;
50 }
51 for(int i = 0; i < level-2; ++i) {
52 if (fFlagForVerticalLines.at(i)) {
53 result+= "| ";
54 } else {
55 result += " ";
56 }
57 }
58 result += "|__Field ";
60 }
61 return result;
62}
63
65{
66 std::string nameAndType{field.GetName() + " (" + field.GetType() + ")"};
67 return nameAndType;
68}
69
70// Entire function only prints 1 Line, when if statement is disregarded.
72{
73 if (level == 1)
74 {
75 for (int i = 0; i < fWidth; ++i) {
76 fOutput << fFrameSymbol;
77 }
78 fOutput << std::endl;
79 }
80 fOutput << fFrameSymbol << ' ';
81 fOutput << RNTupleFormatter::FitString(MakeKeyString(field, level), fAvailableSpaceKeyString);
82 fOutput << " : ";
83 fOutput << RNTupleFormatter::FitString(MakeValueString(field), fAvailableSpaceValueString);
84 fOutput << fFrameSymbol << std::endl;
85}
86
87//---------------------- RPrepareVisitor -------------------------------
88
89
91{
92 ++fNumFields;
93 if (level > fDeepestLevel)
94 fDeepestLevel = level;
95}
96
97//------------------------ RNTupleFormatter -----------------------------
98
99//E.g. ("ExampleString" , space= 8) => "Examp..."
100std::string ROOT::Experimental::RNTupleFormatter::FitString(const std::string &str, int availableSpace) {
101 int strSize{static_cast<int>(str.size())};
102 if (strSize <= availableSpace)
103 return str + std::string(availableSpace - strSize, ' ');
104 else if (availableSpace < 3)
105 return std::string(availableSpace, '.');
106 return std::string(str, 0, availableSpace - 3) + "...";
107}
108
109// Returns std::string of form "1" or "2.1.1"
111{
112 std::string hierarchialOrder{std::to_string(field.GetLevelInfo().GetOrder())};
113 const ROOT::Experimental::Detail::RFieldBase* parentPtr{field.GetParent()};
114 // To avoid having the index of the RootField (-1) in the return value, it is checked if the grandparent is a nullptr (in that case RootField is parent)
115 while (parentPtr && (parentPtr->GetLevelInfo().GetOrder() != -1)) {
116 hierarchialOrder = std::to_string(parentPtr->GetLevelInfo().GetOrder()) + "." + hierarchialOrder;
117 parentPtr = parentPtr->GetParent();
118 }
119 return hierarchialOrder;
120}
#define d(i)
Definition: RSha256.hxx:102
const RFieldBase * GetParent() const
Definition: RField.hxx:249
static std::string FitString(const std::string &str, int availableSpace)
static std::string HierarchialFieldOrder(const Detail::RFieldBase &field)
void VisitField(const Detail::RFieldBase &field, int level) final
std::vector< bool > fFlagForVerticalLines
Keeps track when | is used for the tree-like structure.
std::string MakeValueString(const Detail::RFieldBase &field)
ValueString refers to the right side containing the type and name.
void VisitField(const Detail::RFieldBase &field, int level) final
Prints summary of Field.
std::string MakeKeyString(const Detail::RFieldBase &field, int level)
KeyString refers to the left side containing the word "Field" and its hierarchial order.
const Int_t n
Definition: legend1.C:16
int GetOrder(const RFieldBase *field=nullptr) const
Definition: RField.hxx:120
int GetNumSiblings(const RFieldBase *field=nullptr) const
Definition: RField.hxx:104