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() ) {
22  printf("End of file reached. Exit.\n");
23  break;
24  }
25  evts.push_back(evt);
26  }
27  inputA.close();
28  int i=0;
29  int j=0;
30  while(i==j)
31  {
32  i=rand()% evts.size();
33  j=rand()% evts.size();
34  }
35 
36  std::vector<GenVertexPtr> selectedVtx;
37  for (std::vector<GenParticlePtr>::const_iterator p=evts.at(i)->particles().begin(); p!=evts.at(i)->particles().end(); ++p)
38  for (std::vector<GenVertexPtr>::iterator v=evts.at(j)->vertices().begin(); v!=evts.at(j)->vertices().end(); ++v)
39  {
40  selectedVtx.push_back(*v);
41  }
42 
43  WriterAscii outputA("frominputDelete2.hepmc");
44  if(outputA.failed()) return 2;
45  for (size_t i=0; i<evts.size(); i++) outputA.write_event(*evts[i]);
46  evts.clear();
47  outputA.close();
48  for (std::vector<GenVertexPtr>::const_iterator v=selectedVtx.begin(); v!=selectedVtx.end(); ++v)
49  {
50  Print::line(*v);
51  }
52  if (selectedVtx.front()->parent_event())
53  Print::listing(*(selectedVtx.front()->parent_event()));
54  ReaderAscii inputB("frominputDelete2.hepmc");
55  if(inputB.failed()) return 3;
56  WriterAsciiHepMC2 outputB("fromfrominputDelete2.hepmc");
57  if(outputB.failed()) return 4;
58  while( !inputB.failed() )
59  {
60  GenEvent evt(Units::GEV,Units::MM);
61  inputB.read_event(evt);
62  if( inputB.failed() ) {
63  printf("End of file reached. Exit.\n");
64  break;
65  }
66  outputB.write_event(evt);
67  evt.clear();
68  }
69  inputB.close();
70  outputB.close();
71  return COMPARE_ASCII_FILES("fromfrominputDelete2.hepmc","inputDelete.hepmc");
72 }
GenEvent I/O serialization for structured text files.
GenEvent I/O parsing for structured text files.
Definition: ReaderAscii.h:27
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