Skip to content
Snippets Groups Projects
LCIOFileReader.cpp 2.44 KiB
Newer Older
Markus Frank's avatar
Markus Frank committed
// $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $
//====================================================================
//  AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
//====================================================================
#ifndef DD4HEP_DDG4_LCIOFILEREADER_H
#define DD4HEP_DDG4_LCIOFILEREADER_H
Markus Frank's avatar
Markus Frank committed

// Framework include files
Markus Frank's avatar
Markus Frank committed

// Forward declarations
namespace IO { class LCReader; }

/// Namespace for the AIDA detector description toolkit
namespace DD4hep  {
Markus Frank's avatar
Markus Frank committed

  /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
  namespace Simulation  {

    /// Base class to read lcio event files
    /**
     *  \author  P.Kostka (main author)
     *  \author  M.Frank  (code reshuffeling into new DDG4 scheme)
     *  \version 1.0
     *  \ingroup DD4HEP_SIMULATION
Markus Frank's avatar
Markus Frank committed
     */
    class LCIOFileReader : public LCIOEventReader  {
Markus Frank's avatar
Markus Frank committed
    protected:
      /// Reference to reader object
      IO::LCReader* m_reader;
    public:
      /// Initializing constructor
      LCIOFileReader(const std::string& nam);
Markus Frank's avatar
Markus Frank committed
      /// Default destructor
      /// Read an event and fill a vector of MCParticles.
      virtual EventReaderStatus readParticleCollection(int event_number, EVENT::LCCollection** particles);
Markus Frank's avatar
Markus Frank committed
    };
  }
}
#endif // DD4HEP_DDG4_LCIOFILEREADER_H
Markus Frank's avatar
Markus Frank committed

#include "DD4hep/Printout.h"
#include "DDG4/Factories.h"
#include "UTIL/ILDConf.h"
Markus Frank's avatar
Markus Frank committed

using namespace DD4hep::Simulation;
Markus Frank's avatar
Markus Frank committed

// Factory entry
DECLARE_GEANT4_EVENT_READER_NS(DD4hep::Simulation,LCIOFileReader)
Markus Frank's avatar
Markus Frank committed

/// Initializing constructor
DD4hep::Simulation::LCIOFileReader::LCIOFileReader(const std::string& nam)
Markus Frank's avatar
Markus Frank committed
{
  m_reader = ::lcio::LCFactory::getInstance()->createLCReader();
  printout(INFO,"LCIOFileReader","Created file reader. Try to open input %s",nam.c_str());
Markus Frank's avatar
Markus Frank committed
  m_reader->open(nam);
}

/// Default destructor
DD4hep::Simulation::LCIOFileReader::~LCIOFileReader()    {
/// Read an event and fill a vector of MCParticles.
Geant4EventReader::EventReaderStatus
DD4hep::Simulation::LCIOFileReader::readParticleCollection(int /*event_number */, EVENT::LCCollection** particles)  {
Markus Frank's avatar
Markus Frank committed
  ::lcio::LCEvent* evt = m_reader->readNextEvent();
  if ( evt ) {
    *particles = evt->getCollection(LCIO::MCPARTICLE);
    if ( *particles ) return EVENT_READER_OK;
Markus Frank's avatar
Markus Frank committed
  }
  return EVENT_READER_ERROR;