HepMC3 event record library
testIO7.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"
10#include "HepMC3TestUtils.h"
11using namespace HepMC3;
12int main()
13{
14 ReaderAsciiHepMC2 inputA("inputIO7.hepmc");
15 if(inputA.failed()) return 1;
16 WriterAscii outputA("frominputIO7.hepmc");
17 if(outputA.failed()) return 2;
18 size_t n = 0;
19 while( !inputA.failed() )
20 {
21 GenEvent evt(Units::GEV,Units::MM);
22 inputA.read_event(evt);
23 if( inputA.failed() ) {
24 printf("End of file reached. Exit.\n");
25 break;
26 }
27 evt.set_run_info(std::make_shared<GenRunInfo>());
28 std::vector<std::string> w_names;
29 std::vector<double> w_values;
30 for (size_t i=0; i<n+2; i++) {
31 w_names.push_back(std::string("testname")+std::to_string(i));
32 w_values.push_back(1.0+0.1*i);
33 }
34 evt.run_info()->add_attribute("testrunattribute",std::make_shared<IntAttribute>(10000+n));
35 if (n%2==0)
36 evt.run_info()->set_weight_names(w_names);//Try run info with names
37 else
38 evt.run_info()->set_weight_names(std::vector<std::string>());//Try run info w/o names
39 evt.weights() = w_values;
40 outputA.set_run_info(nullptr);//This instructs reader to take run info from the event
41 outputA.write_event(evt);
42 evt.clear();
43 n++;
44 }
45 inputA.close();
46 outputA.close();
47
48
49 ReaderAscii inputB("frominputIO7.hepmc");
50 if(inputB.failed()) return 3;
51 WriterAscii outputB("fromfrominputIO7.hepmc");
52 if(outputB.failed()) return 4;
53 while( !inputB.failed() )
54 {
55 GenEvent evt(Units::GEV,Units::MM);
56 inputB.read_event(evt);
57 if( inputB.failed() ) {
58 printf("End of file reached. Exit.\n");
59 break;
60 }
61 outputB.set_run_info(nullptr);//This instructs reader to take run info from the event
62 outputB.write_event(evt);
63 evt.clear();
64 }
65 inputB.close();
66 outputB.close();
67 return COMPARE_ASCII_FILES("fromfrominputIO7.hepmc","frominputIO7.hepmc");
68}
Definition of class GenEvent.
Definition of class ReaderAsciiHepMC2.
Definition of class ReaderAscii.
Definition of class WriterAscii.
Stores event-related information.
Definition: GenEvent.h:41
Parser for HepMC2 I/O files.
GenEvent I/O parsing for structured text files.
Definition: ReaderAscii.h:29
GenEvent I/O serialization for structured text files.
Definition: WriterAscii.h:25
HepMC3 main namespace.