32 std::unique_ptr<ROOT::Experimental::Detail::RPageSource> pageSource)
33 : fPageSource(std::move(pageSource))
36 auto descriptorGuard =
fPageSource->GetSharedDescriptorGuard();
43 fUncompressedSize = 0;
45 for (
const auto &colDesc : fDescriptor->GetColumnIterable()) {
46 auto colId = colDesc.GetPhysicalId();
50 auto colType = colDesc.GetModel().GetType();
52 std::uint64_t nElems = 0;
53 std::uint64_t compressedSize = 0;
55 for (
const auto &clusterDescriptor : fDescriptor->GetClusterIterable()) {
56 if (!clusterDescriptor.ContainsColumn(colId)) {
60 auto columnRange = clusterDescriptor.GetColumnRange(colId);
61 nElems += columnRange.fNElements;
63 if (fCompressionSettings == -1) {
64 fCompressionSettings = columnRange.fCompressionSettings;
65 }
else if (fCompressionSettings != columnRange.fCompressionSettings) {
70 std::to_string(fCompressionSettings) +
" vs " +
71 std::to_string(columnRange.fCompressionSettings) +
")"));
74 const auto &pageRange = clusterDescriptor.GetPageRange(colId);
76 for (
const auto &page : pageRange.fPageInfos) {
77 compressedSize += page.fLocator.fBytesOnStorage;
78 fCompressedSize += page.fLocator.fBytesOnStorage;
79 fUncompressedSize += page.fNElements * elemSize;
83 fColumnInfo.emplace(colId,
RColumnInfo(colDesc, compressedSize, elemSize, nElems));
90 std::uint64_t compressedSize = 0;
91 std::uint64_t uncompressedSize = 0;
93 for (
const auto &colDescriptor : fDescriptor->GetColumnIterable(fieldId)) {
94 auto colInfo = GetColumnInfo(colDescriptor.GetPhysicalId());
95 compressedSize += colInfo.GetCompressedSize();
96 uncompressedSize += colInfo.GetUncompressedSize();
99 for (
const auto &subFieldDescriptor : fDescriptor->GetFieldIterable(fieldId)) {
102 auto subFieldInfo = CollectFieldTreeInfo(subFieldId);
104 compressedSize += subFieldInfo.GetCompressedSize();
105 uncompressedSize += subFieldInfo.GetUncompressedSize();
108 auto fieldInfo =
RFieldTreeInfo(fDescriptor->GetFieldDescriptor(fieldId), compressedSize, uncompressedSize);
109 fFieldTreeInfo.emplace(fieldId, fieldInfo);
113std::vector<ROOT::Experimental::DescriptorId_t>
116 std::vector<DescriptorId_t> colIds;
117 std::deque<DescriptorId_t> fieldIdQueue{fieldId};
119 while (!fieldIdQueue.empty()) {
120 auto currId = fieldIdQueue.front();
121 fieldIdQueue.pop_front();
123 for (
const auto &col : fDescriptor->GetColumnIterable(currId)) {
124 if (col.IsAliasColumn()) {
128 colIds.emplace_back(col.GetPhysicalId());
131 for (
const auto &fld : fDescriptor->GetFieldIterable(currId)) {
132 fieldIdQueue.push_back(fld.GetId());
139std::unique_ptr<ROOT::Experimental::RNTupleInspector>
142 auto inspector = std::unique_ptr<RNTupleInspector>(
new RNTupleInspector(std::move(pageSource)));
144 inspector->CollectColumnInfo();
145 inspector->CollectFieldTreeInfo(inspector->GetDescriptor()->GetFieldZeroId());
150std::unique_ptr<ROOT::Experimental::RNTupleInspector>
157 std::unique_ptr<ROOT::Experimental::Detail::RPageSource> pageSource = sourceNTuple->
MakePageSource();
162std::unique_ptr<ROOT::Experimental::RNTupleInspector>
165 auto sourceFile = std::unique_ptr<TFile>(
TFile::Open(std::string(sourceFileName).c_str()));
166 if (!sourceFile || sourceFile->IsZombie()) {
167 throw RException(
R__FAIL(
"cannot open source file " + std::string(sourceFileName)));
169 auto ntuple = std::unique_ptr<ROOT::Experimental::RNTuple>(
173 R__FAIL(
"cannot read RNTuple " + std::string(ntupleName) +
" from " + std::string(sourceFileName)));
176 auto inspector = std::unique_ptr<RNTupleInspector>(
new RNTupleInspector(ntuple->MakePageSource()));
177 inspector->fSourceFile = std::move(sourceFile);
179 inspector->CollectColumnInfo();
180 inspector->CollectFieldTreeInfo(inspector->GetDescriptor()->GetFieldZeroId());
187 int algorithm = fCompressionSettings / 100;
188 int level = fCompressionSettings - (algorithm * 100);
191 " (level " + std::to_string(level) +
")";
199 if (physicalColumnId > fDescriptor->GetNPhysicalColumns()) {
200 throw RException(
R__FAIL(
"No column with physical ID " + std::to_string(physicalColumnId) +
" present"));
203 return fColumnInfo.at(physicalColumnId);
208 size_t typeCount = 0;
210 for (
auto &[colId, colInfo] : fColumnInfo) {
211 if (colInfo.GetType() == colType) {
219const std::vector<ROOT::Experimental::DescriptorId_t>
222 std::vector<DescriptorId_t> colIds;
224 for (
const auto &[colId, colInfo] : fColumnInfo) {
225 if (colInfo.GetType() == colType)
226 colIds.emplace_back(colId);
234 struct ColumnTypeInfo {
236 std::uint64_t nElems, compressedSize, uncompressedSize;
247 std::map<EColumnType, ColumnTypeInfo> colTypeInfo;
249 for (
const auto &[colId, colInfo] : fColumnInfo) {
250 colTypeInfo[colInfo.GetType()] += colInfo;
255 output <<
" column type | count | # elements | compressed bytes | uncompressed bytes\n"
256 <<
"----------------|---------|-----------------|-------------------|--------------------" << std::endl;
257 for (
const auto &[colType, typeInfo] : colTypeInfo) {
259 << typeInfo.count <<
" |" << std::setw(16) << typeInfo.nElems <<
" |" << std::setw(18)
260 << typeInfo.compressedSize <<
" |" << std::setw(18) << typeInfo.uncompressedSize <<
" " << std::endl;
264 output <<
"columnType,count,nElements,compressedSize,uncompressedSize" << std::endl;
265 for (
const auto &[colType, typeInfo] : colTypeInfo) {
267 <<
"," << typeInfo.compressedSize <<
"," << typeInfo.uncompressedSize << std::endl;
276 std::string_view histName, std::string_view histTitle)
278 if (histName ==
"") {
288 if (histTitle ==
"") {
298 auto hist = std::make_unique<TH1D>(std::string(histName).c_str(), std::string(histTitle).c_str(), 1, 0, 1);
301 for (
const auto &[colId, colInfo] : fColumnInfo) {
322 if (fieldId >= fDescriptor->GetNFields()) {
323 throw RException(
R__FAIL(
"No field with ID " + std::to_string(fieldId) +
" present"));
326 return fFieldTreeInfo.at(fieldId);
335 throw RException(
R__FAIL(
"Could not find field `" + std::string(fieldName) +
"`"));
338 return GetFieldTreeInfo(fieldId);
342 bool includeSubFields)
const
344 size_t typeCount = 0;
346 for (
auto &[fldId, fldInfo] : fFieldTreeInfo) {
347 if (!includeSubFields && fldInfo.GetDescriptor().GetParentId() != fDescriptor->GetFieldZeroId()) {
351 if (std::regex_match(fldInfo.GetDescriptor().GetTypeName(), typeNamePattern)) {
359const std::vector<ROOT::Experimental::DescriptorId_t>
362 std::vector<DescriptorId_t> fieldIds;
364 for (
auto &[fldId, fldInfo] : fFieldTreeInfo) {
366 if (!searchInSubFields && fldInfo.GetDescriptor().GetParentId() != fDescriptor->GetFieldZeroId()) {
370 if (std::regex_match(fldInfo.GetDescriptor().GetFieldName(), fieldNamePattern)) {
371 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)
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 available trivial, native content types of a column.
Base class for all ROOT issued exceptions.
Holds column-level storage information.
std::uint64_t GetUncompressedSize() const
std::uint64_t GetNElements() const
std::uint64_t GetCompressedSize() const
Holds field-level storage information.
Inspect on-disk and storage-related information of an RNTuple.
const RFieldTreeInfo & GetFieldTreeInfo(DescriptorId_t fieldId) const
Get storage information for a given (sub)field by ID.
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.
size_t GetColumnCountByType(EColumnType colType) const
Get the number of columns of a given type present in the RNTuple.
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.
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.
RFieldTreeInfo 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.
RNTupleInspector(std::unique_ptr< Detail::RPageSource > pageSource)
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 RColumnInfo & GetColumnInfo(DescriptorId_t physicalColumnId) const
Get storage information for a given column.
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,.
std::unique_ptr< Detail::RPageSource > fPageSource
Representation of an RNTuple data set in a ROOT file.
std::unique_ptr< Detail::RPageSource > MakePageSource(const RNTupleReadOptions &options=RNTupleReadOptions())
Create a page source from the RNTuple object.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
ENTupleInspectorPrintFormat
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)