ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 
 AsgToolConfig (const std::string &val_typeAndName)
 initializing constructor More...
 
 AsgToolConfig (const AsgComponentConfig &val_config)
 initializing constructor More...
 
template<typename T >
::StatusCode makeTool (ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
 make a tool with the given configuration More...
 
template<typename T >
::StatusCode makePrivateTool (ToolHandle< T > &toolHandle) const
 make a private tool with the given configuration More...
 
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 More...
 
const std::string & type () const noexcept
 the type of the component More...
 
void setType (const std::string &val_type)
 set the value of type More...
 
const std::string & name () const noexcept
 the name of the component More...
 
void setName (const std::string &val_name)
 set the value of name More...
 
std::string typeAndName () const
 get type and name at the same time More...
 
void setTypeAndName (const std::string &val_typeAndName)
 set type and name at the same time More...
 
template<typename T >
StatusCode setProperty (const std::string &name, const T &value)
 set the given property More...
 
void setPropertyFromString (const std::string &name, const std::string &value)
 set a given property from a string value More...
 
StatusCode createPrivateTool (const std::string &name, const std::string &toolType)
 create a private tool of the given name and type More...
 
StatusCode addPrivateTool (const std::string &name, AsgComponentConfig toolConfig)
 add a private tool from the given configuration More...
 
std::string createPrivateToolInArray (const std::string &name, const std::string &toolType)
 the array version of createPrivateTool More...
 
std::string addPrivateToolInArray (const std::string &name, AsgComponentConfig toolConfig)
 the array version of addPrivateTool More...
 
StatusCode configureComponentExpert (const std::string &prefix, bool nestedNames) const
 add component configuration to configuration service (expert only) More...
 

Private Member Functions

StatusCode checkTypeName (bool nestedNames) const
 check that the type and name members have the correct format More...
 

Private Attributes

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

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  {}

◆ 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  {
242  AccessSubtoolData result;
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  }

◆ 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] = {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  }

◆ 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] = {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  }

◆ 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  }

◆ 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 364 of file AsgComponentConfig.cxx.

367  {
368  using namespace msgComponentConfig;
369 
370  ANA_CHECK (checkTypeName (nestedNames));
371 
372  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc","AsgComponentConfig");
373  ANA_CHECK (joSvc.retrieve());
374 
375  for (const auto& tool : m_privateTools)
376  {
377  ANA_CHECK (tool.second.m_config.configureComponentExpert (prefix + m_name + ".", true));
378  if (tool.second.m_propName.empty())
379  {
380  std::string toolPath = prefix + m_name + "." + tool.first;
381  joSvc->set (toolPath, tool.second.m_config.typeAndName());
382  }
383  }
384 
385  for (const auto& toolArray : m_toolArrays)
386  {
387  std::vector<std::string> valueArray;
388  for (const auto& tool : toolArray.second)
389  {
390  auto toolConfig = m_privateTools.find (tool);
391  if (toolConfig == m_privateTools.end())
392  {
393  ANA_MSG_ERROR ("Couldn't find private tool with name \"" << tool << "\"");
394  ANA_MSG_ERROR ("This is an internal inconsistency!");
395  return StatusCode::FAILURE;
396  }
397  valueArray.push_back (toolConfig->second.m_config.typeAndName());
398  }
399  std::string valueString = Gaudi::Utils::toString (valueArray);
400  std::string propertyPath = prefix + m_name + "." + toolArray.first;
401  joSvc->set (propertyPath, valueString);
402  }
403 
404  for (const auto& property : m_propertyValues)
405  {
406  std::string propertyPath = prefix + m_name + "." + property.first;
407  joSvc->set (propertyPath, property.second);
408  }
409 
410  return StatusCode::SUCCESS;
411  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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  }

◆ 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()

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  }

◆ 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 278 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 281 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 288 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 285 of file AsgComponentConfig.h.

◆ m_type

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

the value of type

Definition at line 275 of file AsgComponentConfig.h.


The documentation for this class was generated from the following files:
get_generator_info.result
result
Definition: get_generator_info.py:21
asg::AsgComponentConfig::setType
void setType(const std::string &val_type)
set the value of type
Definition: AsgComponentConfig.cxx:82
asg::AsgComponentConfig::m_propertyValues
std::map< std::string, std::string > m_propertyValues
the map of property values
Definition: AsgComponentConfig.h:288
asg::AsgComponentConfig::m_name
std::string m_name
the value of name
Definition: AsgComponentConfig.h:278
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
athena.value
value
Definition: athena.py:124
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
asg::AsgComponentConfig::m_toolArrays
std::map< std::string, std::vector< std::string > > m_toolArrays
the map of (private) tool handle arrays to manage, and the tools they contain
Definition: AsgComponentConfig.h:285
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
asg::AsgComponentConfig::AsgComponentConfig
AsgComponentConfig()=default
standard constructor
asg::AsgComponentConfig::m_type
std::string m_type
the value of type
Definition: AsgComponentConfig.h:275
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
asg::AsgComponentConfig::checkTypeName
StatusCode checkTypeName(bool nestedNames) const
check that the type and name members have the correct format
Definition: AsgComponentConfig.cxx:214
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
asg::AsgComponentConfig::addPrivateToolInArray
std::string addPrivateToolInArray(const std::string &name, AsgComponentConfig toolConfig)
the array version of addPrivateTool
Definition: AsgComponentConfig.cxx:189
asg::AsgComponentConfig::type
const std::string & type() const noexcept
the type of the component
Definition: AsgComponentConfig.cxx:74
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
asg::AsgComponentConfig::configureComponentExpert
StatusCode configureComponentExpert(const std::string &prefix, bool nestedNames) const
add component configuration to configuration service (expert only)
Definition: AsgComponentConfig.cxx:365
asg::AsgComponentConfig::setName
void setName(const std::string &val_name)
set the value of name
Definition: AsgComponentConfig.cxx:98
asg::AsgComponentConfig::name
const std::string & name() const noexcept
the name of the component
Definition: AsgComponentConfig.cxx:90
asg::AsgToolConfig::makeTool
::StatusCode makeTool(ToolHandle< T > &toolHandle, std::shared_ptr< void > &cleanup, bool allowNestedName=false) const
make a tool with the given configuration
asg::AsgComponentConfig::addPrivateTool
StatusCode addPrivateTool(const std::string &name, AsgComponentConfig toolConfig)
add a private tool from the given configuration
Definition: AsgComponentConfig.cxx:168
asg::AsgComponentConfig::accessSubtool
AccessSubtoolData accessSubtool(const std::string &name, std::size_t split)
Definition: AsgComponentConfig.cxx:240
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
ServiceHandle< Gaudi::Interfaces::IOptionsSvc >
asg::AsgComponentConfig::m_privateTools
std::map< std::string, details::AsgComponentPrivateToolConfig > m_privateTools
the map of (private) tools to create
Definition: AsgComponentConfig.h:281
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288