ATLAS Offline Software
Loading...
Searching...
No Matches
HepMcReaderTool Class Reference

#include <HepMcReaderTool.h>

Inheritance diagram for HepMcReaderTool:
Collaboration diagram for HepMcReaderTool:

Public Member Functions

 HepMcReaderTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~HepMcReaderTool ()
 Destructor:
StatusCode initialize ()
 Athena Algorithm's Hooks.
StatusCode execute ()
StatusCode finalize ()
StatusCode read (HepMC::GenEvent *evt)
 Process the HepMC::GenEvent through the I/O frontend.

Protected Member Functions

 HepMcReaderTool ()
 Default constructor:
void setupFrontend (Gaudi::Details::PropertyBase &ioFrontendURL)
 Method to configure the front-end to read out the HepMC::GenEvent.

Protected Attributes

StringProperty m_ioFrontendURL
 URL of the I/O front-end (only "ASCII" for now...) glued with the name of the input file name.
StringProperty m_mcEventsOutputName
 Location of the McEventCollection to be read out.
HepMC::IO_BaseClass * m_ioFrontend
 Abstract base class for the back-end.

Detailed Description

Definition at line 30 of file HepMcReaderTool.h.

Constructor & Destructor Documentation

◆ HepMcReaderTool() [1/2]

HepMcReaderTool::HepMcReaderTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Public methods:

Constructors

Definition at line 33 of file HepMcReaderTool.cxx.

35 :
36 base_class( type, name, parent ),
37 m_ioFrontend( nullptr )
38{
39 //
40 // Property declaration
41 //
42
43 declareProperty( "Input",
44 m_ioFrontendURL = "ascii:hepmc.genevent.txt",
45 "Name of the front-end we'll use to read in the HepMC::GenEvent."
46 "\nEx: ascii:hepmc.genevent.txt" );
48 this );
49
50 declareProperty( "McEventsOutput",
51 m_mcEventsOutputName = "GEN_EVENT",
52 "Output location of the McEventCollection to read out" );
53}
void setupFrontend(Gaudi::Details::PropertyBase &ioFrontendURL)
Method to configure the front-end to read out the HepMC::GenEvent.
StringProperty m_mcEventsOutputName
Location of the McEventCollection to be read out.
StringProperty m_ioFrontendURL
URL of the I/O front-end (only "ASCII" for now...) glued with the name of the input file name.
HepMC::IO_BaseClass * m_ioFrontend
Abstract base class for the back-end.

◆ ~HepMcReaderTool()

HepMcReaderTool::~HepMcReaderTool ( )
virtual

Destructor:

Destructor.

Definition at line 57 of file HepMcReaderTool.cxx.

58{
59 ATH_MSG_DEBUG("Calling destructor");
60
61 delete m_ioFrontend;
62 m_ioFrontend = nullptr;
63}
#define ATH_MSG_DEBUG(x)

◆ HepMcReaderTool() [2/2]

HepMcReaderTool::HepMcReaderTool ( )
protected

Default constructor:

Member Function Documentation

◆ execute()

StatusCode HepMcReaderTool::execute ( )

Definition at line 90 of file HepMcReaderTool.cxx.

91{
92 // create a new McEventCollection and put it into StoreGate
94 if ( evtStore()->record( mcEvts, m_mcEventsOutputName ).isFailure() ) {
95 ATH_MSG_ERROR("Could not record a McEventCollection at ["<< m_mcEventsOutputName << "] !!");
96 return StatusCode::FAILURE;
97 }
98
99 if ( evtStore()->setConst( mcEvts ).isFailure() ) {
100 ATH_MSG_WARNING("Could not setConst McEventCollection at ["<< m_mcEventsOutputName << "] !!");
101 }
102
103 HepMC::GenEvent * evt = new HepMC::GenEvent;
104 mcEvts->push_back(evt);
105
106 return read(evt);
107}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
StatusCode read(HepMC::GenEvent *evt)
Process the HepMC::GenEvent through the I/O frontend.

◆ finalize()

StatusCode HepMcReaderTool::finalize ( )

Definition at line 84 of file HepMcReaderTool.cxx.

85{
86 ATH_MSG_INFO("Finalizing " << name() << "...");
87 return StatusCode::SUCCESS;
88}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode HepMcReaderTool::initialize ( )

