HepMC3 event record library
testDelete.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/GenEvent.h"
7 #include "HepMC3/GenParticle.h"
8 #include "HepMC3/GenVertex.h"
9 #include "HepMC3/ReaderAscii.h"
10 #include "HepMC3/WriterAscii.h"
13 #include "HepMC3TestUtils.h"
14 using namespace HepMC3;
15 int main()
16 {
17  ReaderAsciiHepMC2 inputA("inputDelete.hepmc");
18  if(inputA.failed()) return 1;
19  std::vector<GenEvent> evts;
20  while( !inputA.failed() )
21  {
22  GenEvent evt=GenEvent(Units::GEV,Units::MM);
23  inputA.read_event(evt);
24  if( inputA.failed() ) {
25  printf("End of file reached. Exit.\n");
26  break;
27  }
28  evts.push_back(evt);
29  }
30  inputA.close();
31 //No alien particles should be detached from vertices or removed from events
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  evts[i].remove_particles(evts[j].particles());
40 
41  for (GenParticlePtr p: evts.at(i).particles())
42  evts[j].remove_particle(p);
43 
44  for (GenParticlePtr p: evts.at(i).particles()) {
45  for (GenVertexPtr v: evts.at(j).vertices()) {
46  (v)->remove_particle_in(p);
47  (v)->remove_particle_out(p);
48  }
49  }
50 
51  WriterAscii outputA("frominputDelete.hepmc");
52  if(outputA.failed()) return 2;
53  for (size_t i=0; i<evts.size(); i++) outputA.write_event(evts[i]);
54  evts.clear();
55  outputA.close();
56 
57 
58  ReaderAscii inputB("frominputDelete.hepmc");
59  if(inputB.failed()) return 3;
60  WriterAsciiHepMC2 outputB("fromfrominputDelete.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("fromfrominputDelete.hepmc","inputDelete.hepmc");
76 }
GenEvent I/O serialization for structured text files.
GenEvent I/O parsing for structured text files.
Definition: ReaderAscii.h:29
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:41
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:608
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25