The Gaudi Framework  v38r0 (2143aa4c)
GaudiKernel.Configurable.ConfigurableUser Class Reference
Inheritance diagram for GaudiKernel.Configurable.ConfigurableUser:
Collaboration diagram for GaudiKernel.Configurable.ConfigurableUser:

Public Member Functions

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

Private Member Functions

def __addActiveUseOf (self, other)
 
def __addPassiveUseOf (self, other)
 
def _instanceName (self, cls)
 

Private Attributes

 _enabled
 
 __users__
 
 _applied
 
 __used_instances__
 

Static Private Attributes

 __slots__
 
 __used_configurables__
 
 __queried_configurables__
 

Additional Inherited Members

- Static Public Attributes inherited from GaudiKernel.Configurable.Configurable
 propertyNoValue
 
 indentUnit
 
 printHeaderWidth
 
 printHeaderPre
 
 allConfigurables
 
 configurableServices
 

Detailed Description

Definition at line 1360 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

def 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 type(used) is 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 type(used) is 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 type(queried) is 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()

def 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()

def 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__()

def 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.

Reimplemented in ConfigurableUser.ExampleApplication, ConfigurableUser.ExampleCommon, GaudiExamples.Configuration.GaudiExamplesCommonConf, Gaudi.ConfUser.GaudiPersistency, and ConfigurableUser.ExampleIO.

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__()

def 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()

def GaudiKernel.Configurable.ConfigurableUser._instanceName (   self,
  cls 
)
private
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 type(cls) is str:
1551  clName = cls
1552  else:
1553  clName = cls.__name__
1554  return "%s_%s" % (self.name(), clName)
1555 

◆ applyConf()

def 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()

def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1452 of file Configurable.py.

1452  def getDlls(self):
1453  return None
1454 

◆ getGaudiType()

def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   cls)

Definition at line 1449 of file Configurable.py.

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

◆ getHandle()

def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1455 of file Configurable.py.

1455  def getHandle(self):
1456  return None
1457 

◆ getUsedInstance()

def 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()

def 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()

def 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()

def 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__

GaudiKernel.Configurable.ConfigurableUser.__queried_configurables__
staticprivate

Definition at line 1378 of file Configurable.py.

◆ __slots__

GaudiKernel.Configurable.ConfigurableUser.__slots__
staticprivate

Definition at line 1361 of file Configurable.py.

◆ __used_configurables__

GaudiKernel.Configurable.ConfigurableUser.__used_configurables__
staticprivate

Definition at line 1375 of file Configurable.py.

◆ __used_instances__

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
private

Definition at line 1386 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1384 of file Configurable.py.


The documentation for this class was generated from the following file:
gaudirun.type
type
Definition: gaudirun.py:160
GaudiKernel.ConfigurableDb
Definition: ConfigurableDb.py:1