// -*- C++ -*- // // This file is part of HepMC // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details) // /** * @example HepMC3_fileIO_example.cc * @brief Test of file I/O * * Parses HepMC3 file and saves it as a new HepMC3 file. * The resulting file should be an exact copy of the input file * */ #include "HepMC3/GenEvent.h" #include "HepMC3/ReaderAscii.h" #include "HepMC3/WriterAscii.h" #include "HepMC3/Print.h" #include using namespace HepMC3; /** Main program */ int main(int argc, char **argv) { if( argc<3 ) { cout << "Usage: " << argv[0] << " " << endl; exit(-1); } ReaderAscii input_file (argv[1]); WriterAscii output_file(argv[2]); int events_parsed = 0; while(!input_file.failed()) { GenEvent evt(Units::GEV,Units::MM); // Read event from input file input_file.read_event(evt); // If reading failed - exit loop if( input_file.failed() ) break; // Save event to output file output_file.write_event(evt); if(events_parsed==0) { cout << " First event: " << endl; Print::listing(evt); Print::content(evt); cout << " Testing attribute reading for the first event: " << endl; shared_ptr cs = evt.attribute("GenCrossSection"); shared_ptr hi = evt.attribute("GenHeavyIon"); shared_ptr pi = evt.attribute("GenPdfInfo"); if(cs) { cout << " Has GenCrossSection: "; Print::line(cs); } else cout << " No GenCrossSection " << endl; if(pi) { cout << " Has GenPdfInfo: "; Print::line(pi); } else cout << " No GenPdfInfo " << endl; if(hi) { cout << " Has GenHeavyIon: "; Print::line(hi); } else cout << " No GenHeavyIon " << endl; } ++events_parsed; if( events_parsed%100 == 0 ) cout<<"Events parsed: "<