The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
GaudiKernel.Configurable.ConfigurableUser Class Reference
Inheritance diagram for GaudiKernel.Configurable.ConfigurableUser:
Collaboration diagram for GaudiKernel.Configurable.ConfigurableUser:

Public Member Functions

 __init__ (self, name=Configurable.DefaultName, _enabled=True, **kwargs)
 getGaudiType (cls)
 getDlls (self)
 getHandle (self)
 __detach_used__ (self)
 propagateProperty (self, name, others=None, force=True)
 propagateProperties (self, names=None, others=None, force=True)
 __apply_configuration__ (self)
 applyConf (self)
 getUsedInstance (self, name)
 isApplicable (self)
Public Member Functions inherited from GaudiKernel.Configurable.Configurable
 __new__ (cls, *args, **kwargs)
 __init__ (self, name=DefaultName)
 __getstate__ (self)
 __getnewargs__ (self)
 __setstate__ (self, dict)
 __len__ (self)
 __iter__ (self)
 __deepcopy__ (self, memo)
 __iadd__ (self, configs, descr=None)
 __getattr__ (self, attr)
 __setattr__ (self, name, value)
 __delattr__ (self, attr)
 __bool__ (self)
 remove (self, items)
 removeAll (self)
 copyChild (self, child)
 setParent (self, parentName)
 getParent (self)
 hasParent (self, parent)
 copyChildAndSetParent (self, cfg, parent)
 getChildren (self)
 getTools (self)
 children (self)
 getAllChildren (self)
 getSequence (self)
 setup (self)
 getProperties (self)
 getPropertiesWithDescription (self)
 getValuedProperties (self)
 properties (self)
 getDefaultProperties (cls)
 getDefaultProperty (cls, name)
 getProp (self, name)
 setProp (self, name, value)
 isPropertySet (self, name)
 getType (cls)
 getName (self)
 name (self)
 getJobOptName (self)
 isPublic (self)
 jobOptName (self)
 getFullName (self)
 getFullJobOptName (self)
 getPrintTitle (self)
 getTitleName (self)
 setDefaults (cls, handle)
 clone (self, name=None, **kwargs)
 splitName (self)
 addTool (self, tool, name=None)
 __repr__ (self)
 __str__ (self, indent=0, headerLastIndentUnit=indentUnit)
Public Member Functions inherited from GaudiKernel.ConfigurableMeta.ConfigurableMeta
 __new__ (self, name, bases, dct)
 __call__ (cls, *args, **kwargs)

Protected Member Functions

 _instanceName (self, cls)
Protected Member Functions inherited from GaudiKernel.Configurable.Configurable
 _isInSetDefaults (self)

Protected Attributes

 _enabled = _enabled
bool _applied = False
Protected Attributes inherited from GaudiKernel.Configurable.Configurable
 _name = self.__class__.DefaultedName
bool _inSetDefaults = False
bool _initok = True
bool _setupok = False
bool _unpickling = False
 _properties

Private Member Functions

 __addActiveUseOf (self, other)
 __addPassiveUseOf (self, other)

Private Attributes

list __users__ = []
list __used_instances__ = []

Static Private Attributes

dict __slots__
list __used_configurables__ = []
list __queried_configurables__ = []

Additional Inherited Members

Public Attributes inherited from GaudiKernel.Configurable.Configurable
 configurables
Static Public Attributes inherited from GaudiKernel.Configurable.Configurable
 propertyNoValue
str indentUnit = "| "
int printHeaderWidth = 100
int printHeaderPre = 5
dict allConfigurables = {}
dict configurableServices = {}
Static Protected Member Functions inherited from GaudiKernel.Configurable.Configurable
 _printHeader (indentStr, title)
 _printFooter (indentStr, title)
Static Protected Attributes inherited from GaudiKernel.Configurable.Configurable
bool _configurationLocked = False

Detailed Description

Definition at line 1348 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

GaudiKernel.Configurable.ConfigurableUser.__init__ ( self,
name = Configurable.DefaultName,
_enabled = True,
** kwargs )

Definition at line 1368 of file Configurable.py.

1368 def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1369 super().__init__(name)
1370 for n, v in kwargs.items():
1371 setattr(self, n, v)
1372 self._enabled = _enabled
1373 self.__users__ = []
1374 self._applied = False
1375
1376 # Needed to retrieve the actual class if the declaration in __used_configurables__
1377 # and __queried_configurables__ is done with strings.
1378 from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
1379
1380 # Set the list of users of the used configurables
1381 #
1382 self.__used_instances__ = []
1383 for used in self.__used_configurables__:
1384 # By default we want to use the default name of the instances
1385 # for the used configurables
1386 used_name = Configurable.DefaultName
1387 # If the entry in the list is a tuple, we need a named instance
1388 if isinstance(used, tuple):
1389 used, used_name = used # we re-set used to re-use the code below
1390 if not used_name:
1391 used_name = self._instanceName(used)
1392 # Check is 'used' is a string or not
1393 if isinstance(used, str):
1394 used_class = confDbGetConfigurable(used)
1395 else:
1396 used_class = used
1397 # Instantiate the configurable that we are going to use
1398 try:
1399 inst = used_class(name=used_name, _enabled=False)
1400 except AttributeError:
1401 # This cover the case where the used configurable is not a
1402 # ConfigurableUser instance, i.e. id doesn't have the attribute
1403 # '_enabled'.
1404 inst = used_class(name=used_name)
1405 self.__addActiveUseOf(inst)
1406 for queried in self.__queried_configurables__:
1407 try:
1408 if isinstance(queried, str):
1409 queried = confDbGetConfigurable(queried)
1410 inst = queried(_enabled=False)
1411 except AttributeError:
1412 inst = queried()
1413 self.__addPassiveUseOf(inst)
1414

