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

Detailed Description

Definition at line 27 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:

Constructors.

Definition at line 29 of file HepMcReaderTool.cxx.

29 :
30 base_class( type, name, parent )
31{
32 //
33 // Property declaration
34 //
35
36 declareProperty( "Input", m_ioFrontendURL = "auto:hepmc.genevent.txt", "Name of the front-end we'll use to read in the HepMC::GenEvent.\nEx: ascii:hepmc.genevent.txt" );
37 m_ioFrontendURL.declareUpdateHandler( &HepMcReaderTool::setupFrontend, this );
38 declareProperty( "McEventsOutput", m_mcEventsOutputName = "GEN_EVENT", "Output location of the McEventCollection to read out" );
39}
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.

◆ ~HepMcReaderTool()

HepMcReaderTool::~HepMcReaderTool ( )
virtual

Destructor:

Destructor.

Definition at line 43 of file HepMcReaderTool.cxx.

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

◆ HepMcReaderTool() [2/2]

HepMcReaderTool::HepMcReaderTool ( )
protected

Default constructor:

Member Function Documentation

◆ execute()

StatusCode HepMcReaderTool::execute ( )

Definition at line 73 of file HepMcReaderTool.cxx.

74{
75 // create a new McEventCollection and put it into StoreGate
77 if ( evtStore()->record( mcEvts, m_mcEventsOutputName ).isFailure() ) {
78 ATH_MSG_ERROR("Could not record a McEventCollection at ["<< m_mcEventsOutputName << "] !!");
79 return StatusCode::FAILURE;
80 }
81
82 if ( evtStore()->setConst( mcEvts ).isFailure() ) {
83 ATH_MSG_WARNING("Could not setConst McEventCollection at ["<< m_mcEventsOutputName << "] !!");
84 }
85
87 mcEvts->push_back(evt);
88
89 return read(evt);
90}
#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.
void setConst()
Set the const flag for this expression.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39

◆ finalize()

StatusCode HepMcReaderTool::finalize ( )

Definition at line 67 of file HepMcReaderTool.cxx.

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

◆ initialize()

StatusCode HepMcReaderTool::initialize ( )

Athena Algorithm's Hooks.

Definition at line 50 of file HepMcReaderTool.cxx.

51{
52 ATH_MSG_INFO("Initializing " << name() << "...");
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 frontend
60 if ( !m_ioFrontend ) {
62 }
63
64 return StatusCode::SUCCESS;
65}
std::shared_ptr< HepMC3::Reader > m_ioFrontend
Abstract base class for the back-end.

◆ read()

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

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

Definition at line 92 of file HepMcReaderTool.cxx.

93{
94 m_ioFrontend->read_event(*evt);
95 return StatusCode::SUCCESS;
96}

◆ setupFrontend()

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

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

Definition at line 98 of file HepMcReaderTool.cxx.

99{
100 // defaults
101 std::string protocol = "auto";
102 std::string fileName = "hepmc.genevent.txt";
103
104 // reset internal state
105 m_ioFrontend = nullptr;
106
107 // caching URL
108 const std::string& url = m_ioFrontendURL.value();
109
110 std::string::size_type protocolPos = url.find(s_protocolSep);
111
112 if ( std::string::npos != protocolPos ) {
113 protocol = url.substr( 0, protocolPos );
114 fileName = url.substr( protocolPos + 1, std::string::npos );
115 } else {
116 fileName = url;
117 }
118
119 // get the protocol name in lower cases
120 std::transform( protocol.begin(), protocol.end(), protocol.begin(), [](unsigned char c){ return std::tolower(c); } );
121
122 if ( "auto" == protocol ) {
123 m_ioFrontend = HepMC3::deduce_reader( fileName.c_str());
124 } else if ( "ascii" == protocol ) {
125 m_ioFrontend = std::make_shared<HepMC3::ReaderAsciiHepMC2>( fileName.c_str());
126 } else {
127 msg(MSG::WARNING) << "UNKNOWN protocol [" << protocol << "] !!" << endmsg<< "Will use [ascii] instead..."<< endmsg;
128 protocol = "ascii";
129 m_ioFrontend = std::make_shared<HepMC3::ReaderAsciiHepMC2>( fileName.c_str());
130 }
131 ATH_MSG_DEBUG("Using protocol [" << protocol << "] and write to ["<< fileName << "]");
132}
#define endmsg
static const char *const s_protocolSep
MsgStream & msg
Definition testRead.cxx:32

Member Data Documentation

◆ m_ioFrontend

std::shared_ptr<HepMC3::Reader> HepMcReaderTool::m_ioFrontend {nullptr}
protected

Abstract base class for the back-end.

Definition at line 73 of file HepMcReaderTool.h.

73{nullptr};

◆ 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 65 of file HepMcReaderTool.h.

◆ m_mcEventsOutputName

StringProperty HepMcReaderTool::m_mcEventsOutputName
protected

Location of the McEventCollection to be read out.

Definition at line 69 of file HepMcReaderTool.h.


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