LcioEventSource.cc

Go to the documentation of this file.
00001 // $Header: /cvs/lcd/slic/src/LcioEventSource.cc,v 1.7 2007/04/27 01:54:34 jeremy Exp $
00002 #include "LcioEventSource.hh"
00003 
00004 // slic
00005 #include "LcioMcpFilter.hh"
00006 
00007 namespace slic
00008 {
00009 
00010   LcioEventSource::LcioEventSource(const std::string& fname)
00011     : EventSourceWithInputFile( "LcioEventSource", fname),
00012       m_event(0)
00013   {
00014     m_reader = IOIMPL::LCFactory::getInstance()->createLCReader();
00015 
00016     m_filter = new LcioMcpFilter();
00017   }
00018 
00019   LcioEventSource::~LcioEventSource()
00020   {
00021     delete m_reader;
00022   }
00023 
00024   // open the current file
00025   void LcioEventSource::open()
00026   {
00027     try {
00028 #ifdef SLIC_LOG
00029       log() << LOG::verbose << "opening filename <" << m_filename << ">" << LOG::done;
00030 #endif
00031       m_reader->open( m_filename );
00032       m_fileIsOpen = true;
00033     }
00034     catch (IO::IOException& ioe) {
00035       log() << LOG::error << ioe.what() << LOG::done;
00036       G4Exception("ERROR: Caught exception while reading LCIO input file.");
00037     }
00038   }
00039 
00040   // close the current file
00041   void LcioEventSource::close()
00042   {
00043     try {
00044       m_reader->close();
00045       m_fileIsOpen = false;
00046     }
00047     catch (...) {
00048     }
00049   }
00050 
00051   // read the next event
00052   void LcioEventSource::readNextEvent()
00053   {
00054     m_event = m_reader->readNextEvent();
00055 
00056     if ( 0 == m_event ) {
00057       m_eof = true;
00058     }
00059   }
00060 
00061   void LcioEventSource::dumpCurrentEvent()
00062   {
00063     log() << LOG::debug << "LcioEventSource - Initial MCParticle Collection" << LOG::done;
00064 
00065     LcioMcpManager::instance()->printMcpCollection( "initial" );
00066   }
00067 
00068   void LcioEventSource::generate(G4Event* anEvent)
00069   {
00070     assert( LcioMcpManager::instance()->getInitialMcpCollection() );
00071     LcioManager::instance()
00072       ->getGenerator()
00073       ->generatePrimaryVertexFromMcpCollection(LcioMcpManager::instance()->getInitialMcpCollection(),
00074                                                anEvent );
00075   }
00076 
00077   void LcioEventSource::beginRun(const G4Run* aRun)
00078   {
00079     // do superclass action
00080     EventSourceWithInputFile::beginRun( aRun );
00081   }
00082 
00083   void LcioEventSource::beginEvent(const G4Event* anEvent)
00084   {
00085     // read an event
00086     EventSourceWithInputFile::beginEvent( anEvent );
00087 
00088     // set initial collection to filtered coll w/ gen parts only
00089     LcioMcpManager::instance()
00090       ->setInitialMcpCollection( m_filter->filterSimParticles( getCurrentMcpLCCollection() ) );
00091   }
00092 
00093   EVENT::LCCollection* LcioEventSource::getCurrentMcpLCCollection()
00094   {
00095     EVENT::LCCollection* mcpColl = 0;
00096 
00097     if ( m_event ) {
00098 
00099       mcpColl = LcioMcpManager::instance()->findMcpCollection( m_event );
00100 
00101       if ( mcpColl == 0 ) {
00102         G4Exception("FATAL ERROR: No Mcp collection found in LCIO input event.");
00103       }
00104     }
00105     else {
00106       log() << LOG::error << "LCEvent is null" << LOG::done;
00107     }
00108     return mcpColl;
00109   }
00110 }

Generated on Thu Nov 15 15:24:16 2007 for Simulator for the Linear Collider by  doxygen 1.5.4