Member Function Documentation

◆ __addActiveUseOf()

GaudiKernel.Configurable.ConfigurableUser.__addActiveUseOf ( self,
other )
private
Declare that we are going to modify the Configurable 'other' in our
__apply_configuration__.

Definition at line 1415 of file Configurable.py.

1415 def __addActiveUseOf(self, other):
1416 """
1417 Declare that we are going to modify the Configurable 'other' in our
1418 __apply_configuration__.
1419 """
1420 self.__used_instances__.append(other)
1421 if hasattr(other, "__users__"): # allow usage of plain Configurables
1422 other.__users__.append(self)
1423

◆ __addPassiveUseOf()

GaudiKernel.Configurable.ConfigurableUser.__addPassiveUseOf ( self,
other )
private
Declare that we are going to retrieve property values from the
ConfigurableUser 'other' in our __apply_configuration__.

Definition at line 1424 of file Configurable.py.

1424 def __addPassiveUseOf(self, other):
1425 """
1426 Declare that we are going to retrieve property values from the
1427 ConfigurableUser 'other' in our __apply_configuration__.
1428 """
1429 if not isinstance(other, ConfigurableUser):
1430 raise Error(
1431 f"'{self.name()}': Cannot make passive use of '{other.name()}', it is not a ConfigurableUser"
1432 )
1433 other.__addActiveUseOf(self)
1434

◆ __apply_configuration__()

GaudiKernel.Configurable.ConfigurableUser.__apply_configuration__ ( self)
Function to be overridden to convert the high level configuration into a
low level one.
The default implementation calls applyConf, which is the method defined
in some ConfigurableUser implementations.

Definition at line 1515 of file Configurable.py.

1515 def __apply_configuration__(self):
1516 """
1517 Function to be overridden to convert the high level configuration into a
1518 low level one.
1519 The default implementation calls applyConf, which is the method defined
1520 in some ConfigurableUser implementations.
1521 """
1522 return self.applyConf()
1523

◆ __detach_used__()

GaudiKernel.Configurable.ConfigurableUser.__detach_used__ ( self)
Remove this ConfigurableUser instance from the users list of the used
instances.

Definition at line 1445 of file Configurable.py.

1445 def __detach_used__(self):
1446 """
1447 Remove this ConfigurableUser instance from the users list of the used
1448 instances.
1449 """
1450 for used in self.__used_instances__:
1451 if hasattr(used, "__users__"): # allow usage of plain Configurables
1452 used.__users__.remove(self)
1453

◆ _instanceName()

GaudiKernel.Configurable.ConfigurableUser._instanceName ( self,
cls )
protected
Function used to define the name of the private instance of a given class
name.
This method is used when the __used_configurables_property__ declares the
need of a private used configurable without specifying the name.

Definition at line 1531 of file Configurable.py.

1531 def _instanceName(self, cls):
1532 """
1533 Function used to define the name of the private instance of a given class
1534 name.
1535 This method is used when the __used_configurables_property__ declares the
1536 need of a private used configurable without specifying the name.
1537 """
1538 if isinstance(cls, str):
1539 clName = cls
1540 else:
1541 clName = cls.__name__
1542 return f"{self.name()}_{clName}"
1543

◆ applyConf()

GaudiKernel.Configurable.ConfigurableUser.applyConf ( self)
Function to be overridden to convert the high level configuration into a
low level one.

Definition at line 1524 of file Configurable.py.

1524 def applyConf(self):
1525 """
1526 Function to be overridden to convert the high level configuration into a
1527 low level one.
1528 """
1529 pass
1530

◆ getDlls()

GaudiKernel.Configurable.ConfigurableUser.getDlls ( self)

Definition at line 1439 of file Configurable.py.

1439 def getDlls(self):
1440 return None
1441

◆ getGaudiType()

GaudiKernel.Configurable.ConfigurableUser.getGaudiType ( cls)

Definition at line 1436 of file Configurable.py.

1436 def getGaudiType(cls):
1437 return "User"
1438

◆ getHandle()

GaudiKernel.Configurable.ConfigurableUser.getHandle ( self)

Definition at line 1442 of file Configurable.py.

1442 def getHandle(self):
1443 return None
1444

◆ getUsedInstance()

GaudiKernel.Configurable.ConfigurableUser.getUsedInstance ( self,
name )
Return the used instance with a given name.

Definition at line 1544 of file Configurable.py.

