/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/examples/cpp/rootDict/writeEventTree.C

Go to the documentation of this file.
00001 #ifndef __CINT__ 
00002 #include "IO/LCReader.h"
00003 #include "IOIMPL/LCFactory.h"
00004 #include "IMPL/LCCollectionVec.h"
00005 #include "IMPL/MCParticleImpl.h"
00006 #include "EVENT/LCEvent.h"
00007 #include "UTIL/LCTOOLS.h"
00008 #include <vector>
00009 #endif
00010 
00011 
00012 /** Example script for testing the ROOT LCIO dictionary.
00013  * 
00014  *  writeEventTree: 
00015  *  reads *.slcio file and creates a ROOT tree with one branch
00016  *  that hold the complete event 
00017  *  
00018  */
00019 
00020 void writeEventTree(const char* FILEN) {
00021   
00022   //just in case this script is executed multiple times
00023   delete gROOT->GetListOfFiles()->FindObject( FILEN );
00024   delete gROOT->GetListOfCanvases()->FindObject("c1");
00025   
00026   if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
00027     unsigned res ;
00028     
00029     res = gSystem->Load("$LCIO/lib/liblcio.so"); 
00030     res = gSystem->Load("$LCIO/lib/liblcioDict.so"); 
00031   }
00032   
00033   
00034   //--- create a ROOT file, a tree and a branch ...
00035   
00036   TFile* file = new TFile( "lcioEventTree.root" , "RECREATE");    
00037   
00038   TTree* tree = new TTree( "LCIO" , "lcio event data tree");
00039   
00040   std::string treeName("LCEvent") ;
00041   
00042   
00043   IMPL::LCEventImpl* treeEvt=0 ;
00044 
00045   std::string type("IMPL::LCEventImpl") ;
00046   
00047   TBranch* mcpBranch = tree->Branch( treeName.c_str(), 
00048                                      type.c_str(), 
00049                                      (void*) &treeEvt, 
00050                                      1024, // record size 
00051                                      199    // split level 
00052                                      );
00053   
00054 
00055   std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
00056   
00057   int nEvents = 0  ;
00058 
00059   int maxEvt = 10000 ; 
00060 
00061   IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00062 
00063   lcReader->open( FILEN ) ;
00064   
00065 
00066   //----------- the event loop -----------
00067   while( (evt = lcReader->readNextEvent()) != 0  && nEvents < maxEvt ) {
00068     
00069     if( nEvents < 3 )  // only dump first 3 events
00070       UTIL::LCTOOLS::dumpEvent( evt ) ;
00071 
00072     nEvents ++ ;
00073 
00074 
00075     treeEvt = (IMPL::LCEventImpl*) evt ;
00076     
00077 
00078     tree->Fill() ;
00079 
00080   }
00081   // -------- end of event loop -----------
00082 
00083   file->Write() ;
00084   file->Close() ;
00085   
00086   delete file ;
00087 
00088 
00089   std::cout << std::endl 
00090             <<  "  " <<  nEvents 
00091             << " events read from file: " 
00092             << FILEN << std::endl  ;
00093   
00094   
00095   lcReader->close() ;
00096   
00097   delete lcReader ;
00098 }

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