diff --git a/tree/ntuple/v7/inc/ROOT/RField.hxx b/tree/ntuple/v7/inc/ROOT/RField.hxx index dab60864e760b..29baffec9d2ed 100644 --- a/tree/ntuple/v7/inc/ROOT/RField.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField.hxx @@ -57,7 +57,7 @@ class RFieldVisitor; /// Therefore, the zero field must not be connected to a page source or sink. class RFieldZero final : public RFieldBase { protected: - std::unique_ptr CloneImpl(std::string_view newName) const override; + std::unique_ptr CloneImpl(std::string_view newName) const final; void ConstructValue(void *) const final {} public: @@ -134,7 +134,7 @@ private: protected: std::unique_ptr CloneImpl(std::string_view newName) const final; - void ConstructValue(void *where) const override; + void ConstructValue(void *where) const final; std::unique_ptr GetDeleter() const final { return std::make_unique(fClass); } std::size_t AppendImpl(const void *from) final; @@ -149,11 +149,11 @@ public: ~RClassField() override = default; std::vector SplitValue(const RValue &value) const final; - size_t GetValueSize() const override; + size_t GetValueSize() const final; size_t GetAlignment() const final { return fMaxAlignment; } std::uint32_t GetTypeVersion() const final; std::uint32_t GetTypeChecksum() const final; - void AcceptVisitor(Detail::RFieldVisitor &visitor) const override; + void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; }; /// The field for a class in unsplit mode, which is using ROOT standard streaming @@ -200,7 +200,7 @@ public: RUnsplitField(std::string_view fieldName, std::string_view className, std::string_view typeAlias = ""); RUnsplitField(RUnsplitField &&other) = default; RUnsplitField &operator=(RUnsplitField &&other) = default; - ~RUnsplitField() override = default; + ~RUnsplitField() final = default; size_t GetValueSize() const final; size_t GetAlignment() const final; @@ -239,17 +239,6 @@ public: /// Classes with dictionaries that can be inspected by TClass template class RField final : public RClassField { -protected: - void ConstructValue(void *where) const final - { - if constexpr (std::is_default_constructible_v) { - new (where) T(); - } else { - // If there is no default constructor, try with the IO constructor - new (where) T(static_cast(nullptr)); - } - } - public: static std::string TypeName() { return ROOT::Internal::GetDemangledTypeName(typeid(T)); } RField(std::string_view name) : RClassField(name, TypeName()) @@ -258,17 +247,17 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; template -class RField>::type> : public REnumField { +class RField>::type> final : public REnumField { public: static std::string TypeName() { return ROOT::Internal::GetDemangledTypeName(typeid(T)); } RField(std::string_view name) : REnumField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; /// An artificial field that transforms an RNTuple column that contains the offset of collections into @@ -368,7 +357,7 @@ public: explicit RField(std::string_view name) : RCardinalityField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; size_t GetValueSize() const final { return sizeof(RNTupleCardinality); } size_t GetAlignment() const final { return alignof(RNTupleCardinality); } @@ -431,7 +420,7 @@ private: protected: std::unique_ptr CloneImpl(std::string_view newName) const final; - void ConstructValue(void *where) const override; + void ConstructValue(void *where) const final; std::unique_ptr GetDeleter() const final { return std::make_unique>(); } std::size_t AppendImpl(const void *from) final; @@ -445,7 +434,7 @@ public: RField(std::string_view fieldName); RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; std::vector SplitValue(const RValue &value) const final; size_t GetValueSize() const final; diff --git a/tree/ntuple/v7/inc/ROOT/RField/RFieldFundamental.hxx b/tree/ntuple/v7/inc/ROOT/RField/RFieldFundamental.hxx index b6063bf022781..d145dd403850b 100644 --- a/tree/ntuple/v7/inc/ROOT/RField/RFieldFundamental.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField/RFieldFundamental.hxx @@ -74,7 +74,7 @@ public: explicit RField(std::string_view name) : RSimpleField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; }; @@ -96,7 +96,7 @@ public: explicit RField(std::string_view name) : RSimpleField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; }; @@ -328,7 +328,7 @@ public: RField(std::string_view name) : RIntegralField(name) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; T *Map(NTupleSize_t globalIndex) { return reinterpret_cast(this->BaseType::Map(globalIndex)); } T *Map(RClusterIndex clusterIndex) { return reinterpret_cast(this->BaseType::Map(clusterIndex)); } diff --git a/tree/ntuple/v7/inc/ROOT/RField/RFieldProxiedCollection.hxx b/tree/ntuple/v7/inc/ROOT/RField/RFieldProxiedCollection.hxx index 5afb0a1186cd7..472a112ec1992 100644 --- a/tree/ntuple/v7/inc/ROOT/RField/RFieldProxiedCollection.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField/RFieldProxiedCollection.hxx @@ -160,16 +160,16 @@ protected: std::unique_ptr itemField); protected: - std::unique_ptr CloneImpl(std::string_view newName) const override; + std::unique_ptr CloneImpl(std::string_view newName) const final; const RColumnRepresentations &GetColumnRepresentations() const final; void GenerateColumns() final; void GenerateColumns(const RNTupleDescriptor &desc) final; - void ConstructValue(void *where) const override; - std::unique_ptr GetDeleter() const override; + void ConstructValue(void *where) const final; + std::unique_ptr GetDeleter() const final; - std::size_t AppendImpl(const void *from) override; - void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) override; + std::size_t AppendImpl(const void *from) final; + void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) final; void CommitClusterImpl() final { fNWritten = 0; } @@ -179,10 +179,10 @@ public: RProxiedCollectionField &operator=(RProxiedCollectionField &&other) = default; ~RProxiedCollectionField() override = default; - std::vector SplitValue(const RValue &value) const override; - size_t GetValueSize() const override { return fProxy->Sizeof(); } - size_t GetAlignment() const override { return alignof(std::max_align_t); } - void AcceptVisitor(Detail::RFieldVisitor &visitor) const override; + std::vector SplitValue(const RValue &value) const final; + size_t GetValueSize() const final { return fProxy->Sizeof(); } + size_t GetAlignment() const final { return alignof(std::max_align_t); } + void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; void GetCollectionInfo(NTupleSize_t globalIndex, RClusterIndex *collectionStart, ClusterSize_t *size) const { fPrincipalColumn->GetCollectionInfo(globalIndex, collectionStart, size); @@ -263,9 +263,6 @@ struct IsCollectionProxy : HasCollectionProxyMemberType { /// ``` template class RField::value>::type> final : public RProxiedCollectionField { -protected: - void ConstructValue(void *where) const final { new (where) T(); } - public: static std::string TypeName() { return ROOT::Internal::GetDemangledTypeName(typeid(T)); } RField(std::string_view name) : RProxiedCollectionField(name, TypeName()) @@ -274,7 +271,7 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -283,34 +280,15 @@ public: /// The generic field for a std::map and std::unordered_map class RMapField : public RProxiedCollectionField { -private: - TClass *fItemClass; - -protected: - std::unique_ptr CloneImpl(std::string_view newName) const final; - - std::size_t AppendImpl(const void *from) final; - void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) final; - public: RMapField(std::string_view fieldName, std::string_view typeName, std::unique_ptr itemField); RMapField(RMapField &&other) = default; RMapField &operator=(RMapField &&other) = default; ~RMapField() override = default; - - std::vector SplitValue(const RValue &value) const final; - - size_t GetAlignment() const override { return std::alignment_of>(); } }; template class RField> final : public RMapField { - using ContainerT = typename std::map; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { @@ -323,20 +301,11 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template class RField> final : public RMapField { - using ContainerT = typename std::unordered_map; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { @@ -349,20 +318,11 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template class RField> final : public RMapField { - using ContainerT = typename std::multimap; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { @@ -375,20 +335,11 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template class RField> final : public RMapField { - using ContainerT = typename std::unordered_multimap; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { @@ -401,10 +352,7 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -413,96 +361,55 @@ public: /// The generic field for a std::set and std::unordered_set class RSetField : public RProxiedCollectionField { -protected: - std::unique_ptr CloneImpl(std::string_view newName) const final; - public: RSetField(std::string_view fieldName, std::string_view typeName, std::unique_ptr itemField); RSetField(RSetField &&other) = default; RSetField &operator=(RSetField &&other) = default; ~RSetField() override = default; - - size_t GetAlignment() const override { return std::alignment_of>(); } }; template -class RField> : public RSetField { - using ContainerT = typename std::set; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - +class RField> final : public RSetField { public: static std::string TypeName() { return "std::set<" + RField::TypeName() + ">"; } explicit RField(std::string_view name) : RSetField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template class RField> final : public RSetField { - using ContainerT = typename std::unordered_set; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { return "std::unordered_set<" + RField::TypeName() + ">"; } explicit RField(std::string_view name) : RSetField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template -class RField> : public RSetField { - using ContainerT = typename std::multiset; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - +class RField> final : public RSetField { public: static std::string TypeName() { return "std::multiset<" + RField::TypeName() + ">"; } explicit RField(std::string_view name) : RSetField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; template -class RField> : public RSetField { - using ContainerT = typename std::unordered_multiset; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - +class RField> final : public RSetField { public: static std::string TypeName() { return "std::unordered_multiset<" + RField::TypeName() + ">"; } explicit RField(std::string_view name) : RSetField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } + ~RField() final = default; }; } // namespace Experimental diff --git a/tree/ntuple/v7/inc/ROOT/RField/RFieldRecord.hxx b/tree/ntuple/v7/inc/ROOT/RField/RFieldRecord.hxx index 734fb9e34bcff..b10cbcf207be8 100644 --- a/tree/ntuple/v7/inc/ROOT/RField/RFieldRecord.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField/RFieldRecord.hxx @@ -60,10 +60,10 @@ protected: std::size_t GetItemPadding(std::size_t baseOffset, std::size_t itemAlignment) const; - std::unique_ptr CloneImpl(std::string_view newName) const override; + std::unique_ptr CloneImpl(std::string_view newName) const final; - void ConstructValue(void *where) const override; - std::unique_ptr GetDeleter() const override; + void ConstructValue(void *where) const final; + std::unique_ptr GetDeleter() const final; std::size_t AppendImpl(const void *from) final; void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) final; @@ -111,24 +111,9 @@ public: /// The generic field for `std::pair` types class RPairField : public RRecordField { private: - class RPairDeleter : public RDeleter { - private: - TClass *fClass; - - public: - explicit RPairDeleter(TClass *cl) : fClass(cl) {} - void operator()(void *objPtr, bool dtorOnly) final; - }; - - TClass *fClass = nullptr; static std::string GetTypeList(const std::array, 2> &itemFields); protected: - std::unique_ptr CloneImpl(std::string_view newName) const override; - - void ConstructValue(void *where) const override; - std::unique_ptr GetDeleter() const override { return std::make_unique(fClass); } - RPairField(std::string_view fieldName, std::array, 2> &&itemFields, const std::array &offsets); @@ -158,17 +143,6 @@ private: return {offsetFirst, offsetSecond}; } -protected: - std::unique_ptr CloneImpl(std::string_view newName) const final - { - std::array, 2> items{fSubFields[0]->Clone(fSubFields[0]->GetFieldName()), - fSubFields[1]->Clone(fSubFields[1]->GetFieldName())}; - return std::make_unique>>(newName, std::move(items)); - } - - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { return "std::pair<" + RField::TypeName() + "," + RField::TypeName() + ">"; } explicit RField(std::string_view name, std::array, 2> &&itemFields) @@ -180,7 +154,7 @@ public: explicit RField(std::string_view name) : RField(name, BuildItemFields()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -190,24 +164,9 @@ public: /// The generic field for `std::tuple` types class RTupleField : public RRecordField { private: - class RTupleDeleter : public RDeleter { - private: - TClass *fClass; - - public: - explicit RTupleDeleter(TClass *cl) : fClass(cl) {} - void operator()(void *objPtr, bool dtorOnly) final; - }; - - TClass *fClass = nullptr; static std::string GetTypeList(const std::vector> &itemFields); protected: - std::unique_ptr CloneImpl(std::string_view newName) const override; - - void ConstructValue(void *where) const override; - std::unique_ptr GetDeleter() const override { return std::make_unique(fClass); } - RTupleField(std::string_view fieldName, std::vector> &&itemFields, const std::vector &offsets); @@ -264,18 +223,6 @@ private: return result; } -protected: - std::unique_ptr CloneImpl(std::string_view newName) const final - { - std::vector> items; - for (auto &item : fSubFields) - items.push_back(item->Clone(item->GetFieldName())); - return std::make_unique>>(newName, std::move(items)); - } - - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - public: static std::string TypeName() { return "std::tuple<" + BuildItemTypes() + ">"; } explicit RField(std::string_view name, std::vector> &&itemFields) @@ -287,7 +234,7 @@ public: explicit RField(std::string_view name) : RField(name, BuildItemFields()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; } // namespace Experimental diff --git a/tree/ntuple/v7/inc/ROOT/RField/RFieldSTLMisc.hxx b/tree/ntuple/v7/inc/ROOT/RField/RFieldSTLMisc.hxx index 586991b7ba4d7..34c4d5d46d8d5 100644 --- a/tree/ntuple/v7/inc/ROOT/RField/RFieldSTLMisc.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField/RFieldSTLMisc.hxx @@ -75,7 +75,7 @@ public: explicit RField(std::string_view name) : RAtomicField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -127,7 +127,7 @@ public: explicit RField(std::string_view name) : RBitsetField(name, N) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -151,7 +151,7 @@ public: explicit RField(std::string_view name) : RSimpleField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; }; @@ -236,7 +236,7 @@ public: explicit RField(std::string_view name) : ROptionalField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; class RUniquePtrField : public RNullableField { @@ -278,7 +278,7 @@ public: explicit RField(std::string_view name) : RUniquePtrField(name, TypeName(), std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -315,7 +315,7 @@ public: } RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; size_t GetValueSize() const final { return sizeof(std::string); } size_t GetAlignment() const final { return std::alignment_of(); } @@ -373,7 +373,7 @@ protected: void GenerateColumns() final; void GenerateColumns(const RNTupleDescriptor &desc) final; - void ConstructValue(void *where) const override; + void ConstructValue(void *where) const final; std::unique_ptr GetDeleter() const final; std::size_t AppendImpl(const void *from) final; @@ -394,8 +394,6 @@ public: template class RField> final : public RVariantField { - using ContainerT = typename std::variant; - private: template static std::string BuildItemTypes() @@ -418,15 +416,12 @@ private: return result; } -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - public: static std::string TypeName() { return "std::variant<" + BuildItemTypes() + ">"; } explicit RField(std::string_view name) : RVariantField(name, BuildItemFields()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; } // namespace Experimental diff --git a/tree/ntuple/v7/inc/ROOT/RField/RFieldSequenceContainer.hxx b/tree/ntuple/v7/inc/ROOT/RField/RFieldSequenceContainer.hxx index 6f0641af46d2e..26fa3e9bfc653 100644 --- a/tree/ntuple/v7/inc/ROOT/RField/RFieldSequenceContainer.hxx +++ b/tree/ntuple/v7/inc/ROOT/RField/RFieldSequenceContainer.hxx @@ -62,7 +62,7 @@ private: protected: std::unique_ptr CloneImpl(std::string_view newName) const final; - void ConstructValue(void *where) const override; + void ConstructValue(void *where) const final; std::unique_ptr GetDeleter() const final; std::size_t AppendImpl(const void *from) final; @@ -84,11 +84,6 @@ public: template class RField> : public RArrayField { - using ContainerT = typename std::array; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - public: static std::string TypeName() { return "std::array<" + RField::TypeName() + "," + std::to_string(N) + ">"; } explicit RField(std::string_view name) : RArrayField(name, std::make_unique>("_0"), N) {} @@ -103,7 +98,7 @@ public: explicit RField(std::string_view name) : RField>(name) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; }; //////////////////////////////////////////////////////////////////////////////// @@ -136,16 +131,16 @@ protected: ClusterSize_t fNWritten; std::size_t fValueSize; - std::unique_ptr CloneImpl(std::string_view newName) const override; + std::unique_ptr CloneImpl(std::string_view newName) const final; const RColumnRepresentations &GetColumnRepresentations() const final; void GenerateColumns() final; void GenerateColumns(const RNTupleDescriptor &desc) final; - void ConstructValue(void *where) const override; - std::unique_ptr GetDeleter() const override; + void ConstructValue(void *where) const final; + std::unique_ptr GetDeleter() const final; - std::size_t AppendImpl(const void *from) override; - void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) override; + std::size_t AppendImpl(const void *from) final; + void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) final; std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final; void CommitClusterImpl() final { fNWritten = 0; } @@ -159,8 +154,8 @@ public: ~RRVecField() override = default; std::vector SplitValue(const RValue &value) const final; - size_t GetValueSize() const override; - size_t GetAlignment() const override; + size_t GetValueSize() const final; + size_t GetAlignment() const final; void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; void GetCollectionInfo(NTupleSize_t globalIndex, RClusterIndex *collectionStart, ClusterSize_t *size) const { @@ -174,42 +169,6 @@ public: template class RField> final : public RRVecField { - using ContainerT = typename ROOT::VecOps::RVec; - -protected: - std::unique_ptr CloneImpl(std::string_view newName) const final - { - auto newItemField = fSubFields[0]->Clone(fSubFields[0]->GetFieldName()); - return std::make_unique>>(newName, std::move(newItemField)); - } - - void ConstructValue(void *where) const final { new (where) ContainerT(); } - std::unique_ptr GetDeleter() const final { return std::make_unique>(); } - - std::size_t AppendImpl(const void *from) final - { - auto typedValue = static_cast(from); - auto nbytes = 0; - auto count = typedValue->size(); - for (unsigned i = 0; i < count; ++i) { - nbytes += CallAppendOn(*fSubFields[0], &typedValue->data()[i]); - } - this->fNWritten += count; - fPrincipalColumn->Append(&this->fNWritten); - return nbytes + fPrincipalColumn->GetElement()->GetPackedSize(); - } - void ReadGlobalImpl(NTupleSize_t globalIndex, void *to) final - { - auto typedValue = static_cast(to); - ClusterSize_t nItems; - RClusterIndex collectionStart; - fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems); - typedValue->resize(nItems); - for (unsigned i = 0; i < nItems; ++i) { - CallReadOn(*fSubFields[0], collectionStart + i, &typedValue->data()[i]); - } - } - public: RField(std::string_view fieldName, std::unique_ptr itemField) : RRVecField(fieldName, std::move(itemField)) @@ -219,12 +178,9 @@ public: explicit RField(std::string_view name) : RField(name, std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; static std::string TypeName() { return "ROOT::VecOps::RVec<" + RField::TypeName() + ">"; } - - size_t GetValueSize() const final { return sizeof(ContainerT); } - size_t GetAlignment() const final { return std::alignment_of(); } }; //////////////////////////////////////////////////////////////////////////////// @@ -256,13 +212,13 @@ private: protected: RVectorField(std::string_view fieldName, std::unique_ptr itemField, bool isUntyped); - std::unique_ptr CloneImpl(std::string_view newName) const override; + std::unique_ptr CloneImpl(std::string_view newName) const final; const RColumnRepresentations &GetColumnRepresentations() const final; void GenerateColumns() final; void GenerateColumns(const RNTupleDescriptor &desc) final; - void ConstructValue(void *where) const override { new (where) std::vector(); } + void ConstructValue(void *where) const final { new (where) std::vector(); } std::unique_ptr GetDeleter() const final; std::size_t AppendImpl(const void *from) final; @@ -280,7 +236,7 @@ public: CreateUntyped(std::string_view fieldName, std::unique_ptr itemField); std::vector SplitValue(const RValue &value) const final; - size_t GetValueSize() const override { return sizeof(std::vector); } + size_t GetValueSize() const final { return sizeof(std::vector); } size_t GetAlignment() const final { return std::alignment_of>(); } void AcceptVisitor(Detail::RFieldVisitor &visitor) const final; void GetCollectionInfo(NTupleSize_t globalIndex, RClusterIndex *collectionStart, ClusterSize_t *size) const @@ -295,19 +251,12 @@ public: template class RField> final : public RVectorField { - using ContainerT = typename std::vector; - -protected: - void ConstructValue(void *where) const final { new (where) ContainerT(); } - public: static std::string TypeName() { return "std::vector<" + RField::TypeName() + ">"; } explicit RField(std::string_view name) : RVectorField(name, std::make_unique>("_0")) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; - - size_t GetValueSize() const final { return sizeof(ContainerT); } + ~RField() final = default; }; // std::vector is a template specialization and needs special treatment @@ -339,7 +288,7 @@ public: explicit RField(std::string_view name); RField(RField &&other) = default; RField &operator=(RField &&other) = default; - ~RField() override = default; + ~RField() final = default; std::vector SplitValue(const RValue &value) const final; diff --git a/tree/ntuple/v7/src/RField.cxx b/tree/ntuple/v7/src/RField.cxx index 4458ddbc8ffe7..46ad2c4054cf4 100644 --- a/tree/ntuple/v7/src/RField.cxx +++ b/tree/ntuple/v7/src/RField.cxx @@ -3597,12 +3597,6 @@ ROOT::Experimental::RSetField::RSetField(std::string_view fieldName, std::string { } -std::unique_ptr ROOT::Experimental::RSetField::CloneImpl(std::string_view newName) const -{ - auto newItemField = fSubFields[0]->Clone(fSubFields[0]->GetFieldName()); - return std::make_unique(newName, GetTypeName(), std::move(newItemField)); -} - //------------------------------------------------------------------------------ ROOT::Experimental::RMapField::RMapField(std::string_view fieldName, std::string_view typeName, @@ -3612,63 +3606,12 @@ ROOT::Experimental::RMapField::RMapField(std::string_view fieldName, std::string if (!dynamic_cast(itemField.get())) throw RException(R__FAIL("RMapField inner field type must be of RPairField")); - fItemClass = fProxy->GetValueClass(); - fItemSize = fItemClass->GetClassSize(); + auto *itemClass = fProxy->GetValueClass(); + fItemSize = itemClass->GetClassSize(); Attach(std::move(itemField)); } -std::size_t ROOT::Experimental::RMapField::AppendImpl(const void *from) -{ - std::size_t nbytes = 0; - unsigned count = 0; - TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), const_cast(from)); - for (auto ptr : RCollectionIterableOnce{const_cast(from), fIFuncsWrite, fProxy.get(), 0U}) { - nbytes += CallAppendOn(*fSubFields[0], ptr); - count++; - } - fNWritten += count; - fPrincipalColumn->Append(&fNWritten); - return nbytes + fPrincipalColumn->GetElement()->GetPackedSize(); -} - -void ROOT::Experimental::RMapField::ReadGlobalImpl(NTupleSize_t globalIndex, void *to) -{ - ClusterSize_t nItems; - RClusterIndex collectionStart; - fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &nItems); - - TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), to); - void *obj = - fProxy->Allocate(static_cast(nItems), (fProperties & TVirtualCollectionProxy::kNeedDelete)); - - unsigned i = 0; - for (auto ptr : RCollectionIterableOnce{obj, fIFuncsRead, fProxy.get(), fItemSize}) { - CallReadOn(*fSubFields[0], collectionStart + i, ptr); - i++; - } - - if (obj != to) - fProxy->Commit(obj); -} - -std::vector ROOT::Experimental::RMapField::SplitValue(const RValue &value) const -{ - std::vector result; - auto valueRawPtr = value.GetPtr().get(); - TVirtualCollectionProxy::TPushPop RAII(fProxy.get(), valueRawPtr); - for (auto ptr : RCollectionIterableOnce{valueRawPtr, fIFuncsWrite, fProxy.get(), 0U}) { - result.emplace_back(fSubFields[0]->BindValue(std::shared_ptr(value.GetPtr(), ptr))); - } - return result; -} - -std::unique_ptr ROOT::Experimental::RMapField::CloneImpl(std::string_view newName) const -{ - auto newItemField = fSubFields[0]->Clone(fSubFields[0]->GetFieldName()); - return std::unique_ptr(new RMapField(newName, GetTypeName(), std::move(newItemField))); -} - //------------------------------------------------------------------------------ ROOT::Experimental::RNullableField::RNullableField(std::string_view fieldName, std::string_view typeName, @@ -3928,44 +3871,22 @@ ROOT::Experimental::RPairField::RPairField(std::string_view fieldName, "std::pair<" + GetTypeList(itemFields) + ">") { // ISO C++ does not guarantee any specific layout for `std::pair`; query TClass for the member offsets - fClass = TClass::GetClass(GetTypeName().c_str()); - if (!fClass) + auto *c = TClass::GetClass(GetTypeName().c_str()); + if (!c) throw RException(R__FAIL("cannot get type information for " + GetTypeName())); - fSize = fClass->Size(); + fSize = c->Size(); - auto firstElem = fClass->GetRealData("first"); + auto firstElem = c->GetRealData("first"); if (!firstElem) throw RException(R__FAIL("first: no such member")); fOffsets[0] = firstElem->GetThisOffset(); - auto secondElem = fClass->GetRealData("second"); + auto secondElem = c->GetRealData("second"); if (!secondElem) throw RException(R__FAIL("second: no such member")); fOffsets[1] = secondElem->GetThisOffset(); } -std::unique_ptr -ROOT::Experimental::RPairField::CloneImpl(std::string_view newName) const -{ - std::array, 2> items{fSubFields[0]->Clone(fSubFields[0]->GetFieldName()), - fSubFields[1]->Clone(fSubFields[1]->GetFieldName())}; - - std::unique_ptr result(new RPairField(newName, std::move(items), {fOffsets[0], fOffsets[1]})); - result->fClass = fClass; - return result; -} - -void ROOT::Experimental::RPairField::ConstructValue(void *where) const -{ - fClass->New(where); -} - -void ROOT::Experimental::RPairField::RPairDeleter::operator()(void *objPtr, bool dtorOnly) -{ - fClass->Destructor(objPtr, true /* dtorOnly */); - RDeleter::operator()(objPtr, dtorOnly); -} - //------------------------------------------------------------------------------ std::string @@ -3994,10 +3915,10 @@ ROOT::Experimental::RTupleField::RTupleField(std::string_view fieldName, : ROOT::Experimental::RRecordField(fieldName, std::move(itemFields), {}, "std::tuple<" + GetTypeList(itemFields) + ">") { - fClass = TClass::GetClass(GetTypeName().c_str()); - if (!fClass) + auto *c = TClass::GetClass(GetTypeName().c_str()); + if (!c) throw RException(R__FAIL("cannot get type information for " + GetTypeName())); - fSize = fClass->Size(); + fSize = c->Size(); // ISO C++ does not guarantee neither specific layout nor member names for `std::tuple`. However, most // implementations including libstdc++ (gcc), libc++ (llvm), and MSVC name members as `_0`, `_1`, ..., `_N-1`, @@ -4006,37 +3927,13 @@ ROOT::Experimental::RTupleField::RTupleField(std::string_view fieldName, // members, the assertion below will fail. for (unsigned i = 0; i < fSubFields.size(); ++i) { std::string memberName("_" + std::to_string(i)); - auto member = fClass->GetRealData(memberName.c_str()); + auto member = c->GetRealData(memberName.c_str()); if (!member) throw RException(R__FAIL(memberName + ": no such member")); fOffsets.push_back(member->GetThisOffset()); } } -std::unique_ptr -ROOT::Experimental::RTupleField::CloneImpl(std::string_view newName) const -{ - std::vector> items; - items.reserve(fSubFields.size()); - for (const auto &item : fSubFields) - items.push_back(item->Clone(item->GetFieldName())); - - std::unique_ptr result(new RTupleField(newName, std::move(items), fOffsets)); - result->fClass = fClass; - return result; -} - -void ROOT::Experimental::RTupleField::ConstructValue(void *where) const -{ - fClass->New(where); -} - -void ROOT::Experimental::RTupleField::RTupleDeleter::operator()(void *objPtr, bool dtorOnly) -{ - fClass->Destructor(objPtr, true /* dtorOnly */); - RDeleter::operator()(objPtr, dtorOnly); -} - //------------------------------------------------------------------------------ ROOT::Experimental::RAtomicField::RAtomicField(std::string_view fieldName, std::string_view typeName, diff --git a/tree/ntuple/v7/test/ntuple_compat.cxx b/tree/ntuple/v7/test/ntuple_compat.cxx index b6254e5080a55..32fd263d86f48 100644 --- a/tree/ntuple/v7/test/ntuple_compat.cxx +++ b/tree/ntuple/v7/test/ntuple_compat.cxx @@ -247,7 +247,7 @@ class ROOT::Experimental::RFieldGetTypeName()); EXPECT_EQ((sizeof(std::set)), field.GetValueSize()); EXPECT_EQ((sizeof(std::set)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::set)), field.GetAlignment()); - // For type-erased set fields, we use `alignof(std::set)` to set the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::set)), field.GetAlignment()); EXPECT_LE((alignof(std::set)), otherField->GetAlignment()); auto setSetField = RField>>("setSetField"); @@ -440,9 +438,7 @@ TEST(RNTuple, StdUnorderedSet) EXPECT_EQ(field.GetTypeName(), otherField->GetTypeName()); EXPECT_EQ((sizeof(std::unordered_set)), field.GetValueSize()); EXPECT_EQ((sizeof(std::unordered_set)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::unordered_set)), field.GetAlignment()); - // For type-erased set fields, we use `alignof(std::set)` to set the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::unordered_set)), field.GetAlignment()); EXPECT_LE((alignof(std::unordered_set)), otherField->GetAlignment()); FileRaii fileGuard("test_ntuple_rfield_stdunorderedset.root"); @@ -503,9 +499,7 @@ TEST(RNTuple, StdMultiSet) EXPECT_EQ(field.GetTypeName(), otherField->GetTypeName()); EXPECT_EQ((sizeof(std::multiset)), field.GetValueSize()); EXPECT_EQ((sizeof(std::multiset)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::multiset)), field.GetAlignment()); - // For type-erased set fields, we use `alignof(std::set)` to set the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::multiset)), field.GetAlignment()); EXPECT_LE((alignof(std::multiset)), otherField->GetAlignment()); FileRaii fileGuard("test_ntuple_rfield_stdmultiset.root"); @@ -550,9 +544,7 @@ TEST(RNTuple, StdUnorderedMultiSet) EXPECT_EQ(field.GetTypeName(), otherField->GetTypeName()); EXPECT_EQ((sizeof(std::unordered_multiset)), field.GetValueSize()); EXPECT_EQ((sizeof(std::unordered_multiset)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::unordered_multiset)), field.GetAlignment()); - // For type-erased set fields, we use `alignof(std::set)` to set the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::unordered_multiset)), field.GetAlignment()); EXPECT_LE((alignof(std::unordered_multiset)), otherField->GetAlignment()); FileRaii fileGuard("test_ntuple_rfield_stdmultiset.root"); @@ -597,13 +589,8 @@ TEST(RNTuple, StdMap) EXPECT_EQ(field.GetTypeName(), otherField->GetTypeName()); EXPECT_EQ((sizeof(std::map)), field.GetValueSize()); EXPECT_EQ((sizeof(std::map)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::map)), field.GetAlignment()); - // For type-erased map fields, we use `alignof(std::map)` to map the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::map)), field.GetAlignment()); EXPECT_LE((alignof(std::map)), otherField->GetAlignment()); - // The assumption is that the alignment of inner items does not matter. If at any point there is a mismatch, this - // test should fail. - EXPECT_EQ((alignof(std::map)), otherField->GetAlignment()); auto mapMapField = RField>>("mapMapField"); EXPECT_STREQ("std::map>", mapMapField.GetTypeName().c_str()); @@ -699,13 +686,8 @@ TEST(RNTuple, StdUnorderedMap) EXPECT_STREQ(field.GetTypeName().c_str(), otherField->GetTypeName().c_str()); EXPECT_EQ((sizeof(std::unordered_map)), field.GetValueSize()); EXPECT_EQ((sizeof(std::unordered_map)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::unordered_map)), field.GetAlignment()); - // For type-erased map fields, we use `alignof(std::map)` to map the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::unordered_map)), field.GetAlignment()); EXPECT_LE((alignof(std::unordered_map)), otherField->GetAlignment()); - // The assumption is that the alignment of inner items does not matter. If at any point there is a mismatch, this - // test should fail. - EXPECT_EQ((alignof(std::unordered_map)), otherField->GetAlignment()); EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::unordered_map").Unwrap(), RException); EXPECT_THROW(RFieldBase::Create("myInvalidMap", "std::unordered_map").Unwrap(), RException); @@ -781,13 +763,8 @@ TEST(RNTuple, StdMultiMap) EXPECT_STREQ(field.GetTypeName().c_str(), otherField->GetTypeName().c_str()); EXPECT_EQ((sizeof(std::multimap)), field.GetValueSize()); EXPECT_EQ((sizeof(std::multimap)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::multimap)), field.GetAlignment()); - // For type-erased map fields, we use `alignof(std::map)` to map the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::multimap)), field.GetAlignment()); EXPECT_LE((alignof(std::multimap)), otherField->GetAlignment()); - // The assumption is that the alignment of inner items does not matter. If at any point there is a mismatch, this - // test should fail. - EXPECT_EQ((alignof(std::multimap)), otherField->GetAlignment()); FileRaii fileGuard("test_ntuple_rfield_stdmultimap.root"); { @@ -839,13 +816,8 @@ TEST(RNTuple, StdUnorderedMultiMap) EXPECT_STREQ(field.GetTypeName().c_str(), otherField->GetTypeName().c_str()); EXPECT_EQ((sizeof(std::unordered_multimap)), field.GetValueSize()); EXPECT_EQ((sizeof(std::unordered_multimap)), otherField->GetValueSize()); - EXPECT_EQ((alignof(std::unordered_multimap)), field.GetAlignment()); - // For type-erased map fields, we use `alignof(std::map)` to map the alignment, - // so the actual alignment may be smaller. + EXPECT_LE((alignof(std::unordered_multimap)), field.GetAlignment()); EXPECT_LE((alignof(std::unordered_multimap)), otherField->GetAlignment()); - // The assumption is that the alignment of inner items does not matter. If at any point there is a mismatch, this - // test should fail. - EXPECT_EQ((alignof(std::unordered_multimap)), otherField->GetAlignment()); FileRaii fileGuard("test_ntuple_rfield_stdmultimap.root"); { @@ -1550,8 +1522,8 @@ TEST(RNTuple, Optional) EXPECT_EQ(alignof(std::optional), RField>("f").GetAlignment()); EXPECT_EQ(sizeof(std::optional), RField>("f").GetValueSize()); EXPECT_EQ(alignof(std::optional), RField>("f").GetAlignment()); - EXPECT_EQ(sizeof(std::optional), RField>("f").GetValueSize()); - EXPECT_EQ(alignof(std::optional), RField>("f").GetAlignment()); + EXPECT_LE(sizeof(std::optional), RField>("f").GetValueSize()); + EXPECT_LE(alignof(std::optional), RField>("f").GetAlignment()); FileRaii fileGuard("test_ntuple_optional.root");