Skip to content

Commit 5f53f97

Browse files
committed
[test][io] Add test for renaming rule without classdef
Test for #14491 Original reproducer: #14491 (comment)
1 parent c3f7019 commit 5f53f97

File tree

7 files changed

+269
-0
lines changed

7 files changed

+269
-0
lines changed

roottest/root/io/evolution/versions/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ ROOTTEST_ADD_TEST(ROOT7500
8989
OUTREF execROOT7500.ref
9090
LABELS longtest io)
9191

92+
ROOTTEST_ADD_TEST(ROOT14491writedata
93+
MACRO ROOT14491writedata.cxx+
94+
FIXTURES_SETUP root-io-evolution-versions-ROOT14491writedata
95+
OUTREF ROOT14491writedata.ref
96+
LABELS io)
97+
98+
ROOTTEST_ADD_TEST(ROOT14491readdata
99+
MACRO ROOT14491readdata.cxx+
100+
OUTREF ROOT14491readdata.ref
101+
FIXTURES_REQUIRED root-io-evolution-versions-ROOT14491writedata
102+
LABELS io)
103+
104+
ROOTTEST_ADD_TEST(ROOT14491simpleread
105+
MACRO ROOT14491simpleread.cxx+
106+
OUTREF ROOT14491simpleread.ref
107+
FIXTURES_REQUIRED root-io-evolution-versions-ROOT14491writedata
108+
LABELS io)
109+
92110
ROOTTEST_ADD_TEST(attmarker
93111
COMMAND ${ROOT_hadd_CMD} -f result.root hsimple14.root hsimple20.root
94112
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// See https://github.com/root-project/root/issues/14491#issuecomment-1917587621
2+
3+
#include <vector>
4+
#include <iostream>
5+
#include "Rtypes.h"
6+
7+
template <typename T>
8+
struct Wrapper
9+
{
10+
bool present = true;
11+
T obj;
12+
};
13+
14+
struct MatchedCSCSegment
15+
{
16+
float someValue = 0.0;
17+
18+
MatchedCSCSegment(float in = 0.0) : someValue{in} {}
19+
20+
// The simple update failed if the class version was not set.
21+
// ClassDef(MatchedCSCSegment, 5);
22+
};
23+
24+
struct CSCSegment
25+
{
26+
float someValue;
27+
28+
operator MatchedCSCSegment()
29+
{
30+
return MatchedCSCSegment{someValue};
31+
}
32+
33+
std::vector<MatchedCSCSegment> theDuplicateSegments;
34+
35+
// ClassDef(CSCSegment, 4);
36+
};
37+
38+
static const char *dups_label = "dups ";
39+
static const char *copy_label = "copy ";
40+
41+
#ifdef __ROOTCLING__
42+
#pragma link C++ class MatchedCSCSegment+;
43+
#pragma link C++ class CSCSegment+;
44+
#pragma link C++ class Wrapper<std::vector<CSCSegment>>+;
45+
#pragma read sourceClass="CSCSegment" targetClass="CSCSegment" version="[1-11]" \
46+
checksum="[0x94f3cbee, 2499005422]" \
47+
source="std::vector<CSCSegment> theDuplicateSegments" target="theDuplicateSegments" \
48+
code = "{ std::cout << dups_label << onfile.theDuplicateSegments.size() << std::endl; \
49+
std::copy(onfile.theDuplicateSegments.begin(), onfile.theDuplicateSegments.end(), \
50+
std::back_inserter(theDuplicateSegments)); \
51+
std::cout << copy_label << theDuplicateSegments.size() << std::endl; }"
52+
#endif
53+
54+
#include "TFile.h"
55+
#include "TTree.h"
56+
57+
void test(TTree *t, const char *bname)
58+
{
59+
std::string formula = bname;
60+
formula += "[email protected]()";
61+
t->Scan(formula.c_str());
62+
}
63+
64+
int ROOT14491readdata()
65+
{
66+
auto file = TFile::Open("oldfile14491.root", "READ");
67+
auto t = file->Get<TTree>("t");
68+
t->LoadTree(0);
69+
// gDebug = 7;
70+
test(t, "seg_split");
71+
// gDebug = 0;
72+
test(t, "seg_unsplit");
73+
file->Close();
74+
delete file;
75+
return 0;
76+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
Processing ROOT14491readdata.cxx+...
3+
***********************************
4+
* Row * Instance * seg_split *
5+
***********************************
6+
dups 0
7+
copy 0
8+
dups 1
9+
copy 1
10+
* 0 * 0 * 0 *
11+
***********************************
12+
dups 0
13+
copy 0
14+
dups 1
15+
copy 1
16+
***********************************
17+
* Row * Instance * seg_unspl *
18+
***********************************
19+
dups 0
20+
copy 0
21+
dups 1
22+
copy 2
23+
dups 0
24+
copy 0
25+
dups 1
26+
copy 3
27+
* 0 * 0 * 1 *
28+
***********************************
29+
(int) 0
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// See https://github.com/root-project/root/issues/14491#issuecomment-1917587621
2+
3+
#include <vector>
4+
#include <iostream>
5+
#include "Rtypes.h"
6+
7+
template <typename T>
8+
struct Wrapper
9+
{
10+
bool present = true;
11+
T obj;
12+
};
13+
14+
struct MatchedCSCSegment
15+
{
16+
float someValue = 0.0;
17+
18+
MatchedCSCSegment(float in = 0.0) : someValue{in} {}
19+
20+
// The simple update failed if the class version was not set.
21+
// ClassDef(MatchedCSCSegment, 5);
22+
};
23+
24+
struct CSCSegment
25+
{
26+
float someValue;
27+
28+
operator MatchedCSCSegment()
29+
{
30+
return MatchedCSCSegment{someValue};
31+
}
32+
33+
std::vector<MatchedCSCSegment> theDuplicateSegments;
34+
35+
// ClassDef(CSCSegment, 4);
36+
};
37+
38+
#ifdef __ROOTCLING__
39+
#pragma link C++ class MatchedCSCSegment+;
40+
#pragma link C++ class CSCSegment+;
41+
#pragma link C++ class Wrapper<std::vector<CSCSegment>>+;
42+
#pragma read sourceClass="CSCSegment" targetClass="MatchedCSCSegment"
43+
#endif
44+
45+
#include "TFile.h"
46+
#include "TTree.h"
47+
48+
void test(TTree *t, const char *bname)
49+
{
50+
std::string formula = bname;
51+
formula += "[email protected]()";
52+
t->Scan(formula.c_str());
53+
}
54+
55+
int ROOT14491simpleread()
56+
{
57+
auto file = TFile::Open("oldfile14491.root", "READ");
58+
auto t = file->Get<TTree>("t");
59+
t->LoadTree(0);
60+
// gDebug = 7;
61+
test(t, "seg_split");
62+
// gDebug = 0;
63+
test(t, "seg_unsplit");
64+
file->Close();
65+
delete file;
66+
return 0;
67+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Processing ROOT14491simpleread.cxx+...
3+
***********************************
4+
* Row * Instance * seg_split *
5+
***********************************
6+
* 0 * 0 * 0 *
7+
***********************************
8+
***********************************
9+
* Row * Instance * seg_unspl *
10+
***********************************
11+
* 0 * 0 * 1 *
12+
***********************************
13+
(int) 0
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <vector>
2+
#include <iostream>
3+
#include "Rtypes.h"
4+
5+
template <typename T>
6+
struct Wrapper
7+
{
8+
bool present = true;
9+
T obj;
10+
};
11+
12+
struct MatchedCSCSegment
13+
{
14+
float someValue = 0.0;
15+
16+
MatchedCSCSegment(float in = 0.0) : someValue{in} {}
17+
18+
// The simple update failed if the class version is not set.
19+
// ClassDef(MatchedCSCSegment, 5);
20+
};
21+
22+
struct CSCSegment
23+
{
24+
float someValue;
25+
26+
operator MatchedCSCSegment()
27+
{
28+
return MatchedCSCSegment{someValue};
29+
}
30+
31+
std::vector<CSCSegment> theDuplicateSegments;
32+
// ClassDef(CSCSegment, 3);
33+
};
34+
35+
#ifdef __ROOTCLING__
36+
#pragma link C++ class MatchedCSCSegment+;
37+
#pragma link C++ class CSCSegment+;
38+
#pragma link C++ class Wrapper<std::vector<CSCSegment>>+;
39+
#endif
40+
41+
#include "TFile.h"
42+
#include "TTree.h"
43+
44+
int ROOT14491writedata(const char *filename = "oldfile14491.root")
45+
{
46+
auto file = TFile::Open(filename, "RECREATE");
47+
auto t = new TTree("t", "t");
48+
Wrapper<std::vector<CSCSegment>> w;
49+
50+
CSCSegment c;
51+
c.theDuplicateSegments.push_back(CSCSegment{});
52+
53+
w.obj.push_back(c);
54+
55+
t->Branch("seg_split.", &w, 32000, 99);
56+
t->Branch("seg_unsplit.", &w, 32000, 0);
57+
58+
t->Fill();
59+
file->Write();
60+
// t->Print();
61+
delete file;
62+
return 0;
63+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
Processing ROOT14491writedata.cxx+...
3+
(int) 0

0 commit comments

Comments
 (0)