HepMC3 event record library
testReaderFactory2.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/ReaderAscii.h"
8 #include "HepMC3/WriterAscii.h"
11 #include "HepMC3/ReaderHEPEVT.h"
12 #include "HepMC3/WriterHEPEVT.h"
13 #include "HepMC3/ReaderRootTree.h"
14 #include "HepMC3/WriterRootTree.h"
15 #include "HepMC3/ReaderFactory.h"
16 #include "HepMC3TestUtils.h"
17 using namespace HepMC3;
18 int main()
19 {
20  std::shared_ptr<Reader> input = deduce_reader("inputReaderFactory2.hepmc");
21  if(input->failed()) return 1;
22  WriterAscii outputA("frominputReaderFactory2.hepmc3");
23  WriterAsciiHepMC2 outputB("frominputReaderFactory2.hepmc2");
24  WriterHEPEVT outputC("frominputReaderFactory2.hepevt");
25  WriterRootTree outputD("frominputReaderFactory2.root");
26  if(outputA.failed()) return 2;
27  if(outputB.failed()) return 3;
28  if(outputC.failed()) return 4;
29  if(outputD.failed()) return 5;
30  while( !input->failed() )
31  {
32  GenEvent evt(Units::GEV,Units::MM);
33  input->read_event(evt);
34  if( input->failed() ) {
35  printf("End of file reached. Exit.\n");
36  break;
37  }
38  outputA.write_event(evt);
39  outputB.write_event(evt);
40  outputC.write_event(evt);
41  outputD.write_event(evt);
42  evt.clear();
43  }
44  input->close();
45  outputA.close();
46  outputB.close();
47  outputC.close();
48  outputD.close();
49 
50  std::vector<std::shared_ptr<Reader> > inputv;
51  inputv.push_back(deduce_reader("frominputReaderFactory2.hepmc3"));
52  inputv.push_back(deduce_reader("frominputReaderFactory2.hepmc2"));
53  inputv.push_back(deduce_reader("frominputReaderFactory2.hepevt"));
54  inputv.push_back(deduce_reader("frominputReaderFactory2.root"));
55 
56  std::vector<WriterAsciiHepMC2*> outputv;
57 
58  outputv.push_back(new WriterAsciiHepMC2("AA.hepmc2"));
59  outputv.push_back(new WriterAsciiHepMC2("BB.hepmc2"));
60  outputv.push_back(new WriterAsciiHepMC2("CC.hepmc2"));
61  outputv.push_back(new WriterAsciiHepMC2("DD.hepmc2"));
62 
63  for (size_t i=0; i<inputv.size(); i++)
64  while( !inputv.at(i)->failed() )
65  {
66  GenEvent evt(Units::GEV,Units::MM);
67  inputv.at(i)->read_event(evt);
68  if( inputv.at(i)->failed() ) {
69  printf("End of file reached. Exit.\n");
70  break;
71  }
72  outputv.at(i)->write_event(evt);
73  evt.clear();
74  }
75  for (size_t i=0; i<outputv.size(); i++) outputv.at(i)->close();
76 
77  return COMPARE_ASCII_FILES("AA.hepmc2","BB.hepmc2")+COMPARE_ASCII_FILES("BB.hepmc2","DD.hepmc2");
78 }
GenEvent I/O serialization for structured text files.
Definition of class WriterHEPEVT.
Definition of class ReaderHEPEVT.
Definition of class WriterRootTree.
Definition of class WriterAscii.
Definition of class ReaderRootTree.
std::shared_ptr< Reader > deduce_reader(std::istream &stream)
This function will deduce the type of input stream based on its content and will return appropriate R...
GenEvent I/O serialization for HEPEVT files.
Definition: WriterHEPEVT.h:27
Definition of class ReaderAsciiHepMC2.
Stores event-related information.
Definition: GenEvent.h:41
GenEvent I/O serialization for root files based on root TTree.
Definition of class ReaderAscii.
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