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