Skip to content

Commit

Permalink
[ntuple] Smaller improvement to the RClusterPool interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Jun 30, 2020
1 parent e7fab28 commit 1bb4a66
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
8 changes: 5 additions & 3 deletions tree/ntuple/v7/inc/ROOT/RClusterPool.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private:
};


RPageSource *fPageSource;
/// Every cluster pool is responsible for exactly one page source that triggers loading of the clusters
/// (GetCluster()) and is used for implementating the I/O and cluster memory allocation (PageSource::LoadCluster()).
RPageSource &fPageSource;
/// The number of clusters before the currently active cluster that should stay in the pool if present
unsigned int fWindowPre;
/// The number of desired clusters in the pool, including the currently active cluster
Expand Down Expand Up @@ -111,8 +113,8 @@ private:

public:
static constexpr unsigned int kDefaultPoolSize = 4;
RClusterPool(RPageSource *pageSource, unsigned int size);
explicit RClusterPool(RPageSource *pageSource) : RClusterPool(pageSource, kDefaultPoolSize) {}
RClusterPool(RPageSource &pageSource, unsigned int size);
explicit RClusterPool(RPageSource &pageSource) : RClusterPool(pageSource, kDefaultPoolSize) {}
RClusterPool(const RClusterPool &other) = delete;
RClusterPool &operator =(const RClusterPool &other) = delete;
~RClusterPool();
Expand Down
2 changes: 1 addition & 1 deletion tree/ntuple/v7/inc/ROOT/RNTuple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private:
std::unique_ptr<RNTupleReader> fDisplayReader;
Detail::RNTupleMetrics fMetrics;

void ConnectModel(RNTupleModel &model);
void ConnectModel(const RNTupleModel &model);
RNTupleReader *GetDisplayReader();

public:
Expand Down
6 changes: 3 additions & 3 deletions tree/ntuple/v7/src/RClusterPool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool ROOT::Experimental::Detail::RClusterPool::RInFlightCluster::operator <(cons
return false;
}

ROOT::Experimental::Detail::RClusterPool::RClusterPool(RPageSource *pageSource, unsigned int size)
ROOT::Experimental::Detail::RClusterPool::RClusterPool(RPageSource &pageSource, unsigned int size)
: fPageSource(pageSource)
, fPool(size, nullptr)
, fThreadIo(&RClusterPool::ExecLoadClusters, this)
Expand Down Expand Up @@ -93,7 +93,7 @@ void ROOT::Experimental::Detail::RClusterPool::ExecLoadClusters()
return;

// TODO(jblomer): the page source needs to be capable of loading multiple clusters in one go
auto cluster = fPageSource->LoadCluster(item.fClusterId, item.fColumns);
auto cluster = fPageSource.LoadCluster(item.fClusterId, item.fColumns);

