Skip to content

Commit

Permalink
[ntuple] Add check for default entry existence
Browse files Browse the repository at this point in the history
  • Loading branch information
enirolf committed Oct 30, 2024
1 parent 6d5a6cf commit 9d876cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tree/ntuple/v7/src/RNTupleModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ void ROOT::Experimental::RNTupleModel::RegisterSubfield(std::string_view qualifi
parent = parent->GetParent();
}

AddSubfield(qualifiedFieldName, *fDefaultEntry);
if (fDefaultEntry)
AddSubfield(qualifiedFieldName, *fDefaultEntry);
fRegisteredSubfields.emplace(qualifiedFieldName);
}

Expand Down
13 changes: 13 additions & 0 deletions tree/ntuple/v7/test/ntuple_model.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ TEST(RNTupleModel, RegisterSubfield)
}
}

TEST(RNTupleModel, RegisterSubfieldBare)
{
auto model = RNTupleModel::CreateBare();
model->MakeField<CustomStruct>("struct");
model->RegisterSubfield("struct.a");
model->Freeze();

EXPECT_THROW(model->GetDefaultEntry(), RException);

const auto entry = model->CreateEntry();
EXPECT_TRUE(entry->GetPtr<float>("struct.a"));
}

TEST(RNTupleModel, CloneRegisteredSubfield)
{
auto model = RNTupleModel::Create();
Expand Down

0 comments on commit 9d876cd

Please sign in to comment.