Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RNTupleDescriptorFmt.cxx
Go to the documentation of this file.
1/// \file RNTupleDescriptorFmt.cxx
2/// \ingroup NTuple
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2019-08-25
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
16#include <ROOT/RNTupleUtil.hxx>
17
18#include <algorithm>
19#include <iomanip>
20#include <ostream>
21#include <unordered_map>
22#include <vector>
23
24namespace {
25
26struct ClusterInfo {
27 std::uint64_t fFirstEntry = 0;
28 std::uint32_t fNPages = 0;
29 std::uint32_t fNEntries = 0;
30 std::uint32_t fNBytesOnStorage = 0;
31 std::uint32_t fNBytesInMemory = 0;
32
33 bool operator==(const ClusterInfo &other) const { return fFirstEntry == other.fFirstEntry; }
34
35 bool operator<(const ClusterInfo &other) const { return fFirstEntry < other.fFirstEntry; }
36};
37
38struct ColumnInfo {
39 ROOT::DescriptorId_t fPhysicalColumnId = 0;
40 ROOT::DescriptorId_t fLogicalColumnId = 0;
41 ROOT::DescriptorId_t fFieldId = 0;
42 std::uint64_t fNElements = 0;
43 std::uint64_t fNPages = 0;
44 std::uint64_t fNBytesOnStorage = 0;
45 std::uint32_t fElementSize = 0;
46 std::uint32_t fColumnIndex = 0;
47 std::uint16_t fRepresentationIndex = 0;
49 std::string fFieldName;
50 std::string fFieldDescription;
51
52 bool operator<(const ColumnInfo &other) const
53 {
54 if (fFieldName == other.fFieldName) {
55 if (fRepresentationIndex == other.fRepresentationIndex)
56 return fColumnIndex < other.fColumnIndex;
57 return fRepresentationIndex < other.fRepresentationIndex;
58 }
59 return fFieldName < other.fFieldName;
60 }
61};
62
63std::string GetFieldName(ROOT::DescriptorId_t fieldId, const ROOT::RNTupleDescriptor &ntupleDesc)
64{
65 const auto &fieldDesc = ntupleDesc.GetFieldDescriptor(fieldId);
66 if (fieldDesc.GetParentId() == ROOT::kInvalidDescriptorId)
67 return fieldDesc.GetFieldName();
68 return GetFieldName(fieldDesc.GetParentId(), ntupleDesc) + "." + fieldDesc.GetFieldName();
69}
70
71std::string GetFieldDescription(ROOT::DescriptorId_t fFieldId, const ROOT::RNTupleDescriptor &ntupleDesc)
72{
73 const auto &fieldDesc = ntupleDesc.GetFieldDescriptor(fFieldId);
74 return fieldDesc.GetFieldDescription();
75}
76
77} // anonymous namespace
78
80{
81 std::vector<ColumnInfo> columns;
82 std::vector<ClusterInfo> clusters;
83 std::unordered_map<ROOT::DescriptorId_t, unsigned int> cluster2Idx;
84 clusters.reserve(fClusterDescriptors.size());
85 for (const auto &cluster : fClusterDescriptors) {
86 ClusterInfo info;
87 info.fFirstEntry = cluster.second.GetFirstEntryIndex();
88 info.fNEntries = cluster.second.GetNEntries();
89 cluster2Idx[cluster.first] = clusters.size();
90 clusters.emplace_back(info);
91 }
92
93 std::uint64_t nBytesOnStorage = 0;
94 std::uint64_t nBytesInMemory = 0;
95 std::uint64_t nPages = 0;
96 int compression = -1;
97 for (const auto &column : fColumnDescriptors) {
98 // Alias columns (columns of projected fields) don't contribute to the storage consumption. Count them
99 // but don't add the the page sizes to the overall volume.
100 if (column.second.IsAliasColumn())
101 continue;
102
103 // We generate the default memory representation for the given column type in order
104 // to report the size _in memory_ of column elements
105 auto elementSize = ROOT::Internal::RColumnElementBase::Generate(column.second.GetType())->GetSize();
106
107 ColumnInfo info;
108 info.fPhysicalColumnId = column.second.GetPhysicalId();
109 info.fLogicalColumnId = column.second.GetLogicalId();
110 info.fFieldId = column.second.GetFieldId();
111 info.fColumnIndex = column.second.GetIndex();
112 info.fElementSize = elementSize;
113 info.fType = column.second.GetType();
114 info.fRepresentationIndex = column.second.GetRepresentationIndex();
115
116 for (const auto &cluster : fClusterDescriptors) {
117 auto columnRange = cluster.second.GetColumnRange(column.second.GetPhysicalId());
118 if (columnRange.IsSuppressed())
119 continue;
120
121 info.fNElements += columnRange.GetNElements();
122 if (compression == -1 && columnRange.GetCompressionSettings()) {
123 compression = *columnRange.GetCompressionSettings();
124 }
125 const auto &pageRange = cluster.second.GetPageRange(column.second.GetPhysicalId());
126 auto idx = cluster2Idx[cluster.first];
127 for (const auto &page : pageRange.GetPageInfos()) {
128 nBytesOnStorage += page.GetLocator().GetNBytesOnStorage();
129 nBytesInMemory += page.GetNElements() * elementSize;
130 clusters[idx].fNBytesOnStorage += page.GetLocator().GetNBytesOnStorage();
131 clusters[idx].fNBytesInMemory += page.GetNElements() * elementSize;
132 ++clusters[idx].fNPages;
133 info.fNBytesOnStorage += page.GetLocator().GetNBytesOnStorage();
134 ++info.fNPages;
135 ++nPages;
136 }
137 }
138 columns.emplace_back(info);
139 }
142 output << "============================================================\n";
143 output << "NTUPLE: " << GetName() << "\n";
144 output << "Compression: " << compression << "\n";
145 output << "------------------------------------------------------------\n";
146 output << " # Entries: " << GetNEntries() << "\n";
147 output << " # Fields: " << GetNFields() << "\n";
148 output << " # Columns: " << GetNPhysicalColumns() << "\n";
149 output << " # Alias Columns: " << GetNLogicalColumns() - GetNPhysicalColumns() << "\n";
150 output << " # Pages: " << nPages << "\n";
151 output << " # Clusters: " << GetNClusters() << "\n";
152 output << " Size on storage: " << nBytesOnStorage << " B" << "\n";
153 output << " Compression rate: " << std::fixed << std::setprecision(2)
154 << float(nBytesInMemory) / float(nBytesOnStorage) << "\n";
155 output << " Header size: " << headerSize << " B"
156 << "\n";
157 output << " Footer size: " << footerSize << " B"
158 << "\n";
159 output << " Metadata / data: " << std::fixed << std::setprecision(3)
160 << float(headerSize + footerSize) / float(nBytesOnStorage) << "\n";
161 output << "------------------------------------------------------------\n";
162 output << "CLUSTER DETAILS\n";
163 output << "------------------------------------------------------------" << std::endl;
164
165 std::sort(clusters.begin(), clusters.end());
166 for (unsigned int i = 0; i < clusters.size(); ++i) {
167 output << " # " << std::setw(5) << i << " Entry range: [" << clusters[i].fFirstEntry << ".."
168 << clusters[i].fFirstEntry + clusters[i].fNEntries - 1 << "] -- " << clusters[i].fNEntries << "\n";
169 output << " " << " # Pages: " << clusters[i].fNPages << "\n";
170 output << " " << " Size on storage: " << clusters[i].fNBytesOnStorage << " B\n";
171 output << " " << " Compression: " << std::fixed << std::setprecision(2)
172 << float(clusters[i].fNBytesInMemory) / float(float(clusters[i].fNBytesOnStorage)) << std::endl;
173 }
174
175 output << "------------------------------------------------------------\n";
176 output << "COLUMN DETAILS\n";
177 output << "------------------------------------------------------------\n";
178 for (auto &col : columns) {
179 col.fFieldName = GetFieldName(col.fFieldId, *this).substr(1);
180 col.fFieldDescription = GetFieldDescription(col.fFieldId, *this);
181 }
182 std::sort(columns.begin(), columns.end());
183 for (const auto &col : columns) {
184 auto avgPageSize = (col.fNPages == 0) ? 0 : (col.fNBytesOnStorage / col.fNPages);
185 auto avgElementsPerPage = (col.fNPages == 0) ? 0 : (col.fNElements / col.fNPages);
186 std::string nameAndType = std::string(" ") + col.fFieldName + " [#" + std::to_string(col.fColumnIndex);
187 if (col.fRepresentationIndex > 0)
188 nameAndType += " / R." + std::to_string(col.fRepresentationIndex);
189 nameAndType += "] -- " + std::string{ROOT::Internal::RColumnElementBase::GetColumnTypeName(col.fType)};
190 std::string id = std::string("{id:") + std::to_string(col.fLogicalColumnId) + "}";
191 if (col.fLogicalColumnId != col.fPhysicalColumnId)
192 id += " --alias--> " + std::to_string(col.fPhysicalColumnId);
193 output << nameAndType << std::setw(60 - nameAndType.length()) << id << "\n";
194 if (!col.fFieldDescription.empty())
195 output << " Description: " << col.fFieldDescription << "\n";
196 output << " # Elements: " << col.fNElements << "\n";
197 output << " # Pages: " << col.fNPages << "\n";
198 output << " Avg elements / page: " << avgElementsPerPage << "\n";
199 output << " Avg page size: " << avgPageSize << " B\n";
200 output << " Size on storage: " << col.fNBytesOnStorage << " B\n";
201 output << " Compression: " << std::fixed << std::setprecision(2)
202 << float(col.fElementSize * col.fNElements) / float(col.fNBytesOnStorage) << "\n";
203 output << "............................................................" << std::endl;
204 }
205}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Bool_t operator<(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:106
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition TDatime.h:102
The available trivial, native content types of a column.
static const char * GetColumnTypeName(ROOT::ENTupleColumnType type)
static std::unique_ptr< RColumnElementBase > Generate(ROOT::ENTupleColumnType type)
If CppT == void, use the default C++ type for the given column type.
The on-storage metadata of an RNTuple.
std::uint64_t GetOnDiskFooterSize() const
const std::string & GetName() const
ROOT::NTupleSize_t GetNEntries() const
We know the number of entries from adding the cluster summaries.
std::unordered_map< ROOT::DescriptorId_t, RClusterDescriptor > fClusterDescriptors
Potentially a subset of all the available clusters.
std::size_t GetNClusters() const
std::size_t GetNPhysicalColumns() const
void PrintInfo(std::ostream &output) const
std::unordered_map< ROOT::DescriptorId_t, RColumnDescriptor > fColumnDescriptors
std::size_t GetNFields() const
std::uint64_t GetOnDiskHeaderSize() const
std::size_t GetNLogicalColumns() const
const_iterator begin() const
const_iterator end() const
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr DescriptorId_t kInvalidDescriptorId
static void output()