ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
EL::PythonConfigBase Class Reference

the base class for the python configuration of any asg::AsgComponent More...

#include <PythonConfigBase.h>

Inheritance diagram for EL::PythonConfigBase:
Collaboration diagram for EL::PythonConfigBase:

Public Member Functions

 PythonConfigBase ()
 standard constructor More...
 
 PythonConfigBase (const std::string &val_typeAndName)
 initializing constructor More...
 
virtual ~PythonConfigBase ()=default
 Virtual destructor, to make PyROOT happy. More...
 
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...
 
const std::string & componentType () const noexcept
 the actual component type to create More...
 
void setComponentType (const std::string &val_componentType)
 

Private Member Functions

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

Private Attributes

std::string m_componentType
 the value of componentType More...
 
std::string m_type
 the value of type More...
 
std::string m_name
 the value of name More...
 
std::map< std::string, details::AsgComponentPrivateToolConfig > m_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

the base class for the python configuration of any asg::AsgComponent

Most of the functionality is provided by asg::AsgComponentConfig, with this class mostly adding one extra member that allows to the the component type. Another benefit of this class is that this is its own type, meaning overload resolution can tell that an object got set from python.

Definition at line 35 of file PythonConfigBase.h.

Constructor & Destructor Documentation

◆ PythonConfigBase() [1/2]

EL::PythonConfigBase::PythonConfigBase ( )

standard constructor

Guarantee
strong
Failures
out of memory I

Definition at line 21 of file PythonConfigBase.cxx.

23  {}

◆ PythonConfigBase() [2/2]

EL::PythonConfigBase::PythonConfigBase ( const std::string &  val_typeAndName)
explicit

initializing constructor

Guarantee
strong
Failures
out of memory II

Definition at line 27 of file PythonConfigBase.cxx.

29  : AsgComponentConfig (val_typeAndName)
30  {}

◆ ~PythonConfigBase()

virtual EL::PythonConfigBase::~PythonConfigBase ( )
virtualdefault

Virtual destructor, to make PyROOT happy.

Without it ROOT 6.22+ does not allow Python classes to inherit from this type.

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  }

◆ componentType()

const std::string & EL::PythonConfigBase::componentType ( ) const
noexcept

the actual component type to create

Guarantee
no-fail / strong
Failures
out of memory II [2]

Definition at line 34 of file PythonConfigBase.cxx.

36  {
37  return m_componentType;
38  }

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

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

◆ setComponentType()

void EL::PythonConfigBase::setComponentType ( const std::string &  val_componentType)

Definition at line 42 of file PythonConfigBase.cxx.

44  {
45  m_componentType = val_componentType;
46  }

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

std::string EL::PythonConfigBase::m_componentType
private

the value of componentType

Definition at line 87 of file PythonConfigBase.h.

◆ 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
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
asg::AsgComponentConfig::setName
void setName(const std::string &val_name)
set the value of name
Definition: AsgComponentConfig.cxx:98
EL::PythonConfigBase::m_componentType
std::string m_componentType
the value of componentType
Definition: PythonConfigBase.h:87
asg::AsgComponentConfig::name
const std::string & name() const noexcept
the name of the component
Definition: AsgComponentConfig.cxx:90
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