Skip to content

Commit 3d9bf61

Browse files
committed
[ntuple] fix map field reconciliation
1 parent 2231faf commit 3d9bf61

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tree/ntuple/inc/ROOT/RField/RFieldProxiedCollection.hxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ public:
277277
kMultiMap,
278278
kUnorderedMultiMap
279279
};
280+
281+
private:
282+
EMapType fMapType;
283+
284+
protected:
285+
std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
286+
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
287+
288+
public:
280289
RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField);
281290
RMapField(RMapField &&other) = default;
282291
RMapField &operator=(RMapField &&other) = default;

tree/ntuple/src/RFieldMeta.cxx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,14 +871,35 @@ void ROOT::RProxiedCollectionField::AcceptVisitor(ROOT::Detail::RFieldVisitor &v
871871
//------------------------------------------------------------------------------
872872

873873
ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::unique_ptr<RFieldBase> itemField)
874-
: RProxiedCollectionField(fieldName, EnsureValidClass(BuildMapTypeName(mapType, itemField.get())))
874+
: RProxiedCollectionField(fieldName, EnsureValidClass(BuildMapTypeName(mapType, itemField.get()))), fMapType(mapType)
875875
{
876876
auto *itemClass = fProxy->GetValueClass();
877877
fItemSize = itemClass->GetClassSize();
878878

879879
Attach(std::move(itemField));
880880
}
881881

882+
std::unique_ptr<ROOT::RFieldBase> ROOT::RMapField::CloneImpl(std::string_view newName) const
883+
{
884+
return std::make_unique<RMapField>(newName, fMapType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
885+
}
886+
887+
void ROOT::RMapField::ReconcileOnDiskField(const RNTupleDescriptor &desc)
888+
{
889+
static const std::vector<std::string> prefixesRegular = {"std::map<", "std::unordered_map<", "std::set<"};
890+
891+
const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
892+
EnsureMatchingOnDiskField(fieldDesc, kDiffTypeName).ThrowOnError();
893+
894+
switch (fMapType) {
895+
case EMapType::kMap:
896+
case EMapType::kUnorderedMap: EnsureMatchingTypePrefix(fieldDesc, prefixesRegular).ThrowOnError(); break;
897+
default:
898+
break;
899+
// no restrictions for multimaps
900+
}
901+
}
902+
882903
//------------------------------------------------------------------------------
883904

884905
ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)

0 commit comments

Comments
 (0)