ATLAS Offline Software
Loading...
Searching...
No Matches
HepMcReaderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// HepMcReaderTool.cxx
7// Implementation file for class HepMcReaderTool
8// Author: S.Binet<binet@cern.ch>
10
11
12// STL includes
13#include <algorithm>
14#include <cctype>
15
16
17//HepMC includes
21
22// McParticleTools includes
23#include "HepMcReaderTool.h"
24
25static const char * const s_protocolSep = ":";
26
29HepMcReaderTool::HepMcReaderTool( const std::string& type, const std::string& name, const IInterface* parent ) :
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}
40
44{
45 ATH_MSG_DEBUG("Calling destructor");
46}
47
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}
66
68{
69 ATH_MSG_INFO("Finalizing " << name() << "...");
70 return StatusCode::SUCCESS;
71}
72
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}
91
93{
94 m_ioFrontend->read_event(*evt);
95 return StatusCode::SUCCESS;
96}
97
98void HepMcReaderTool::setupFrontend( Gaudi::Details::PropertyBase& /*prop*/ )
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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const char *const s_protocolSep
value_type push_back(value_type pElem)
Add an element to the end of the collection.
void setupFrontend(Gaudi::Details::PropertyBase &ioFrontendURL)
Method to configure the front-end to read out the HepMC::GenEvent.
StatusCode initialize()
Athena Algorithm's Hooks.
StringProperty m_mcEventsOutputName
Location of the McEventCollection to be read out.
StatusCode read(HepMC::GenEvent *evt)
Process the HepMC::GenEvent through the I/O frontend.
std::shared_ptr< HepMC3::Reader > m_ioFrontend
Abstract base class for the back-end.
StringProperty m_ioFrontendURL
URL of the I/O front-end (only "ASCII" for now...) glued with the name of the input file name.
StatusCode finalize()
StatusCode execute()
virtual ~HepMcReaderTool()
Destructor:
HepMcReaderTool()
Default constructor:
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
MsgStream & msg
Definition testRead.cxx:32