00001 #include "lcio.h"
00002
00003 #include "IO/LCWriter.h"
00004 #include "IO/LCReader.h"
00005 #include "IO/LCEventListener.h"
00006 #include "IO/LCRunListener.h"
00007
00008 #include "EVENT/LCIO.h"
00009
00010
00011 #include <cstdlib>
00012 #include <iostream>
00013
00014 using namespace std ;
00015 using namespace lcio ;
00016
00017
00018
00019
00020
00021
00022
00023 class RunEventProcessor : public LCRunListener, public LCEventListener{
00024
00025 protected:
00026 LCWriter* lcWrt ;
00027 int nEvent ;
00028
00029 public:
00030
00031 RunEventProcessor(const char* outFileName) : nEvent(0) {
00032
00033
00034 lcWrt = LCFactory::getInstance()->createLCWriter() ;
00035
00036 try{ lcWrt->open( outFileName , LCIO::WRITE_NEW ) ; }
00037
00038 catch(IOException& e){
00039 cout << "[RunEventProcessor()] Can't open file for writing - "
00040 << e.what() << endl ;
00041 exit(1) ;
00042 }
00043
00044 }
00045
00046 ~RunEventProcessor(){
00047
00048 lcWrt->close() ;
00049 cout << endl << " " << nEvent << " events copied ! " << endl ;
00050 }
00051
00052 void modifyEvent( LCEvent * evt ) { ; }
00053
00054 void processEvent( LCEvent * evt ) {
00055
00056
00057 lcWrt->writeEvent( evt ) ;
00058 nEvent ++ ;
00059
00060
00061 }
00062
00063 void modifyRunHeader(LCRunHeader* run){ ;}
00064
00065
00066 void processRunHeader( LCRunHeader* run){
00067
00068
00069 lcWrt->writeRunHeader( run ) ;
00070
00071
00072 }
00073
00074 } ;
00075
00076
00077
00078 int main(int argc, char** argv ){
00079
00080 char* inFileName ;
00081 char* outFileName ;
00082
00083 try{
00084
00085
00086 LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
00087
00088 if( argc < 3 ){
00089 cout << "usage: copyfix infilename outfilename " << endl ;
00090 exit(1) ;
00091 }
00092
00093 inFileName = argv[1] ;
00094 outFileName = argv[2] ;
00095
00096
00097 try{ lcReader->open( inFileName ) ; }
00098
00099 catch( IOException& e){
00100 cout << "Can't open file : " << e.what() << endl ;
00101 exit(1) ;
00102 }
00103
00104
00105
00106 {
00107 RunEventProcessor evtProc( outFileName) ;
00108
00109 lcReader->registerLCRunListener( &evtProc ) ;
00110 lcReader->registerLCEventListener( &evtProc ) ;
00111
00112 lcReader->readStream() ;
00113 }
00114
00115 lcReader->close() ;
00116
00117 }
00118
00119 catch(exception& ex){
00120 cout << "something went wrong: " << ex.what() << endl ;
00121 }
00122
00123 return 0 ;
00124
00125 }
00126
00127
00128