HepMC3 event record library
test
testMultipleCopies.cc
1
//////////////////////////////////////////////////////////////////////////
2
// testMultipleCopies.cc.in
3
//
4
// garren@fnal.gov, January 2008
5
// Multiple events in memory at the same time
6
// run with valgrind or some other leak checker
7
//////////////////////////////////////////////////////////////////////////
8
//
9
10
#include <fstream>
11
#include "
HepMC3/GenEvent.h
"
12
#include "
HepMC3/GenCrossSection.h
"
13
#include "
HepMC3/GenParticle.h
"
14
#include "
HepMC3/WriterAscii.h
"
15
#include "
HepMC3/ReaderAscii.h
"
16
#include "
HepMC3/ReaderAsciiHepMC2.h
"
17
#include "
HepMC3/Print.h
"
18
#include "HepMC3TestUtils.h"
19
using namespace
HepMC3
;
20
int
main
()
21
{
22
// use output file
23
std::ofstream os(
"testMultipleCopies.out"
);
24
{
25
// declare an input strategy
26
ReaderAsciiHepMC2
ascii_in(
"inputMultipleCopies1.hepmc"
);
27
if
(ascii_in.failed())
return
1;
28
// declare another input strategy
29
ReaderAsciiHepMC2
ascii_in2(
"inputMultipleCopies2.hepmc"
);
30
if
(ascii_in2.failed())
return
2;
31
std::ofstream os1(
"testMultipleOriginals.out"
);
32
std::ofstream os2(
"testMultipleCopies1.out"
) ;
33
std::ofstream os3(
"testMultipleCopies2.out"
) ;
34
WriterAscii
out1(os1);
35
WriterAscii
out2(os2);
36
WriterAscii
out3(os3);
37
// declare an instance of the event selection predicate
38
// IsGoodEvent is_good_event;
39
40
//........................................EVENT LOOP
41
int
icount=0;
42
int
num_good_events=0;
43
int
icnt;
44
GenEvent
evt1;
45
ascii_in.read_event(evt1);
46
if
(ascii_in.failed())
return
3;
47
GenEvent
evt2;
48
ascii_in2.read_event(evt2);
49
if
(ascii_in2.failed())
return
4;
50
GenEvent
evt3;
51
ascii_in.read_event(evt3);
52
if
(ascii_in.failed())
return
5;
53
while
( !ascii_in.failed() && !ascii_in2.failed() )
54
{
55
icount++;
56
//if ( icount%50==1 )
57
os <<
"Processing Event Number "
<< icount
58
<<
" stream 1 # "
<< evt1.
event_number
()
59
<<
" stream 2 # "
<< evt2.
event_number
()
60
<< std::endl;
61
62
//AV if ( is_good_event(&evt1) )
63
{
64
65
os <<
"good event in stream 1 # "
66
<< evt1.
event_number
() << std::endl;
67
out1.write_event(evt1);
68
++num_good_events;
69
GenEvent
ec = evt1;
70
out3.write_event(ec);
71
icnt=0;
72
for
(
auto
p1: ec.
particles
())
73
{
74
++icnt;
75
os <<
"particle "
<< icnt <<
" barcode "
<< std::endl;
76
}
77
GenEvent
evt4(evt1);
78
out2.write_event(evt4);
79
//AV if( !compareGenEvent(&evt1,&evt4) ) { return -1; }
80
evt4.clear();
81
}
82
// clean up and get next events
83
evt1.
clear
();
84
evt2.
clear
();
85
ascii_in.read_event(evt1);
86
ascii_in2.read_event(evt2);
87
}
88
// might have either evt1 or evt2 still in memory, cleanup here
89
evt1.
clear
();
90
evt2.
clear
();
91
evt3.
clear
();
92
93
//........................................PRINT RESULT
94
os << std::endl;
95
os << num_good_events <<
" out of "
<< icount
96
<<
" processed events passed the cuts."
<< std::endl;
97
os << std::endl;
98
os <<
" GenEvent copy constructor passes the test"
<< std::endl;
99
os << std::endl;
100
ascii_in.close();
101
ascii_in2.close();
102
}
103
104
// test operator= and swap
105
{
106
// declare an input strategy
107
ReaderAsciiHepMC2
ascii_in(
"inputMultipleCopies1.hepmc"
);
108
if
(ascii_in.failed())
return
4;
109
//
110
GenEvent
evt5;
111
ascii_in.read_event(evt5);
112
GenEvent
evt6;
113
os <<
"event number for evt5: "
<< evt5.
event_number
() << std::endl;
114
os <<
"event number for evt6: "
<< evt6.
event_number
() << std::endl;
115
// copy GenEvent object
116
evt6 = evt5;
117
//AV if( !compareGenEvent(&evt5,&evt6) ) { return -4; }
118
evt5.
clear
();
119
os <<
"event number for evt6 after copy: "
<< evt6.
event_number
() << std::endl;
120
os << std::endl;
121
evt6.
clear
();
122
os <<
" GenEvent operator= passes the test"
<< std::endl;
123
os << std::endl;
124
125
ascii_in.read_event(evt5);
126
if
(ascii_in.failed())
return
5;
127
ascii_in.read_event(evt6);
128
if
(ascii_in.failed())
return
6;
129
GenEvent
evt7(evt5);
130
GenEvent
evt8(evt6);
131
os <<
"event number for evt5: "
<< evt5.
event_number
() << std::endl;
132
os <<
"event number for evt6: "
<< evt6.
event_number
() << std::endl;
133
os <<
"before swap, evt5 has: "
<< evt5.
vertices
().size() <<
" vertices and "
134
<< evt5.
particles
().size() <<
" particles"
<< std::endl;
135
os <<
"before swap, evt6 has: "
<< evt6.
vertices
().size() <<
" vertices and "
136
<< evt6.
particles
().size() <<
" particles"
<< std::endl;
137
os <<
"before swap, evt7 has: "
<< evt7.vertices().size() <<
" vertices and "
138
<< evt7.particles().size() <<
" particles"
<< std::endl;
139
os <<
"before swap, evt8 has: "
<< evt8.vertices().size() <<
" vertices and "
140
<< evt8.particles().size() <<
" particles"
<< std::endl;
141
std::swap(evt6,evt5);
142
os <<
"event number for evt5 after swap: "
<< evt5.
event_number
() << std::endl;
143
os <<
"event number for evt6 after swap: "
<< evt6.
event_number
() << std::endl;
144
// evt6 should now match evt7
145
os <<
"after swap, evt6 has: "
<< evt6.
vertices
().size() <<
" vertices and "
146
<< evt6.
particles
().size() <<
" particles"
<< std::endl;
147
os <<
"after swap, evt7 has: "
<< evt7.vertices().size() <<
" vertices and "
148
<< evt7.particles().size() <<
" particles"
<< std::endl;
149
//AV if( !compareGenEvent(&evt6,&evt7) ) { return -6; }
150
// evt5 should now match evt8
151
os <<
"after swap, evt5 has: "
<< evt5.
vertices
().size() <<
" vertices and "
152
<< evt5.
particles
().size() <<
" particles"
<< std::endl;
153
os <<
"after swap, evt8 has: "
<< evt8.vertices().size() <<
" vertices and "
154
<< evt8.particles().size() <<
" particles"
<< std::endl;
155
//AV if( !compareGenEvent(&evt5,&evt8) ) { return -5; }
156
os << std::endl;
157
os <<
" GenEvent swap passes the test"
<< std::endl;
158
os << std::endl;
159
evt5.
clear
();
160
evt6.
clear
();
161
evt7.clear();
162
evt8.clear();
163
}
164
bool
passed=(
165
(COMPARE_ASCII_FILES(
"testMultipleCopies1.out"
,
"testMultipleCopies2.out"
)==0)
166
&&
167
(COMPARE_ASCII_FILES(
"testMultipleCopies1.out"
,
"testMultipleOriginals.out"
)==0)
168
);
169
if
(!passed)
return
1;
170
return
0;
171
}
GenEvent.h
Definition of class GenEvent.
HepMC3::GenEvent::event_number
int event_number() const
Get event number.
Definition:
GenEvent.h:135
HepMC3::WriterAscii
GenEvent I/O serialization for structured text files.
Definition:
WriterAscii.h:25
HepMC3::GenEvent
Stores event-related information.
Definition:
GenEvent.h:41
HepMC3
HepMC3 main namespace.
Definition:
AnalysisExample.h:18
HepMC3::GenEvent::clear
void clear()
Remove contents of this event.
Definition:
GenEvent.cc:609
HepMC3::GenEvent::vertices
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
Definition:
GenEvent.cc:44
GenParticle.h
Definition of class GenParticle.
ReaderAsciiHepMC2.h
Definition of class ReaderAsciiHepMC2.
WriterAscii.h
Definition of class WriterAscii.
Print.h
Definition of static class Print.
HepMC3::ReaderAsciiHepMC2
Parser for HepMC2 I/O files.
Definition:
ReaderAsciiHepMC2.h:30
ReaderAscii.h
Definition of class ReaderAscii.
HepMC3::GenEvent::particles
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition:
GenEvent.cc:40
main
int main(int argc, char **argv)
Definition:
rootIOTree_example_read.cc:23
GenCrossSection.h
Definition of attribute class GenCrossSection.
Generated on Thu Nov 28 2019 00:00:00 for HepMC3 event record library by
1.8.16