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() ) {printf("End of file reached. Exit.\n"); break;}
21  evts.push_back(evt);
22  }
23  inputA.close();
24 //No alien particles should be detached from vertices or removed from events
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  evts[i].remove_particles(evts[j].particles());
33 
34  for (GenParticlePtr p: evts.at(i).particles())
35  evts[j].remove_particle(p);
36 
37  for (GenParticlePtr p: evts.at(i).particles()){
38  for (GenVertexPtr v: evts.at(j).vertices()){
39  (v)->remove_particle_in(p);
40  (v)->remove_particle_out(p);
41  }
42  }
43 
44  WriterAscii outputA("frominputDelete.hepmc");
45  if(outputA.failed()) return 2;
46  for (size_t i=0;i<evts.size();i++) outputA.write_event(evts[i]);
47  evts.clear();
48  outputA.close();
49 
50 
51  ReaderAscii inputB("frominputDelete.hepmc");
52  if(inputB.failed()) return 3;
53  WriterAsciiHepMC2 outputB("fromfrominputDelete.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("fromfrominputDelete.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.
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:411
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25