![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // garren@fnal.gov, October 2007 00003 // 00004 // Read back the file written by example_MyPythia 00006 // To Compile: go to the example directory and type: 00007 // gmake example_ReadMyPythia.exe 00008 // 00009 00010 #include <iostream> 00011 #include <fstream> 00012 #include "HepMC/IO_GenEvent.h" 00013 #include "HepMC/GenEvent.h" 00014 00015 int main() { 00016 // 00017 //........................................define an input scope 00018 { 00019 // open input stream 00020 std::ifstream istr( "example_MyPythia.dat" ); 00021 if( !istr ) { 00022 std::cerr << "example_ReadMyPythia: cannot open example_MyPythia.dat" << std::endl; 00023 exit(-1); 00024 } 00025 HepMC::IO_GenEvent ascii_in(istr); 00026 // open output stream (alternate method) 00027 HepMC::IO_GenEvent ascii_out("example_MyPythia2.dat",std::ios::out); 00028 // now read the file 00029 int icount=0; 00030 HepMC::GenEvent* evt = ascii_in.read_next_event(); 00031 while ( evt ) { 00032 icount++; 00033 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount 00034 << " its # " << evt->event_number() 00035 << std::endl; 00036 // write the event out to the ascii file 00037 ascii_out << evt; 00038 delete evt; 00039 ascii_in >> evt; 00040 } 00041 //........................................PRINT RESULT 00042 std::cout << icount << " events found. Finished." << std::endl; 00043 } // ascii_out and istr destructors are called here 00044 00045 return 0; 00046 } 00047 00048 00049