Athena Algorithm's Hooks.

Definition at line 67 of file HepMcReaderTool.cxx.

68{
69 ATH_MSG_INFO("Initializing " << name() << "...");
70 // Get pointer to StoreGateSvc and cache it :
71 if ( !evtStore().retrieve().isSuccess() ) {
72 ATH_MSG_ERROR("Unable to retrieve pointer to StoreGateSvc");
73 return StatusCode::FAILURE;
74 }
75
76 // setup frontend
77 if ( nullptr == m_ioFrontend ) {
79 }
80
81 return StatusCode::SUCCESS;
82}
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ read()

StatusCode HepMcReaderTool::read ( HepMC::GenEvent * evt)

Process the HepMC::GenEvent through the I/O frontend.

Non-const methods:

Definition at line 113 of file HepMcReaderTool.cxx.

114{
115#ifdef HEPMC3
116 m_ioFrontend->read_event(*evt);
117#else
118 m_ioFrontend->fill_next_event(evt);
119#endif
120
121 return StatusCode::SUCCESS;
122}

◆ setupFrontend()

void HepMcReaderTool::setupFrontend ( Gaudi::Details::PropertyBase & ioFrontendURL)
protected

Method to configure the front-end to read out the HepMC::GenEvent.

Definition at line 124 of file HepMcReaderTool.cxx.

125{
126 // defaults
127 std::string protocol = "ascii";
128 std::string fileName = "hepmc.genevent.txt";
129
130 // reset internal state
131 if ( m_ioFrontend ) {
132 delete m_ioFrontend;
133 m_ioFrontend = nullptr;
134 }
135
136 // caching URL
137 const std::string& url = m_ioFrontendURL.value();
138
139 std::string::size_type protocolPos = url.find(s_protocolSep);
140
141 if ( std::string::npos != protocolPos ) {
142 protocol = url.substr( 0, protocolPos );
143 fileName = url.substr( protocolPos+1, std::string::npos );
144 } else {
145 //protocol = "ascii";
146 fileName = url;
147 }
148
149 // get the protocol name in lower cases
150 std::transform( protocol.begin(), protocol.end(), protocol.begin(), [](unsigned char c){ return std::tolower(c); } );
151
152#ifdef HEPMC3
153 if ( "ascii" == protocol ) {
154 m_ioFrontend = new HepMC3::ReaderAsciiHepMC2( fileName.c_str());
155
156 } else {
157 msg(MSG::WARNING) << "UNKNOWN protocol [" << protocol << "] !!" << endmsg<< "Will use [ascii] instead..."<< endmsg;
158 protocol = "ascii";
159 m_ioFrontend = new HepMC3::ReaderAsciiHepMC2( fileName.c_str());
160 }
161#else
162 if ( "ascii" == protocol ) {
163 m_ioFrontend = new HepMC::IO_GenEvent( fileName.c_str(), std::ios::in );
164
165 } else {
166 msg(MSG::WARNING) << "UNKNOWN protocol [" << protocol << "] !!" << endmsg << "Will use [ascii] instead..."<< endmsg;
167 protocol = "ascii";
168 m_ioFrontend = new HepMC::IO_GenEvent( fileName.c_str(), std::ios::in );
169 }
170#endif
171
172 ATH_MSG_DEBUG("Using protocol [" << protocol << "] and write to ["<< fileName << "]");
173}
#define endmsg
static const char *const s_protocolSep
MsgStream & msg
Definition testRead.cxx:32

Member Data Documentation

◆ m_ioFrontend

HepMC::IO_BaseClass* HepMcReaderTool::m_ioFrontend
protected

Abstract base class for the back-end.

Definition at line 94 of file HepMcReaderTool.h.

◆ m_ioFrontendURL

StringProperty HepMcReaderTool::m_ioFrontendURL
protected

URL of the I/O front-end (only "ASCII" for now...) glued with the name of the input file name.

Ex: "ascii:/home/foo/hepmc.txt" If no protocol separator ':' is found, fallback is "ASCII"

Definition at line 83 of file HepMcReaderTool.h.

◆ m_mcEventsOutputName

StringProperty HepMcReaderTool::m_mcEventsOutputName
protected

Location of the McEventCollection to be read out.

Definition at line 87 of file HepMcReaderTool.h.


The documentation for this class was generated from the following files: