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.
std::shared_ptr< HepMC3::Writer > m_ioBackend {nullptr}
 Abstract base class for the back-end.

Detailed Description

Definition at line 25 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", m_ioBackendURL = "ascii:hepmc.genevent.txt", "Name of the back-end we'll use to write out the HepMC::GenEvent.\nEx: ascii:hepmc.genevent.txt" );
36 m_ioBackendURL.declareUpdateHandler( &HepMcWriterTool::setupBackend, this );
37 declareProperty( "McEvents", m_mcEventsName = "GEN_EVENT", "Input location of the McEventCollection to write out" );
38}
StringProperty m_ioBackendURL
URL of the I/O back-end (only "ASCII" for now...) glued with the name of the output file name.
std::shared_ptr< HepMC3::Writer > 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 42 of file HepMcWriterTool.cxx.

43{
44 ATH_MSG_DEBUG("Calling destructor");
45}
#define ATH_MSG_DEBUG(x)

◆ HepMcWriterTool() [2/2]

HepMcWriterTool::HepMcWriterTool ( )
protected

Default constructor:

Member Function Documentation

◆ execute()

StatusCode HepMcWriterTool::execute ( )

Definition at line 73 of file HepMcWriterTool.cxx.

74{
75 // retrieve the McEventCollection
76 const McEventCollection * mcEvts = nullptr;
77 if ( evtStore()->retrieve( mcEvts, m_mcEventsName ).isFailure() || nullptr == mcEvts ) {
78 ATH_MSG_ERROR("Could not retrieve a McEventCollection at [" << m_mcEventsName << "] !!");
79 return StatusCode::FAILURE;
80 }
81
82 if ( mcEvts->empty() ) {
83 ATH_MSG_WARNING("McEventCollection at ["<<m_mcEventsName<<"] is EMPTY !!");
84 return StatusCode::FAILURE;
85 }
86
87 const HepMC::GenEvent * evt = mcEvts->front();
88 if ( !evt ) {
89 ATH_MSG_ERROR("Retrieved NULL pointer to HepMC::GenEvent !!");
90 return StatusCode::FAILURE;
91 }
92
93 return write(evt);
94}
#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.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39

◆ finalize()

StatusCode HepMcWriterTool::finalize ( )

Definition at line 67 of file HepMcWriterTool.cxx.

68{
69 ATH_MSG_INFO("Finalizing " << name() << "...");
70 return StatusCode::SUCCESS;
71}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode HepMcWriterTool::initialize ( )

Athena Algorithm's Hooks.

Definition at line 49 of file HepMcWriterTool.cxx.

50{
51 ATH_MSG_INFO("Initializing " << name() << "...");
52
53 // Get pointer to StoreGateSvc and cache it :
54 if ( !evtStore().retrieve().isSuccess() ) {
55 ATH_MSG_ERROR("Unable to retrieve pointer to StoreGateSvc");
56 return StatusCode::FAILURE;
57 }
58
59 // setup backend
60 if (!m_ioBackend ) {
62 }
63
64 return StatusCode::SUCCESS;
65}

◆ setupBackend()

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

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

Definition at line 106 of file HepMcWriterTool.cxx.

107{
108 // defaults
109 std::string protocol = "asciiv3";
110 std::string fileName = "hepmc.genevent.txt";
111
112 // reset internal state
113 m_ioBackend = nullptr;
114
115 // caching URL
116 const std::string& url = m_ioBackendURL.value();
117
118 std::string::size_type protocolPos = url.find(s_protocolSep);
119
120 if ( std::string::npos != protocolPos ) {
121 protocol = url.substr( 0, protocolPos );
122 fileName = url.substr( protocolPos + 1, std::string::npos );
123 } else {
124 fileName = url;
125 }
126
127 // get the protocol name in lower cases
128 std::transform( protocol.begin(), protocol.end(), protocol.begin(), [](unsigned char c){ return std::tolower(c); } );
129 if ( "ascii" == protocol ) {
130 m_ioBackend = std::make_shared<HepMC3::WriterAsciiHepMC2>( fileName.c_str());
131 } else if ( "asciiv3" == protocol ) {
132 m_ioBackend = std::make_shared<HepMC3::WriterAscii>( fileName.c_str());
133 } else {
134 ATH_MSG_WARNING("UNKNOWN protocol [" << protocol << "] !!" << endmsg << "Will use [ascii] instead...");
135 protocol = "asciiv3";
136 m_ioBackend = std::make_shared<HepMC3::WriterAscii>( fileName.c_str());
137 }
138 ATH_MSG_DEBUG("Using protocol [" << protocol << "] and write to ["<< fileName << "]");
139}
#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 100 of file HepMcWriterTool.cxx.

101{
102 m_ioBackend->write_event(*evt);
103 return StatusCode::SUCCESS;
104}

Member Data Documentation

◆ m_ioBackend

std::shared_ptr<HepMC3::Writer> HepMcWriterTool::m_ioBackend {nullptr}
protected

Abstract base class for the back-end.

Definition at line 73 of file HepMcWriterTool.h.

73{nullptr};

◆ 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 63 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 69 of file HepMcWriterTool.h.


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