33 std::unique_ptr<ROOT::Experimental::Internal::RPageSource> pageSource)
34 : fPageSource(std::move(pageSource))
37 auto descriptorGuard =
fPageSource->GetSharedDescriptorGuard();
47 fUncompressedSize = 0;
49 for (
const auto &colDesc : fDescriptor->GetColumnIterable()) {
50 if (colDesc.IsAliasColumn())
53 auto colId = colDesc.GetPhysicalId();
57 auto colType = colDesc.GetModel().GetType();
59 std::uint64_t nElems = 0;
60 std::vector<std::uint64_t> compressedPageSizes{};
62 for (
const auto &clusterDescriptor : fDescriptor->GetClusterIterable()) {
63 if (!clusterDescriptor.ContainsColumn(colId)) {
67 auto columnRange = clusterDescriptor.GetColumnRange(colId);
68 nElems += columnRange.fNElements;
70 if (fCompressionSettings == -1) {
71 fCompressionSettings = columnRange.fCompressionSettings;
72 }
else if (fCompressionSettings != columnRange.fCompressionSettings &&
78 std::to_string(fCompressionSettings) +
" vs " +
79 std::to_string(columnRange.fCompressionSettings) +
")"));
82 const auto &pageRange = clusterDescriptor.GetPageRange(colId);
84 for (
const auto &page : pageRange.fPageInfos) {
85 compressedPageSizes.emplace_back(page.fLocator.fBytesOnStorage);
86 fUncompressedSize += page.fNElements * elemSize;
90 fCompressedSize += std::accumulate(compressedPageSizes.begin(), compressedPageSizes.end(), 0);
91 fColumnInfo.emplace(colId,
RColumnInspector(colDesc, compressedPageSizes, elemSize, nElems));
98 std::uint64_t compressedSize = 0;
99 std::uint64_t uncompressedSize = 0;
101 for (
const auto &colDescriptor : fDescriptor->GetColumnIterable(fieldId)) {
102 auto colInfo = GetColumnInspector(colDescriptor.GetPhysicalId());
103 compressedSize += colInfo.GetCompressedSize();
104 uncompressedSize += colInfo.GetUncompressedSize();
107 for (
const auto &subFieldDescriptor : fDescriptor->GetFieldIterable(fieldId)) {
110 auto subFieldInfo = CollectFieldTreeInfo(subFieldId);
112 compressedSize += subFieldInfo.GetCompressedSize();
113 uncompressedSize += subFieldInfo.GetUncompressedSize();
116 auto fieldInfo =
RFieldTreeInspector(fDescriptor->GetFieldDescriptor(fieldId), compressedSize, uncompressedSize);
117 fFieldTreeInfo.emplace(fieldId, fieldInfo);
121std::vector<ROOT::Experimental::DescriptorId_t>
124 std::vector<DescriptorId_t> colIds;
125 std::deque<DescriptorId_t> fieldIdQueue{fieldId};
127 while (!fieldIdQueue.empty()) {
128 auto currId = fieldIdQueue.front();
129 fieldIdQueue.pop_front();
131 for (
const auto &col : fDescriptor->GetColumnIterable(currId)) {
132 if (col.IsAliasColumn()) {
136 colIds.emplace_back(col.GetPhysicalId());
139 for (
const auto &fld : fDescriptor->GetFieldIterable(currId)) {
140 fieldIdQueue.push_back(fld.GetId());
147std::unique_ptr<ROOT::Experimental::RNTupleInspector>
155 return std::unique_ptr<RNTupleInspector>(
new RNTupleInspector(std::move(pageSource)));
158std::unique_ptr<ROOT::Experimental::RNTupleInspector>
162 return std::unique_ptr<RNTupleInspector>(
new RNTupleInspector(std::move(pageSource)));
167 int algorithm = fCompressionSettings / 100;
168 int level = fCompressionSettings - (algorithm * 100);
171 " (level " + std::to_string(level) +
")";
179 if (physicalColumnId > fDescriptor->GetNPhysicalColumns()) {
180 throw RException(
R__FAIL(
"No column with physical ID " + std::to_string(physicalColumnId) +
" present"));
183 return fColumnInfo.at(physicalColumnId);
188 size_t typeCount = 0;
190 for (
auto &[colId, colInfo] : fColumnInfo) {
191 if (colInfo.GetType() == colType) {
199const std::vector<ROOT::Experimental::DescriptorId_t>
202 std::vector<DescriptorId_t> colIds;
204 for (
const auto &[colId, colInfo] : fColumnInfo) {
205 if (colInfo.GetType() == colType)
206 colIds.emplace_back(colId);
214 std::set<EColumnType> colTypes;
216 for (
const auto &[colId, colInfo] : fColumnInfo) {
217 colTypes.emplace(colInfo.GetType());
220 return std::vector(colTypes.begin(), colTypes.end());
225 struct ColumnTypeInfo {
227 std::uint64_t nElems, compressedSize, uncompressedSize;
238 std::map<EColumnType, ColumnTypeInfo> colTypeInfo;
240 for (
const auto &[colId, colInfo] : fColumnInfo) {
241 colTypeInfo[colInfo.GetType()] += colInfo;
246 output <<
" column type | count | # elements | compressed bytes | uncompressed bytes\n"
247 <<
"----------------|---------|-----------------|-------------------|--------------------" << std::endl;
248 for (
const auto &[colType, typeInfo] : colTypeInfo) {
250 << typeInfo.count <<
" |" << std::setw(16) << typeInfo.nElems <<
" |" << std::setw(18)
251 << typeInfo.compressedSize <<
" |" << std::setw(18) << typeInfo.uncompressedSize <<
" " << std::endl;
255 output <<
"columnType,count,nElements,compressedSize,uncompressedSize" << std::endl;
256 for (
const auto &[colType, typeInfo] : colTypeInfo) {
258 <<
"," << typeInfo.compressedSize <<
"," << typeInfo.uncompressedSize << std::endl;
267 std::string_view histName, std::string_view histTitle)
269 if (histName.empty()) {
279 if (histTitle.empty()) {
289 auto hist = std::make_unique<TH1D>(std::string(histName).c_str(), std::string(histTitle).c_str(), 1, 0, 1);
292 for (
const auto &[colId, colInfo] : fColumnInfo) {
309 std::string histName,
310 std::string histTitle,
size_t nBins)
312 if (histTitle.empty())
313 histTitle =
"Page size distribution for column with ID " + std::to_string(physicalColumnId);
315 return GetPageSizeDistribution({physicalColumnId}, histName, histTitle, nBins);
320 std::string histName, std::string histTitle,
size_t nBins)
322 if (histName.empty())
324 if (histTitle.empty())
327 auto perTypeHist = GetPageSizeDistribution({colType}, histName, histTitle, nBins);
329 if (perTypeHist->GetNhists() < 1)
330 return std::make_unique<TH1D>(histName.c_str(), histTitle.c_str(), 64, 0, 0);
332 auto hist = std::unique_ptr<TH1D>(
dynamic_cast<TH1D *
>(perTypeHist->GetHists()->First()));
334 hist->SetName(histName.c_str());
335 hist->SetTitle(histTitle.c_str());
336 hist->SetXTitle(
"Page size (B)");
337 hist->SetYTitle(
"N_{pages}");
343 std::string histName, std::string histTitle,
size_t nBins)
345 auto hist = std::make_unique<TH1D>();
347 if (histName.empty())
348 histName =
"pageSizeHist";
349 hist->SetName(histName.c_str());
350 if (histTitle.empty())
351 histTitle =
"Page size distribution";
352 hist->SetTitle(histTitle.c_str());
353 hist->SetXTitle(
"Page size (B)");
354 hist->SetYTitle(
"N_{pages}");
356 std::vector<std::uint64_t> pageSizes;
357 std::for_each(colIds.begin(), colIds.end(), [
this, &pageSizes](
const auto colId) {
358 auto colInfo = GetColumnInspector(colId);
359 pageSizes.insert(pageSizes.end(), colInfo.GetCompressedPageSizes().begin(),
360 colInfo.GetCompressedPageSizes().end());
363 auto histMinMax = std::minmax_element(pageSizes.begin(), pageSizes.end());
364 hist->SetBins(nBins, *histMinMax.first,
365 *histMinMax.second + ((*histMinMax.second - *histMinMax.first) /
static_cast<double>(nBins)));
367 for (
const auto pageSize : pageSizes) {
368 hist->Fill(pageSize);
375 std::initializer_list<ROOT::Experimental::EColumnType> colTypes, std::string histName, std::string histTitle,
378 if (histName.empty())
379 histName =
"pageSizeHist";
380 if (histTitle.empty())
381 histTitle =
"Per-column type page size distribution";
383 auto stackedHist = std::make_unique<THStack>(histName.c_str(), histTitle.c_str());
385 double histMin = std::numeric_limits<double>::max();
387 std::map<EColumnType, std::vector<std::uint64_t>> pageSizes;
389 std::vector<EColumnType> colTypeVec = colTypes;
390 if (std::empty(colTypes)) {
391 colTypeVec = GetColumnTypes();
394 for (
const auto colType : colTypeVec) {
395 auto colIds = GetColumnsByType(colType);
400 std::vector<std::uint64_t> pageSizesForColType;
401 std::for_each(colIds.cbegin(), colIds.cend(), [
this, &pageSizesForColType](
const auto colId) {
402 auto colInfo = GetColumnInspector(colId);
403 pageSizesForColType.insert(pageSizesForColType.end(), colInfo.GetCompressedPageSizes().begin(),
404 colInfo.GetCompressedPageSizes().end());
406 pageSizes.emplace(colType, pageSizesForColType);
408 auto histMinMax = std::minmax_element(pageSizesForColType.begin(), pageSizesForColType.end());
409 histMin = std::min(histMin,
static_cast<double>(*histMinMax.first));
410 histMax = std::max(histMax,
static_cast<double>(*histMinMax.second));
413 for (
const auto &[colType, pageSizesForColType] : pageSizes) {
414 auto hist = std::make_unique<TH1D>(
417 histMax + ((histMax - histMin) /
static_cast<double>(nBins)));
419 for (
const auto pageSize : pageSizesForColType) {
420 hist->Fill(pageSize);
423 stackedHist->Add(hist.release());
434 if (fieldId >= fDescriptor->GetNFields()) {
435 throw RException(
R__FAIL(
"No field with ID " + std::to_string(fieldId) +
" present"));
438 return fFieldTreeInfo.at(fieldId);
447 throw RException(
R__FAIL(
"Could not find field `" + std::string(fieldName) +
"`"));
450 return GetFieldTreeInspector(fieldId);
454 bool includeSubFields)
const
456 size_t typeCount = 0;
458 for (
auto &[fldId, fldInfo] : fFieldTreeInfo) {
459 if (!includeSubFields && fldInfo.GetDescriptor().GetParentId() != fDescriptor->GetFieldZeroId()) {
463 if (std::regex_match(fldInfo.GetDescriptor().GetTypeName(), typeNamePattern)) {
471const std::vector<ROOT::Experimental::DescriptorId_t>
474 std::vector<DescriptorId_t> fieldIds;
476 for (
auto &[fldId, fldInfo] : fFieldTreeInfo) {
478 if (!searchInSubFields && fldInfo.GetDescriptor().GetParentId() != fDescriptor->GetFieldZeroId()) {
482 if (std::regex_match(fldInfo.GetDescriptor().GetFieldName(), fieldNamePattern)) {
483 fieldIds.emplace_back(fldId);
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
std::string & operator+=(std::string &left, const TString &right)
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.
static std::unique_ptr< RPageSourceFile > CreateFromAnchor(const RNTuple &anchor, const RNTupleReadOptions &options=RNTupleReadOptions())
Used from the RNTuple class to build a datasource if the anchor is already available.
static std::unique_ptr< RPageSource > Create(std::string_view ntupleName, std::string_view location, const RNTupleReadOptions &options=RNTupleReadOptions())
Guess the concrete derived page source from the file name (location)
Base class for all ROOT issued exceptions.
Provides column-level storage information.
std::uint64_t GetCompressedSize() const
std::uint64_t GetUncompressedSize() const
std::uint64_t GetNElements() const
Provides field-level storage information.
Inspect on-disk and storage-related information of an RNTuple.
const RColumnInspector & GetColumnInspector(DescriptorId_t physicalColumnId) const
Get storage information for a given column.
const std::vector< DescriptorId_t > GetFieldsByName(const std::regex &fieldNamePattern, bool searchInSubFields=true) const
Get the IDs of (sub-)fields whose name matches the given string.
std::unique_ptr< Internal::RPageSource > fPageSource
const std::vector< EColumnType > GetColumnTypes()
Get all column types present in the RNTuple being inspected.
size_t GetColumnCountByType(EColumnType colType) const
Get the number of columns of a given type present in the RNTuple.
RNTupleInspector(std::unique_ptr< Internal::RPageSource > pageSource)
std::string GetCompressionSettingsAsString() const
Get a string describing compression settings of the RNTuple being inspected.
static std::unique_ptr< RNTupleInspector > Create(RNTuple *sourceNTuple)
Create a new RNTupleInspector.
std::unique_ptr< TH1D > GetPageSizeDistribution(DescriptorId_t physicalColumnId, std::string histName="", std::string histTitle="", size_t nBins=64)
Get a histogram containing the size distribution of the compressed pages for an individual column.
const std::vector< DescriptorId_t > GetColumnsByType(EColumnType colType)
Get the IDs of all columns with the given type.
void PrintColumnTypeInfo(ENTupleInspectorPrintFormat format=ENTupleInspectorPrintFormat::kTable, std::ostream &output=std::cout)
Print storage information per column type.
RFieldTreeInspector CollectFieldTreeInfo(DescriptorId_t fieldId)
Recursively gather field-level information.
std::unique_ptr< RNTupleDescriptor > fDescriptor
std::vector< DescriptorId_t > GetColumnsByFieldId(DescriptorId_t fieldId) const
Get the columns that make up the given field, including its subfields.
void CollectColumnInfo()
Gather column-level and RNTuple-level information.
size_t GetFieldCountByType(const std::regex &typeNamePattern, bool searchInSubFields=true) const
Get the number of fields of a given type or class present in the RNTuple.
const RFieldTreeInspector & GetFieldTreeInspector(DescriptorId_t fieldId) const
Get storage information for a given (sub)field by ID.
std::unique_ptr< TH1D > GetColumnTypeInfoAsHist(ENTupleInspectorHist histKind, std::string_view histName="", std::string_view histTitle="")
Get a histogram showing information for each column type present,.
Representation of an RNTuple data set in a ROOT file.
1-D histogram with a double per channel (see TH1 documentation)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
ENTupleInspectorPrintFormat
constexpr int kUnknownCompressionSettings
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
constexpr DescriptorId_t kInvalidDescriptorId
EValues
Note: this is only temporarily a struct and will become a enum class hence the name.
static std::string AlgorithmToString(EAlgorithm::EValues algorithm)