Skip to content

Commit 4aa1007

Browse files
committed
[ntuple] Add RPagePersistentSink::AddColumnRepresentation
Internal functionality to be used by the Merger
1 parent d89a682 commit 4aa1007

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

tree/ntuple/inc/ROOT/RPageStorage.hxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ public:
544544
[[nodiscard]] std::unique_ptr<RNTupleModel>
545545
InitFromDescriptor(const ROOT::RNTupleDescriptor &descriptor, bool copyClusters);
546546

547+
void
548+
AddColumnRepresentation(const ROOT::RFieldDescriptor &field, std::span<const ENTupleColumnType> newRepresentation);
549+
547550
void CommitSuppressedColumn(ColumnHandle_t columnHandle) final;
548551
void CommitPage(ColumnHandle_t columnHandle, const ROOT::Internal::RPage &page) final;
549552
void CommitSealedPage(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final;

tree/ntuple/src/RPageStorage.cxx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,57 @@ ROOT::Internal::RPagePersistentSink::InitFromDescriptor(const ROOT::RNTupleDescr
10491049
return model;
10501050
}
10511051

1052+
void ROOT::Internal::RPagePersistentSink::AddColumnRepresentation(const ROOT::RFieldDescriptor &field,
1053+
std::span<const ENTupleColumnType> newRepresentation)
1054+
{
1055+
R__ASSERT(field.GetColumnCardinality() > 0);
1056+
R__ASSERT(!field.GetLogicalColumnIds().empty());
1057+
R__ASSERT(newRepresentation.size() == field.GetColumnCardinality());
1058+
1059+
const auto firstPhysicalIndex = fDescriptorBuilder.GetDescriptor().GetNPhysicalColumns();
1060+
const auto reprIndex = field.GetLogicalColumnIds().size() / field.GetColumnCardinality();
1061+
1062+
fDescriptorBuilder.ShiftAliasColumns(newRepresentation.size());
1063+
1064+
std::uint16_t columnIndex = 0; // index into the representation
1065+
for (auto columnType : newRepresentation) {
1066+
// Extending columns with variable bit width is currently unsupported.
1067+
const auto [rangeMin, rangeMax] = ROOT::Internal::RColumnElementBase::GetValidBitRange(columnType);
1068+
R__ASSERT(rangeMin == rangeMax);
1069+
1070+
const auto firstReprColumnId = field.GetLogicalColumnIds()[columnIndex];
1071+
const auto &firstReprColumnRange = fOpenColumnRanges.at(firstReprColumnId);
1072+
const auto columnId = firstPhysicalIndex + columnIndex;
1073+
1074+
RColumnDescriptorBuilder columnBuilder;
1075+
columnBuilder.LogicalColumnId(columnId)
1076+
.PhysicalColumnId(columnId)
1077+
.FieldId(field.GetId())
1078+
.BitsOnStorage(rangeMax)
1079+
.Type(columnType)
1080+
.Index(columnIndex)
1081+
// NOTE: marking this column as suppressed with the minus sign
1082+
.FirstElementIndex(-firstReprColumnRange.GetFirstElementIndex())
1083+
.RepresentationIndex(reprIndex);
1084+
fDescriptorBuilder.AddColumn(columnBuilder.MakeDescriptor().Unwrap());
1085+
1086+
ROOT::RClusterDescriptor::RColumnRange columnRange;
1087+
columnRange.SetPhysicalColumnId(columnId);
1088+
columnRange.SetFirstElementIndex(firstReprColumnRange.GetFirstElementIndex());
1089+
columnRange.SetNElements(0);
1090+
columnRange.SetCompressionSettings(GetWriteOptions().GetCompression());
1091+
fOpenColumnRanges.emplace_back(columnRange);
1092+
1093+
ROOT::RClusterDescriptor::RPageRange pageRange;
1094+
pageRange.SetPhysicalColumnId(columnId);
1095+
fOpenPageRanges.emplace_back(std::move(pageRange));
1096+
1097+
fSerializationContext.MapPhysicalColumnId(columnId);
1098+
1099+
++columnIndex;
1100+
}
1101+
}
1102+
10521103
void ROOT::Internal::RPagePersistentSink::CommitSuppressedColumn(ColumnHandle_t columnHandle)
10531104
{
10541105
fOpenColumnRanges.at(columnHandle.fPhysicalId).SetIsSuppressed(true);

0 commit comments

Comments
 (0)