HepMC3 event record library
testIO10.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"
11#include "HepMC3TestUtils.h"
12#include "HepMC3/ReaderMT.h"
13#include <algorithm>
14using namespace HepMC3;
15int main()
16{
17 ReaderMT<ReaderAsciiHepMC2,3> inputA("inputIO10.hepmc");
18 std::vector<GenEvent> inputA_events;
19 if(inputA.failed()) return 1;
20 while( !inputA.failed() )
21 {
22 GenEvent evt(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 inputA_events.push_back(evt);
29 }
30 inputA.close();
31 WriterAscii outputA("frominputIO10.hepmc");
32 if(outputA.failed()) return 2;
33 std::sort(inputA_events.begin(), inputA_events.end(), [](const GenEvent& lhs, const GenEvent& rhs) {
34 return lhs.event_number() < rhs.event_number();
35 });
36 for (auto& e: inputA_events) outputA.write_event(e);
37 outputA.close();
38 inputA_events.clear();
39
40 ReaderMT<ReaderAscii,2> inputB("frominputIO10.hepmc");
41 std::vector<GenEvent> inputB_events;
42 if(inputB.failed()) return 3;
43 while( !inputB.failed() )
44 {
45 GenEvent evt(Units::GEV,Units::MM);
46 inputB.read_event(evt);
47 if( inputB.failed() ) {
48 printf("End of file reached. Exit.\n");
49 break;
50 }
51 inputB_events.push_back(evt);
52 }
53 inputB.close();
54 WriterAsciiHepMC2 outputB("fromfrominputIO10.hepmc");
55 if(outputB.failed()) return 4;
56 std::sort(inputB_events.begin(), inputB_events.end(), [](const GenEvent& lhs, const GenEvent& rhs) {
57 return lhs.event_number() < rhs.event_number();
58 });
59 for (auto& e: inputB_events) outputB.write_event(e);
60 outputB.close();
61 inputB_events.clear();
62
63 return COMPARE_ASCII_FILES("fromfrominputIO10.hepmc","inputIO10.hepmc");
64}
Definition of class GenEvent.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Definition of class ReaderMT.
Definition of class WriterAsciiHepMC2.
Definition of class WriterAscii.
Stores event-related information.
Definition: GenEvent.h:41
Multithreader GenEvent I/O parsing.
Definition: ReaderMT.h:27
GenEvent I/O serialization for structured text files.
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25
HepMC3 main namespace.