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

Protected Member Functions

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

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. More...
 
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. More...
 
HepMC::IO_BaseClass * m_ioBackend
 Abstract base class for the back-end. More...
 

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 }

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

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

◆ finalize()

StatusCode HepMcWriterTool::finalize ( )

Definition at line 79 of file HepMcWriterTool.cxx.

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

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

◆ 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:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
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
HepMcWriterTool::m_ioBackendURL
StringProperty m_ioBackendURL
URL of the I/O back-end (only "ASCII" for now...) glued with the name of the output file name.
Definition: HepMcWriterTool.h:82
HepMcWriterTool::m_mcEventsName
StringProperty m_mcEventsName
Location of the McEventCollection to be written out If there is more than 1 HepMC::GenEvent in the Mc...
Definition: HepMcWriterTool.h:88
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
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HepMcWriterTool::setupBackend
void setupBackend(Gaudi::Details::PropertyBase &ioBackendURL)
Method to configure the back-end to write out the HepMC::GenEvent.
Definition: HepMcWriterTool.cxx:122
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:32
HepMcWriterTool::m_ioBackend
HepMC::IO_BaseClass * m_ioBackend
Abstract base class for the back-end.
Definition: HepMcWriterTool.h:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
HepMcWriterTool::write
StatusCode write(const HepMC::GenEvent *evt)
Process the HepMC::GenEvent through the I/O backend.
Definition: HepMcWriterTool.cxx:112
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
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.