Skip to content
Snippets Groups Projects
Commit 4cf0411d authored by Florine de Geus's avatar Florine de Geus Committed by Jakob Blomer
Browse files

[ntuple] Remove use of RNTupleReader

parent 660b782c
Branches
No related tags found
No related merge requests found
...@@ -54,14 +54,14 @@ std::cout << "The compression factor is " << std::fixed << std::setprecision(2) ...@@ -54,14 +54,14 @@ std::cout << "The compression factor is " << std::fixed << std::setprecision(2)
// clang-format on // clang-format on
class RNTupleInspector { class RNTupleInspector {
private: private:
RNTupleInspector() = default; std::shared_ptr<ROOT::Experimental::Detail::RPageSource> fPageSource;
const RNTupleDescriptor *fSourceNTupleDescriptor;
int fCompressionSettings; int fCompressionSettings;
std::uint64_t fCompressedSize; std::uint64_t fCompressedSize;
std::uint64_t fUncompressedSize; std::uint64_t fUncompressedSize;
float fCompressionFactor; float fCompressionFactor;
RNTupleInspector(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> pageSource) : fPageSource(pageSource) {};
void CollectSizeData(); void CollectSizeData();
public: public:
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
~RNTupleInspector() = default; ~RNTupleInspector() = default;
/// Creates a new inspector for a given RNTuple. /// Creates a new inspector for a given RNTuple.
static RResult<std::unique_ptr<RNTupleInspector>> Create(std::unique_ptr<RNTupleReader> &sourceNTupleReader); static RResult<std::unique_ptr<RNTupleInspector>> Create(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> pageSource);
static RResult<std::unique_ptr<RNTupleInspector>> Create(RNTuple *sourceNTuple); static RResult<std::unique_ptr<RNTupleInspector>> Create(RNTuple *sourceNTuple);
/// Get the name of the RNTuple being inspected. /// Get the name of the RNTuple being inspected.
......
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
void ROOT::Experimental::RNTupleInspector::CollectSizeData() void ROOT::Experimental::RNTupleInspector::CollectSizeData()
{ {
fPageSource->Attach();
auto descriptorGuard = fPageSource->GetSharedDescriptorGuard();
int compressionSettings = -1; int compressionSettings = -1;
std::uint64_t compressedSize = 0; std::uint64_t compressedSize = 0;
std::uint64_t uncompressedSize = 0; std::uint64_t uncompressedSize = 0;
for (const auto &clusterDescriptor : fSourceNTupleDescriptor->GetClusterIterable()) { for (const auto &clusterDescriptor : descriptorGuard->GetClusterIterable()) {
compressedSize += clusterDescriptor.GetBytesOnStorage(); compressedSize += clusterDescriptor.GetBytesOnStorage();
if (compressionSettings == -1) { if (compressionSettings == -1) {
...@@ -35,13 +37,13 @@ void ROOT::Experimental::RNTupleInspector::CollectSizeData() ...@@ -35,13 +37,13 @@ void ROOT::Experimental::RNTupleInspector::CollectSizeData()
} }
} }
for (uint64_t colId = 0; colId < fSourceNTupleDescriptor->GetNColumns(); ++colId) { for (uint64_t colId = 0; colId < descriptorGuard->GetNColumns(); ++colId) {
const ROOT::Experimental::RColumnDescriptor &colDescriptor = fSourceNTupleDescriptor->GetColumnDescriptor(colId); const ROOT::Experimental::RColumnDescriptor &colDescriptor = descriptorGuard->GetColumnDescriptor(colId);
uint64_t elemSize = uint64_t elemSize =
ROOT::Experimental::Detail::RColumnElementBase::Generate(colDescriptor.GetModel().GetType())->GetSize(); ROOT::Experimental::Detail::RColumnElementBase::Generate(colDescriptor.GetModel().GetType())->GetSize();
uint64_t nElems = fSourceNTupleDescriptor->GetNElements(colId); uint64_t nElems = descriptorGuard->GetNElements(colId);
uncompressedSize += nElems * elemSize; uncompressedSize += nElems * elemSize;
} }
...@@ -51,35 +53,28 @@ void ROOT::Experimental::RNTupleInspector::CollectSizeData() ...@@ -51,35 +53,28 @@ void ROOT::Experimental::RNTupleInspector::CollectSizeData()
} }
ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RNTupleInspector>> ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RNTupleInspector>>
ROOT::Experimental::RNTupleInspector::Create(std::unique_ptr<RNTupleReader> &sourceNTupleReader) ROOT::Experimental::RNTupleInspector::Create(std::shared_ptr<ROOT::Experimental::Detail::RPageSource> pageSource)
{ {
auto inspector = std::unique_ptr<RNTupleInspector>(new RNTupleInspector()); auto inspector = std::unique_ptr<RNTupleInspector>(new RNTupleInspector(pageSource));
inspector->fSourceNTupleDescriptor = sourceNTupleReader->GetDescriptor();
if (!inspector->fSourceNTupleDescriptor) {
return R__FAIL("cannot get descriptor for provided RNTuple");
}
inspector->CollectSizeData(); inspector->CollectSizeData();
return inspector; return inspector;
} }
ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RNTupleInspector>> ROOT::Experimental::RResult<std::unique_ptr<ROOT::Experimental::RNTupleInspector>>
ROOT::Experimental::RNTupleInspector::Create(ROOT::Experimental::RNTuple *sourceNTuple) ROOT::Experimental::RNTupleInspector::Create(ROOT::Experimental::RNTuple *sourceNTuple)
{ {
auto reader = ROOT::Experimental::RNTupleReader::Open(sourceNTuple); std::shared_ptr<ROOT::Experimental::Detail::RPageSource> pageSource = sourceNTuple->MakePageSource();
if (!reader) {
return R__FAIL("cannot get reader for provided RNTuple");
}
return ROOT::Experimental::RNTupleInspector::Create(reader); return ROOT::Experimental::RNTupleInspector::Create(pageSource);
} }
std::string ROOT::Experimental::RNTupleInspector::GetName() std::string ROOT::Experimental::RNTupleInspector::GetName()
{ {
return fSourceNTupleDescriptor->GetName(); fPageSource->Attach();
auto descriptorGuard = fPageSource->GetSharedDescriptorGuard();
return descriptorGuard->GetName();
} }
int ROOT::Experimental::RNTupleInspector::GetCompressionSettings() int ROOT::Experimental::RNTupleInspector::GetCompressionSettings()
......
...@@ -2,16 +2,15 @@ ...@@ -2,16 +2,15 @@
#include <ROOT/RNTupleOptions.hxx> #include <ROOT/RNTupleOptions.hxx>
#include <TFile.h> #include <TFile.h>
#include <TTree.h>
#include <cstdio> // #include <cstdio>
#include <string> // #include <string>
#include <tuple> // #include <tuple>
#include <utility> // #include <utility>
#include <vector>
#include "ntupleutil_test.hxx" #include "ntupleutil_test.hxx"
using ROOT::Experimental::RNTuple;
using ROOT::Experimental::RNTupleInspector; using ROOT::Experimental::RNTupleInspector;
using ROOT::Experimental::RNTupleModel; using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleReader; using ROOT::Experimental::RNTupleReader;
...@@ -26,8 +25,10 @@ TEST(RNTupleInspector, Name) ...@@ -26,8 +25,10 @@ TEST(RNTupleInspector, Name)
RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath()); RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath());
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_EQ("ntuple", inspector->GetName()); EXPECT_EQ("ntuple", inspector->GetName());
} }
...@@ -46,9 +47,10 @@ TEST(RNTupleInspector, CompressionSettings) ...@@ -46,9 +47,10 @@ TEST(RNTupleInspector, CompressionSettings)
ntuple->Fill(); ntuple->Fill();
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_EQ(505, inspector->GetCompressionSettings()); EXPECT_EQ(505, inspector->GetCompressionSettings());
} }
...@@ -67,9 +69,10 @@ TEST(RNTupleInspector, SizeUncompressed) ...@@ -67,9 +69,10 @@ TEST(RNTupleInspector, SizeUncompressed)
ntuple->Fill(); ntuple->Fill();
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_EQ(sizeof(int32_t), inspector->GetUncompressedSize()); EXPECT_EQ(sizeof(int32_t), inspector->GetUncompressedSize());
EXPECT_EQ(inspector->GetCompressedSize(), inspector->GetUncompressedSize()); EXPECT_EQ(inspector->GetCompressedSize(), inspector->GetUncompressedSize());
} }
...@@ -91,9 +94,10 @@ TEST(RNTupleInspector, SizeCompressed) ...@@ -91,9 +94,10 @@ TEST(RNTupleInspector, SizeCompressed)
} }
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_NE(inspector->GetCompressedSize(), inspector->GetUncompressedSize()); EXPECT_NE(inspector->GetCompressedSize(), inspector->GetUncompressedSize());
} }
...@@ -105,9 +109,10 @@ TEST(RNTupleInspector, SizeEmpty) ...@@ -105,9 +109,10 @@ TEST(RNTupleInspector, SizeEmpty)
RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath()); RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath());
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_EQ(0, inspector->GetCompressedSize()); EXPECT_EQ(0, inspector->GetCompressedSize());
EXPECT_EQ(0, inspector->GetUncompressedSize()); EXPECT_EQ(0, inspector->GetUncompressedSize());
} }
...@@ -129,9 +134,10 @@ TEST(RNTupleInspector, SingleIntFieldCompression) ...@@ -129,9 +134,10 @@ TEST(RNTupleInspector, SingleIntFieldCompression)
} }
} }
auto ntuple = RNTupleReader::Open("ntuple", fileGuard.GetPath()); std::unique_ptr<TFile> file(TFile::Open(fileGuard.GetPath().c_str()));
auto ntuple = file->Get<RNTuple>("ntuple");
auto inspector = RNTupleInspector::Create(ntuple).Unwrap(); auto inspector = RNTupleInspector::Create(ntuple).Unwrap();
EXPECT_LT(0, inspector->GetCompressedSize()); EXPECT_LT(0, inspector->GetCompressedSize());
EXPECT_LT(inspector->GetCompressedSize(), inspector->GetUncompressedSize()); EXPECT_LT(inspector->GetCompressedSize(), inspector->GetUncompressedSize());
EXPECT_GT(inspector->GetCompressionFactor(), 1); EXPECT_GT(inspector->GetCompressionFactor(), 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment