1515// - RField<TObject>
1616// - RVariantField
1717
18+ #include < ROOT/RAlignmentUtils.hxx>
1819#include < ROOT/RField.hxx>
1920#include < ROOT/RFieldBase.hxx>
2021#include < ROOT/RFieldUtils.hxx>
@@ -117,6 +118,12 @@ TEnum *EnsureValidEnum(std::string_view enumName)
117118 return e;
118119}
119120
121+ void EnsureValidAlignment (std::size_t align)
122+ {
123+ if (!ROOT::Internal::IsValidAlignment (align))
124+ throw ROOT::RException (R__FAIL (std::string (" invalid alignment: " ) + std::to_string (align)));
125+ }
126+
120127// / Create a comma-separated list of type names from the given fields. Uses either the real type names or the
121128// / type aliases (if there are any, otherwise the actual type name). Used to construct template argument lists
122129// / for templated types such as std::pair<...>, std::tuple<...>, std::variant<...>.
@@ -187,8 +194,7 @@ std::string BuildMapTypeName(ROOT::RMapField::EMapType mapType, const ROOT::RFie
187194ROOT ::RClassField::RClassField(std::string_view fieldName, const RClassField &source)
188195 : ROOT ::RFieldBase(fieldName, source.GetTypeName(), ROOT ::ENTupleStructure::kRecord , false /* isSimple */ ),
189196 fClass (source.fClass ),
190- fSubfieldsInfo(source.fSubfieldsInfo ),
191- fMaxAlignment(source.fMaxAlignment )
197+ fSubfieldsInfo(source.fSubfieldsInfo )
192198{
193199 for (const auto &f : source.GetConstSubfields ()) {
194200 RFieldBase::Attach (f->Clone (f->GetFieldName ()));
@@ -281,7 +287,6 @@ ROOT::RClassField::~RClassField()
281287
282288void ROOT::RClassField::Attach (std::unique_ptr<RFieldBase> child, RSubfieldInfo info)
283289{
284- fMaxAlignment = std::max (fMaxAlignment , child->GetAlignment ());
285290 fSubfieldsInfo .push_back (info);
286291 RFieldBase::Attach (std::move (child));
287292}
@@ -623,11 +628,18 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::RClassField::SplitValue(const RValue
623628 return result;
624629}
625630
626- size_t ROOT::RClassField::GetValueSize () const
631+ std:: size_t ROOT::RClassField::GetValueSize () const
627632{
628633 return fClass ->GetClassSize ();
629634}
630635
636+ std::size_t ROOT::RClassField::GetAlignment () const
637+ {
638+ const auto align = fClass ->GetClassAlignment ();
639+ EnsureValidAlignment (align);
640+ return align;
641+ }
642+
631643std::uint32_t ROOT::RClassField::GetTypeVersion () const
632644{
633645 return fClass ->GetClassVersion ();
@@ -657,8 +669,7 @@ void ROOT::RClassField::AcceptVisitor(ROOT::Detail::RFieldVisitor &visitor) cons
657669ROOT ::Experimental::RSoAField::RSoAField(std::string_view fieldName, const RSoAField &source)
658670 : ROOT ::RFieldBase(fieldName, source.GetTypeName(), ROOT ::ENTupleStructure::kCollection , false /* isSimple */ ),
659671 fSoAClass (source.fSoAClass ),
660- fSoAMemberOffsets(source.fSoAMemberOffsets ),
661- fMaxAlignment(source.fMaxAlignment )
672+ fSoAMemberOffsets(source.fSoAMemberOffsets )
662673{
663674 fTraits = source.GetTraits ();
664675 Attach (source.fSubfields [0 ]->Clone (source.fSubfields [0 ]->GetFieldName ()));
@@ -757,8 +768,6 @@ ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, TClass *clS
757768 leftType + " vs. " + rightType + " )" ));
758769 }
759770
760- fMaxAlignment = std::max (fMaxAlignment , vecField->GetAlignment ());
761-
762771 assert (itr->second < fSoAMemberOffsets .size ());
763772 fSoAMemberOffsets [itr->second ] = dataMember->GetOffset ();
764773 nMembers++;
@@ -863,7 +872,7 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::Experimental::RSoAField::SplitValue(
863872 return std::vector<RValue>();
864873}
865874
866- size_t ROOT::Experimental::RSoAField::GetValueSize () const
875+ std:: size_t ROOT::Experimental::RSoAField::GetValueSize () const
867876{
868877 return fSoAClass ->GetClassSize ();
869878}
@@ -878,6 +887,13 @@ std::uint32_t ROOT::Experimental::RSoAField::GetTypeChecksum() const
878887 return fSoAClass ->GetCheckSum ();
879888}
880889
890+ std::size_t ROOT::Experimental::RSoAField::GetAlignment () const
891+ {
892+ const auto align = fSoAClass ->GetClassAlignment ();
893+ EnsureValidAlignment (align);
894+ return align;
895+ }
896+
881897const std::type_info *ROOT ::Experimental::RSoAField::GetPolymorphicTypeInfo() const
882898{
883899 // TODO(jblomer): factor out
@@ -1198,6 +1214,18 @@ std::vector<ROOT::RFieldBase::RValue> ROOT::RProxiedCollectionField::SplitValue(
11981214 return result;
11991215}
12001216
1217+ std::size_t ROOT::RProxiedCollectionField::GetValueSize () const
1218+ {
1219+ return fProxy ->Sizeof ();
1220+ }
1221+
1222+ std::size_t ROOT::RProxiedCollectionField::GetAlignment () const
1223+ {
1224+ const auto align = fProxy ->GetCollectionClass ()->GetClassAlignment ();
1225+ EnsureValidAlignment (align);
1226+ return align;
1227+ }
1228+
12011229void ROOT::RProxiedCollectionField::AcceptVisitor (ROOT ::Detail::RFieldVisitor &visitor) const
12021230{
12031231 visitor.VisitProxiedCollectionField (*this );
@@ -1405,7 +1433,9 @@ ROOT::RExtraTypeInfoDescriptor ROOT::RStreamerField::GetExtraTypeInfo() const
14051433
14061434std::size_t ROOT::RStreamerField::GetAlignment () const
14071435{
1408- return std::min (alignof (std::max_align_t ), GetValueSize ()); // TODO(jblomer): fix me
1436+ const auto align = fClass ->GetClassAlignment ();
1437+ EnsureValidAlignment (align);
1438+ return align;
14091439}
14101440
14111441std::size_t ROOT::RStreamerField::GetValueSize () const
0 commit comments