ATLAS Offline Software
Loading...
Searching...
No Matches
StandaloneToolHandle.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#ifndef ASG_TOOLS__STANDALONE_TOOL_HANDLE_H
9#define ASG_TOOLS__STANDALONE_TOOL_HANDLE_H
10
12
13namespace asg
14{
42
43 template<typename T> class StandaloneToolHandle final
44 {
47
48 public:
50 StandaloneToolHandle (const std::string& typeAndName)
52
53
56 StatusCode initialize ();
57
60 StatusCode retrieve ();
61
64 T *get () {
65 checkIsInitialized (); return m_pointer;}
66 const T *get () const {
67 checkIsInitialized (); return m_pointer;}
70 const T *operator -> () const {
71 checkIsInitialized (); return m_pointer;}
73 checkIsInitialized (); return *m_pointer;}
74 const T& operator * () const {
75 checkIsInitialized (); return *m_pointer;}
76
77
82 const ToolHandle<std::remove_const_t<T>>& getHandle ();
83
84
85
94
95 public:
96
97 auto typeAndName () const {
98 return m_config.typeAndName();}
99 auto name () const {
100 return m_config.name();}
101 void setTypeAndName (const std::string& typeAndName) {
103 m_config.setTypeAndName (typeAndName);}
104 template<typename T2>
105 StatusCode setProperty (const std::string& name, T2&& value) {
107 return m_config.setProperty (name, value);}
108 StatusCode createPrivateTool (const std::string& name,
109 const std::string& toolType) {
111 return m_config.createPrivateTool (name, toolType);}
112
113
114
117
118 private:
119
121 T *m_pointer {nullptr};
122
124 ToolHandle<std::remove_const_t<T>> m_toolHandle;
125
127 std::shared_ptr<void> m_cleanup;
128
131
132
134 void checkNotInitialized () const;
135
141 void checkIsInitialized () const;
142 };
143
144
145
146 template<typename T> StatusCode StandaloneToolHandle<T> ::
147 retrieve ()
148 {
149 if (m_pointer == nullptr)
150 return initialize ();
151 else
152 return StatusCode::SUCCESS;
153 }
154
155
156
157 template<typename T> StatusCode StandaloneToolHandle<T> ::
159 {
161 if (m_config.makeTool (m_toolHandle, m_cleanup, true).isFailure())
162 return StatusCode::FAILURE;
164 return StatusCode::SUCCESS;
165 }
166
167
168
169 template<typename T> const ToolHandle<std::remove_const_t<T>>& StandaloneToolHandle<T> ::
170 getHandle ()
171 {
173 return m_toolHandle;
174 }
175
176
177
178 template<typename T> void StandaloneToolHandle<T> ::
180 {
181 if (m_pointer)
182 throw std::logic_error ("trying to configure StandaloneToolHandle after it was initialized/retrieved");
183 }
184
185
186
187 template<typename T> void StandaloneToolHandle<T> ::
188 checkIsInitialized () const
189 {
190 if (m_pointer == nullptr)
191 throw std::logic_error ("trying to use StandaloneToolHandle that was never initialized/retrieved");
192 }
193
194
195
196 template <typename T>
197 std::ostream& operator << (std::ostream& str, const StandaloneToolHandle<T>& obj)
198 {
199 return str << "StandaloneToolHandle:" << obj.typeAndName();
200 }
201}
202
203#endif
an object that can create a AsgTool
an "initializing" ToolHandle for stand-alone applications
StatusCode createPrivateTool(const std::string &name, const std::string &toolType)
StatusCode setProperty(const std::string &name, T2 &&value)
ToolHandle< std::remove_const_t< CP::IMuonEfficiencyScaleFactors > > m_toolHandle
StatusCode retrieve()
initialize the tool, will succeed if the tool was already initialized
void checkNotInitialized() const
check that we are not initialized yet
void setTypeAndName(const std::string &typeAndName)
const ToolHandle< std::remove_const_t< T > > & getHandle()
get the contained handle
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
T * get()
access the wrapped tool
StandaloneToolHandle(const std::string &typeAndName)
void checkIsInitialized() const
check that we are initialized, forcing in-place initialization if necessary
std::ostream & operator<<(std::ostream &str, const AnaToolHandle< T > &obj)
standard output operator
void initialize()