Skip to content

Commit

Permalink
[ntuple] avoid shared pointer for RColumn::fTeam
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Aug 1, 2024
1 parent e1ce683 commit f11ca91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 3 additions & 5 deletions tree/ntuple/v7/inc/ROOT/RColumn.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private:
NTupleSize_t fFirstElementIndex = 0;
/// Used to pack and unpack pages on writing/reading
std::unique_ptr<RColumnElementBase> fElement;
/// The column team is a set of columns that serve the same column index for different representation IDs
/// Initially, the team has only one member, the very column it belongs to. Through MergeTeams(), two column
/// The column team is a set of columns that serve the same column index for different representation IDs.
/// Initially, the team has only one member, the very column it belongs to. Through MergeTeams(), two columns
/// can join forces. The team is used to react on suppressed columns: if the current team member has a suppressed
/// column for a MapPage() call, it get the page from the active column in the corresponding cluster.
std::shared_ptr<std::vector<RColumn *>> fTeam;
std::vector<RColumn *> fTeam;
/// Points into fTeam to the column that successfully returned the last page.
std::size_t fLastGoodTeamIdx = 0;

Expand Down Expand Up @@ -117,8 +117,6 @@ private:
fWritePage[otherIdx].Reset(0);
}

void TeamUp(const RColumn &other) { fTeam = other.fTeam; }

public:
template <typename CppT>
static std::unique_ptr<RColumn> Create(EColumnType type, std::uint32_t columnIdx, std::uint16_t representationIdx)
Expand Down
27 changes: 17 additions & 10 deletions tree/ntuple/v7/src/RColumn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

#include <TError.h>

#include <algorithm>
#include <cassert>
#include <utility>

ROOT::Experimental::Internal::RColumn::RColumn(EColumnType type, std::uint32_t columnIndex,
std::uint16_t representationIndex)
: fType(type),
fIndex(columnIndex),
fRepresentationIndex(representationIndex),
fTeam(std::make_shared<std::vector<RColumn *>>(std::vector<RColumn *>{this}))
: fType(type), fIndex(columnIndex), fRepresentationIndex(representationIndex), fTeam({this})
{
// TODO(jblomer): fix for column types with configurable bit length once available
const auto [minBits, maxBits] = RColumnElementBase::GetValidBitRange(type);
Expand Down Expand Up @@ -115,10 +113,10 @@ bool ROOT::Experimental::Internal::RColumn::TryMapPage(NTupleSize_t globalIndex)
// the page population fails.
fReadPage = RPage();

const auto nTeam = fTeam->size();
const auto nTeam = fTeam.size();
std::size_t iTeam = 1;
do {
fReadPage = fPageSource->PopulatePage(fTeam->at(fLastGoodTeamIdx)->GetHandleSource(), globalIndex);
fReadPage = fPageSource->PopulatePage(fTeam.at(fLastGoodTeamIdx)->GetHandleSource(), globalIndex);
if (fReadPage.IsValid())
break;
fLastGoodTeamIdx = (fLastGoodTeamIdx + 1) % nTeam;
Expand All @@ -135,10 +133,10 @@ bool ROOT::Experimental::Internal::RColumn::TryMapPage(RClusterIndex clusterInde
// the page population fails.
fReadPage = RPage();

const auto nTeam = fTeam->size();
const auto nTeam = fTeam.size();
std::size_t iTeam = 1;
do {
fReadPage = fPageSource->PopulatePage(fTeam->at(fLastGoodTeamIdx)->GetHandleSource(), clusterIndex);
fReadPage = fPageSource->PopulatePage(fTeam.at(fLastGoodTeamIdx)->GetHandleSource(), clusterIndex);
if (fReadPage.IsValid())
break;
fLastGoodTeamIdx = (fLastGoodTeamIdx + 1) % nTeam;
Expand All @@ -150,6 +148,15 @@ bool ROOT::Experimental::Internal::RColumn::TryMapPage(RClusterIndex clusterInde

void ROOT::Experimental::Internal::RColumn::MergeTeams(RColumn &other)
{
fTeam->emplace_back(&other);
other.TeamUp(*this);
// We are working on very small vectors here, so quadratic complexity works
for (auto *c : other.fTeam) {
if (std::find(fTeam.begin(), fTeam.end(), c) == fTeam.end())
fTeam.emplace_back(c);
}

for (auto c : fTeam) {
if (c == this)
continue;
c->fTeam = fTeam;
}
}

0 comments on commit f11ca91

Please sign in to comment.