diff --git a/tree/ntuple/v7/inc/ROOT/RField.hxx b/tree/ntuple/v7/inc/ROOT/RField.hxx index bc5587ad80efe..5592ecf22ccee 100644 --- a/tree/ntuple/v7/inc/ROOT/RField.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField.hxx @@ -348,6 +348,8 @@ protected: } const RColumnRepresentations &GetColumnRepresentations() const final; + using RSimpleField::GenerateColumns; + void GenerateColumns() final { throw RException(R__FAIL("RField must only be used for reading")); } public: static std::string TypeName() { return "ROOT::Experimental::ClusterSize_t"; } diff --git a/tree/ntuple/v7/src/RField.cxx b/tree/ntuple/v7/src/RField.cxx index fb0c744fc96f9..8a4a43506d2a4 100644 --- a/tree/ntuple/v7/src/RField.cxx +++ b/tree/ntuple/v7/src/RField.cxx @@ -150,8 +150,7 @@ std::tuple> ParseArrayType(std::string_view typ std::string GetCanonicalTypeName(const std::string &typeName) { // The following types are asummed to be canonical names; thus, do not perform `typedef` resolution on those - if (typeName == "ROOT::Experimental::ClusterSize_t" || typeName.substr(0, 5) == "std::" || - typeName.substr(0, 39) == "ROOT::Experimental::RNTupleCardinality<") + if (typeName.substr(0, 5) == "std::" || typeName.substr(0, 39) == "ROOT::Experimental::RNTupleCardinality<") return typeName; return TClassEdit::ResolveTypedef(typeName.c_str()); @@ -652,9 +651,7 @@ ROOT::Experimental::RFieldBase::Create(const std::string &fieldName, const std:: std::unique_ptr result; - if (canonicalType == "ROOT::Experimental::ClusterSize_t") { - result = std::make_unique>(fieldName); - } else if (canonicalType == "bool") { + if (canonicalType == "bool") { result = std::make_unique>(fieldName); } else if (canonicalType == "char") { result = std::make_unique>(fieldName); diff --git a/tree/ntuple/v7/test/ntuple_packing.cxx b/tree/ntuple/v7/test/ntuple_packing.cxx index 54fa176bc281e..6e480cbe40b5d 100644 --- a/tree/ntuple/v7/test/ntuple_packing.cxx +++ b/tree/ntuple/v7/test/ntuple_packing.cxx @@ -263,6 +263,30 @@ AddReal32QuantField(RNTupleModel &model, const std::string &fieldName, std::size model.AddField(std::move(fld)); } +namespace { + +// Test writing index32/64 columns +class RFieldTestIndexColumn final : public ROOT::Experimental::RSimpleField { +protected: + std::unique_ptr CloneImpl(std::string_view newName) const final + { + return std::make_unique(newName); + } + const RColumnRepresentations &GetColumnRepresentations() const final + { + static RColumnRepresentations representations({{EColumnType::kSplitIndex64}, {EColumnType::kSplitIndex32}}, {}); + return representations; + } + +public: + explicit RFieldTestIndexColumn(std::string_view name) : RSimpleField(name, "ROOT::Experimental::ClusterSize_t") {} + RFieldTestIndexColumn(RFieldTestIndexColumn &&other) = default; + RFieldTestIndexColumn &operator=(RFieldTestIndexColumn &&other) = default; + ~RFieldTestIndexColumn() override = default; +}; + +} // anonymous namespace + TEST(Packing, OnDiskEncoding) { FileRaii fileGuard("test_ntuple_packing_ondiskencoding.root"); @@ -280,10 +304,14 @@ TEST(Packing, OnDiskEncoding) AddField(*model, "float"); AddField(*model, "float16"); AddField(*model, "double"); - AddField(*model, "index32"); - AddField(*model, "index64"); AddReal32TruncField(*model, "float32Trunc", 11); AddReal32QuantField(*model, "float32Quant", 7, 0.0, 1.0); + auto fldIdx32 = std::make_unique("index32"); + fldIdx32->SetColumnRepresentatives({{EColumnType::kSplitIndex32}}); + model->AddField(std::move(fldIdx32)); + auto fldIdx64 = std::make_unique("index64"); + fldIdx64->SetColumnRepresentatives({{EColumnType::kSplitIndex64}}); + model->AddField(std::move(fldIdx64)); auto fldStr = std::make_unique>("str"); model->AddField(std::move(fldStr)); { @@ -396,8 +424,7 @@ TEST(Packing, OnDiskEncoding) unsigned char expF32Quant[] = {0xd8, 0x37}; EXPECT_EQ(memcmp(sealedPage.GetBuffer(), expF32Quant, sizeof(expF32Quant)), 0); - auto reader = RNTupleReader::Open("ntuple", fileGuard.GetPath()); - EXPECT_EQ(EColumnType::kIndex64, reader->GetModel().GetField("str").GetColumnRepresentatives()[0][0]); + auto reader = RNTupleReader::Open(RNTupleModel::Create(), "ntuple", fileGuard.GetPath()); EXPECT_EQ(2u, reader->GetNEntries()); auto viewStr = reader->GetView("str"); EXPECT_EQ(std::string("abc"), viewStr(0));