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

#include <HepMcWriterTool.h>

Inheritance diagram for HepMcWriterTool:
Collaboration diagram for HepMcWriterTool:

Public Member Functions

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

Protected Member Functions

 HepMcWriterTool ()
 Default constructor:
void setupBackend (Gaudi::Details::PropertyBase &ioBackendURL)
 Method to configure the back-end to write out the HepMC::GenEvent.

Protected Attributes

StringProperty m_ioBackendURL
 URL of the I/O back-end (only "ASCII" for now...) glued with the name of the output file name.
StringProperty m_mcEventsName
 Location of the McEventCollection to be written out If there is more than 1 HepMC::GenEvent in the McEventCollection we will send warning messages, and just write the first one.
HepMC::IO_BaseClass * m_ioBackend
 Abstract base class for the back-end.

Detailed Description

Definition at line 29 of file HepMcWriterTool.h.

Constructor & Destructor Documentation

◆ HepMcWriterTool() [1/2]

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

Constructor with parameters:

Constructors.

Definition at line 27 of file HepMcWriterTool.cxx.

27 :
28 base_class( type, name, parent ),
29 m_ioBackend( nullptr )
30{
31 //
32 // Property declaration
33 //
34
35 declareProperty( "Output",
36 m_ioBackendURL = "ascii:hepmc.genevent.txt",
37 "Name of the back-end we'll use to write out the HepMC::GenEvent."
38 "\nEx: ascii:hepmc.genevent.txt" );
39 m_ioBackendURL.declareUpdateHandler( &HepMcWriterTool::setupBackend,
40 this );
41
42 declareProperty( "McEvents",
43 m_mcEventsName = "GEN_EVENT",
44 "Input location of the McEventCollection to write out" );
45}
StringProperty m_ioBackendURL
URL of the I/O back-end (only "ASCII" for now...) glued with the name of the output file name.
HepMC::IO_BaseClass * m_ioBackend
Abstract base class for the back-end.
StringProperty m_mcEventsName
Location of the McEventCollection to be written out If there is more than 1 HepMC::GenEvent in the Mc...
void setupBackend(Gaudi::Details::PropertyBase &ioBackendURL)
Method to configure the back-end to write out the HepMC::GenEvent.

◆ ~HepMcWriterTool()

HepMcWriterTool::~HepMcWriterTool ( )
virtual

Destructor:

Destructor.

Definition at line 49 of file HepMcWriterTool.cxx.

50{
51 ATH_MSG_DEBUG("Calling destructor");
52
53 if ( m_ioBackend ) {
54 delete m_ioBackend;
55 m_ioBackend = nullptr;
56 }
57}
#define ATH_MSG_DEBUG(x)

◆ HepMcWriterTool() [2/2]

HepMcWriterTool::HepMcWriterTool ( )
protected

Default constructor:

Member Function Documentation

◆ execute()

StatusCode HepMcWriterTool::execute ( )

Definition at line 85 of file HepMcWriterTool.cxx.

86{
87 // retrieve the McEventCollection
88 const McEventCollection * mcEvts = nullptr;
89 if ( evtStore()->retrieve( mcEvts, m_mcEventsName ).isFailure() || nullptr == mcEvts ) {
90 ATH_MSG_ERROR("Could not retrieve a McEventCollection at [" << m_mcEventsName << "] !!");
91 return StatusCode::FAILURE;
92 }
93
94 if ( mcEvts->empty() ) {
95 ATH_MSG_WARNING("McEventCollection at ["<<m_mcEventsName<<"] is EMPTY !!");
96 return StatusCode::FAILURE;
97 }
98
99 const HepMC::GenEvent * evt = mcEvts->front();
100 if ( !evt ) {
101 ATH_MSG_ERROR("Retrieved NULL pointer to HepMC::GenEvent !!");
102 return StatusCode::FAILURE;
103 }
104
105 return write(evt);
106}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
const T * front() const
Access the first element in the collection as an rvalue.
bool empty() const noexcept
Returns true if the collection is empty.
StatusCode write(const HepMC::GenEvent *evt)
Process the HepMC::GenEvent through the I/O backend.
retrieve(aClass, aKey=None)
Definition PyKernel.py:110

◆ finalize()

StatusCode HepMcWriterTool::finalize ( )

Definition at line 79 of file HepMcWriterTool.cxx.

80{
81 ATH_MSG_INFO("Finalizing " << name() << "...");
82 return StatusCode::SUCCESS;
83}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode HepMcWriterTool::initialize ( )

Athena Algorithm's Hooks.

Definition at line 61 of file HepMcWriterTool.cxx.

62{
63 ATH_MSG_INFO("Initializing " << name() << "...");
64
65 // Get pointer to StoreGateSvc and cache it :
66 if ( !evtStore().retrieve().isSuccess() ) {
67 ATH_MSG_ERROR("Unable to retrieve pointer to StoreGateSvc");
68 return StatusCode::FAILURE;
69 }
70
71 // setup backend
72 if ( nullptr == m_ioBackend ) {
74 }
75
76 return StatusCode::SUCCESS;
77}

◆ setupBackend()

void HepMcWriterTool::setupBackend ( Gaudi::Details::PropertyBase & ioBackendURL)
protected

Method to configure the back-end to write out the HepMC::GenEvent.

Definition at line 122 of file HepMcWriterTool.cxx.

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

◆ write()

StatusCode HepMcWriterTool::write ( const HepMC::GenEvent * evt)

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

Non-const methods:

Definition at line 112 of file HepMcWriterTool.cxx.

113{
114#ifdef HEPMC3
115 m_ioBackend->write_event(*evt);
116#else
117 m_ioBackend->write_event(evt);
118#endif
119 return StatusCode::SUCCESS;
120}

Member Data Documentation

◆ m_ioBackend

HepMC::IO_BaseClass* HepMcWriterTool::m_ioBackend
protected

Abstract base class for the back-end.

Definition at line 95 of file HepMcWriterTool.h.

◆ m_ioBackendURL

StringProperty HepMcWriterTool::m_ioBackendURL
protected

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

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

Definition at line 82 of file HepMcWriterTool.h.

◆ m_mcEventsName

StringProperty HepMcWriterTool::m_mcEventsName
protected

Location of the McEventCollection to be written out If there is more than 1 HepMC::GenEvent in the McEventCollection we will send warning messages, and just write the first one.

Definition at line 88 of file HepMcWriterTool.h.


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