/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/EXAMPLE/stdhepjob.cc File Reference

#include "lcio.h"
#include "IO/LCWriter.h"
#include "EVENT/LCIO.h"
#include "IMPL/LCEventImpl.h"
#include "IMPL/LCRunHeaderImpl.h"
#include "UTIL/LCStdHepRdr.h"
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <memory>

Include dependency graph for stdhepjob.cc:

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main ( int  argc,
char **  argv 
)

Simple test program to demonstrate reading of binary .stdhep generator files. Writes MCParticle collections to the outputfile stdhepjob.slcio.

Definition at line 25 of file stdhepjob.cc.

00025                                 {
00026   
00027   if(argc < 4) {
00028     
00029      std::cout << " usage: stdhepjob infile.stdhep outfile.slcio maxEvt " <<  std::endl 
00030                << "   infile.stdhep    - input file name "  <<  std::endl 
00031                << "   outfile.slcio    - ouput file name "  <<  std::endl 
00032                << "   maxEvt           - max number of events to read [-1: all]"  <<  std::endl  ;
00033      
00034     return 1;
00035   }
00036     
00037   std::string inFile  = argv[1] ;
00038   std::string outFile = argv[2] ;
00039   int maxEvt = std::atoi( argv[3] ) ; 
00040 
00041 
00042   std::cout << "==================================================== " << std::endl
00043             << " stdhepjob : " << std::endl  ;
00044 
00045   // Open an instance of the StdHep Reader with the given filename
00046   LCStdHepRdr rdr( inFile.c_str()  ) ;
00047   
00048   std::cout << " opened file : " << inFile << std::endl ;
00049   
00050   rdr.printHeader() ;
00051 
00052   // create sio writer
00053   std::auto_ptr<LCWriter> lcWrt( LCFactory::getInstance()->createLCWriter() ) ;
00054   
00055   lcWrt->open( outFile )  ;
00056   
00057   std::auto_ptr<LCRunHeaderImpl> runHdr(  new LCRunHeaderImpl ) ; 
00058   
00059   runHdr->setRunNumber( 0 ) ;
00060   
00061   std::string detName("Unknown")  ;
00062   runHdr->setDetectorName( detName ) ;
00063       
00064   std::stringstream description ; 
00065 
00066   description << " file generated with LCIO stdhepjob from "  << inFile  ;
00067 
00068   runHdr->setDescription( description.str()  ) ;
00069 
00070   lcWrt->writeRunHeader( runHdr.get()  ) ;
00071 
00072   int count = 0; 
00073 
00074   try {
00075 
00076     while( maxEvt < 0  || count < maxEvt ){
00077         
00078       std::auto_ptr<LCEventImpl> evt( new LCEventImpl() ) ;
00079         
00080       evt->setRunNumber(  0   ) ;
00081       evt->setEventNumber( count ) ;
00082       evt->setDetectorName( detName ) ;
00083         
00084       // read the next stdhep event and add an MCParticle collection to the event
00085       rdr.updateNextEvent( evt.get()  , "MCParticle" ) ;
00086         
00087       lcWrt->writeEvent( evt.get()  ) ;
00088         
00089       ++count ;
00090         
00091     } // evt loop
00092   }
00093     
00094   catch( IO::EndOfDataException& e ) {  
00095   }
00096     
00097   std::cout << "  converted " << count << " events - written to LCIO " << outFile  << std::endl ;
00098     
00099   std::cout << "==================================================== " 
00100             << std::endl << std::endl ;
00101     
00102   lcWrt->close() ;
00103   
00104   return 0 ;
00105 
00106 }


Generated on Mon Jan 7 13:16:42 2013 for MicromegasFramework by  doxygen 1.4.7