/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/examples/cpp/rootDict/writeTree.C File Reference

#include "IO/LCReader.h"
#include "IOIMPL/LCFactory.h"
#include "IMPL/LCCollectionVec.h"
#include "IMPL/MCParticleImpl.h"
#include "EVENT/LCEvent.h"
#include "UTIL/LCTOOLS.h"
#include <vector>

Include dependency graph for writeTree.C:

Go to the source code of this file.

Functions

void writeTree (const char *FILEN)


Function Documentation

void writeTree ( const char *  FILEN  ) 

Example script for testing the ROOT LCIO dictionary.

writeTree: reads *.slcio file and writes the MCParticle collection to a branch of type std::vector<IMPL::MCParticleImpl*> in file lcioTree.root

Definition at line 21 of file writeTree.C.

00021                                   {
00022   
00023   std::string mcpName("MCParticlesSkimmed") ;
00024 
00025 
00026   //just in case this script is executed multiple times
00027   delete gROOT->GetListOfFiles()->FindObject( FILEN );
00028   delete gROOT->GetListOfCanvases()->FindObject("c1");
00029   
00030   if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
00031     unsigned res ;
00032     
00033     res = gSystem->Load("${LCIO}/lib/liblcio.so"); 
00034     res = gSystem->Load("${LCIO}/lib/liblcioDict.so"); 
00035   }
00036   
00037   
00038   //--- create a ROOT file, a tree and a branch ...
00039 
00040   TFile* file = new TFile( "lcioTree.root" , "RECREATE");    
00041 
00042   TTree* tree = new TTree( "LCIO" , "lcio event data tree");
00043   
00044 
00045   
00046   //  IMPL::LCCollectionVec* treeCol = 0 ;
00047   //  std::string mcpType("IMPL::LCCollectionVec") ;
00048 
00049   std::vector<IMPL::MCParticleImpl*>* treeCol = new std::vector<IMPL::MCParticleImpl*> ;
00050   std::string mcpType("std::vector<IMPL::MCParticleImpl*>") ;
00051   
00052 
00053   TBranch* mcpBranch = tree->Branch( mcpName.c_str(), 
00054                                      mcpType.c_str(), 
00055                                      (void*) &treeCol, 
00056                                      1024, // record size 
00057                                      99    // split level 
00058                                      );
00059   
00060 
00061   std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
00062   
00063   int nEvents = 0  ;
00064   int maxEvt = 10000 ;  // change as needed
00065 
00066   IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00067 
00068   lcReader->open( FILEN ) ;
00069   
00070 
00071   IMPL::LCCollectionVec emptyCol ;
00072   
00073   //----------- the event loop -----------
00074   while( (evt = lcReader->readNextEvent()) != 0  && nEvents < maxEvt ) {
00075     
00076     UTIL::LCTOOLS::dumpEvent( evt ) ;
00077     nEvents ++ ;
00078 
00079 
00080     // ------- fill the MCParticle collection to the branch...
00081 
00082     IMPL::LCCollectionVec* col = (IMPL::LCCollectionVec*) evt->getCollection( mcpName  ) ;
00083 
00084 //     treeCol = col ? col : emptyCol ;
00085     
00086     treeCol->clear() ;
00087 
00088     int nMCP = col->getNumberOfElements() ;
00089 
00090     for(int i=0 ; i<nMCP ; ++i){
00091 
00092       treeCol->push_back( (IMPL::MCParticleImpl*) col->getElementAt(i)  ) ;
00093     }
00094 
00095 
00096     tree->Fill() ;
00097 
00098   }
00099   // -------- end of event loop -----------
00100 
00101   file->Write() ;
00102   file->Close() ;
00103   
00104   delete file ;
00105 
00106 
00107   std::cout << std::endl 
00108             <<  "  " <<  nEvents 
00109             << " events read from file: " 
00110             << FILEN << std::endl  ;
00111   
00112   
00113   lcReader->close() ;
00114   
00115   delete lcReader ;
00116 }


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