// Meanwhile, the user might have requested clusters outside the look-ahead window, so that we don't
// need the cluster anymore, in which case we simply discard it right away, before moving it to the pool
Expand Down Expand Up @@ -183,7 +183,7 @@ std::shared_ptr<ROOT::Experimental::Detail::RCluster>
ROOT::Experimental::Detail::RClusterPool::GetCluster(
DescriptorId_t clusterId, const RPageSource::ColumnSet_t &columns)
{
const auto &desc = fPageSource->GetDescriptor();
const auto &desc = fPageSource.GetDescriptor();

// Determine previous cluster ids that we keep if they happen to be in the pool
std::set<DescriptorId_t> keep;
Expand Down
2 changes: 1 addition & 1 deletion tree/ntuple/v7/src/RNTuple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <TError.h>


void ROOT::Experimental::RNTupleReader::ConnectModel(RNTupleModel &model) {
void ROOT::Experimental::RNTupleReader::ConnectModel(const RNTupleModel &model) {
std::unordered_map<const Detail::RFieldBase *, DescriptorId_t> fieldPtr2Id;
fieldPtr2Id[model.GetFieldZero()] = fSource->GetDescriptor().GetFieldZeroId();
for (auto &field : *model.GetFieldZero()) {
Expand Down
2 changes: 1 addition & 1 deletion tree/ntuple/v7/src/RPageStorageFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ ROOT::Experimental::Detail::RPageSourceFile::RPageSourceFile(std::string_view nt
, fMetrics("RPageSourceFile")
, fPageAllocator(std::make_unique<RPageAllocatorFile>())
, fPagePool(std::make_shared<RPagePool>())
, fClusterPool(std::make_unique<RClusterPool>(this))
, fClusterPool(std::make_unique<RClusterPool>(*this))
{
fCtrNReadV = fMetrics.MakeCounter<decltype(fCtrNReadV)>("nReadV", "", "number of vector read requests");
fCtrNRead = fMetrics.MakeCounter<decltype(fCtrNRead)>("nRead", "", "number of byte ranges read");
Expand Down
30 changes: 16 additions & 14 deletions tree/ntuple/v7/test/ntuple_cluster.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,48 +202,50 @@ TEST(Cluster, AdoptClusters)

TEST(ClusterPool, Windows)
{
EXPECT_DEATH(RClusterPool(nullptr, 0), ".*");
RClusterPool c1(nullptr, 1);
RPageSourceMock ps;

EXPECT_DEATH(RClusterPool(ps, 0), ".*");
RClusterPool c1(ps, 1);
EXPECT_EQ(0U, c1.GetWindowPre());
EXPECT_EQ(1U, c1.GetWindowPost());
RClusterPool c2(nullptr, 2);
RClusterPool c2(ps, 2);
EXPECT_EQ(0U, c2.GetWindowPre());
EXPECT_EQ(2U, c2.GetWindowPost());
RClusterPool c3(nullptr, 3);
RClusterPool c3(ps, 3);
EXPECT_EQ(1U, c3.GetWindowPre());
EXPECT_EQ(2U, c3.GetWindowPost());
RClusterPool c5(nullptr, 5);
RClusterPool c5(ps, 5);
EXPECT_EQ(1U, c5.GetWindowPre());
EXPECT_EQ(4U, c5.GetWindowPost());
RClusterPool c6(nullptr, 6);
RClusterPool c6(ps, 6);
EXPECT_EQ(2U, c6.GetWindowPre());
EXPECT_EQ(4U, c6.GetWindowPost());
RClusterPool c9(nullptr, 9);
RClusterPool c9(ps, 9);
EXPECT_EQ(2U, c9.GetWindowPre());
EXPECT_EQ(7U, c9.GetWindowPost());
RClusterPool c10(nullptr, 10);
RClusterPool c10(ps, 10);
EXPECT_EQ(3U, c10.GetWindowPre());
EXPECT_EQ(7U, c10.GetWindowPost());
RClusterPool c15(nullptr, 15);
RClusterPool c15(ps, 15);
EXPECT_EQ(3U, c15.GetWindowPre());
EXPECT_EQ(12U, c15.GetWindowPost());
RClusterPool c16(nullptr, 16);
RClusterPool c16(ps, 16);
EXPECT_EQ(4U, c16.GetWindowPre());
EXPECT_EQ(12U, c16.GetWindowPost());
}

TEST(ClusterPool, GetClusterBasics)
{
RPageSourceMock p1;
RClusterPool c1(&p1, 1);
RClusterPool c1(p1, 1);
c1.GetCluster(3, {0});
ASSERT_EQ(1U, p1.fReqsClusterIds.size());
EXPECT_EQ(3U, p1.fReqsClusterIds[0]);
EXPECT_EQ(RPageSource::ColumnSet_t({0U}), p1.fReqsColumns[0]);

RPageSourceMock p2;
{
RClusterPool c2(&p2, 2);
RClusterPool c2(p2, 2);
c2.GetCluster(0, {0});
}
ASSERT_EQ(2U, p2.fReqsClusterIds.size());
Expand All @@ -254,7 +256,7 @@ TEST(ClusterPool, GetClusterBasics)

RPageSourceMock p3;
{
RClusterPool c3(&p3, 4);
RClusterPool c3(p3, 4);
c3.GetCluster(2, {0});
}
ASSERT_EQ(3U, p3.fReqsClusterIds.size());
Expand All @@ -270,7 +272,7 @@ TEST(ClusterPool, GetClusterBasics)
TEST(ClusterPool, GetClusterIncrementally)
{
RPageSourceMock p1;
RClusterPool c1(&p1, 1);
RClusterPool c1(p1, 1);
c1.GetCluster(3, {0});
ASSERT_EQ(1U, p1.fReqsClusterIds.size());
EXPECT_EQ(3U, p1.fReqsClusterIds[0]);
Expand Down

0 comments on commit 1bb4a66

Please sign in to comment.