Skip to content
Snippets Groups Projects
LCIOFileReader.cpp 2.25 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; }

Markus Frank's avatar
Markus Frank committed
/*
 *   DD4hep namespace declaration
 */
namespace DD4hep   {
  /*
   *   lcio namespace declaration
   */
Markus Frank's avatar
Markus Frank committed

    /** @class LcioEventReader LcioEventReader.h DDG4/LcioEventReader.h
     * 
     * Base class to read lcio event files
     *
     * @author  P.Kostka (main author)
     * @author  M.Frank  (code reshuffeling into new DDG4 scheme)
     * @version 1.0
     */
    struct 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, int);
Markus Frank's avatar
Markus Frank committed
      /// Default destructor
Markus Frank's avatar
Markus Frank committed
      /// Read an event and return a LCCollectionVec of MCParticles.
      virtual EVENT::LCCollection *readParticles();
Markus Frank's avatar
Markus Frank committed
    };
  }
}
#endif // DD4HEP_DDG4_LCIOFILEREADER_H
Markus Frank's avatar
Markus Frank committed

#include "DD4hep/Printout.h"
#include "DD4hep/Primitives.h"
Markus Frank's avatar
Markus Frank committed
#include "lcio.h"
#include "EVENT/LCIO.h"
#include "IO/LCReader.h"

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

// Factory entry
DECLARE_LCIO_EVENT_READER(LCIOFileReader)
Markus Frank's avatar
Markus Frank committed

/// Initializing constructor
LCIOFileReader::LCIOFileReader(const std::string& nam, int /* arg */) 
: LCIOEventReader(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
LCIOFileReader::~LCIOFileReader()    {
  DD4hep::deletePtr(m_reader);
Markus Frank's avatar
Markus Frank committed
}

/// Read an event and return a LCCollectionVec of MCParticles.
EVENT::LCCollection *LCIOFileReader::readParticles()   {
Markus Frank's avatar
Markus Frank committed
  ::lcio::LCEvent* evt = m_reader->readNextEvent();
  if ( evt ) {
    return evt->getCollection(LCIO::MCPARTICLE);
Markus Frank's avatar
Markus Frank committed
  }
  return 0;
}