diff --git a/tree/ntuple/doc/Architecture.md b/tree/ntuple/doc/Architecture.md index 311a24ee2f12d..bac0abc91f8c0 100644 --- a/tree/ntuple/doc/Architecture.md +++ b/tree/ntuple/doc/Architecture.md @@ -187,7 +187,7 @@ During its lifetime, a field undergoes the following possible state transitions: The RField class hierarchy is fixed and not meant to be extended by user classes. -### RField::RValue +### RFieldBase::RValue The `RValue` class makes the connection between an object in memory and the corresponding field used for I/O. It contains a shared pointer of the object, i.e. RNTuple and the application share ownership of objects. The object in an RValue can either be created by an RNTuple field (cf. `RField::CreateValue()` method) diff --git a/tree/ntuple/inc/ROOT/RField.hxx b/tree/ntuple/inc/ROOT/RField.hxx index 0857c99e6eba2..b1acdfc1bbdd2 100644 --- a/tree/ntuple/inc/ROOT/RField.hxx +++ b/tree/ntuple/inc/ROOT/RField.hxx @@ -297,7 +297,7 @@ public: template class RField>::type> final : public REnumField { public: - static std::string TypeName() { return ROOT::Internal::GetDemangledTypeName(typeid(T)); } + static std::string TypeName() { return ROOT::Internal::GetRenormalizedTypeName(typeid(T)); } RField(std::string_view name) : REnumField(name, TypeName()) {} RField(RField &&other) = default; RField &operator=(RField &&other) = default; @@ -352,12 +352,13 @@ protected: void ConstructValue(void *where) const final { new (where) T{0}; } -public: RSimpleField(std::string_view name, std::string_view type) : RFieldBase(name, type, ROOT::ENTupleStructure::kLeaf, true /* isSimple */) { fTraits |= kTraitTrivialType; } + +public: RSimpleField(RSimpleField &&other) = default; RSimpleField &operator=(RSimpleField &&other) = default; ~RSimpleField() override = default; @@ -393,12 +394,14 @@ namespace ROOT { template class RField> final : public RCardinalityField { + using CardinalityType = RNTupleCardinality; + protected: std::unique_ptr CloneImpl(std::string_view newName) const final { - return std::make_unique>>(newName); + return std::make_unique(newName); } - void ConstructValue(void *where) const final { new (where) RNTupleCardinality(0); } + void ConstructValue(void *where) const final { new (where) CardinalityType(0); } /// Get the number of elements of the collection identified by globalIndex void ReadGlobalImpl(ROOT::NTupleSize_t globalIndex, void *to) final @@ -406,7 +409,7 @@ protected: RNTupleLocalIndex collectionStart; ROOT::NTupleSize_t size; fPrincipalColumn->GetCollectionInfo(globalIndex, &collectionStart, &size); - *static_cast *>(to) = size; + *static_cast(to) = size; } /// Get the number of elements of the collection identified by clusterIndex @@ -415,7 +418,7 @@ protected: RNTupleLocalIndex collectionStart; ROOT::NTupleSize_t size; fPrincipalColumn->GetCollectionInfo(localIndex, &collectionStart, &size); - *static_cast *>(to) = size; + *static_cast(to) = size; } std::size_t ReadBulkImpl(const RBulkSpec &bulkSpec) final @@ -424,7 +427,7 @@ protected: ROOT::NTupleSize_t collectionSize; fPrincipalColumn->GetCollectionInfo(bulkSpec.fFirstIndex, &collectionStart, &collectionSize); - auto typedValues = static_cast *>(bulkSpec.fValues); + auto typedValues = static_cast(bulkSpec.fValues); typedValues[0] = collectionSize; auto lastOffset = collectionStart.GetIndexInCluster() + collectionSize; @@ -452,8 +455,8 @@ public: RField &operator=(RField &&other) = default; ~RField() final = default; - size_t GetValueSize() const final { return sizeof(RNTupleCardinality); } - size_t GetAlignment() const final { return alignof(RNTupleCardinality); } + size_t GetValueSize() const final { return sizeof(CardinalityType); } + size_t GetAlignment() const final { return alignof(CardinalityType); } }; /// TObject requires special handling of the fBits and fUniqueID members @@ -495,8 +498,7 @@ public: void AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) const final; }; -// Has to be implemented after the definition of all RField types -// The void type is specialized in RField.cxx +// Have to be implemented after the definition of all RField types namespace Internal { @@ -527,6 +529,8 @@ std::unique_ptr::deleter> RField return std::unique_ptr(static_cast(CreateObjectRawPtr())); } +// The void type is specialized in RField.cxx + template <> struct RFieldBase::RCreateObjectDeleter { using deleter = RCreateObjectDeleter; diff --git a/tree/ntuple/inc/ROOT/RFieldBase.hxx b/tree/ntuple/inc/ROOT/RFieldBase.hxx index 90c9ff9b54cb3..404ffc85ddd8a 100644 --- a/tree/ntuple/inc/ROOT/RFieldBase.hxx +++ b/tree/ntuple/inc/ROOT/RFieldBase.hxx @@ -30,6 +30,7 @@ namespace ROOT { +class REntry; class RFieldBase; class RClassField; @@ -697,8 +698,9 @@ public: /// Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field. /// Fields can create RValue objects through RFieldBase::CreateValue(), RFieldBase::BindValue()) or /// RFieldBase::SplitValue(). -class RFieldBase::RValue { +class RFieldBase::RValue final { friend class RFieldBase; + friend class ROOT::REntry; private: RFieldBase *fField = nullptr; ///< The field that created the RValue @@ -713,9 +715,13 @@ public: RValue &operator=(RValue &&other) = default; ~RValue() = default; +private: std::size_t Append() { return fField->Append(fObjPtr.get()); } + +public: void Read(ROOT::NTupleSize_t globalIndex) { fField->Read(globalIndex, fObjPtr.get()); } void Read(RNTupleLocalIndex localIndex) { fField->Read(localIndex, fObjPtr.get()); } + void Bind(std::shared_ptr objPtr) { fObjPtr = objPtr; } void BindRawPtr(void *rawPtr); /// Replace the current object pointer by a pointer to a new object constructed by the field @@ -769,7 +775,7 @@ on the same range, where in each read operation a different subset of values is The memory of the value array is managed by the RBulkValues class. */ // clang-format on -class RFieldBase::RBulkValues { +class RFieldBase::RBulkValues final { private: friend class RFieldBase;