Skip to content

Commit

Permalink
[ntuple] Add inner field type check for std::map fields
Browse files Browse the repository at this point in the history
Inner fields *must* be of type `RPairField`. Ideally this should be done
at compile time through the constructor argument type, but this is still
causing issues and needs further investigation. Thus, this runtime check
is added as a temporary solution.
  • Loading branch information
enirolf authored and jblomer committed Nov 21, 2023
1 parent b1057b5 commit 32b80ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tree/ntuple/v7/src/RField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,9 @@ ROOT::Experimental::RMapField::RMapField(std::string_view fieldName, std::string
std::unique_ptr<Detail::RFieldBase> itemField)
: RProxiedCollectionField(fieldName, typeName, TClass::GetClass(std::string(typeName).c_str()))
{
if (!dynamic_cast<RPairField *>(itemField.get()))
throw RException(R__FAIL("RMapField inner field type must be of RPairField"));

fItemClass = fProxy->GetValueClass();
fItemSize = fItemClass->GetClassSize();

Expand Down
5 changes: 5 additions & 0 deletions tree/ntuple/v7/test/ntuple_types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ TEST(RNTuple, StdMap)
EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::map<char>").Unwrap(), RException);
EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::map<char, std::string, int>").Unwrap(), RException);

auto invalidInnerField = RFieldBase::Create("someIntField", "int").Unwrap();
EXPECT_THROW(std::make_unique<ROOT::Experimental::RMapField>("myInvalidMap", "std::map<char, int>",
std::move(invalidInnerField)),
RException);

FileRaii fileGuard("test_ntuple_rfield_stdmap.root");
{
auto model = RNTupleModel::Create();
Expand Down

0 comments on commit 32b80ad

Please sign in to comment.