Skip to content

Commit

Permalink
[ntuple] improve compression settings access in inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Jan 14, 2025
1 parent 2296923 commit 414a240
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
7 changes: 4 additions & 3 deletions tree/ntupleutil/v7/inc/ROOT/RNTupleInspector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ auto rntuple = std::unique_ptr<RNTuple>(file->Get<RNTuple>("NTupleName"));
auto inspector = RNTupleInspector::Create(*rntuple);
std::cout << "The compression factor is " << inspector->GetCompressionFactor()
<< " using compression settings " << inspector->GetCompressionSettings()
<< " using compression settings " << inspector->GetCompressionSettingsAsString()
<< std::endl;
~~~
*/
Expand Down Expand Up @@ -135,7 +135,7 @@ public:
private:
std::unique_ptr<Internal::RPageSource> fPageSource;
std::unique_ptr<RNTupleDescriptor> fDescriptor;
std::optional<std::uint32_t> fCompressionSettings;
std::optional<std::uint32_t> fCompressionSettings; ///< The compression settings are unknown for an empty ntuple
std::uint64_t fCompressedSize = 0;
std::uint64_t fUncompressedSize = 0;

Expand Down Expand Up @@ -210,10 +210,11 @@ public:
///
/// \return The integer representation (\f$algorithm * 10 + level\f$, where \f$algorithm\f$ follows
/// ROOT::RCompressionSetting::ELevel::EValues) of the compression settings used for the inspected RNTuple.
/// Empty for an empty ntuple.
///
/// \note Here, we assume that the compression settings are consistent across all clusters and columns. If this is
/// not the case, an exception will be thrown when RNTupleInspector::Create is called.
int GetCompressionSettings() const { return fCompressionSettings.value(); }
std::optional<std::uint32_t> GetCompressionSettings() const { return fCompressionSettings; }

/////////////////////////////////////////////////////////////////////////////
/// \brief Get a string describing compression settings of the RNTuple being inspected.
Expand Down
7 changes: 5 additions & 2 deletions tree/ntupleutil/v7/src/RNTupleInspector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ ROOT::Experimental::RNTupleInspector::Create(std::string_view ntupleName, std::s

std::string ROOT::Experimental::RNTupleInspector::GetCompressionSettingsAsString() const
{
int algorithm = fCompressionSettings.value() / 100;
int level = fCompressionSettings.value() - (algorithm * 100);
if (!fCompressionSettings)
return "unknown";

int algorithm = *fCompressionSettings / 100;
int level = *fCompressionSettings - (algorithm * 100);

return RCompressionSetting::AlgorithmToString(static_cast<RCompressionSetting::EAlgorithm::EValues>(algorithm)) +
" (level " + std::to_string(level) + ")";
Expand Down
16 changes: 14 additions & 2 deletions tree/ntupleutil/v7/test/ntuple_inspector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEST(RNTupleInspector, CompressionSettings)

auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());

EXPECT_EQ(207, inspector->GetCompressionSettings());
EXPECT_EQ(207, *inspector->GetCompressionSettings());
EXPECT_EQ("LZMA (level 7)", inspector->GetCompressionSettingsAsString());
}

Expand Down Expand Up @@ -94,7 +94,19 @@ TEST(RNTupleInspector, UnknownCompression)
}

auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
EXPECT_EQ(505, inspector->GetCompressionSettings());
EXPECT_EQ(505, *inspector->GetCompressionSettings());
}

TEST(RNTupleInspector, Empty)
{
FileRaii fileGuard("test_ntuple_inspector_empty.root");
{
auto writer = RNTupleWriter::Recreate(RNTupleModel::Create(), "ntuple", fileGuard.GetPath());
}

auto inspector = RNTupleInspector::Create("ntuple", fileGuard.GetPath());
EXPECT_FALSE(inspector->GetCompressionSettings());
EXPECT_EQ("unknown", inspector->GetCompressionSettingsAsString());
}

TEST(RNTupleInspector, SizeUncompressedSimple)
Expand Down

0 comments on commit 414a240

Please sign in to comment.