Skip to content

Commit 2231faf

Browse files
committed
[ntuple] fix set field reconciliation
1 parent 2554f8d commit 2231faf

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

tree/dataframe/test/datasource_ntuple.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ TEST_F(RNTupleDSTest, AlternativeColumnTypes)
455455

456456
auto multipleAlternativeTypes =
457457
df.Define("nJets", [](const std::vector<float> &jets) { return jets.size(); }, {"jets"})
458-
.Define("smallestJet", [](const std::set<float> &jets) { return *(jets.begin()); }, {"jets"})
458+
.Define("smallestJet", [](const std::multiset<float> &jets) { return *(jets.begin()); }, {"jets"})
459459
.Min<float>("smallestJet")
460460
.GetValue();
461461
EXPECT_FLOAT_EQ(1.f, multipleAlternativeTypes);

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected:
154154
/// (Attach() and setting fItemSize)
155155
RProxiedCollectionField(std::string_view fieldName, TClass *classp);
156156

157-
std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
157+
std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const override;
158158
const RColumnRepresentations &GetColumnRepresentations() const final;
159159
void GenerateColumns() final;
160160
void GenerateColumns(const ROOT::RNTupleDescriptor &desc) final;
@@ -165,7 +165,7 @@ protected:
165165
std::size_t AppendImpl(const void *from) final;
166166
void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final;
167167

168-
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
168+
void ReconcileOnDiskField(const RNTupleDescriptor &desc) override;
169169

170170
void CommitClusterImpl() final { fNWritten = 0; }
171171

@@ -364,6 +364,15 @@ public:
364364
kMultiSet,
365365
kUnorderedMultiSet
366366
};
367+
368+
private:
369+
ESetType fSetType;
370+
371+
protected:
372+
std::unique_ptr<RFieldBase> CloneImpl(std::string_view newName) const final;
373+
void ReconcileOnDiskField(const RNTupleDescriptor &desc) final;
374+
375+
public:
367376
RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField);
368377
RSetField(RSetField &&other) = default;
369378
RSetField &operator=(RSetField &&other) = default;

tree/ntuple/src/RFieldMeta.cxx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,34 @@ ROOT::RMapField::RMapField(std::string_view fieldName, EMapType mapType, std::un
882882
//------------------------------------------------------------------------------
883883

884884
ROOT::RSetField::RSetField(std::string_view fieldName, ESetType setType, std::unique_ptr<RFieldBase> itemField)
885-
: ROOT::RProxiedCollectionField(fieldName, EnsureValidClass(BuildSetTypeName(setType, *itemField)))
885+
: ROOT::RProxiedCollectionField(fieldName, EnsureValidClass(BuildSetTypeName(setType, *itemField))),
886+
fSetType(setType)
886887
{
887888
fItemSize = itemField->GetValueSize();
888889
Attach(std::move(itemField));
889890
}
890891

892+
std::unique_ptr<ROOT::RFieldBase> ROOT::RSetField::CloneImpl(std::string_view newName) const
893+
{
894+
return std::make_unique<RSetField>(newName, fSetType, fSubfields[0]->Clone(fSubfields[0]->GetFieldName()));
895+
}
896+
897+
void ROOT::RSetField::ReconcileOnDiskField(const RNTupleDescriptor &desc)
898+
{
899+
static const std::vector<std::string> prefixesRegular = {"std::set<", "std::unordered_set<", "std::map<"};
900+
901+
const auto &fieldDesc = desc.GetFieldDescriptor(GetOnDiskId());
902+
EnsureMatchingOnDiskField(fieldDesc, kDiffTypeName).ThrowOnError();
903+
904+
switch (fSetType) {
905+
case ESetType::kSet:
906+
case ESetType::kUnorderedSet: EnsureMatchingTypePrefix(fieldDesc, prefixesRegular).ThrowOnError(); break;
907+
default:
908+
break;
909+
// no restrictions for multisets
910+
}
911+
}
912+
891913
//------------------------------------------------------------------------------
892914

893915
namespace {

0 commit comments

Comments
 (0)