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