1544 def getUsedInstance(self, name):
1545 """
1546 Return the used instance with a given name.
1547 """
1548 for i in self.__used_instances__:
1549 if i.name() == name:
1550 if hasattr(i, "_enabled"):
1551 # ensure that the instances retrieved through the method are
1552 # enabled
1553 i._enabled = True
1554 return i
1555 raise KeyError(name)
1556

◆ isApplicable()

GaudiKernel.Configurable.ConfigurableUser.isApplicable ( self)
Return True is the instance can be "applied".

Reimplemented from GaudiKernel.Configurable.Configurable.

Definition at line 1557 of file Configurable.py.

1557 def isApplicable(self):
1558 """
1559 Return True is the instance can be "applied".
1560 """
1561 return (not self.__users__) and (not self._applied)
1562
1563
1564# list of callables to be called after all the __apply_configuration__ are called.

◆ propagateProperties()

GaudiKernel.Configurable.ConfigurableUser.propagateProperties ( self,
names = None,
others = None,
force = True )
Call propagateProperty for each property listed in 'names'.
If 'names' is None, all the properties are propagated.

Definition at line 1504 of file Configurable.py.

1504 def propagateProperties(self, names=None, others=None, force=True):
1505 """
1506 Call propagateProperty for each property listed in 'names'.
1507 If 'names' is None, all the properties are propagated.
1508 """
1509 if names is None:
1510 # use all the non-private slots
1511 names = [p for p in self.__slots__ if not p.startswith("_")]
1512 for n in names:
1513 self.propagateProperty(n, others, force)
1514

◆ propagateProperty()

GaudiKernel.Configurable.ConfigurableUser.propagateProperty ( self,
name,
others = None,
force = True )
Propagate the property 'name' (if set) to other configurables (if possible).
'others' can be:
    None:
        propagate to all the entries in __used_configurables__
    a configurable instance:
        propagate only to it
    list of configurable instances:
        propagate to all of them.


The logic is:
- if the local property is set, the other property will be overwritten
- local property not set and other set => keep other
- local property not set and other not set => overwrite the default for
    ConfigurableUser instances and set the property for Configurables

Definition at line 1454 of file Configurable.py.

1454 def propagateProperty(self, name, others=None, force=True):
1455 """
1456 Propagate the property 'name' (if set) to other configurables (if possible).
1457 'others' can be:
1458 None:
1459 propagate to all the entries in __used_configurables__
1460 a configurable instance:
1461 propagate only to it
1462 list of configurable instances:
1463 propagate to all of them.
1464
1465
1466 The logic is:
1467 - if the local property is set, the other property will be overwritten
1468 - local property not set and other set => keep other
1469 - local property not set and other not set => overwrite the default for
1470 ConfigurableUser instances and set the property for Configurables
1471 """
1472 # transform 'others' to a list of configurable instances
1473 if others is None:
1474 others = self.__used_instances__
1475 elif type(others) not in [list, tuple]:
1476 others = [others]
1477 # these can be computed before the loop
1478 local_is_set = self.isPropertySet(name)
1479 value = self.getProp(name)
1480 # loop over the others that do have 'name' in their slots
1481 for other in [o for o in others if name in o.__slots__]:
1482 # If self property is set, use it
1483 if local_is_set:
1484 if other.isPropertySet(name):
1485 log.warning(
1486 "Property '{prop}' is set in both '{self}' and '{other}', using '{self}.{prop}'".format(
1487 self=self.name(), other=other.name(), prop=name
1488 )
1489 )
1490 other.setProp(name, value)
1491 # If not, and other property also not set, propagate the default
1492 elif not other.isPropertySet(name):
1493 if isinstance(other, ConfigurableUser):
1494 otherType = type(other._properties[name].getDefault())
1495 other._properties[name].setDefault(value)
1496 if otherType in (list, dict, set):
1497 # Special case for list and dictionaries:
1498 # also set the property to the same value of the default (copy)
1499 other.setProp(name, otherType(value))
1500 else:
1501 other.setProp(name, value)
1502 # If not set and other set, do nothing
1503
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

Member Data Documentation

◆ __queried_configurables__

list GaudiKernel.Configurable.ConfigurableUser.__queried_configurables__ = []
staticprivate

Definition at line 1366 of file Configurable.py.

◆ __slots__

dict GaudiKernel.Configurable.ConfigurableUser.__slots__
staticprivate
Initial value:
= {
"__users__": [],
"__used_instances__": [],
"_enabled": True,
"_applied": False,
}

Definition at line 1349 of file Configurable.py.

◆ __used_configurables__

list GaudiKernel.Configurable.ConfigurableUser.__used_configurables__ = []
staticprivate

Definition at line 1363 of file Configurable.py.

◆ __used_instances__

list GaudiKernel.Configurable.ConfigurableUser.__used_instances__ = []
private

Definition at line 1382 of file Configurable.py.

◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__ = []
private

Definition at line 1373 of file Configurable.py.

◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied = False
protected

Definition at line 1374 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled = _enabled
protected

Definition at line 1372 of file Configurable.py.


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