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

#include "lcio.h"
#include "IO/LCReader.h"
#include "IMPL/LCTOOLS.h"
#include "EVENT/LCRunHeader.h"
#include <cstdlib>

Include dependency graph for anajob.cc:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Variables

static std::vector< std::string > FILEN


Function Documentation

int main ( int  argc,
char **  argv 
)

Example for an analysis job. No concrete implementations are needed for reading the data - just the EVENT interfaces. In a first loop we read the run information and then reopen the file(s) for event loop. See LCTOOLS::dumpEvent(const LCEvent* evt) ) for details on how to access the data in the LCEvent.

Definition at line 23 of file anajob.cc.

00023                                 {
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 }


Variable Documentation

std::vector<std::string> FILEN [static]

Definition at line 10 of file anajob.cc.


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