Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ntuple] Add RNTupleModel::GetMutableField #16713

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[ntuple] Add RNTupleModel::GetMutableField
Similar to GetMutableFieldZero(), it must only be called on unfrozen
models.
hahnjo committed Oct 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit df519dd4cff82e4a865914c68ca750f7fd54e981
1 change: 1 addition & 0 deletions tree/ntuple/v7/inc/ROOT/RNTupleModel.hxx
Original file line number Diff line number Diff line change
@@ -363,6 +363,7 @@ public:
/// Mutable access to the root field is used to make adjustments to the fields.
RFieldZero &GetMutableFieldZero();
const RFieldZero &GetConstFieldZero() const { return *fFieldZero; }
RFieldBase &GetMutableField(std::string_view fieldName);
const RFieldBase &GetConstField(std::string_view fieldName) const;

const std::string &GetDescription() const { return fDescription; }
11 changes: 11 additions & 0 deletions tree/ntuple/v7/src/RNTupleModel.cxx
Original file line number Diff line number Diff line change
@@ -354,6 +354,17 @@ ROOT::Experimental::RFieldZero &ROOT::Experimental::RNTupleModel::GetMutableFiel
return *fFieldZero;
}

ROOT::Experimental::RFieldBase &ROOT::Experimental::RNTupleModel::GetMutableField(std::string_view fieldName)
{
if (IsFrozen())
throw RException(R__FAIL("invalid attempt to get mutable field of frozen model"));
auto f = FindField(fieldName);
if (!f)
throw RException(R__FAIL("invalid field: " + std::string(fieldName)));

return *f;
}

const ROOT::Experimental::RFieldBase &ROOT::Experimental::RNTupleModel::GetConstField(std::string_view fieldName) const
{
auto f = FindField(fieldName);
8 changes: 8 additions & 0 deletions tree/ntuple/v7/test/ntuple_model.cxx
Original file line number Diff line number Diff line change
@@ -67,11 +67,13 @@ TEST(RNTupleModel, GetField)
auto m = RNTupleModel::Create();
m->MakeField<int>("x");
m->MakeField<CustomStruct>("cs");
m->GetMutableField("cs.v1._0").SetColumnRepresentatives({{EColumnType::kReal32}});
m->Freeze();
EXPECT_EQ(m->GetConstField("x").GetFieldName(), "x");
EXPECT_EQ(m->GetConstField("x").GetTypeName(), "std::int32_t");
EXPECT_EQ(m->GetConstField("cs.v1").GetFieldName(), "v1");
EXPECT_EQ(m->GetConstField("cs.v1").GetTypeName(), "std::vector<float>");
EXPECT_EQ(m->GetConstField("cs.v1._0").GetColumnRepresentatives()[0][0], EColumnType::kReal32);
try {
m->GetConstField("nonexistent");
FAIL() << "invalid field name should throw";
@@ -90,6 +92,12 @@ TEST(RNTupleModel, GetField)
} catch (const RException &err) {
EXPECT_THAT(err.what(), testing::HasSubstr("frozen model"));
}
try {
m->GetMutableField("x");
FAIL() << "GetMutableField should throw";
} catch (const RException &err) {
EXPECT_THAT(err.what(), testing::HasSubstr("frozen model"));
}
EXPECT_EQ("", m->GetConstFieldZero().GetQualifiedFieldName());
EXPECT_EQ("x", m->GetConstField("x").GetQualifiedFieldName());
EXPECT_EQ("cs", m->GetConstField("cs").GetQualifiedFieldName());
Loading