/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/src/lcio/AddDifSynchro.cpp

Go to the documentation of this file.
00001 /* @version $Revision: 1328 $ * @modifiedby $Author: jacquem $ * @lastmodified $Date: 2011-10-03 17:04:17 +0200 (Mon, 03 Oct 2011) $ */
00002 #include "lcio/AddDifSynchro.hh"
00003 #include "lcio.h"
00004 
00005 #include "IO/LCWriter.h"
00006 #include "IO/LCReader.h"
00007 #include "IO/LCEventListener.h"
00008 #include "IO/LCRunListener.h"
00009 
00010 #include "EVENT/LCIO.h"
00011 #include "EVENT/TrackerRawData.h"
00012 
00013 #include "IMPL/LCEventImpl.h" 
00014 #include "IMPL/LCCollectionVec.h"
00015 #include "IMPL/SimCalorimeterHitImpl.h"
00016 #include "IMPL/CalorimeterHitImpl.h"
00017 #include "IMPL/MCParticleImpl.h" 
00018 #include "IMPL/TrackerHitImpl.h" 
00019 #include "IMPL/TrackImpl.h" 
00020 #include "IMPL/ClusterImpl.h" 
00021 #include "IMPL/ReconstructedParticleImpl.h" 
00022 #include "IMPL/VertexImpl.h" 
00023 //#include "IMPL/ParticleIDImpl.h" 
00024 #include "IMPL/LCFlagImpl.h" 
00025 #include "UTIL/LCTOOLS.h"
00026 #include "UTIL/PIDHandler.h"
00027 //#include "UTIL/IndexMap.h"
00028 #include "IMPL/LCRelationImpl.h"
00029 
00030 #include "UTIL/LCRelationNavigator.h"
00031 
00032 #include <iostream>
00033 #include <algorithm>
00034 
00035 using namespace std ;
00036 using namespace lcio ;
00037 
00038 //static std::string FILEN = "simjob.slcio" ;
00039 //static std::string OUTFILEN = "recjob.slcio" ;
00040 //static const int NHITS = 50 ;  // calorimeter hits per event
00041 //static const int nRecP = 10 ; // number of reconstructed particles
00042 
00043 /** Example of reading events from the file, add sth. to the event
00044  * and write it to a new file. This uses the listener mechanism to read 
00045  * the input file (run headers and events) record by record. <br>
00046  * 
00047  *  The RunEventProcessor class is defined for processing run and event records.
00048  *  This is our analysis module.
00049  *  For simplicity it is defined in the same file - in a real world application 
00050  *  it should of course be defined in separate header and source files.
00051  *  
00052  */
00053 
00054   
00055   AddDifSynchro::AddDifSynchro(const string _difSyncrhoFileName, const string _outputFile) : nEvent(0) , difSyncrhoFileName(_difSyncrhoFileName){
00056 
00057     
00058 
00059     // Get Event Number from DifSynchro file
00060     IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00061     lcReader->open( difSyncrhoFileName ) ;
00062     LCEvent* evt = NULL;
00063     //----------- the event loop -----------
00064     while( (evt = lcReader->readNextEvent()) != 0 )
00065     {
00066                 syncEvtId.push_back(evt->getParameters().getIntVal("Dif_syncro" ));
00067         }
00068 
00069     // open outputfile
00070     lcWrt = LCFactory::getInstance()->createLCWriter() ;
00071 
00072     try{ 
00073       lcWrt->setCompressionLevel( 9 ) ;
00074       lcWrt->open( _outputFile , LCIO::WRITE_NEW ) ; 
00075     } 
00076     
00077     catch(IOException& e){
00078       cout << "[RunEventProcessor()] Can't open file for writing -  " 
00079            << e.what()  << endl ;
00080       exit(1) ;
00081     }
00082     
00083   }
00084   
00085   AddDifSynchro::~AddDifSynchro(){
00086 
00087     // close outputfile
00088         cout << endl << "Done !" << endl;
00089     lcWrt->close()  ;
00090     delete lcWrt ;
00091   }
00092   
00093   void AddDifSynchro::processEvent( LCEvent * evt ) { /* used for 'read only' access*/ 
00094 
00095         // Write current read event and just modifing (add Dif_synchro parameter)
00096     nEvent ++ ;
00097     lcWrt->writeEvent( evt ) ;
00098   }
00099 
00100   void AddDifSynchro::modifyEvent( LCEvent * evt ) {
00101 
00102     // here we can modify existing objects that have been read from a stream:
00103         // get first list element
00104         int difEvtId = syncEvtId.front();
00105         // erase first list element
00106         syncEvtId.pop_front();
00107         evt->parameters().setValue("Dif_syncro",difEvtId ) ;
00108     cout << "Write Event[" << evt->getEventNumber() << "] \r" << flush;
00109 
00110   }
00111   
00112 
00113   void AddDifSynchro::processRunHeader( LCRunHeader* run){
00114 
00115     // just copy run headers to the outputfile
00116     lcWrt->writeRunHeader( run ) ;
00117         cout << "Write Run Header"<< endl;
00118   }
00119 
00120   void AddDifSynchro::modifyRunHeader(LCRunHeader* run){/*  we don't modify anything */;}
00121 
00122 
00123 

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