ATLAS Offline Software
Loading...
Searching...
No Matches
asg::AsgToolConfig Class Reference

an object that can create a AsgTool More...

#include <AsgToolConfig.h>

Inheritance diagram for asg::AsgToolConfig:
Collaboration diagram for asg::AsgToolConfig:

Public Member Functions

 AsgToolConfig ()=default
 standard constructor
 AsgToolConfig (const std::string &val_typeAndName)
 initializing constructor
 AsgToolConfig (const AsgComponentConfig &val_config)
 initializing constructor
template<typename T>
::StatusCode makeTool (ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
 make a tool with the given configuration
template<typename T>
::StatusCode makePrivateTool (ToolHandle< T > &toolHandle) const
 make a private tool with the given configuration
template<typename T>
::StatusCode makeTool (ToolHandle< T > &toolHandle, std::shared_ptr< void > &, bool allowNestedName) const
template<typename T>
::StatusCode makePrivateTool (ToolHandle< T > &toolHandle) const
bool empty () const noexcept
 whether all properties are unset
const std::string & type () const noexcept
 the type of the component
void setType (const std::string &val_type)
 set the value of type
const std::string & name () const noexcept
 the name of the component
void setName (const std::string &val_name)
 set the value of name
std::string typeAndName () const
 get type and name at the same time
void setTypeAndName (const std::string &val_typeAndName)
 set type and name at the same time
template<typename T>
StatusCode setProperty (const std::string &name, const T &value)
 set the given property
template<typename T>
StatusCode setProperty (const std::string &name, const Gaudi::Property< T > &value)
void setPropertyFromString (const std::string &name, const std::string &value)
 set a given property from a string value
StatusCode createPrivateTool (const std::string &name, const std::string &toolType)
 create a private tool of the given name and type
StatusCode addPrivateTool (const std::string &name, AsgComponentConfig toolConfig)
 add a private tool from the given configuration
std::string createPrivateToolInArray (const std::string &name, const std::string &toolType)
 the array version of createPrivateTool
std::string addPrivateToolInArray (const std::string &name, AsgComponentConfig toolConfig)
 the array version of addPrivateTool
StatusCode configureComponentExpert (const std::string &prefix, bool nestedNames) const
 add component configuration to configuration service (expert only)

Private Member Functions

StatusCode checkTypeName (bool nestedNames) const
 check that the type and name members have the correct format
AccessSubtoolData accessSubtool (const std::string &name, std::size_t split)

Private Attributes

std::string m_type
 the value of type
std::string m_name
 the value of name
std::map< std::string, details::AsgComponentPrivateToolConfigm_privateTools
 the map of (private) tools to create
std::map< std::string, std::vector< std::string > > m_toolArrays
 the map of (private) tool handle arrays to manage, and the tools they contain
std::map< std::string, std::string > m_propertyValues
 the map of property values

Detailed Description

an object that can create a AsgTool

Definition at line 21 of file AsgToolConfig.h.

Constructor & Destructor Documentation

◆ AsgToolConfig() [1/3]

asg::AsgToolConfig::AsgToolConfig ( )
default

standard constructor

Guarantee
strong
Failures
out of memory I

◆ AsgToolConfig() [2/3]

asg::AsgToolConfig::AsgToolConfig ( const std::string & val_typeAndName)
explicit

initializing constructor

Guarantee
strong
Failures
out of memory II

Definition at line 24 of file AsgToolConfig.cxx.

26 : AsgComponentConfig (val_typeAndName)
27 {}
AsgComponentConfig()=default
standard constructor

◆ AsgToolConfig() [3/3]

asg::AsgToolConfig::AsgToolConfig ( const AsgComponentConfig & val_config)
explicit

initializing constructor

Guarantee
strong
Failures
out of memory II

Definition at line 31 of file AsgToolConfig.cxx.

33 : AsgComponentConfig (val_config)
34 {}

Member Function Documentation

◆ accessSubtool()

AsgComponentConfig::AccessSubtoolData asg::AsgComponentConfig::accessSubtool ( const std::string & name,
std::size_t split )
privateinherited

Definition at line 239 of file AsgComponentConfig.cxx.

241 {
243 auto subtool = m_privateTools.find (name.substr (0, split));
244 if (subtool == m_privateTools.end())
245 throw std::runtime_error ("trying to access unknown private tool: " + name.substr (0, split));
246 result.config = &(subtool->second.m_config);
247 result.prefix = name.substr (0, split + 1);
248 result.name = name.substr (split + 1);
249 return result;
250 }
std::map< std::string, details::AsgComponentPrivateToolConfig > m_privateTools
the map of (private) tools to create
const std::string & name() const noexcept
the name of the component
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
access the configuration for the given subtool

◆ addPrivateTool()

StatusCode asg::AsgComponentConfig::addPrivateTool ( const std::string & name,
AsgComponentConfig toolConfig )
inherited

add a private tool from the given configuration

This will ignore the name set in toolConfig and use whatever name is given instead.

Guarantee
basic
Failures
out of memory II

Definition at line 167 of file AsgComponentConfig.cxx.

170 {
171 using namespace msgComponentConfig;
172
173 auto split = name.find ('.');
174 if (split == std::string::npos)
175 {
176 toolConfig.setName (name);
177 m_privateTools[name] = {std::move(toolConfig), ""};
178 return StatusCode::SUCCESS;
179 } else
180 {
181 auto subtool = accessSubtool (name, split);
182 return subtool.config->addPrivateTool (subtool.name, std::move (toolConfig));
183 }
184 }
AccessSubtoolData accessSubtool(const std::string &name, std::size_t split)

◆ addPrivateToolInArray()

std::string asg::AsgComponentConfig::addPrivateToolInArray ( const std::string & name,
AsgComponentConfig toolConfig )
inherited

the array version of addPrivateTool

This will ignore the name set in toolConfig and use whatever name is given instead.

Guarantee
basic
Failures
out of memory II

Definition at line 188 of file AsgComponentConfig.cxx.

191 {
192 using namespace msgComponentConfig;
193
194 auto split = name.find ('.');
195 if (split == std::string::npos)
196 {
197 auto& arrayData = m_toolArrays[name];
198 auto myname = makeArrayName (name, arrayData.size());
199 toolConfig.setName (myname);
200 m_privateTools[myname] = {std::move(toolConfig), name};
201 arrayData.push_back (myname);
202 return myname;
203 } else
204 {
205 auto subtool = accessSubtool (name, split);
206 return subtool.prefix + subtool.config
207 ->addPrivateToolInArray (subtool.name, std::move (toolConfig));
208 }
209 }
std::map< std::string, std::vector< std::string > > m_toolArrays
the map of (private) tool handle arrays to manage, and the tools they contain

◆ checkTypeName()

StatusCode asg::AsgComponentConfig::checkTypeName ( bool nestedNames) const
privateinherited

check that the type and name members have the correct format

Guarantee
strong
Failures
type or name doesn't have proper format

Definition at line 213 of file AsgComponentConfig.cxx.

215 {
216 using namespace msgComponentConfig;
217
218 std::regex typeExpr ("[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*");
219 if (!std::regex_match (m_type, typeExpr))
220 {
221 ANA_MSG_ERROR ("type \"" << m_type << "\" does not match format expression");
222 return StatusCode::FAILURE;
223 }
224 std::regex nameExpr;
225 if (nestedNames)
226 nameExpr = std::regex ("[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*(@[0-9]+)?");
227 else
228 nameExpr = std::regex ("[A-Za-z_][A-Za-z0-9_]*(@[0-9]+)?");
229 if (!std::regex_match (m_name, nameExpr))
230 {
231 ANA_MSG_ERROR ("name \"" << m_name << "\" does not match format expression");
232 return StatusCode::FAILURE;
233 }
234 return StatusCode::SUCCESS;
235 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
std::string m_type
the value of type
std::string m_name
the value of name

◆ configureComponentExpert()

StatusCode asg::AsgComponentConfig::configureComponentExpert ( const std::string & prefix,
bool nestedNames ) const
inherited

add component configuration to configuration service (expert only)

In Athena we are not creating components (we leave that to the proper Athena services), but instead we load the configuration values up first, then ask for the component to be created the normal way. This makes sure that if we dump the configuration it will include this component, and as a bonus it avoids the whole issue of having to deal with Athena factory functions.

Guarantee
basic
Failures
configuration errors

Definition at line 385 of file AsgComponentConfig.cxx.

388 {
389 using namespace msgComponentConfig;
390
391 ANA_CHECK (checkTypeName (nestedNames));
392
393 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AsgComponentConfig");
394 ANA_CHECK (joSvc.retrieve());
395
396 for (const auto& tool : m_privateTools)
397 {
398 ANA_CHECK (tool.second.m_config.configureComponentExpert (prefix + m_name + ".", true));
399 if (tool.second.m_propName.empty())
400 {
401 std::string toolPath = prefix + m_name + "." + tool.first;
402 joSvc->set (toolPath, tool.second.m_config.typeAndName());
403 }
404 }
405
406 for (const auto& toolArray : m_toolArrays)
407 {
408 std::vector<std::string> valueArray;
409 for (const auto& tool : toolArray.second)
410 {
411 auto toolConfig = m_privateTools.find (tool);
412 if (toolConfig == m_privateTools.end())
413 {
414 ANA_MSG_ERROR ("Couldn't find private tool with name \"" << tool << "\"");
415 ANA_MSG_ERROR ("This is an internal inconsistency!");
416 return StatusCode::FAILURE;
417 }
418 valueArray.push_back (toolConfig->second.m_config.typeAndName());
419 }
420 std::string valueString = Gaudi::Utils::toString (valueArray);
421 std::string propertyPath = prefix + m_name + "." + toolArray.first;
422 joSvc->set (propertyPath, valueString);
423 }
424
425 for (const auto& property : m_propertyValues)
426 {
427 std::string propertyPath = prefix + m_name + "." + property.first;
428 joSvc->set (propertyPath, property.second);
429 }
430
431 return StatusCode::SUCCESS;
432 }
#define ANA_CHECK(EXP)
check whether the given expression was successful
std::map< std::string, std::string > m_propertyValues
the map of property values
StatusCode checkTypeName(bool nestedNames) const
check that the type and name members have the correct format

◆ createPrivateTool()

StatusCode asg::AsgComponentConfig::createPrivateTool ( const std::string & name,
const std::string & toolType )
inherited

create a private tool of the given name and type

This is the only way you can configure tool properties through AsgComponentConfig: You need to add it the tool to the component configuration and then you can set individual properties on the tool, using the property name "tool.property".

If you want to add a subtool for a tool, you can do this by calling it "tool.subtool". Note that you will have to create both the tool and the subtool this way, i.e. you can't configure a subtool without also configuring the tool that owns it.

You can apply this to tools held by either ToolHandle or asg::AnaToolHandle, but if you configure a tool held by an AnaToolHandle this way it will completely replace teh tool configuration done in the component itself.

The calling convention is somewhat inverted compared to setTypeAndName() calls, but otherwise they would be inverted compared to the setProperty() calls. :(

Guarantee
strong
Failures
out of memory II

Definition at line 149 of file AsgComponentConfig.cxx.

152 {
153 return addPrivateTool (name, AsgComponentConfig(toolType + "/" + name));
154 }
StatusCode addPrivateTool(const std::string &name, AsgComponentConfig toolConfig)
add a private tool from the given configuration

◆ createPrivateToolInArray()

std::string asg::AsgComponentConfig::createPrivateToolInArray ( const std::string & name,
const std::string & toolType )
inherited

the array version of createPrivateTool

This returns the actual name of the tool to allow setting properties on it.

Guarantee
basic
Failures
out of memory II

Definition at line 158 of file AsgComponentConfig.cxx.

161 {
162 return addPrivateToolInArray (name, AsgComponentConfig(toolType + "/" + name));
163 }
std::string addPrivateToolInArray(const std::string &name, AsgComponentConfig toolConfig)
the array version of addPrivateTool

◆ empty()

bool asg::AsgComponentConfig::empty ( ) const
noexceptinherited

whether all properties are unset

Guarantee
no-fail

Definition at line 63 of file AsgComponentConfig.cxx.

65 {
66 return
67 m_type.empty() && m_name.empty() &&
68 m_privateTools.empty() && m_propertyValues.empty();
69 }

◆ makePrivateTool() [1/2]

template<typename T>
::StatusCode asg::AsgToolConfig::makePrivateTool ( ToolHandle< T > & toolHandle) const

make a private tool with the given configuration

This requires a parent pointer to be set on the ToolHandle to work, and for the parent to derive from AsgComponent in AnalysisBase. That allows to attach the cleanup of the tool to the parent component.

For practical purposes, when using an AsgToolConfig to create a private tool owned by a parent tool/algorithm inside the initialize of the tool/algorithm, this is the preferred way of doing so.

Guarantee
basic
Failures
configuration errors
tool creation/initialization errors

◆ makePrivateTool() [2/2]

template<typename T>
::StatusCode asg::AsgToolConfig::makePrivateTool ( ToolHandle< T > & toolHandle) const

Definition at line 188 of file AsgToolConfig.h.

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 }
::StatusCode makeTool(ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
make a tool with the given configuration

◆ makeTool() [1/2]

template<typename T>
::StatusCode asg::AsgToolConfig::makeTool ( ToolHandle< T > & toolHandle,
std::shared_ptr< void > & ,
bool allowNestedName ) const

Definition at line 171 of file AsgToolConfig.h.

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 }
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
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)

◆ makeTool() [2/2]

template<typename T>
::StatusCode asg::AsgToolConfig::makeTool ( ToolHandle< T > & toolHandle,
std::shared_ptr< void > & cleanup,
bool allowNestedName = false ) const

make a tool with the given configuration

Note that the exact creational patterns are not determined yet (25 Mar 20), but presumably if you are using EventLoop you would rely on EventLoop to create your tool from this object. For use within unit tests we may use this method, but we may also change the signature.

We may also use this class as a replacement for AnaToolHandle in which case this would at least have to be updated to at the very least work on a ToolHandle, but so far this code isn't even dual-use.

The argument allowNestedName should probably be omitted in most cases. I mostly added it to allow AnaToolHandle to create new tools via an AsgToolConfig (06 Jan 21), for which a number of existing users rely on making nested names. Usually when you want a nested name you ought to set the parent on the ToolHandle and then use a non-nested name for the name of the config.

Guarantee
basic
Failures
configuration errors
tool creation/initialization errors

◆ name()

const std::string & asg::AsgComponentConfig::name ( ) const
noexceptinherited

the name of the component

Guarantee
no-fail

Definition at line 89 of file AsgComponentConfig.cxx.

91 {
92 return m_name;
93 }

◆ setName()

void asg::AsgComponentConfig::setName ( const std::string & val_name)
inherited

set the value of name

Guarantee
strong
Failures
out of memory II

Definition at line 97 of file AsgComponentConfig.cxx.

99 {
100 m_name = val_name;
101 }

◆ setProperty() [1/2]

template<typename T>
StatusCode asg::AsgComponentConfig::setProperty ( const std::string & name,
const Gaudi::Property< T > & value )
inherited

◆ setProperty() [2/2]

template<typename T>
StatusCode asg::AsgComponentConfig::setProperty ( const std::string & name,
const T & value )
inherited

set the given property

Guarantee
strong
Failures
could not convert to string
out of memory II

◆ setPropertyFromString()

void asg::AsgComponentConfig::setPropertyFromString ( const std::string & name,
const std::string & value )
inherited

set a given property from a string value

Guarantee
strong
Failures
out of memory II

Definition at line 132 of file AsgComponentConfig.cxx.

135 {
136 auto split = name.find ('.');
137 if (split == std::string::npos)
138 {
140 } else
141 {
142 auto subtool = accessSubtool (name, split);
143 subtool.config->setPropertyFromString (subtool.name, value);
144 }
145 }

◆ setType()

void asg::AsgComponentConfig::setType ( const std::string & val_type)
inherited

set the value of type

Guarantee
strong
Failures
out of memory II

Definition at line 81 of file AsgComponentConfig.cxx.

83 {
84 m_type = val_type;
85 }

◆ setTypeAndName()

void asg::AsgComponentConfig::setTypeAndName ( const std::string & val_typeAndName)
inherited

set type and name at the same time

Guarantee
basic
Failures
out of memory II

Definition at line 115 of file AsgComponentConfig.cxx.

117 {
118 const auto split = val_typeAndName.find ('/');
119 if (split == std::string::npos)
120 {
121 setType (val_typeAndName);
122 setName (val_typeAndName);
123 } else
124 {
125 setType (val_typeAndName.substr (0,split));
126 setName (val_typeAndName.substr (split+1));
127 }
128 }
void setType(const std::string &val_type)
set the value of type
void setName(const std::string &val_name)
set the value of name

◆ type()

const std::string & asg::AsgComponentConfig::type ( ) const
noexceptinherited

the type of the component

Guarantee
no-fail

Definition at line 73 of file AsgComponentConfig.cxx.

75 {
76 return m_type;
77 }

◆ typeAndName()

std::string asg::AsgComponentConfig::typeAndName ( ) const
inherited

get type and name at the same time

Guarantee
basic
Failures
out of memory II

Definition at line 105 of file AsgComponentConfig.cxx.

107 {
108 if (m_name == m_type)
109 return m_name;
110 return m_type + "/" + m_name;
111 }

Member Data Documentation

◆ m_name

std::string asg::AsgComponentConfig::m_name
privateinherited

the value of name

Definition at line 281 of file AsgComponentConfig.h.

◆ m_privateTools

std::map<std::string, details::AsgComponentPrivateToolConfig> asg::AsgComponentConfig::m_privateTools
privateinherited

the map of (private) tools to create

Definition at line 284 of file AsgComponentConfig.h.

◆ m_propertyValues

std::map<std::string,std::string> asg::AsgComponentConfig::m_propertyValues
privateinherited

the map of property values

Definition at line 291 of file AsgComponentConfig.h.

◆ m_toolArrays

std::map<std::string,std::vector<std::string> > asg::AsgComponentConfig::m_toolArrays
privateinherited

the map of (private) tool handle arrays to manage, and the tools they contain

Definition at line 288 of file AsgComponentConfig.h.

◆ m_type

std::string asg::AsgComponentConfig::m_type
privateinherited

the value of type

Definition at line 278 of file AsgComponentConfig.h.


The documentation for this class was generated from the following files: