HepMC3 event record library
testDelete.cc
1 // -*- C++ -*-
2 #include "HepMC3/GenEvent.h"
3 #include "HepMC3/GenParticle.h"
4 #include "HepMC3/GenVertex.h"
5 #include "HepMC3/ReaderAscii.h"
6 #include "HepMC3/WriterAscii.h"
9 #include "HepMC3TestUtils.h"
10 using namespace HepMC3;
11 int main()
12 {
13  ReaderAsciiHepMC2 inputA("inputDelete.hepmc");
14  if(inputA.failed()) return 1;
15  std::vector<GenEvent> evts;
16  while( !inputA.failed() )
17  {
18  GenEvent evt=GenEvent(Units::GEV,Units::MM);
19  inputA.read_event(evt);
20  if( inputA.failed() ) {
21  printf("End of file reached. Exit.\n");
22  break;
23  }
24  evts.push_back(evt);
25  }
26  inputA.close();
27 //No alien particles should be detached from vertices or removed from events
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  evts[i].remove_particles(evts[j].particles());
36 
37  for (GenParticlePtr p: evts.at(i).particles())
38  evts[j].remove_particle(p);
39 
40  for (GenParticlePtr p: evts.at(i).particles()) {
41  for (GenVertexPtr v: evts.at(j).vertices()) {
42  (v)->remove_particle_in(p);
43  (v)->remove_particle_out(p);
44  }
45  }
46 
47  WriterAscii outputA("frominputDelete.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 
53 
54  ReaderAscii inputB("frominputDelete.hepmc");
55  if(inputB.failed()) return 3;
56  WriterAsciiHepMC2 outputB("fromfrominputDelete.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("fromfrominputDelete.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.
Parser for HepMC2 I/O files.
Definition of class ReaderAsciiHepMC2.
Stores event-related information.
Definition: GenEvent.h:42
Definition of class ReaderAscii.
Definition of class WriterAsciiHepMC2.
int main(int argc, char **argv)
Definition of class GenEvent.
void clear()
Remove contents of this event.
Definition: GenEvent.cc:438
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25