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 ()));
@@ -756,8 +767,6 @@ ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, TClass *clS
756767 leftType + " vs. " + rightType + " )" ));
757768 }
758769
759- fMaxAlignment = std::max (fMaxAlignment , vecField->GetAlignment ());
760-
761770 assert (itr->second < fSoAMemberOffsets .size ());
762771 fSoAMemberOffsets [itr->second ] = dataMember->GetOffset ();
763772 nMembers++;
@@ -862,7 +871,7 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(
862871 return std::vector<RValue>();
863872}
864873
865- size_t ROOT::Experimental::RSoAField::GetValueSize () const
874+ std:: size_t ROOT::Experimental::RSoAField::GetValueSize () const
866875{
867876 return fSoAClass ->GetClassSize ();
868877}
@@ -877,6 +886,13 @@ std::uint32_t ROOT::Experimental::RSoAField::GetTypeChecksum() const
877886 return fSoAClass ->GetCheckSum ();
878887}
879888
889+ std::size_t ROOT::Experimental::RSoAField::GetAlignment () const
890+ {
891+ const auto align = fSoAClass ->GetClassAlignment ();
892+ EnsureValidAlignment (align);
893+ return align;
894+ }
895+
880896const std::type_info *ROOT ::Experimental::RSoAField::GetPolymorphicTypeInfo() const
881897{
882898 // TODO(jblomer): factor out
@@ -1197,6 +1213,18 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(
11971213 return result;
11981214}
11991215
1216+ std::size_t ROOT::RProxiedCollectionField::GetValueSize () const
1217+ {
1218+ return fProxy ->Sizeof ();
1219+ }
1220+
1221+ std::size_t ROOT::RProxiedCollectionField::GetAlignment () const
1222+ {
1223+ const auto align = fProxy ->GetCollectionClass ()->GetClassAlignment ();
1224+ EnsureValidAlignment (align);
1225+ return align;
1226+ }
1227+
12001228void ROOT::RProxiedCollectionField::AcceptVisitor (ROOT ::Detail::RFieldVisitor &visitor) const
12011229{
12021230 visitor.VisitProxiedCollectionField (*this );
@@ -1404,7 +1432,9 @@ ROOT::RExtraTypeInfoDescriptor ROOT::RStreamerField::GetExtraTypeInfo() const
14041432
14051433std::size_t ROOT::RStreamerField::GetAlignment () const
14061434{
1407- return std::min (alignof (std::max_align_t ), GetValueSize ()); // TODO(jblomer): fix me
1435+ const auto align = fClass ->GetClassAlignment ();
1436+ EnsureValidAlignment (align);
1437+ return align;
14081438}
14091439
14101440std::size_t ROOT::RStreamerField::GetValueSize () const
0 commit comments