ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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: More...
 
virtual ~HepMcReaderTool ()
 Destructor: More...
 
StatusCode initialize ()
 Athena Algorithm's Hooks. More...
 
StatusCode execute ()
 
StatusCode finalize ()
 
StatusCode read (HepMC::GenEvent *evt)
 Process the HepMC::GenEvent through the I/O frontend. More...
 

Protected Member Functions

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

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. More...
 
StringProperty m_mcEventsOutputName
 Location of the McEventCollection to be read out. More...
 
HepMC::IO_BaseClass * m_ioFrontend
 Abstract base class for the back-end. More...
 

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" );
47  m_ioFrontendURL.declareUpdateHandler( &HepMcReaderTool::setupFrontend,
48  this );
49 
50  declareProperty( "McEventsOutput",
51  m_mcEventsOutputName = "GEN_EVENT",
52  "Output location of the McEventCollection to read out" );
53 }

◆ ~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 }

◆ 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
93  McEventCollection * mcEvts = new McEventCollection;
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 }

◆ finalize()

StatusCode HepMcReaderTool::finalize ( )

Definition at line 84 of file HepMcReaderTool.cxx.

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

◆ 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 }

◆ 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 }

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:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HepMcReaderTool::m_ioFrontend
HepMC::IO_BaseClass * m_ioFrontend
Abstract base class for the back-end.
Definition: HepMcReaderTool.h:94
McEventCollection
McEventCollection
Definition: GeneratorObjectsTPCnv.cxx:60
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
physics_parameters.url
string url
Definition: physics_parameters.py:27
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HepMcReaderTool::read
StatusCode read(HepMC::GenEvent *evt)
Process the HepMC::GenEvent through the I/O frontend.
Definition: HepMcReaderTool.cxx:113
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:32
HepMcReaderTool::m_mcEventsOutputName
StringProperty m_mcEventsOutputName
Location of the McEventCollection to be read out.
Definition: HepMcReaderTool.h:87
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
HepMcReaderTool::m_ioFrontendURL
StringProperty m_ioFrontendURL
URL of the I/O front-end (only "ASCII" for now...) glued with the name of the input file name.
Definition: HepMcReaderTool.h:83
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
python.compressB64.c
def c
Definition: compressB64.py:93
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
HepMcReaderTool::setupFrontend
void setupFrontend(Gaudi::Details::PropertyBase &ioFrontendURL)
Method to configure the front-end to read out the HepMC::GenEvent.
Definition: HepMcReaderTool.cxx:124