LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
copyfix.cc
Go to the documentation of this file.
1 #include "lcio.h"
2 
3 #include "IO/LCWriter.h"
4 #include "IO/LCReader.h"
5 #include "IO/LCEventListener.h"
6 #include "IO/LCRunListener.h"
7 
8 #include "EVENT/LCIO.h"
9 
10 
11 #include <cstdlib>
12 #include <iostream>
13 
14 using namespace std ;
15 using namespace lcio ;
16 
17 
22 // class for processing run and event records
24 
25 protected:
26  LCWriter* lcWrt{NULL} ;
27  int nEvent{0} ;
28 
29 public:
30  RunEventProcessor(const RunEventProcessor&) = delete ;
31  RunEventProcessor operator=(const RunEventProcessor&) = delete ;
32 
33  RunEventProcessor(const char* outFileName) : nEvent(0) {
34 
35  // open outputfile
36  lcWrt = LCFactory::getInstance()->createLCWriter() ;
37 
38  try{ lcWrt->open( outFileName , LCIO::WRITE_NEW ) ; }
39 
40  catch(IOException& e){
41  cout << "[RunEventProcessor()] Can't open file for writing - "
42  << e.what() << endl ;
43  exit(1) ;
44  }
45 
46  }
47 
49  // close outputfile
50  lcWrt->close() ;
51  cout << endl << " " << nEvent << " events copied ! " << endl ;
52  }
53 
54  void modifyEvent( LCEvent * /*evt*/ ) { /*no changes to event ! */ ; }
55 
56  void processEvent( LCEvent * evt ) {
57 
58  // just copy events to outputfiles
59  lcWrt->writeEvent( evt ) ;
60  nEvent ++ ;
61 // cout << " event: " << evt->getEventNumber()
62 // << " [run: " << evt->getRunNumber() << "] copied" << endl ;
63  }
64 
65  void modifyRunHeader(LCRunHeader* /*run*/){ /*no changes to event ! */ ;}
66 
67  // don't manipulate run headers - use analyze
68  void processRunHeader( LCRunHeader* run){
69 
70  // just copy run headers to the outputfile
71  lcWrt->writeRunHeader( run ) ;
72 // cout << "run : " << run->getRunNumber() << " ["
73 // << run->getDescription() << "] - header copied " << endl ;
74  }
75 
76 } ;
77 
78 //=============================================================================
79 
80 int main(int argc, char** argv ){
81 
82  char* inFileName ;
83  char* outFileName ;
84 
85  try{ // a large try block for debugging ....
86 
87  // create reader and writer for input and output streams
88  LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
89 
90  if( argc < 3 ){
91  cout << "usage: copyfix infilename outfilename " << endl ;
92  exit(1) ;
93  }
94  // read file names from command line
95  inFileName = argv[1] ;
96  outFileName = argv[2] ;
97 
98 
99  try{ lcReader->open( inFileName ) ; }
100 
101  catch( IOException& e){
102  cout << "Can't open file : " << e.what() << endl ;
103  exit(1) ;
104  }
105 
106  // create a new RunEventProcessor, register it with the reader
107  // and read and proccess the whole stream
108  {
109  RunEventProcessor evtProc( outFileName) ;
110 
111  lcReader->registerLCRunListener( &evtProc ) ;
112  lcReader->registerLCEventListener( &evtProc ) ;
113 
114  lcReader->readStream() ;
115  }
116 
117  lcReader->close() ;
118 
119  }
120 
121  catch(exception& ex){
122  cout << "something went wrong: " << ex.what() << endl ;
123  }
124 
125  return 0 ;
126 
127 }
128 
129 //=============================================================================
130 
void modifyEvent(LCEvent *)
Definition: copyfix.cc:54
T endl(T...args)
Little tool that copies LCIO files on an event by event and run by run basis, thus fixing files that ...
Definition: copyfix.cc:23
void processEvent(LCEvent *evt)
Definition: copyfix.cc:56
RunEventProcessor(const char *outFileName)
Definition: copyfix.cc:33
T exit(T...args)
T what(T...args)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
void processRunHeader(LCRunHeader *run)
Definition: copyfix.cc:68
STL class.
LCReader * lcReader
Definition: lsh.cc:78
void modifyRunHeader(LCRunHeader *)
Definition: copyfix.cc:65