Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:18

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 /** \addtogroup Geant4EventReader
0015  *
0016  @{
0017   \package LCIOStdHepReader
0018  * \brief Base class to read StdHep files
0019  *
0020  *
0021 @}
0022  */
0023 
0024 #ifndef DD4HEP_DDG4_LCIOSTDHEPREADER_H
0025 #define DD4HEP_DDG4_LCIOSTDHEPREADER_H
0026 
0027 // LCIO include files
0028 #include <UTIL/LCStdHepRdr.h>
0029 
0030 // Framework include files
0031 #include "LCIOEventReader.h"
0032 
0033 /// Namespace for the AIDA detector description toolkit
0034 namespace dd4hep  {
0035 
0036   /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
0037   namespace sim  {
0038 
0039     /// Base class to read StdHep files with lcio
0040     /**
0041      *  \author  P.Kostka (main author)
0042      *  \author  M.Frank  (code reshuffeling into new DDG4 scheme)
0043      *  \version 1.0
0044      *  \ingroup DD4HEP_SIMULATION
0045      */
0046     class LCIOStdHepReader : public LCIOEventReader  {
0047     protected:
0048       /// Reference to Reader object
0049       UTIL::LCStdHepRdr* m_reader;
0050     public:
0051       /// Initializing constructor
0052       LCIOStdHepReader(const std::string& nam);
0053       /// Default destructor
0054       virtual ~LCIOStdHepReader();
0055       /// Read an event and fill a vector of MCParticles.
0056       virtual EventReaderStatus readParticleCollection(int event_number,
0057                                                        EVENT::LCCollection** particles)  override;
0058       virtual EventReaderStatus moveToEvent(int event_number)  override;
0059       virtual EventReaderStatus skipEvent()  override { return EVENT_READER_OK; }
0060 
0061     };
0062   }     /* End namespace lcio   */
0063 }       /* End namespace dd4hep */
0064 #endif  /* DD4HEP_DDG4_LCIOSTDHEPREADER_H */
0065 
0066 //==========================================================================
0067 //  AIDA Detector description implementation 
0068 //--------------------------------------------------------------------------
0069 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0070 // All rights reserved.
0071 //
0072 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0073 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0074 //
0075 // Author     : M.Frank
0076 //
0077 //==========================================================================
0078 
0079 // Framework include files
0080 #include <DDG4/Factories.h>
0081 
0082 // Factory entry
0083 DECLARE_GEANT4_EVENT_READER_NS(dd4hep::sim,LCIOStdHepReader)
0084 
0085 using namespace dd4hep::sim;
0086 
0087 /// Initializing constructor
0088 LCIOStdHepReader::LCIOStdHepReader(const std::string& nam)
0089   : LCIOEventReader(nam), m_reader(new UTIL::LCStdHepRdr(m_name.c_str()))
0090 {
0091 }
0092 
0093 /// Default destructor
0094 LCIOStdHepReader::~LCIOStdHepReader()    {
0095   dd4hep::detail::deletePtr(m_reader);
0096 }
0097 
0098 
0099 /// skipEvents if required
0100 Geant4EventReader::EventReaderStatus
0101 LCIOStdHepReader::moveToEvent(int event_number) {
0102   if( m_currEvent == 0 && event_number != 0 ) {
0103     printout(INFO,"LCIOStdHepReader::moveToEvent","Skipping the first %d events ", event_number );
0104     printout(INFO,"LCIOStdHepReader::moveToEvent","Event number before skipping: %d", m_currEvent );
0105     while ( m_currEvent < event_number ) {
0106       EVENT::LCCollection* particles = m_reader->readEvent();
0107       if ( 0 == particles ) return EVENT_READER_EOF;
0108       delete particles;
0109       ++m_currEvent;
0110     }
0111   }
0112   printout(INFO,"LCIOStdHepReader::moveToEvent","Event number after skipping: %d", m_currEvent );
0113   return EVENT_READER_OK;
0114 }
0115 
0116 /// Read an event and fill a vector of MCParticles.
0117 Geant4EventReader::EventReaderStatus
0118 LCIOStdHepReader::readParticleCollection(int /*event_number*/, EVENT::LCCollection** particles)  {
0119 
0120   *particles = m_reader->readEvent();
0121   ++m_currEvent;
0122 
0123   if ( 0 == *particles ) return EVENT_READER_EOF;
0124   return EVENT_READER_OK;
0125 }