HepMC3 event record library
test
testDelete2.cc
1
// -*- C++ -*-
2
//
3
// This file is part of HepMC
4
// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5
//
6
#include "
HepMC3/Print.h
"
7
#include "
HepMC3/GenEvent.h
"
8
#include "
HepMC3/GenParticle.h
"
9
#include "
HepMC3/GenVertex.h
"
10
#include "
HepMC3/ReaderAscii.h
"
11
#include "
HepMC3/WriterAscii.h
"
12
#include "
HepMC3/ReaderAsciiHepMC2.h
"
13
#include "
HepMC3/WriterAsciiHepMC2.h
"
14
#include "HepMC3TestUtils.h"
15
using namespace
HepMC3
;
16
int
main
()
17
{
18
ReaderAsciiHepMC2
inputA(
"inputDelete2.hepmc"
);
19
if
(inputA.failed())
return
1;
20
std::vector<std::shared_ptr<GenEvent> > evts;
21
while
( !inputA.failed() )
22
{
23
std::shared_ptr<GenEvent> evt= std::make_shared<GenEvent>();
24
inputA.read_event(*evt);
25
if
( inputA.failed() ) {
26
printf(
"End of file reached. Exit.\n"
);
27
break
;
28
}
29
evts.push_back(evt);
30
}
31
inputA.close();
32
int
i=0;
33
int
j=0;
34
while
(i==j)
35
{
36
i=rand()% evts.size();
37
j=rand()% evts.size();
38
}
39
40
std::vector<GenVertexPtr> selectedVtx;
41
for
(std::vector<GenParticlePtr>::const_iterator p=evts.at(i)->particles().begin(); p!=evts.at(i)->particles().end(); ++p)
42
for
(std::vector<GenVertexPtr>::iterator v=evts.at(j)->vertices().begin(); v!=evts.at(j)->vertices().end(); ++v)
43
{
44
selectedVtx.push_back(*v);
45
}
46
47
WriterAscii
outputA(
"frominputDelete2.hepmc"
);
48
if
(outputA.failed())
return
2;
49
for
(
size_t
i=0; i<evts.size(); i++) outputA.write_event(*evts[i]);
50
evts.clear();
51
outputA.close();
52
for
(std::vector<GenVertexPtr>::const_iterator v=selectedVtx.begin(); v!=selectedVtx.end(); ++v)
53
{
54
Print::line
(*v);
55
}
56
if
(selectedVtx.front()->parent_event())
57
Print::listing
(*(selectedVtx.front()->parent_event()));
58
ReaderAscii
inputB(
"frominputDelete2.hepmc"
);
59
if
(inputB.failed())
return
3;
60
WriterAsciiHepMC2
outputB(
"fromfrominputDelete2.hepmc"
);
61
if
(outputB.failed())
return
4;
62
while
( !inputB.failed() )
63
{
64
GenEvent
evt(Units::GEV,Units::MM);
65
inputB.read_event(evt);
66
if
( inputB.failed() ) {
67
printf(
"End of file reached. Exit.\n"
);
68
break
;
69
}
70
outputB.write_event(evt);
71
evt.clear();
72
}
73
inputB.close();
74
outputB.close();
75
return
COMPARE_ASCII_FILES(
"fromfrominputDelete2.hepmc"
,
"inputDelete2.hepmc"
);
76
}
GenEvent.h
Definition of class GenEvent.
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::WriterAsciiHepMC2
GenEvent I/O serialization for structured text files.
Definition:
WriterAsciiHepMC2.h:27
GenVertex.h
Definition of class GenVertex.
HepMC3
HepMC3 main namespace.
Definition:
AnalysisExample.h:19
GenParticle.h
Definition of class GenParticle.
HepMC3::ReaderAscii
GenEvent I/O parsing for structured text files.
Definition:
ReaderAscii.h:29
HepMC3::Print::listing
static void listing(std::ostream &os, const GenEvent &event, unsigned short precision=2)
Print event in listing (HepMC2) format.
Definition:
Print.cc:50
ReaderAsciiHepMC2.h
Definition of class ReaderAsciiHepMC2.
WriterAscii.h
Definition of class WriterAscii.
Print.h
Definition of static class Print.
WriterAsciiHepMC2.h
Definition of class WriterAsciiHepMC2.
HepMC3::ReaderAsciiHepMC2
Parser for HepMC2 I/O files.
Definition:
ReaderAsciiHepMC2.h:30
ReaderAscii.h
Definition of class ReaderAscii.
main
int main(int argc, char **argv)
Definition:
rootIOTree_example_read.cc:23
HepMC3::Print::line
static void line(std::ostream &os, const GenEvent &event, bool attributes=false)
Print one-line info.
Definition:
Print.cc:202
Generated on Mon Jul 27 2020 00:00:00 for HepMC3 event record library by
1.8.18