ATLAS Offline Software
Loading...
Searching...
No Matches
python.PythonConfig.PrivateToolConfig Class Reference
Collaboration diagram for python.PythonConfig.PrivateToolConfig:

Public Member Functions

 __init__ (self, algorithm, prefix, type)
 __getattr__ (self, name)
 __setattr__ (self, key, value)
 __str__ (self)

Protected Attributes

 _algorithm = algorithm
 _prefix = prefix
 _type = type
dict _props = {}

Detailed Description

Standalone Private Tool Configuration

This class is used to mimic the behaviour of Athena tool configurable
classes. To be able to set the properties of private tools used by
dual-use algorithms in a way that's valid for both Athena and EventLoop.

Definition at line 284 of file PythonConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.PythonConfig.PrivateToolConfig.__init__ ( self,
algorithm,
prefix,
type )
Constructor for an private tool configuration object

Definition at line 292 of file PythonConfig.py.

292 def __init__( self, algorithm, prefix, type ):
293 """Constructor for an private tool configuration object
294 """
295
296 self._algorithm = algorithm
297 self._prefix = prefix
298 self._type = type
299 self._props = {}
300

Member Function Documentation

◆ __getattr__()

python.PythonConfig.PrivateToolConfig.__getattr__ ( self,
name )
Get a previously set property value from the configuration

This function allows us to retrieve the value of a tool property that
was already set for an algorithm's private tool, to possibly use it in
some configuration decisions in the Python code itself.

Keyword arguments:
  name -- The name of the property

Definition at line 301 of file PythonConfig.py.

301 def __getattr__( self, name ):
302 """Get a previously set property value from the configuration
303
304 This function allows us to retrieve the value of a tool property that
305 was already set for an algorithm's private tool, to possibly use it in
306 some configuration decisions in the Python code itself.
307
308 Keyword arguments:
309 name -- The name of the property
310 """
311
312 # Short-circuit internal/dunder attribute lookups, which are never
313 # properties (and would otherwise recurse if '_props' is missing):
314 if name.startswith( '_' ):
315 raise AttributeError( name )
316
317 # Fail if the property was not (yet) set:
318 if name not in self._props:
319 raise AttributeError(
320 f'Property "{name}" was not set on '
321 f'"{self._algorithm.type()}/{self._algorithm.name()}.{self._prefix}"' )
322
323 # Return the property value:
324 return self._props[ name ]
325

◆ __setattr__()

python.PythonConfig.PrivateToolConfig.__setattr__ ( self,
key,
value )
Set a tool property on an existing configuration object

This function allows us to set/override properties on a private tool
of an algorithm configuration object. Allowing for the following syntax:

   alg = ...
   alg.Tool.IntProperty = 66
   alg.Tool.FloatProperty = 3.141592
   alg.Tool.StringProperty = "Foo"

Keyword arguments:
  key   -- The key/name of the property
  value -- The value to set for the property

Definition at line 326 of file PythonConfig.py.

326 def __setattr__( self, key, value ):
327 """Set a tool property on an existing configuration object
328
329 This function allows us to set/override properties on a private tool
330 of an algorithm configuration object. Allowing for the following syntax:
331
332 alg = ...
333 alg.Tool.IntProperty = 66
334 alg.Tool.FloatProperty = 3.141592
335 alg.Tool.StringProperty = "Foo"
336
337 Keyword arguments:
338 key -- The key/name of the property
339 value -- The value to set for the property
340 """
341
342 # Private variables should be set directly:
343 if key[ 0 ] == '_':
344 return super().__setattr__( key, value )
345
346 # Construct the full name, used in the C++ code:
347 fullName = self._prefix + "." + key
348
349 # Set the property, and remember its value:
350 self._algorithm.setPropertyFromString( fullName,
351 stringPropValue( value ) )
352 self._props[ key ] = copy.deepcopy( value )
353

◆ __str__()

python.PythonConfig.PrivateToolConfig.__str__ ( self)
Print the private tool configuration in a user friendly way

This is just to help with debugging configurations, allowing
the user to get a nice printout of their job configuration.

Definition at line 354 of file PythonConfig.py.

354 def __str__( self ):
355 """Print the private tool configuration in a user friendly way
356
357 This is just to help with debugging configurations, allowing
358 the user to get a nice printout of their job configuration.
359 """
360
361 name = f'Private Tool {self._type}/{self._prefix}'
362 result = ' \n'
363 result += PythonConfig._printHeader( name )
364 result += '\n'
365 for key, value in sorted( self._props.items() ):
366 if isinstance( value, str ):
367 printedValue = f"'{value}'"
368 else:
369 printedValue = value
370 result += f"|- {key}: {indentBy( printedValue, '| ' )}\n"
371 result += PythonConfig._printFooter( name )
372 return result
373
374

Member Data Documentation

◆ _algorithm

python.PythonConfig.PrivateToolConfig._algorithm = algorithm
protected

Definition at line 296 of file PythonConfig.py.

◆ _prefix

python.PythonConfig.PrivateToolConfig._prefix = prefix
protected

Definition at line 297 of file PythonConfig.py.

◆ _props

dict python.PythonConfig.PrivateToolConfig._props = {}
protected

Definition at line 299 of file PythonConfig.py.

◆ _type

python.PythonConfig.PrivateToolConfig._type = type
protected

Definition at line 298 of file PythonConfig.py.


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