1414// - RField<TObject>
1515// - RVariantField
1616
17+ #include < ROOT/BitUtils.hxx>
1718#include < ROOT/RField.hxx>
1819#include < ROOT/RFieldBase.hxx>
1920#include < ROOT/RFieldUtils.hxx>
@@ -116,6 +117,12 @@ TEnum *EnsureValidEnum(std::string_view enumName)
116117 return e;
117118}
118119
120+ void EnsureValidAlignment (std::size_t align)
121+ {
122+ if (align == 0 || align > ROOT ::RFieldBase::kMaxAlignment || !ROOT::Internal::IsPowerOfTwo (align))
123+ throw ROOT::RException (R__FAIL (std::string (" invalid alignment: " ) + std::to_string (align)));
124+ }
125+
119126// / Create a comma-separated list of type names from the given fields. Uses either the real type names or the
120127// / type aliases (if there are any, otherwise the actual type name). Used to construct template argument lists
121128// / for templated types such as std::pair<...>, std::tuple<...>, std::variant<...>.
@@ -186,8 +193,7 @@ std::string BuildMapTypeName(ROOT::RMapField::EMapType mapType, const ROOT::RFie
186193ROOT ::RClassField::RClassField(std::string_view fieldName, const RClassField &source)
187194 : ROOT ::RFieldBase(fieldName, source.GetTypeName(), ROOT ::ENTupleStructure::kRecord , false /* isSimple */ ),
188195 fClass (source.fClass ),
189- fSubfieldsInfo(source.fSubfieldsInfo ),
190- fMaxAlignment(source.fMaxAlignment )
196+ fSubfieldsInfo(source.fSubfieldsInfo )
191197{
192198 for (const auto &f : source.GetConstSubfields ()) {
193199 RFieldBase::Attach (f->Clone (f->GetFieldName ()));
@@ -280,7 +286,6 @@ ROOT::RClassField::~RClassField()
280286
281287void ROOT::RClassField::Attach (std::unique_ptr<RFieldBase> child, RSubfieldInfo info)
282288{
283- fMaxAlignment = std::max (fMaxAlignment , child->GetAlignment ());
284289 fSubfieldsInfo .push_back (info);
285290 RFieldBase::Attach (std::move (child));
286291}
@@ -622,11 +627,18 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue
622627 return result;
623628}
624629
625- size_t ROOT::RClassField::GetValueSize () const
630+ std:: size_t ROOT::RClassField::GetValueSize () const
626631{
627632 return fClass ->GetClassSize ();
628633}
629634
635+ std::size_t ROOT::RClassField::GetAlignment () const
636+ {
637+ const auto align = fClass ->GetClassAlignment ();
638+ EnsureValidAlignment (align);
639+ return align;
640+ }
641+
630642std::uint32_t ROOT::RClassField::GetTypeVersion () const
631643{
632644 return fClass ->GetClassVersion ();
@@ -656,8 +668,7 @@ void ROOT::RClassField::AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) cons
656668ROOT ::Experimental::RSoAField::RSoAField(std::string_view fieldName, const RSoAField &source)
657669 : ROOT ::RFieldBase(fieldName, source.GetTypeName(), ROOT ::ENTupleStructure::kCollection , false /* isSimple */ ),
658670 fSoAClass (source.fSoAClass ),
659- fSoAMemberOffsets(source.fSoAMemberOffsets ),
660- fMaxAlignment(source.fMaxAlignment )
671+ fSoAMemberOffsets(source.fSoAMemberOffsets )
661672{
662673 fTraits = source.GetTraits ();
663674 Attach (source.fSubfields [0 ]->Clone (source.fSubfields [0 ]->GetFieldName ()));
@@ -763,8 +774,6 @@ ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, TClass *clS
763774 leftType + " vs. " + rightType + " )" ));
764775 }
765776
766- fMaxAlignment = std::max (fMaxAlignment , vecField->GetAlignment ());
767-
768777 assert (itr->second < fSoAMemberOffsets .size ());
769778 fSoAMemberOffsets [itr->second ] = dataMember->GetOffset ();
770779 nMembers++;
@@ -910,7 +919,7 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(
910919 return values;
911920}
912921
913- size_t ROOT::Experimental::RSoAField::GetValueSize () const
922+ std:: size_t ROOT::Experimental::RSoAField::GetValueSize () const
914923{
915924 return fSoAClass ->GetClassSize ();
916925}
@@ -925,6 +934,13 @@ std::uint32_t ROOT::Experimental::RSoAField::GetTypeChecksum() const
925934 return fSoAClass ->GetCheckSum ();
926935}
927936
937+ std::size_t ROOT::Experimental::RSoAField::GetAlignment () const
938+ {
939+ const auto align = fSoAClass ->GetClassAlignment ();
940+ EnsureValidAlignment (align);
941+ return align;
942+ }
943+
928944const std::type_info *ROOT ::Experimental::RSoAField::GetPolymorphicTypeInfo() const
929945{
930946 // TODO(jblomer): factor out
@@ -1250,6 +1266,18 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(
12501266 return result;
12511267}
12521268
1269+ std::size_t ROOT::RProxiedCollectionField::GetValueSize () const
1270+ {
1271+ return fProxy ->Sizeof ();
1272+ }
1273+
1274+ std::size_t ROOT::RProxiedCollectionField::GetAlignment () const
1275+ {
1276+ const auto align = fProxy ->GetCollectionClass ()->GetClassAlignment ();
1277+ EnsureValidAlignment (align);
1278+ return align;
1279+ }
1280+
12531281void ROOT::RProxiedCollectionField::AcceptVisitor (ROOT ::Detail::RFieldVisitor &visitor) const
12541282{
12551283 visitor.VisitProxiedCollectionField (*this );
@@ -1457,7 +1485,9 @@ ROOT::RExtraTypeInfoDescriptor ROOT::RStreamerField::GetExtraTypeInfo() const
14571485
14581486std::size_t ROOT::RStreamerField::GetAlignment () const
14591487{
1460- return std::min (alignof (std::max_align_t ), GetValueSize ()); // TODO(jblomer): fix me
1488+ const auto align = fClass ->GetClassAlignment ();
1489+ EnsureValidAlignment (align);
1490+ return align;
14611491}
14621492
14631493std::size_t ROOT::RStreamerField::GetValueSize () const
0 commit comments