From 5f53f976af95ffddbc4ef18ea59761ae8ed03504 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Fri, 9 May 2025 09:19:06 +0200 Subject: [PATCH] [test][io] Add test for renaming rule without classdef Test for https://github.com/root-project/root/issues/14491 Original reproducer: https://github.com/root-project/root/issues/14491#issuecomment-1917587621 --- .../root/io/evolution/versions/CMakeLists.txt | 18 +++++ .../evolution/versions/ROOT14491readdata.cxx | 76 +++++++++++++++++++ .../evolution/versions/ROOT14491readdata.ref | 29 +++++++ .../versions/ROOT14491simpleread.cxx | 67 ++++++++++++++++ .../versions/ROOT14491simpleread.ref | 13 ++++ .../evolution/versions/ROOT14491writedata.cxx | 63 +++++++++++++++ .../evolution/versions/ROOT14491writedata.ref | 3 + 7 files changed, 269 insertions(+) create mode 100644 roottest/root/io/evolution/versions/ROOT14491readdata.cxx create mode 100644 roottest/root/io/evolution/versions/ROOT14491readdata.ref create mode 100644 roottest/root/io/evolution/versions/ROOT14491simpleread.cxx create mode 100644 roottest/root/io/evolution/versions/ROOT14491simpleread.ref create mode 100644 roottest/root/io/evolution/versions/ROOT14491writedata.cxx create mode 100644 roottest/root/io/evolution/versions/ROOT14491writedata.ref diff --git a/roottest/root/io/evolution/versions/CMakeLists.txt b/roottest/root/io/evolution/versions/CMakeLists.txt index 9bd7ab6608887..a7555583d608f 100644 --- a/roottest/root/io/evolution/versions/CMakeLists.txt +++ b/roottest/root/io/evolution/versions/CMakeLists.txt @@ -89,6 +89,24 @@ ROOTTEST_ADD_TEST(ROOT7500 OUTREF execROOT7500.ref LABELS longtest io) +ROOTTEST_ADD_TEST(ROOT14491writedata + MACRO ROOT14491writedata.cxx+ + FIXTURES_SETUP root-io-evolution-versions-ROOT14491writedata + OUTREF ROOT14491writedata.ref + LABELS io) + +ROOTTEST_ADD_TEST(ROOT14491readdata + MACRO ROOT14491readdata.cxx+ + OUTREF ROOT14491readdata.ref + FIXTURES_REQUIRED root-io-evolution-versions-ROOT14491writedata + LABELS io) + +ROOTTEST_ADD_TEST(ROOT14491simpleread + MACRO ROOT14491simpleread.cxx+ + OUTREF ROOT14491simpleread.ref + FIXTURES_REQUIRED root-io-evolution-versions-ROOT14491writedata + LABELS io) + ROOTTEST_ADD_TEST(attmarker COMMAND ${ROOT_hadd_CMD} -f result.root hsimple14.root hsimple20.root WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/roottest/root/io/evolution/versions/ROOT14491readdata.cxx b/roottest/root/io/evolution/versions/ROOT14491readdata.cxx new file mode 100644 index 0000000000000..e5e45483b193d --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491readdata.cxx @@ -0,0 +1,76 @@ +// See https://github.com/root-project/root/issues/14491#issuecomment-1917587621 + +#include +#include +#include "Rtypes.h" + +template +struct Wrapper +{ + bool present = true; + T obj; +}; + +struct MatchedCSCSegment +{ + float someValue = 0.0; + + MatchedCSCSegment(float in = 0.0) : someValue{in} {} + + // The simple update failed if the class version was not set. + // ClassDef(MatchedCSCSegment, 5); +}; + +struct CSCSegment +{ + float someValue; + + operator MatchedCSCSegment() + { + return MatchedCSCSegment{someValue}; + } + + std::vector theDuplicateSegments; + + // ClassDef(CSCSegment, 4); +}; + +static const char *dups_label = "dups "; +static const char *copy_label = "copy "; + +#ifdef __ROOTCLING__ +#pragma link C++ class MatchedCSCSegment+; +#pragma link C++ class CSCSegment+; +#pragma link C++ class Wrapper>+; +#pragma read sourceClass="CSCSegment" targetClass="CSCSegment" version="[1-11]" \ + checksum="[0x94f3cbee, 2499005422]" \ + source="std::vector theDuplicateSegments" target="theDuplicateSegments" \ + code = "{ std::cout << dups_label << onfile.theDuplicateSegments.size() << std::endl; \ + std::copy(onfile.theDuplicateSegments.begin(), onfile.theDuplicateSegments.end(), \ + std::back_inserter(theDuplicateSegments)); \ + std::cout << copy_label << theDuplicateSegments.size() << std::endl; }" +#endif + +#include "TFile.h" +#include "TTree.h" + +void test(TTree *t, const char *bname) +{ + std::string formula = bname; + formula += ".obj.theDuplicateSegments@.size()"; + t->Scan(formula.c_str()); +} + +int ROOT14491readdata() +{ + auto file = TFile::Open("oldfile14491.root", "READ"); + auto t = file->Get("t"); + t->LoadTree(0); + // gDebug = 7; + test(t, "seg_split"); + // gDebug = 0; + test(t, "seg_unsplit"); + file->Close(); + delete file; + return 0; +} diff --git a/roottest/root/io/evolution/versions/ROOT14491readdata.ref b/roottest/root/io/evolution/versions/ROOT14491readdata.ref new file mode 100644 index 0000000000000..7ed0fccc99e1a --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491readdata.ref @@ -0,0 +1,29 @@ + +Processing ROOT14491readdata.cxx+... +*********************************** +* Row * Instance * seg_split * +*********************************** +dups 0 +copy 0 +dups 1 +copy 1 +* 0 * 0 * 0 * +*********************************** +dups 0 +copy 0 +dups 1 +copy 1 +*********************************** +* Row * Instance * seg_unspl * +*********************************** +dups 0 +copy 0 +dups 1 +copy 2 +dups 0 +copy 0 +dups 1 +copy 3 +* 0 * 0 * 1 * +*********************************** +(int) 0 diff --git a/roottest/root/io/evolution/versions/ROOT14491simpleread.cxx b/roottest/root/io/evolution/versions/ROOT14491simpleread.cxx new file mode 100644 index 0000000000000..d8a03db1ecc09 --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491simpleread.cxx @@ -0,0 +1,67 @@ +// See https://github.com/root-project/root/issues/14491#issuecomment-1917587621 + +#include +#include +#include "Rtypes.h" + +template +struct Wrapper +{ + bool present = true; + T obj; +}; + +struct MatchedCSCSegment +{ + float someValue = 0.0; + + MatchedCSCSegment(float in = 0.0) : someValue{in} {} + + // The simple update failed if the class version was not set. + // ClassDef(MatchedCSCSegment, 5); +}; + +struct CSCSegment +{ + float someValue; + + operator MatchedCSCSegment() + { + return MatchedCSCSegment{someValue}; + } + + std::vector theDuplicateSegments; + + // ClassDef(CSCSegment, 4); +}; + +#ifdef __ROOTCLING__ +#pragma link C++ class MatchedCSCSegment+; +#pragma link C++ class CSCSegment+; +#pragma link C++ class Wrapper>+; +#pragma read sourceClass="CSCSegment" targetClass="MatchedCSCSegment" +#endif + +#include "TFile.h" +#include "TTree.h" + +void test(TTree *t, const char *bname) +{ + std::string formula = bname; + formula += ".obj.theDuplicateSegments@.size()"; + t->Scan(formula.c_str()); +} + +int ROOT14491simpleread() +{ + auto file = TFile::Open("oldfile14491.root", "READ"); + auto t = file->Get("t"); + t->LoadTree(0); + // gDebug = 7; + test(t, "seg_split"); + // gDebug = 0; + test(t, "seg_unsplit"); + file->Close(); + delete file; + return 0; +} diff --git a/roottest/root/io/evolution/versions/ROOT14491simpleread.ref b/roottest/root/io/evolution/versions/ROOT14491simpleread.ref new file mode 100644 index 0000000000000..0b494076a7443 --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491simpleread.ref @@ -0,0 +1,13 @@ + +Processing ROOT14491simpleread.cxx+... +*********************************** +* Row * Instance * seg_split * +*********************************** +* 0 * 0 * 0 * +*********************************** +*********************************** +* Row * Instance * seg_unspl * +*********************************** +* 0 * 0 * 1 * +*********************************** +(int) 0 diff --git a/roottest/root/io/evolution/versions/ROOT14491writedata.cxx b/roottest/root/io/evolution/versions/ROOT14491writedata.cxx new file mode 100644 index 0000000000000..a4174c6891ded --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491writedata.cxx @@ -0,0 +1,63 @@ +#include +#include +#include "Rtypes.h" + +template +struct Wrapper +{ + bool present = true; + T obj; +}; + +struct MatchedCSCSegment +{ + float someValue = 0.0; + + MatchedCSCSegment(float in = 0.0) : someValue{in} {} + + // The simple update failed if the class version is not set. + // ClassDef(MatchedCSCSegment, 5); +}; + +struct CSCSegment +{ + float someValue; + + operator MatchedCSCSegment() + { + return MatchedCSCSegment{someValue}; + } + + std::vector theDuplicateSegments; + // ClassDef(CSCSegment, 3); +}; + +#ifdef __ROOTCLING__ +#pragma link C++ class MatchedCSCSegment+; +#pragma link C++ class CSCSegment+; +#pragma link C++ class Wrapper>+; +#endif + +#include "TFile.h" +#include "TTree.h" + +int ROOT14491writedata(const char *filename = "oldfile14491.root") +{ + auto file = TFile::Open(filename, "RECREATE"); + auto t = new TTree("t", "t"); + Wrapper> w; + + CSCSegment c; + c.theDuplicateSegments.push_back(CSCSegment{}); + + w.obj.push_back(c); + + t->Branch("seg_split.", &w, 32000, 99); + t->Branch("seg_unsplit.", &w, 32000, 0); + + t->Fill(); + file->Write(); + // t->Print(); + delete file; + return 0; +} diff --git a/roottest/root/io/evolution/versions/ROOT14491writedata.ref b/roottest/root/io/evolution/versions/ROOT14491writedata.ref new file mode 100644 index 0000000000000..c60c91ea0fbf4 --- /dev/null +++ b/roottest/root/io/evolution/versions/ROOT14491writedata.ref @@ -0,0 +1,3 @@ + +Processing ROOT14491writedata.cxx+... +(int) 0