diff --git a/tree/ntuple/src/RFieldMeta.cxx b/tree/ntuple/src/RFieldMeta.cxx index dd1d70955a31d..75cbb1b1cdf06 100644 --- a/tree/ntuple/src/RFieldMeta.cxx +++ b/tree/ntuple/src/RFieldMeta.cxx @@ -911,7 +911,9 @@ ROOT::Experimental::RSoAField::RSoAField(std::string_view fieldName, TClass *clS } catch (ROOT::RException &e) { throw RException(R__FAIL("invalid record type of SoA field " + GetTypeName() + " [" + e.what() + "]")); } - R__ASSERT(fClass->GetClassVersion() >= 0); + if (fClass->GetClassVersion() <= 0) { + throw RException(R__FAIL(std::string("SoA class ") + GetTypeName() + " is transient or unversioned.")); + } if (static_cast(fClass->GetClassVersion()) != fSubfields[0]->GetTypeVersion()) { throw RException(R__FAIL(std::string("version mismatch between SoA type and underlying record type: ") + std::to_string(fClass->GetClassVersion()) + " vs. " + diff --git a/tree/ntuple/test/SoAField.hxx b/tree/ntuple/test/SoAField.hxx index 89704b2765da0..2135b724507bf 100644 --- a/tree/ntuple/test/SoAField.hxx +++ b/tree/ntuple/test/SoAField.hxx @@ -23,6 +23,10 @@ struct SoAVersionMismatch { ClassDefNV(SoAVersionMismatch, 4); }; +struct RecordUnversioned {}; + +struct SoAUnversioned {}; + struct RecordSimple { float fX; float fY; diff --git a/tree/ntuple/test/SoAFieldLinkDef.h b/tree/ntuple/test/SoAFieldLinkDef.h index 44e0ffe512c63..69beee8e05a78 100644 --- a/tree/ntuple/test/SoAFieldLinkDef.h +++ b/tree/ntuple/test/SoAFieldLinkDef.h @@ -6,6 +6,9 @@ #pragma link C++ options=rntupleSoARecord(xyz) class SoAUnknownRecord+; #pragma link C++ options=rntupleSoARecord(Record) class SoAVersionMismatch+; +#pragma link C++ class RecordUnversioned+; +#pragma link C++ options=rntupleSoARecord(RecordUnversioned) class SoAUnversioned+; + #pragma link C++ class RecordSimple+; #pragma link C++ options=rntupleSoARecord(RecordSimple) class SoASimple+; #pragma link C++ options=rntupleSoARecord(RecordSimple) class SoASimpleSwapped+; diff --git a/tree/ntuple/test/ntuple_soa.cxx b/tree/ntuple/test/ntuple_soa.cxx index 6bf4f198199f8..f5cce61171bcc 100644 --- a/tree/ntuple/test/ntuple_soa.cxx +++ b/tree/ntuple/test/ntuple_soa.cxx @@ -70,6 +70,13 @@ TEST(RNTuple, SoACheck) EXPECT_THAT(e.what(), ::testing::HasSubstr("version mismatch between SoA type and underlying record type")); } + try { + auto f = std::make_unique("f", "SoAUnversioned"); + FAIL() << "creating unversioned SoA field should fail"; + } catch (const ROOT::RException &e) { + EXPECT_THAT(e.what(), ::testing::HasSubstr("is transient or unversioned")); + } + try { auto f = std::make_unique("f", "SoASimpleBadArray"); FAIL() << "creating SoA field with arrays should fail";