From 4a60b1ac6e684b30286cb2c90e8419cd69ee3c87 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Mon, 13 Jan 2025 11:28:11 -0600 Subject: [PATCH] io: for rule input don't use virtual function if class changed --- io/io/src/TStreamerInfo.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/io/io/src/TStreamerInfo.cxx b/io/io/src/TStreamerInfo.cxx index b28d57d9bf38d..f00ec70de9809 100644 --- a/io/io/src/TStreamerInfo.cxx +++ b/io/io/src/TStreamerInfo.cxx @@ -288,10 +288,13 @@ namespace { memType = TVirtualStreamerInfo::kAnyP; } } else { - if (memClass->IsTObject()) { - memType = TVirtualStreamerInfo::kObject; - } else if (memClass->GetCollectionProxy()) { + if (memClass->GetCollectionProxy()) { memType = TVirtualStreamerInfo::kSTL; + } else if(memClass->IsTObject() && memClass == element->GetClassPointer()) { + // If there is a change in the class type, we can't use the TObject::Streamer + // virtual function: it would streame the data using the in-memory type rather + // than the onfile type. + memType = TVirtualStreamerInfo::kObject; } else { memType = TVirtualStreamerInfo::kAny; } @@ -349,6 +352,13 @@ namespace { void UpdateFromRule(const TStreamerInfo *info, const ROOT::TSchemaRule::TSources *s, TStreamerElement *element) { auto [memClass, memType, datasize, dimensions, totaldim] = GetSourceType(s, element); + if (element->GetType() == TVirtualStreamerInfo::kObject && memClass != element->GetClassPointer()) + { + // If there is a change in the class type, we can't use the TObject::Streamer + // virtual function: it would streame the data using the in-memory type rather + // than the onfile type. + element->SetType(TVirtualStreamerInfo::kAny); + } element->SetNewType( memType ); element->SetNewClass( memClass ); // We can not change the recorded dimensions. Let's check that