HepMC3 event record library
testIO9.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"
9#include "HepMC3/ReaderGZ.h"
10#include "HepMC3/WriterGZ.h"
13#include "HepMC3TestUtils.h"
14using namespace HepMC3;
15int main()
16{
17 ReaderAsciiHepMC2 inputA("inputIO9.hepmc");
18 if(inputA.failed()) return 1;
19 const std::vector<Compression> supported = HepMC3::supported_compression_types;
20 std::vector<std::shared_ptr<Writer> > writersGZ;
21 for (auto w: supported) {
22 switch (w) {
23 case Compression::z: {
24 writersGZ.push_back(std::shared_ptr<Writer>(new WriterGZ<WriterAsciiHepMC2,Compression::z>("frominputIO9.hepmc."+std::to_string(w))));
25 break;
26 }
27 case Compression::lzma: {
28 writersGZ.push_back(std::shared_ptr<Writer>(new WriterGZ<WriterAsciiHepMC2,Compression::lzma>("frominputIO9.hepmc."+std::to_string(w))));
29 break;
30 }
31 case Compression::bz2: {
32 writersGZ.push_back(std::shared_ptr<Writer>(new WriterGZ<WriterAsciiHepMC2,Compression::bz2>("frominputIO9.hepmc."+std::to_string(w))));
33 break;
34 }
35 default: {
36 return 9;
37 }
38 }
39 if(writersGZ.back()->failed()) return 10+writersGZ.size();
40
41 }
42 while( !inputA.failed() )
43 {
44 GenEvent evt(Units::GEV,Units::MM);
45 inputA.read_event(evt);
46 if( inputA.failed() ) {
47 printf("End of file reached. Exit.\n");
48 break;
49 }
50 for (auto w: writersGZ) w->write_event(evt);
51 evt.clear();
52 }
53 inputA.close();
54 for (auto w: writersGZ) w->close();
55 writersGZ.clear();
56
57 int result = 0;
58 for (auto w: supported) {
59 ReaderGZ<ReaderAsciiHepMC2> inputB("frominputIO9.hepmc."+std::to_string(w));
60 if(inputB.failed()) return 20;
61
62 WriterAsciiHepMC2 outputB("fromfrominputIO9" + std::to_string(w) + ".hepmc");
63 if(outputB.failed()) return 4;
64 while( !inputB.failed() )
65 {
66 GenEvent evt(Units::GEV,Units::MM);
67 inputB.read_event(evt);
68 if( inputB.failed() ) {
69 printf("End of file reached. Exit.\n");
70 break;
71 }
72 outputB.write_event(evt);
73 evt.clear();
74 }
75 inputB.close();
76 outputB.close();
77 result += COMPARE_ASCII_FILES("fromfrominputIO9" + std::to_string(w) + ".hepmc","inputIO9.hepmc");
78 }
79 return result;
80}
Definition of class GenEvent.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Definition of class ReaderGZ.
Definition of class WriterAsciiHepMC2.
Definition of class WriterAscii.
Definition of class WriterGZ.
Stores event-related information.
Definition: GenEvent.h:41
Parser for HepMC2 I/O files.
GenEvent I/O parsing for compressed files.
Definition: ReaderGZ.h:27
GenEvent I/O serialization for structured text files.
GenEvent I/O serialization for compressed files.
Definition: WriterGZ.h:25
HepMC3 main namespace.