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