ATLAS Offline Software
Loading...
Searching...
No Matches
AsgToolConfig.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9#ifndef ASG_TOOLS_ASG_TOOL_CONFIG_H
10#define ASG_TOOLS_ASG_TOOL_CONFIG_H
11
13#include <AsgTools/ToolHandle.h>
14
15namespace asg
16{
17 class AsgTool;
18
20
22 {
23 //
24 // public interface
25 //
26
32 public:
33 AsgToolConfig () = default;
34
35
41 public:
42 explicit AsgToolConfig (const std::string& val_typeAndName);
43
44
50 public:
51 explicit AsgToolConfig (const AsgComponentConfig& val_config);
52
53
80 public:
81 template<typename T> ::StatusCode
82 makeTool (ToolHandle<T>& toolHandle,
83 std::shared_ptr<void>& cleanup,
84 bool allowNestedName = false) const;
85
86
104 public:
105 template<typename T> ::StatusCode
106 makePrivateTool (ToolHandle<T>& toolHandle) const;
107
108
109
110 //
111 // private interface
112 //
113 };
114
115
116
117 //
118 // template methods
119 //
120
121#ifdef XAOD_STANDALONE
122
123 template<typename T> ::StatusCode AsgToolConfig ::
124 makeTool (ToolHandle<T>& toolHandle,
125 std::shared_ptr<void>& cleanup,
126 bool allowNestedName) const
127 {
128 using namespace msgComponentConfig;
129
130 std::string prefix = toolHandle.parentName() + ".";
131
132 std::unique_ptr<T> tool;
133 ANA_CHECK (makeComponentExpert (tool, "new %1% (\"%2%\")", allowNestedName, prefix));
134 ANA_CHECK (tool->initialize());
135
136 std::shared_ptr<T> mycleanup (tool.release());
137 toolHandle = mycleanup.get();
138 cleanup = mycleanup;
139
140 ANA_MSG_DEBUG ("Created component of type " << type());
141 return StatusCode::SUCCESS;
142 }
143
144 template<typename T> ::StatusCode AsgToolConfig ::
145 makePrivateTool (ToolHandle<T>& toolHandle) const
146 {
147 using namespace msgComponentConfig;
148
149 INamedInterface *parentNamed = toolHandle.parent();
150 if (parentNamed == nullptr)
151 {
152 ANA_MSG_ERROR ("need to pass private ToolHandle into makePrivateTool");
153 return StatusCode::FAILURE;
154 }
155 AsgComponent *parentComponent = dynamic_cast<AsgComponent*>(parentNamed);
156 if (parentComponent == nullptr)
157 {
158 ANA_MSG_ERROR ("parent \"" << parentNamed->name() << "\" for makePrivateTool() does not inherit from AsgComponent");
159 return StatusCode::FAILURE;
160 }
161
162 std::shared_ptr<void> cleanup;
163 if (makeTool (toolHandle, cleanup).isFailure())
164 return StatusCode::FAILURE;
165 parentComponent->addCleanup (cleanup);
166 return StatusCode::SUCCESS;
167 }
168
169#else
170
171 template<typename T> ::StatusCode AsgToolConfig ::
172 makeTool (ToolHandle<T>& toolHandle,
173 std::shared_ptr<void>& /*cleanup*/,
174 bool allowNestedName) const
175 {
176 using namespace msgComponentConfig;
177
178 std::string prefix = toolHandle.parentName() + ".";
179
180 ANA_CHECK (configureComponentExpert (prefix, allowNestedName));
181 toolHandle.setTypeAndName (type() + "/" + name());
182 ANA_CHECK (toolHandle.retrieve());
183
184 ANA_MSG_DEBUG ("Created component of type " << type());
185 return StatusCode::SUCCESS;
186 }
187
188 template<typename T> ::StatusCode AsgToolConfig ::
189 makePrivateTool (ToolHandle<T>& toolHandle) const
190 {
191 using namespace msgComponentConfig;
192
193 // This is safe, because the `makeTool` function in athena does
194 // not use the cleanup argument.
195 std::shared_ptr<void> cleanup;
196 return makeTool (toolHandle, cleanup);
197 }
198
199#endif
200
201}
202
203#endif
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
an object that stores the configuration for an AsgComponent and is able to create one from it
const std::string & name() const noexcept
the name of the component
const std::string & type() const noexcept
the type of the component
StatusCode configureComponentExpert(const std::string &prefix, bool nestedNames) const
add component configuration to configuration service (expert only)
AsgComponentConfig()=default
standard constructor
AsgToolConfig()=default
standard constructor
::StatusCode makeTool(ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
make a tool with the given configuration
::StatusCode makePrivateTool(ToolHandle< T > &toolHandle) const
make a private tool with the given configuration
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47