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

an object that can create a AsgService More...

#include <AsgServiceConfig.h>

Inheritance diagram for asg::AsgServiceConfig:
Collaboration diagram for asg::AsgServiceConfig:

Public Member Functions

 AsgServiceConfig ()=default
 standard constructor More...
 
 AsgServiceConfig (const std::string &val_typeAndName)
 initializing constructor More...
 
 AsgServiceConfig (const AsgComponentConfig &val_config)
 initializing constructor More...
 
virtual ~AsgServiceConfig ()=default
 Virtual destructor, to make PyROOT happy. More...
 
template<typename T >
::StatusCode makeService (std::shared_ptr< T > &service) const
 
template<typename T >
::StatusCode makeService (ServiceHandle< T > &service) 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...
 
template<typename T >
::StatusCode makeService (std::shared_ptr< T > &service) const
 make a service with the given configuration More...
 
template<typename T >
::StatusCode makeService (ServiceHandle< T > &service) const
 

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 AsgService

Definition at line 24 of file AsgServiceConfig.h.

Constructor & Destructor Documentation

◆ AsgServiceConfig() [1/3]

asg::AsgServiceConfig::AsgServiceConfig ( )
default

standard constructor

Guarantee
strong
Failures
out of memory I

◆ AsgServiceConfig() [2/3]

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

initializing constructor

Guarantee
strong
Failures
out of memory II

Definition at line 24 of file AsgServiceConfig.cxx.

26  : AsgComponentConfig (val_typeAndName)
27  {}

◆ AsgServiceConfig() [3/3]

asg::AsgServiceConfig::AsgServiceConfig ( const AsgComponentConfig val_config)
explicit

initializing constructor

Guarantee
strong
Failures
out of memory II

Definition at line 31 of file AsgServiceConfig.cxx.

33  : AsgComponentConfig (val_config)
34  {}

◆ ~AsgServiceConfig()

virtual asg::AsgServiceConfig::~AsgServiceConfig ( )
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  }

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

◆ makeService() [1/4]

template<typename T >
::StatusCode asg::AsgServiceConfig::makeService ( ServiceHandle< T > &  service) const

◆ makeService() [2/4]

template<typename T >
::StatusCode asg::AsgServiceConfig::makeService ( ServiceHandle< T > &  service) const

Definition at line 166 of file AsgServiceConfig.h.

168  {
169  using namespace msgComponentConfig;
170 
171  ANA_CHECK (configureComponentExpert ("", false));
172  service.setTypeAndName (typeAndName());
173  ANA_CHECK (service.retrieve());
174  ANA_CHECK (dynamic_cast<::AthService*>(&*service)->sysInitialize());
175 
176  ANA_MSG_DEBUG ("Created component of type " << type());
177  return StatusCode::SUCCESS;
178  }

◆ makeService() [3/4]

template<typename T >
::StatusCode asg::AsgServiceConfig::makeService ( std::shared_ptr< T > &  service) const

make a service with the given configuration

\warn This is mostly meant as a low level interface to be used in unit tests and internally by framework functions that manage services. As a user you should mostly rely on the python configuration or on passing the AsgServiceConfig object to your framework, which will then create and manage the service for you.

\warn Regardless of which function you use, the memory management and cleanup of services differs between stand-alone use and Athena. In EventLoop you receive an owning pointer/handle that can be shared with other users and will release the service when the last reference is deleted. In Athena the framework itself will hold on to the service (or at least its configuration) and release it at the end of the job, even if no user code references it. As a user you should not rely on the service still being around after you destroy the last reference, or on the service being around after framework teardown has started.

Guarantee
strong
Failures
configuration errors
service creation/initialization errors

◆ makeService() [4/4]

template<typename T >
::StatusCode asg::AsgServiceConfig::makeService ( std::shared_ptr< T > &  service) const

Definition at line 145 of file AsgServiceConfig.h.

147  {
148  using namespace msgComponentConfig;
149 
150  ServiceHandle<T> serviceHandle (typeAndName(), "AsgServiceConfig");
151  ANA_CHECK (makeService (serviceHandle));
152 
153  // This creates an unmanaged shared pointer, i.e. a pointer that
154  // doesn't actually own the pointed to object, it will neither
155  // guarantee to keep the object around until its own destruction,
156  // nor will it ever trigger a destruction of the object on its own
157  // destruction. Since the athena framework will keep the services
158  // around until the end of the job, that ought to be safe if used
159  // as advertised.
160  service = std::shared_ptr<T> (std::shared_ptr<void>(), &*serviceHandle);
161 
162  ANA_MSG_DEBUG ("Created component of type " << type());
163  return StatusCode::SUCCESS;
164  }

◆ 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:122
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
AthService
Definition: AthService.h:32
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::typeAndName
std::string typeAndName() const
get type and name at the same time
Definition: AsgComponentConfig.cxx:106
asg::AsgComponentConfig::name
const std::string & name() const noexcept
the name of the component
Definition: AsgComponentConfig.cxx:90
asg::AsgServiceConfig::makeService
::StatusCode makeService(std::shared_ptr< T > &service) const
make a service 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