Skip to content

Commit 4aeb16a

Browse files
authored
Merge pull request #47408 from iarspider/fix-TestRunnerDataFormatsFWLite
Fix TestRunnerDataFormatsFWLite unit test
2 parents 03b8bd8 + b598349 commit 4aeb16a

File tree

6 files changed

+246
-261
lines changed

6 files changed

+246
-261
lines changed

DataFormats/FWLite/test/chainevent_looping_cint.C

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ using namespace std;
44

55
#if defined(__CINT__) && !defined(__MAKECINT__)
66
class loadFWLite {
7-
public:
8-
loadFWLite() {
9-
gSystem->Load("libFWCoreFWLite");
10-
FWLiteEnabler::enable();
11-
}
7+
public:
8+
loadFWLite() {
9+
gSystem->Load("libFWCoreFWLite");
10+
FWLiteEnabler::enable();
11+
}
1212
};
1313

1414
static loadFWLite lfw;
@@ -20,93 +20,93 @@ static loadFWLite lfw;
2020
#include "DataFormats/TestObjects/interface/ThingCollection.h"
2121
#endif
2222

23-
void chainevent_looping_cint()
24-
{
25-
vector<string> files;
26-
files.push_back("empty_a.root");
27-
files.push_back("good_a.root");
28-
files.push_back("empty_a.root");
29-
files.push_back("good_b.root");
30-
files.push_back("empty_a.root");
31-
fwlite::ChainEvent e(files);
23+
int chainevent_looping_cint() {
24+
vector<string> files;
25+
files.push_back("empty_a.root");
26+
files.push_back("good_a.root");
27+
files.push_back("empty_a.root");
28+
files.push_back("good_b.root");
29+
files.push_back("empty_a.root");
30+
fwlite::ChainEvent e(files);
31+
32+
int i = 0;
33+
int returnValue = 0;
34+
TFile* f = 0;
3235

33-
int i =0;
34-
int returnValue = 0;
35-
TFile* f = 0;
36+
for (; e.isValid(); ++e, ++i) {
37+
if (e.getTFile() != f) {
38+
f = e.getTFile();
39+
cout << "New file " << f->GetName() << endl;
40+
}
3641

37-
for( ;e.isValid();++e,++i) {
38-
if (e.getTFile() != f) {
39-
f = e.getTFile();
40-
cout << "New file " << f->GetName() << endl;
42+
fwlite::Handle<vector<edmtest::Thing> > pThing;
43+
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
44+
pThing.getByLabel(e, "Thing");
45+
46+
for (i = 0; i != pThing.ref().size(); ++i) {
47+
cout << pThing.ref().at(i).a << " ";
48+
}
49+
cout << endl;
4150
}
51+
if (i == 0) {
52+
cout << "First loop failed!" << endl;
53+
returnValue = 1;
54+
}
55+
e.toBegin();
4256

43-
fwlite::Handle<vector<edmtest::Thing> > pThing;
44-
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
45-
pThing.getByLabel(e,"Thing");
46-
47-
for(i=0; i!=pThing.ref().size();++i) {
48-
cout <<pThing.ref().at(i).a<<" ";
57+
i = 0;
58+
for (; e; ++e, ++i) {
4959
}
50-
cout << endl;
51-
}
52-
if (i==0) {
53-
cout <<"First loop failed!"<<endl;
54-
returnValue = 1;
55-
}
56-
e.toBegin();
5760

58-
i=0;
59-
for( ;e;++e,++i) {
60-
}
61+
if (i == 0) {
62+
cout << "Second loop failed!" << endl;
63+
returnValue = 1;
64+
}
6165

62-
if (i==0) {
63-
cout <<"Second loop failed!"<<endl;
64-
returnValue = 1;
65-
}
66+
i = 0;
67+
for (e.toBegin(); !e.atEnd(); ++e, ++i) {
68+
fwlite::Handle<vector<edmtest::Thing> > pThing;
69+
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
70+
pThing.getByLabel(e, "Thing");
6671

67-
i=0;
68-
for(e.toBegin(); !e.atEnd();++e,++i) {
69-
fwlite::Handle<vector<edmtest::Thing> > pThing;
70-
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
71-
pThing.getByLabel(e,"Thing");
72-
73-
for(i=0; i!=pThing.ref().size();++i) {
74-
cout <<pThing.ref().at(i).a<<" ";
75-
}
76-
cout << endl;
77-
//DOES NOT WORK in CINT
78-
//for(vector<edmtest::Thing>::const_iterator it = pThing.data()->begin(); it != pThing.data()->end();++it) {
79-
// cout <<(*it).a<<endl;
80-
//}
81-
}
82-
if (i==0) {
83-
cout <<"Third loop failed!"<<endl;
84-
returnValue = 1;
85-
}
86-
e.to(0);
87-
for (int j = 0; j<20; ++j) {
88-
int k = rand() % 10;
89-
if(e.to(k)) {
90-
edm::EventID id = e.id();
91-
cout << "Entry " << k << " Run " << id.run() << " event " << id.event() << endl;
92-
} else {
93-
cout <<"Entry "<<k<<" is not valid"<<endl;
72+
for (i = 0; i != pThing.ref().size(); ++i) {
73+
cout << pThing.ref().at(i).a << " ";
74+
}
75+
cout << endl;
76+
//DOES NOT WORK in CINT
77+
//for(vector<edmtest::Thing>::const_iterator it = pThing.data()->begin(); it != pThing.data()->end();++it) {
78+
// cout <<(*it).a<<endl;
79+
//}
80+
}
81+
if (i == 0) {
82+
cout << "Third loop failed!" << endl;
83+
returnValue = 1;
84+
}
85+
e.to(0);
86+
for (int j = 0; j < 20; ++j) {
87+
int k = rand() % 10;
88+
if (e.to(k)) {
89+
edm::EventID id = e.id();
90+
cout << "Entry " << k << " Run " << id.run() << " event " << id.event() << endl;
91+
} else {
92+
cout << "Entry " << k << " is not valid" << endl;
93+
}
9494
}
95-
}
9695

9796
e.to(0);
9897
long size = e.size();
9998
edm::EventID last;
100-
for (long l = 0; l<size; ++l) {
99+
for (long l = 0; l < size; ++l) {
101100
e.to(l);
102101
edm::EventID id = e.id();
103102
cout << "Entry " << l << " Run " << id.run() << " event " << id.event() << endl;
104-
if(last == id) {
103+
if (last == id) {
105104
returnValue = 1;
106-
cout <<"duplicate event ("<<id.run()<<","<<id.event()<<") seen at index "<<l<<" while testing 'to'"<<endl;
105+
cout << "duplicate event (" << id.run() << "," << id.event() << ") seen at index " << l << " while testing 'to'"
106+
<< endl;
107107
break;
108108
}
109109
}
110110

111-
exit(returnValue);
111+
return returnValue;
112112
}

DataFormats/FWLite/test/event_looping_cint.C

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ using namespace std;
44

55
#if defined(__CINT__) && !defined(__MAKECINT__)
66
class loadFWLite {
7-
public:
8-
loadFWLite() {
9-
gSystem->Load("libFWCoreFWLite");
10-
FWLiteEnabler::enable();
11-
}
7+
public:
8+
loadFWLite() {
9+
gSystem->Load("libFWCoreFWLite");
10+
FWLiteEnabler::enable();
11+
}
1212
};
1313

1414
static loadFWLite lfw;
@@ -20,57 +20,56 @@ static loadFWLite lfw;
2020
#include "DataFormats/TestObjects/interface/ThingCollection.h"
2121
#endif
2222

23-
void event_looping_cint()
24-
{
25-
TFile f("good_a.root");
26-
fwlite::Event e(&f);
23+
int event_looping_cint() {
24+
TFile f("good_a.root");
25+
fwlite::Event e(&f);
26+
27+
int i = 0;
28+
int returnValue = 0;
29+
for (; e.isValid(); ++e, ++i) {
30+
fwlite::Handle<vector<edmtest::Thing> > pThing;
31+
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
32+
pThing.getByLabel(e, "Thing");
2733

28-
int i =0;
29-
int returnValue = 0;
30-
for( ;e.isValid();++e,++i) {
31-
fwlite::Handle<vector<edmtest::Thing> > pThing;
32-
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
33-
pThing.getByLabel(e,"Thing");
34-
35-
for(int i=0; i!=pThing.ref().size();++i) {
36-
cout <<pThing.ref().at(i).a<< " ";
34+
for (int i = 0; i != pThing.ref().size(); ++i) {
35+
cout << pThing.ref().at(i).a << " ";
36+
}
37+
cout << endl;
3738
}
38-
cout << endl;
39-
}
40-
if (i==0) {
41-
cout <<"First loop failed!"<<endl;
42-
returnValue = 1;
43-
}
44-
e.toBegin();
39+
if (i == 0) {
40+
cout << "First loop failed!" << endl;
41+
returnValue = 1;
42+
}
43+
e.toBegin();
4544

46-
i=0;
47-
for( ;e;++e,++i) {
48-
}
45+
i = 0;
46+
for (; e; ++e, ++i) {
47+
}
4948

50-
if (i==0) {
51-
cout <<"Second loop failed!"<<endl;
52-
returnValue = 1;
53-
}
49+
if (i == 0) {
50+
cout << "Second loop failed!" << endl;
51+
returnValue = 1;
52+
}
5453

55-
i=0;
56-
for(e.toBegin(); !e.atEnd();++e,++i) {
57-
fwlite::Handle<vector<edmtest::Thing> > pThing;
58-
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
59-
pThing.getByLabel(e,"Thing");
60-
61-
for(int i=0; i!=pThing.ref().size();++i) {
62-
cout <<pThing.ref().at(i).a<<" ";
63-
}
64-
cout << endl;
54+
i = 0;
55+
for (e.toBegin(); !e.atEnd(); ++e, ++i) {
56+
fwlite::Handle<vector<edmtest::Thing> > pThing;
57+
//pThing.getByLabel(e,"Thing","","TEST"); //WORKS
58+
pThing.getByLabel(e, "Thing");
6559

66-
//DOES NOT WORK
67-
//for(vector<edmtest::Thing>::const_iterator it = pThing.data()->begin(); it != pThing.data()->end();++it) {
68-
// cout <<(*it).a<<endl;
69-
//}
70-
}
71-
if (i==0) {
72-
cout <<"Third loop failed!"<<endl;
73-
returnValue = 1;
74-
}
75-
exit(returnValue);
60+
for (int i = 0; i != pThing.ref().size(); ++i) {
61+
cout << pThing.ref().at(i).a << " ";
62+
}
63+
cout << endl;
64+
65+
//DOES NOT WORK
66+
//for(vector<edmtest::Thing>::const_iterator it = pThing.data()->begin(); it != pThing.data()->end();++it) {
67+
// cout <<(*it).a<<endl;
68+
//}
69+
}
70+
if (i == 0) {
71+
cout << "Third loop failed!" << endl;
72+
returnValue = 1;
73+
}
74+
return returnValue;
7675
}

DataFormats/FWLite/test/event_looping_consumes_cint.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static loadFWLite lfw;
2222
#include "DataFormats/TestObjects/interface/ThingCollection.h"
2323
#endif
2424

25-
void event_looping_consumes_cint() {
25+
int event_looping_consumes_cint() {
2626
TFile f("good_a.root");
2727
fwlite::Event e(&f);
2828

@@ -43,5 +43,5 @@ void event_looping_consumes_cint() {
4343
cout << "First loop failed!" << endl;
4444
returnValue = 1;
4545
}
46-
exit(returnValue);
46+
return returnValue;
4747
}

0 commit comments

Comments
 (0)