ATLAS Offline Software
Loading...
Searching...
No Matches
GenBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef GENERATORMODULES_GENBASE_H
6#define GENERATORMODULES_GENBASE_H
7
9#include "GaudiKernel/ServiceHandle.h"
10#include "GaudiKernel/IIncidentSvc.h"
15
16#include "AtlasHepMC/GenEvent.h"
19
20
21#include <string>
22#include <vector>
23#include <map>
24
25
43class GenBase : public AthAlgorithm {
44public:
45
47
48
50 GenBase(const std::string& name, ISvcLocator* pSvcLocator);
51
53 virtual ~GenBase() { }
54
56
57
59
60 virtual StatusCode initialize() override;
61 virtual StatusCode execute(const EventContext&) override { return StatusCode::SUCCESS; }
63
64
66
67
73 if (events()->empty())
74 ATH_MSG_ERROR("McEventCollection is empty during first event access");
75 return *(events()->begin());
76 }
77
79 const HepMC::GenEvent* event_const( const EventContext& ctx ) const {
80 const McEventCollection* coll = events_const(ctx);
81 if (coll->empty())
82 ATH_MSG_ERROR("Const McEventCollection is empty during first event access");
83 return *(coll->begin());
84 }
85
91
93 const McEventCollection* events_const( const EventContext& ctx ) const {
95 if (!ret.isValid())
96 ATH_MSG_ERROR("No McEventCollection found in StoreGate with key " << m_mcevents_const.key());
97 return ret.cptr();
98 }
99
101
102
103protected:
104
106
107
108 std::string m_mcEventKey{};
110 BooleanProperty m_mkMcEvent{this, "MakeMcEvent", false, "Create a new MC event collection if it doesn't exist"};
112
113private:
114
115
117 SG::ReadHandleKey<McEventCollection> m_mcevents_const{ this, "McEventKey", "GEN_EVENT", "StoreGate key of the MC event collection" };
118
119};
120
121
122#endif
#define ATH_MSG_ERROR(x)
Helpers for checking error return status codes and reporting errors.
Property holding a SG store/key/clid from which a ReadHandle is made.
static const Attributes_t empty
Define macros for attributes used to control the static checker.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool empty() const noexcept
Returns true if the collection is empty.
HepMC::GenEvent *event ATLAS_NOT_CONST_THREAD_SAFE()
Access the current signal event (first in the McEventCollection).
Definition GenBase.h:72
McEventCollection *events ATLAS_NOT_CONST_THREAD_SAFE()
Access the current event's McEventCollection.
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT).
Definition GenBase.h:108
virtual StatusCode initialize() override
Definition GenBase.cxx:17
const HepMC::GenEvent * event_const(const EventContext &ctx) const
Access the current signal event (const).
Definition GenBase.h:79
virtual ~GenBase()
Virtual destructor.
Definition GenBase.h:53
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenBase.cxx:11
BooleanProperty m_mkMcEvent
Flag to determine if a new MC event collection should be made if it doesn't exist.
Definition GenBase.h:110
const McEventCollection * events_const(const EventContext &ctx) const
Access the current event's McEventCollection (const).
Definition GenBase.h:93
virtual StatusCode execute(const EventContext &) override
Execute method.
Definition GenBase.h:61
SG::ReadHandleKey< McEventCollection > m_mcevents_const
Const handle to the MC event collection.
Definition GenBase.h:117
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())