From 32b80ad491f121fb52b1672a9468c8f1fad7490a Mon Sep 17 00:00:00 2001 From: Florine de Geus Date: Mon, 20 Nov 2023 12:29:18 +0100 Subject: [PATCH] [ntuple] Add inner field type check for `std::map` fields 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. --- tree/ntuple/v7/src/RField.cxx | 3 +++ tree/ntuple/v7/test/ntuple_types.cxx | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/tree/ntuple/v7/src/RField.cxx b/tree/ntuple/v7/src/RField.cxx index e6606e6b07e8a..3fc1fee0b33e4 100644 --- a/tree/ntuple/v7/src/RField.cxx +++ b/tree/ntuple/v7/src/RField.cxx @@ -2682,6 +2682,9 @@ ROOT::Experimental::RMapField::RMapField(std::string_view fieldName, std::string std::unique_ptr itemField) : RProxiedCollectionField(fieldName, typeName, TClass::GetClass(std::string(typeName).c_str())) { + if (!dynamic_cast(itemField.get())) + throw RException(R__FAIL("RMapField inner field type must be of RPairField")); + fItemClass = fProxy->GetValueClass(); fItemSize = fItemClass->GetClassSize(); diff --git a/tree/ntuple/v7/test/ntuple_types.cxx b/tree/ntuple/v7/test/ntuple_types.cxx index e193dc588a3e5..4e6eabbde75c3 100644 --- a/tree/ntuple/v7/test/ntuple_types.cxx +++ b/tree/ntuple/v7/test/ntuple_types.cxx @@ -455,6 +455,11 @@ TEST(RNTuple, StdMap) EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::map").Unwrap(), RException); EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::map").Unwrap(), RException); + auto invalidInnerField = RFieldBase::Create("someIntField", "int").Unwrap(); + EXPECT_THROW(std::make_unique("myInvalidMap", "std::map", + std::move(invalidInnerField)), + RException); + FileRaii fileGuard("test_ntuple_rfield_stdmap.root"); { auto model = RNTupleModel::Create();