HepMC Reference Documentation

HepMC

testDeprecated.cc.in

The HepMC tests can also serve as useful examples This program checks the deprecated IO_Ascii class. IO_Ascii is slated for removal in the 2.05 release.

00001 
00002 // testDeprecated.cc.in
00003 //
00004 // garren@fnal.gov, March 2006
00005 // This program checks the deprecated IO_Ascii output format.
00006 // Apply an event selection to the events in testAscii.input
00007 // Events containing a photon of pT > 25 GeV pass the selection and are
00008 // written to "testAscii.dat"
00010 //
00011 
00012 #include "HepMC/IO_Ascii.h"
00013 #include "HepMC/GenEvent.h"
00014 
00015 // define methods and classes used by this test
00016 #include "IsGoodEvent.h"
00017 
00018 int main() { 
00019     // declare an instance of the event selection predicate
00020     IsGoodEvent is_good_event;
00021     {
00022         // declare an input strategy to read the data produced with the 
00023         // example_MyPythia
00024         HepMC::IO_Ascii ascii_in("@srcdir@/testAscii.input",std::ios::in);
00025         if ( ascii_in.rdstate() == std::ios::failbit ) {
00026             std::cerr << "ERROR input file @srcdir@/testAscii.input is needed "
00027                       << "and does not exist.  Exit." << std::endl;
00028             return 1;
00029         }
00030         // declare another IO_Ascii for writing out the good events
00031         HepMC::IO_Ascii ascii_out("testAscii.dat",std::ios::out);
00032         if ( ascii_out.rdstate() == std::ios::failbit ) {
00033             std::cerr << "ERROR opening output file testAscii.dat.  Exit."
00034                       << std::endl;
00035             return 1;
00036         }
00037         //........................................EVENT LOOP
00038         int icount=0;
00039         int num_good_events=0;
00040         HepMC::GenEvent* evt = ascii_in.read_next_event();
00041         while ( evt ) {
00042             icount++;
00043             if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
00044                                           << " its # " << evt->event_number() 
00045                                           << std::endl;
00046             if ( is_good_event(evt) ) {
00047                 ascii_out << evt;
00048                 ++num_good_events;
00049             }
00050 
00051             // clean up and get next event
00052             delete evt;
00053             ascii_in >> evt;
00054         }
00055         //........................................PRINT RESULT
00056         std::cout << num_good_events << " out of " << icount 
00057                   << " processed events passed the cuts. Finished." << std::endl;
00058     }
00059               
00060 }

Generated on Wed Jun 3 16:53:00 2009 for HepMC by  doxygen 1.5.1-3