ATLAS Offline Software
Loading...
Searching...
No Matches
WriteDecorHandleTriplet.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#pragma once
6
9
10#include "AsgTools/AsgTool.h"
17#include "xAODPFlow/PFO.h"
20#include <memory>
21#include <stdexcept>
22
23template<typename T>
25{
26 std::unique_ptr<SG::WriteDecorHandle<xAOD::IParticleContainer, T>> m_standard;
27 std::unique_ptr<SG::WriteDecorHandle<xAOD::IParticleContainer, T>> m_charged;
28 std::unique_ptr<SG::WriteDecorHandle<xAOD::IParticleContainer, T>> m_neutral;
29 unsigned short m_objectType{};
30
31 void checkType() {
32 switch (m_objectType) {
37 return;
38 break;
39
40 default:
41 throw std::runtime_error(
42 "WriteDecorHandleTriplet: Unsupported input type " +
43 std::to_string(static_cast<int>(m_objectType)));
44 }
45
46 }
47
48 public:
49
50 void setObjectType(unsigned short type)
51 {
53 checkType();
54 }
55
58 const EventContext& ctx)
59 {
61 std::make_unique<
63 >(key, ctx);
64 }
65
68 const EventContext& ctx)
69 {
70 m_charged =
71 std::make_unique<
73 >(key, ctx);
74 }
75
78 const EventContext& ctx)
79 {
80 m_neutral =
81 std::make_unique<
83 >(key, ctx);
84 }
85
87 {
88 switch (m_objectType) {
89
92 return (*m_standard)(part);
93
95 {
96 auto& pfo = static_cast<const xAOD::PFO&>(part);
97 return pfo.isCharged()
98 ? (*m_charged)(pfo)
99 : (*m_neutral)(pfo);
100 }
101
103 {
104 auto& fe = static_cast<const xAOD::FlowElement&>(part);
105 return fe.isCharged()
106 ? (*m_charged)(fe)
107 : (*m_neutral)(fe);
108 }
109
110 default:
111 throw std::runtime_error("WriteDecorHandleTriplet: Unsupported input type");
112 }
113 }
114};
115
116template<typename T>
118{
122
123 static bool startsWith(
124 const std::string& value,
125 const std::string& prefix)
126 {
127 return value.compare(0, prefix.size(), prefix) == 0;
128 }
129
130 public:
131
133 asg::AsgTool* owner,
134 const std::string& propertyName,
135 const std::string& decorName,
136 const std::string& description)
137 : m_standard(
138 owner,
139 propertyName.c_str(),
140 decorName.c_str(),
141 description.c_str())
142 , m_charged(
143 owner,
144 ("Charged" + propertyName).c_str(),
145 decorName.c_str(),
146 ("Charged " + description).c_str())
147 , m_neutral(
148 owner,
149 ("Neutral" + propertyName).c_str(),
150 decorName.c_str(),
151 ("Neutral " + description).c_str())
152 {}
153
154 StatusCode assign(
155 const std::string& standardCont,
156 const std::string& chargedCont,
157 const std::string& neutralCont)
158 {
159 if (!standardCont.empty() && !startsWith(m_standard.key(), standardCont + ".")) {
160 ATH_CHECK(m_standard.assign(
161 standardCont + "." + m_standard.key()));
162 }
163
164 if (!chargedCont.empty() && !startsWith(m_charged.key(), chargedCont + ".")) {
165 ATH_CHECK(m_charged.assign(
166 chargedCont + "." + m_charged.key()));
167 }
168
169 if (!neutralCont.empty() && !startsWith(m_neutral.key(), neutralCont + ".")) {
170 ATH_CHECK(m_neutral.assign(
171 neutralCont + "." + m_neutral.key()));
172 }
173
174 return StatusCode::SUCCESS;
175 }
176
177 StatusCode initialize()
178 {
179 ATH_CHECK(m_standard.initialize());
180 ATH_CHECK(m_charged.initialize());
181 ATH_CHECK(m_neutral.initialize());
182
183 return StatusCode::SUCCESS;
184 }
185
186 WriteDecorHandleTriplet<T> makeHandles(const unsigned short& inputType, const EventContext& ctx) const
187 {
189 handles.setObjectType(inputType);
190
191
192 if (inputType == xAOD::Type::CaloCluster || inputType==xAOD::Type::TrackCaloCluster) {
193 handles.setStandard(m_standard, ctx);
194 }
195 else if (inputType == xAOD::Type::ParticleFlow || inputType==xAOD::Type::FlowElement) {
196 handles.setCharged(m_charged, ctx);
197 handles.setNeutral(m_neutral, ctx);
198 }
199
200 return handles;
201 }
202};
203
204
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for adding a decoration to an object.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
static bool startsWith(const std::string &value, const std::string &prefix)
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_charged
WriteDecorHandleKeyTriplet(asg::AsgTool *owner, const std::string &propertyName, const std::string &decorName, const std::string &description)
WriteDecorHandleTriplet< T > makeHandles(const unsigned short &inputType, const EventContext &ctx) const
StatusCode assign(const std::string &standardCont, const std::string &chargedCont, const std::string &neutralCont)
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_neutral
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_standard
std::unique_ptr< SG::WriteDecorHandle< xAOD::IParticleContainer, T > > m_neutral
void setStandard(const SG::WriteDecorHandleKey< xAOD::IParticleContainer > &key, const EventContext &ctx)
std::unique_ptr< SG::WriteDecorHandle< xAOD::IParticleContainer, T > > m_standard
void setNeutral(const SG::WriteDecorHandleKey< xAOD::IParticleContainer > &key, const EventContext &ctx)
void setCharged(const SG::WriteDecorHandleKey< xAOD::IParticleContainer > &key, const EventContext &ctx)
void setObjectType(unsigned short type)
T & operator()(const xAOD::IParticle &part)
std::unique_ptr< SG::WriteDecorHandle< xAOD::IParticleContainer, T > > m_charged
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
Class providing the definition of the 4-vector interface.
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:93
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ TrackCaloCluster
The object is a track-calo-cluster.
Definition ObjectType.h:51
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16