ATLAS Offline Software
WriteHepMC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TruthIO/WriteHepMC.h"
6 
7 
8 WriteHepMC::WriteHepMC(const std::string& name, ISvcLocator* pSvcLocator)
9  : GenBase(name, pSvcLocator)
10 {
11  declareProperty("OutputFile", m_outfile="events.hepmc");
12  declareProperty("Precision", m_precision=8);
13 }
14 
15 
18 #ifdef HEPMC3
19  m_hepmcio.reset(new HepMC3::WriterAsciiHepMC2(m_outfile) );
20  m_hepmcio->set_precision(m_precision);
21 #else
22  m_hepmcio.reset( new HepMC::IO_GenEvent(m_outfile) );
23  m_hepmcio->precision(m_precision);
24 #endif
25  return StatusCode::SUCCESS;
26 }
27 
28 
30  // Just write out the first (i.e. signal) event in the collection
31 #ifdef HEPMC3
32  m_hepmcio->write_event(*(event_const()));
33 #else
34  m_hepmcio->write_event(event_const());
35 #endif
36  return StatusCode::SUCCESS;
37 }
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
WriteHepMC::m_outfile
std::string m_outfile
Definition: WriteHepMC.h:21
WriteHepMC::m_hepmcio
std::unique_ptr< HepMC::IO_GenEvent > m_hepmcio
Definition: WriteHepMC.h:27
WriteHepMC::m_precision
int m_precision
Definition: WriteHepMC.h:22
GenBase
Base class for common behaviour of MC truth algorithms.
Definition: GenBase.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
WriteHepMC::WriteHepMC
WriteHepMC(const std::string &name, ISvcLocator *pSvcLocator)
Definition: WriteHepMC.cxx:8
WriteHepMC::initialize
StatusCode initialize()
Definition: WriteHepMC.cxx:16
WriteHepMC::execute
StatusCode execute()
Definition: WriteHepMC.cxx:29
WriteHepMC.h
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17
GenBase::event_const
const HepMC::GenEvent * event_const() const
Access the current signal event (const)
Definition: GenBase.h:83