DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
LCIOStdHepReader.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
24 #ifndef DD4HEP_DDG4_LCIOSTDHEPREADER_H
25 #define DD4HEP_DDG4_LCIOSTDHEPREADER_H
26 
27 // LCIO include files
28 #include <UTIL/LCStdHepRdr.h>
29 
30 // Framework include files
31 #include "LCIOEventReader.h"
32 
34 namespace dd4hep {
35 
37  namespace sim {
38 
40 
47  protected:
49  UTIL::LCStdHepRdr* m_reader;
50  public:
52  LCIOStdHepReader(const std::string& nam);
54  virtual ~LCIOStdHepReader();
56  virtual EventReaderStatus readParticleCollection(int event_number,
57  EVENT::LCCollection** particles) override;
58  virtual EventReaderStatus moveToEvent(int event_number) override;
59  virtual EventReaderStatus skipEvent() override { return EVENT_READER_OK; }
60 
61  };
62  } /* End namespace lcio */
63 } /* End namespace dd4hep */
64 #endif /* DD4HEP_DDG4_LCIOSTDHEPREADER_H */
65 
66 //==========================================================================
67 // AIDA Detector description implementation
68 //--------------------------------------------------------------------------
69 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
70 // All rights reserved.
71 //
72 // For the licensing terms see $DD4hepINSTALL/LICENSE.
73 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
74 //
75 // Author : M.Frank
76 //
77 //==========================================================================
78 
79 // Framework include files
80 #include <DDG4/Factories.h>
81 
82 // Factory entry
84 
85 using namespace dd4hep::sim;
86 
88 LCIOStdHepReader::LCIOStdHepReader(const std::string& nam)
89  : LCIOEventReader(nam), m_reader(new UTIL::LCStdHepRdr(m_name.c_str()))
90 {
91 }
92 
95  dd4hep::detail::deletePtr(m_reader);
96 }
97 
98 
101 LCIOStdHepReader::moveToEvent(int event_number) {
102  if( m_currEvent == 0 && event_number != 0 ) {
103  printout(INFO,"LCIOStdHepReader::moveToEvent","Skipping the first %d events ", event_number );
104  printout(INFO,"LCIOStdHepReader::moveToEvent","Event number before skipping: %d", m_currEvent );
105  while ( m_currEvent < event_number ) {
106  EVENT::LCCollection* particles = m_reader->readEvent();
107  if ( 0 == particles ) return EVENT_READER_EOF;
108  delete particles;
109  ++m_currEvent;
110  }
111  }
112  printout(INFO,"LCIOStdHepReader::moveToEvent","Event number after skipping: %d", m_currEvent );
113  return EVENT_READER_OK;
114 }
115 
118 LCIOStdHepReader::readParticleCollection(int /*event_number*/, EVENT::LCCollection** particles) {
119 
120  *particles = m_reader->readEvent();
121  ++m_currEvent;
122 
123  if ( 0 == *particles ) return EVENT_READER_EOF;
124  return EVENT_READER_OK;
125 }
dd4hep::sim::Geant4EventReader::EVENT_READER_EOF
@ EVENT_READER_EOF
Definition: Geant4InputAction.h:75
dd4hep::sim::LCIOStdHepReader::m_reader
UTIL::LCStdHepRdr * m_reader
Reference to Reader object.
Definition: LCIOStdHepReader.cpp:49
dd4hep::sim::Geant4EventReader::EventReaderStatus
EventReaderStatus
Status codes of the event reader object. Anything with NOT low-bit set is an error.
Definition: Geant4InputAction.h:68
dd4hep::sim::LCIOStdHepReader::readParticleCollection
virtual EventReaderStatus readParticleCollection(int event_number, EVENT::LCCollection **particles) override
Read an event and fill a vector of MCParticles.
dd4hep::sim::LCIOEventReader
Base class to read lcio files.
Definition: LCIOEventReader.h:35
DECLARE_GEANT4_EVENT_READER_NS
#define DECLARE_GEANT4_EVENT_READER_NS(name_space, name)
Plugin defintion to create event reader objects.
Definition: Factories.h:240
m_reader
UriReader * m_reader
Pointer to URI reader.
Definition: DocumentHandler.cpp:155
dd4hep::sim::Geant4EventReader::m_currEvent
int m_currEvent
Current event number.
Definition: Geant4InputAction.h:83
dd4hep::sim::LCIOStdHepReader::moveToEvent
virtual EventReaderStatus moveToEvent(int event_number) override
Move to the indicated event number.
LCIOEventReader.h
dd4hep::sim::LCIOStdHepReader::~LCIOStdHepReader
virtual ~LCIOStdHepReader()
Default destructor.
dd4hep::sim::LCIOStdHepReader::LCIOStdHepReader
LCIOStdHepReader(const std::string &nam)
Initializing constructor.
LCIOStdHepReader
Base class to read StdHep files.
UTIL
LCIO namespace. See http://lcio.desy.de.
Definition: DD4hepGroups.h:85
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4EventReader::EVENT_READER_OK
@ EVENT_READER_OK
Definition: Geant4InputAction.h:70
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::LCIOStdHepReader::skipEvent
virtual EventReaderStatus skipEvent() override
Skip event. To be implemented for sequential sources.
Definition: LCIOStdHepReader.cpp:59