/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/EXAMPLE/anajob.cc

Go to the documentation of this file.
00001 #include "lcio.h"
00002 
00003 #include "IO/LCReader.h"
00004 #include "IMPL/LCTOOLS.h"
00005 #include "EVENT/LCRunHeader.h" 
00006 
00007 #include <cstdlib>
00008 
00009 //static const char* FILEN = "recjob.slcio" ; // default file name 
00010 static std::vector<std::string> FILEN ; 
00011 
00012 using namespace std ;
00013 using namespace lcio ;
00014 
00015 /** Example for an analysis job. No concrete implementations are needed
00016  *  for reading the data - just the EVENT interfaces. 
00017  *  In a first loop we read the run information and then reopen the file(s) for
00018  *  event loop.
00019  *  See LCTOOLS::dumpEvent(const LCEvent* evt) ) for details on how to access 
00020  *  the data in the LCEvent.  
00021  */
00022 
00023 int main(int argc, char** argv ){
00024 
00025   // read file names from command line (only argument) 
00026   if( argc < 2) {
00027     cout << " usage:  anajob <input-file1> [[input-file2],...]" << endl ;
00028     exit(1) ;
00029   }
00030   for(int i=1 ; i < argc ; i++){
00031       FILEN.push_back( argv[i] )  ;
00032   }
00033   int nFiles = argc-1 ;
00034   
00035   LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
00036   
00037   // first we read the run information
00038   
00039   
00040   // for reading from one file only use sth. like:
00041   //  const char* FILEN = "recjob.slcio" ;
00042   lcReader->open( FILEN ) ;
00043   
00044 
00045   cout << " will open and read from files: " << endl ;  
00046   for(int i=0 ; i < nFiles ; i++){
00047     cout  << "     "  << FILEN[i] << endl ; 
00048   }  
00049 
00050   LCRunHeader *runHdr ;
00051   
00052   // use a try catch block here: if sth. went wrong with reading the run data we 
00053   // still can try and read the event data - see below
00054   try{  
00055 
00056     // loop over all run headers
00057     while( ( runHdr = lcReader->readNextRunHeader() ) != 0 ){
00058       
00059       LCTOOLS::dumpRunHeader( runHdr ) ;
00060 //       cout << "  Run : " << runHdr->getRunNumber() 
00061 //         << " - "      << runHdr->getDetectorName() 
00062 //         << ":  "      << runHdr->getDescription()  << endl ;
00063     }
00064     
00065   }catch(IOException& e){
00066     cout << " io error when reading run data : " << e.what() << endl ;
00067   }
00068   cout << endl ;
00069   
00070   lcReader->close() ;
00071   
00072   
00073   // now loop over the file again and dump event data
00074 
00075   lcReader->open( FILEN ) ;
00076 
00077   //  cout << " reopened " << FILEN << " for reading " << endl ; 
00078   cout << " will reopen and read from files: " << endl ;  
00079   for(int i=0 ; i < nFiles ; i++){
00080     cout  << "     "  << FILEN[i] << endl ; 
00081   }  
00082   
00083   LCEvent* evt ;
00084   int nEvents = 0 ;
00085   
00086   //----------- the event loop -----------
00087   while( (evt = lcReader->readNextEvent()) != 0 ) {
00088     
00089     LCTOOLS::dumpEvent( evt ) ;
00090     nEvents ++ ;
00091   } 
00092   // -------- end of event loop -----------
00093   
00094   cout << endl <<  "  " <<  nEvents << " events read from files: " << endl  ;
00095   for(int i=0 ; i < nFiles ; i++){
00096     cout  << "     "  << FILEN[i] << endl ; 
00097   }  
00098 
00099   
00100   lcReader->close() ;
00101   delete lcReader ;
00102   return 0 ;
00103 }
00104 
00105   

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7