The Gaudi Framework  master (69a68366)
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 1352 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1372 of file Configurable.py.

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

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 1419 of file Configurable.py.

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

◆ __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 1428 of file Configurable.py.

1428 def __addPassiveUseOf(self, other):
1429 """
1430 Declare that we are going to retrieve property values from the
1431 ConfigurableUser 'other' in our __apply_configuration__.
1432 """
1433 if not isinstance(other, ConfigurableUser):
1434 raise Error(
1435 "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser"
1436 % (self.name(), other.name())
1437 )
1438 other.__addActiveUseOf(self)
1439

◆ __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 1519 of file Configurable.py.

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

◆ __detach_used__()

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

Definition at line 1450 of file Configurable.py.

1450 def __detach_used__(self):
1451 """
1452 Remove this ConfigurableUser instance from the users list of the used
1453 instances.
1454 """
1455 for used in self.__used_instances__:
1456 if hasattr(used, "__users__"): # allow usage of plain Configurables
1457 used.__users__.remove(self)
1458

◆ _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 1535 of file Configurable.py.

1535 def _instanceName(self, cls):
1536 """
1537 Function used to define the name of the private instance of a given class
1538 name.
1539 This method is used when the __used_configurables_property__ declares the
1540 need of a private used configurable without specifying the name.
1541 """
1542 if isinstance(cls, str):
1543 clName = cls
1544 else:
1545 clName = cls.__name__
1546 return "%s_%s" % (self.name(), clName)
1547

◆ applyConf()

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

Definition at line 1528 of file Configurable.py.

1528 def applyConf(self):
1529 """
1530 Function to be overridden to convert the high level configuration into a
1531 low level one.
1532 """
1533 pass
1534

◆ getDlls()

GaudiKernel.Configurable.ConfigurableUser.getDlls ( self)

Definition at line 1444 of file Configurable.py.

1444 def getDlls(self):
1445 return None
1446

◆ getGaudiType()

GaudiKernel.Configurable.ConfigurableUser.getGaudiType ( cls)

Definition at line 1441 of file Configurable.py.

1441 def getGaudiType(cls):
1442 return "User"
1443

◆ getHandle()

GaudiKernel.Configurable.ConfigurableUser.getHandle ( self)

Definition at line 1447 of file Configurable.py.

1447 def getHandle(self):
1448 return None
1449

◆ getUsedInstance()

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

Definition at line 1548 of file Configurable.py.

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

◆ isApplicable()

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

Reimplemented from GaudiKernel.Configurable.Configurable.

Definition at line 1561 of file Configurable.py.

1561 def isApplicable(self):
1562 """
1563 Return True is the instance can be "applied".
1564 """
1565 return (not self.__users__) and (not self._applied)
1566
1567
1568# 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 1508 of file Configurable.py.

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

◆ 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 1459 of file Configurable.py.

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

Member Data Documentation

◆ __queried_configurables__

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

Definition at line 1370 of file Configurable.py.

◆ __slots__

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

Definition at line 1353 of file Configurable.py.

◆ __used_configurables__

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

Definition at line 1367 of file Configurable.py.

◆ __used_instances__

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

Definition at line 1386 of file Configurable.py.

◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__ = []
private

Definition at line 1377 of file Configurable.py.

◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied = False
protected

Definition at line 1378 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled = _enabled
protected

Definition at line 1376 of file Configurable.py.


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