The Gaudi Framework  master (ff829712)
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 1360 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1380 of file Configurable.py.

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

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

1427 def __addActiveUseOf(self, other):
1428 """
1429 Declare that we are going to modify the Configurable 'other' in our
1430 __apply_configuration__.
1431 """
1432 self.__used_instances__.append(other)
1433 if hasattr(other, "__users__"): # allow usage of plain Configurables
1434 other.__users__.append(self)
1435

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

1436 def __addPassiveUseOf(self, other):
1437 """
1438 Declare that we are going to retrieve property values from the
1439 ConfigurableUser 'other' in our __apply_configuration__.
1440 """
1441 if not isinstance(other, ConfigurableUser):
1442 raise Error(
1443 "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser"
1444 % (self.name(), other.name())
1445 )
1446 other.__addActiveUseOf(self)
1447

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

1527 def __apply_configuration__(self):
1528 """
1529 Function to be overridden to convert the high level configuration into a
1530 low level one.
1531 The default implementation calls applyConf, which is the method defined
1532 in some ConfigurableUser implementations.
1533 """
1534 return self.applyConf()
1535

◆ __detach_used__()

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

Definition at line 1458 of file Configurable.py.

1458 def __detach_used__(self):
1459 """
1460 Remove this ConfigurableUser instance from the users list of the used
1461 instances.
1462 """
1463 for used in self.__used_instances__:
1464 if hasattr(used, "__users__"): # allow usage of plain Configurables
1465 used.__users__.remove(self)
1466

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

1543 def _instanceName(self, cls):
1544 """
1545 Function used to define the name of the private instance of a given class
1546 name.
1547 This method is used when the __used_configurables_property__ declares the
1548 need of a private used configurable without specifying the name.
1549 """
1550 if isinstance(cls, str):
1551 clName = cls
1552 else:
1553 clName = cls.__name__
1554 return "%s_%s" % (self.name(), clName)
1555

◆ applyConf()

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

Definition at line 1536 of file Configurable.py.

1536 def applyConf(self):
1537 """
1538 Function to be overridden to convert the high level configuration into a
1539 low level one.
1540 """
1541 pass
1542

◆ getDlls()

GaudiKernel.Configurable.ConfigurableUser.getDlls ( self)

Definition at line 1452 of file Configurable.py.

1452 def getDlls(self):
1453 return None
1454

◆ getGaudiType()

GaudiKernel.Configurable.ConfigurableUser.getGaudiType ( cls)

Definition at line 1449 of file Configurable.py.

1449 def getGaudiType(cls):
1450 return "User"
1451

◆ getHandle()

GaudiKernel.Configurable.ConfigurableUser.getHandle ( self)

Definition at line 1455 of file Configurable.py.

1455 def getHandle(self):
1456 return None
1457

◆ getUsedInstance()

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

Definition at line 1556 of file Configurable.py.

1556 def getUsedInstance(self, name):
1557 """
1558 Return the used instance with a given name.
1559 """
1560 for i in self.__used_instances__:
1561 if i.name() == name:
1562 if hasattr(i, "_enabled"):
1563 # ensure that the instances retrieved through the method are
1564 # enabled
1565 i._enabled = True
1566 return i
1567 raise KeyError(name)
1568

◆ isApplicable()

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

Reimplemented from GaudiKernel.Configurable.Configurable.

Definition at line 1569 of file Configurable.py.

1569 def isApplicable(self):
1570 """
1571 Return True is the instance can be "applied".
1572 """
1573 return (not self.__users__) and (not self._applied)
1574
1575
1576# 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 1516 of file Configurable.py.

1516 def propagateProperties(self, names=None, others=None, force=True):
1517 """
1518 Call propagateProperty for each property listed in 'names'.
1519 If 'names' is None, all the properties are propagated.
1520 """
1521 if names is None:
1522 # use all the non-private slots
1523 names = [p for p in self.__slots__ if not p.startswith("_")]
1524 for n in names:
1525 self.propagateProperty(n, others, force)
1526

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

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

Member Data Documentation

◆ __queried_configurables__

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

Definition at line 1378 of file Configurable.py.

◆ __slots__

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

Definition at line 1361 of file Configurable.py.

◆ __used_configurables__

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

Definition at line 1375 of file Configurable.py.

◆ __used_instances__

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

Definition at line 1394 of file Configurable.py.

◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__ = []
private

Definition at line 1385 of file Configurable.py.

◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied = False
protected

Definition at line 1386 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled = _enabled
protected

Definition at line 1384 of file Configurable.py.


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