24#include <unordered_map>
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;
37 return fFirstEntry == other.fFirstEntry;
40 bool operator <(
const ClusterInfo &other)
const {
41 return fFirstEntry < other.fFirstEntry;
47 std::uint64_t fLocalOrder = 0;
48 std::uint64_t fNElements = 0;
49 std::uint64_t fNPages = 0;
50 std::uint64_t fBytesOnStorage = 0;
51 std::uint32_t fElementSize = 0;
53 std::string fFieldName;
55 bool operator <(
const ColumnInfo &other)
const {
56 if (fFieldName == other.fFieldName)
57 return fLocalOrder < other.fLocalOrder;
58 return fFieldName < other.fFieldName;
68 return GetFieldName(fieldDesc.GetParentId(), ntupleDesc) +
"." + fieldDesc.GetFieldName();
99 std::vector<ColumnInfo> columns;
100 std::vector<ClusterInfo> clusters;
101 std::unordered_map<DescriptorId_t, unsigned int> cluster2Idx;
104 info.fFirstEntry = cluster.second.GetFirstEntryIndex();
105 info.fNEntries = cluster.second.GetNEntries();
106 cluster2Idx[cluster.first] = clusters.size();
107 clusters.emplace_back(info);
110 std::uint64_t bytesOnStorage = 0;
111 std::uint64_t bytesInMemory = 0;
112 std::uint64_t nPages = 0;
113 int compression = -1;
116 auto elementSize = element.GetSize();
119 info.fFieldId = column.second.GetFieldId();
120 info.fLocalOrder = column.second.GetIndex();
121 info.fElementSize = elementSize;
122 info.fType = column.second.GetModel().GetType();
125 auto columnRange = cluster.second.GetColumnRange(column.first);
126 info.fNElements += columnRange.fNElements;
127 if (compression == -1) {
128 compression = columnRange.fCompressionSettings;
130 const auto &pageRange = cluster.second.GetPageRange(column.first);
131 auto idx = cluster2Idx[cluster.first];
132 for (
const auto &page : pageRange.fPageInfos) {
133 bytesOnStorage += page.fLocator.fBytesOnStorage;
134 bytesInMemory += page.fNElements * elementSize;
135 clusters[idx].fBytesOnStorage += page.fLocator.fBytesOnStorage;
136 clusters[idx].fBytesInMemory += page.fNElements * elementSize;
137 ++clusters[idx].fNPages;
138 info.fBytesOnStorage += page.fLocator.fBytesOnStorage;
143 columns.emplace_back(info);
147 output <<
"============================================================" << std::endl;
149 output <<
"Compression: " << compression << std::endl;
150 output <<
"------------------------------------------------------------" << std::endl;
154 output <<
" # Pages: " << nPages << std::endl;
156 output <<
" Size on storage: " << bytesOnStorage <<
" B" << std::endl;
157 output <<
" Compression rate: " << std::fixed << std::setprecision(2)
158 << float(bytesInMemory) / float(bytesOnStorage) << std::endl;
159 output <<
" Header size: " << headerSize <<
" B" << std::endl;
160 output <<
" Footer size: " << footerSize <<
" B" << std::endl;
161 output <<
" Meta-data / data: " << std::fixed << std::setprecision(3)
162 << float(headerSize + footerSize) / float(bytesOnStorage) << std::endl;
163 output <<
"------------------------------------------------------------" << std::endl;
164 output <<
"CLUSTER DETAILS" << std::endl;
165 output <<
"------------------------------------------------------------" << std::endl;
167 std::sort(clusters.begin(), clusters.end());
168 for (
unsigned int i = 0; i < clusters.size(); ++i) {
169 output <<
" # " << std::setw(5) << i
170 <<
" Entry range: [" << clusters[i].fFirstEntry <<
".."
171 << clusters[i].fFirstEntry + clusters[i].fNEntries <<
") -- " << clusters[i].fNEntries << std::endl;
173 <<
" # Pages: " << clusters[i].fNPages << std::endl;
175 <<
" Size on storage: " << clusters[i].fBytesOnStorage <<
" B" << std::endl;
177 <<
" Compression: " << std::fixed << std::setprecision(2)
178 << float(clusters[i].fBytesInMemory) / float(
float(clusters[i].fBytesOnStorage)) << std::endl;
181 output <<
"------------------------------------------------------------" << std::endl;
182 output <<
"COLUMN DETAILS" << std::endl;
183 output <<
"------------------------------------------------------------" << std::endl;
184 for (
auto &col : columns)
185 col.fFieldName = GetFieldName(col.fFieldId, *
this).substr(1);
186 std::sort(columns.begin(), columns.end());
187 for (
const auto &col : columns) {
188 auto avgPageSize = (col.fNPages == 0) ? 0 : (col.fBytesOnStorage / col.fNPages);
189 auto avgElementsPerPage = (col.fNPages == 0) ? 0 : (col.fNElements / col.fNPages);
190 output <<
" " << col.fFieldName <<
" [#" << col.fLocalOrder <<
"]" <<
" -- "
191 << GetColumnTypeName(col.fType) << std::endl;
192 output <<
" # Elements: " << col.fNElements << std::endl;
193 output <<
" # Pages: " << col.fNPages << std::endl;
194 output <<
" Avg elements / page: " << avgElementsPerPage << std::endl;
195 output <<
" Avg page size: " << avgPageSize <<
" B" << std::endl;
196 output <<
" Size on storage: " << col.fBytesOnStorage <<
" B" << std::endl;
197 output <<
" Compression: " << std::fixed << std::setprecision(2)
198 << float(col.fElementSize * col.fNElements) / float(col.fBytesOnStorage) << std::endl;
199 output <<
"............................................................" << std::endl;
Bool_t operator<(const TDatime &d1, const TDatime &d2)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
static RColumnElementBase Generate(EColumnType type)
The available trivial, native content types of a column.
std::string GetFieldName() const
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::uint32_t SerializeHeader(void *buffer) const
We deliberately do not use ROOT's built-in serialization in order to allow for use of RNTuple's witho...
std::string GetName() const
std::size_t GetNClusters() const
std::unordered_map< DescriptorId_t, RColumnDescriptor > fColumnDescriptors
NTupleSize_t GetNEntries() const
std::uint32_t SerializeFooter(void *buffer) const
Serializes cluster meta data. Returns the number of bytes and fills buffer if it is not nullptr.
std::size_t GetNFields() const
const RFieldDescriptor & GetFieldDescriptor(DescriptorId_t fieldId) const
std::size_t GetNColumns() 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(int code)