Skip to content

Commit

Permalink
[ntuple] Add non-const RNTupleModel::GetField
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnjo committed Oct 18, 2024
1 parent 66b212d commit 69baf3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions tree/ntuple/v7/inc/ROOT/RNTupleModel.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public:

RFieldZero &GetFieldZero() { return *fFieldZero; }
const RFieldZero &GetFieldZero() const { return *fFieldZero; }
RFieldBase &GetField(std::string_view fieldName);
const RFieldBase &GetField(std::string_view fieldName) const;

const std::string &GetDescription() const { return fDescription; }
Expand Down
9 changes: 9 additions & 0 deletions tree/ntuple/v7/src/RNTupleModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ ROOT::Experimental::RNTupleModel::AddProjectedField(std::unique_ptr<RFieldBase>
return RResult<void>::Success();
}

ROOT::Experimental::RFieldBase &ROOT::Experimental::RNTupleModel::GetField(std::string_view fieldName)
{
auto f = FindField(fieldName);
if (!f)
throw RException(R__FAIL("invalid field: " + std::string(fieldName)));

return *f;
}

const ROOT::Experimental::RFieldBase &ROOT::Experimental::RNTupleModel::GetField(std::string_view fieldName) const
{
auto f = FindField(fieldName);
Expand Down
3 changes: 3 additions & 0 deletions tree/ntuple/v7/test/ntuple_model.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ TEST(RNTupleModel, GetField)
{
auto model = RNTupleModel::CreateBare();
model->MakeField<std::vector<float>>("v1");
model->MakeField<std::vector<float>>("v2");

for (auto &subfield : model->GetFieldZero()) {
if (subfield.GetTypeName() == "float") {
subfield.SetColumnRepresentatives({{EColumnType::kReal32}});
}
}
model->GetField("v2._0").SetColumnRepresentatives({{EColumnType::kReal16}});

EXPECT_EQ(EColumnType::kReal32, model->GetField("v1._0").GetColumnRepresentatives()[0][0]);
EXPECT_EQ(EColumnType::kReal16, model->GetField("v2._0").GetColumnRepresentatives()[0][0]);
}

TEST(RNTupleModel, EstimateWriteMemoryUsage)
Expand Down

0 comments on commit 69baf3d

Please sign in to comment.