The Gaudi Framework  v36r16 (ea80daf8)
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 1359 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1379 of file Configurable.py.

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

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

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

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

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

◆ __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, ConfigurableUser.ExampleIO, and Gaudi.ConfUser.GaudiPersistency.

Definition at line 1526 of file Configurable.py.

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

◆ __detach_used__()

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

Definition at line 1457 of file Configurable.py.

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

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

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

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

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

◆ getDlls()

def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1451 of file Configurable.py.

1451  def getDlls(self):
1452  return None
1453 

◆ getGaudiType()

def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   cls)

Definition at line 1448 of file Configurable.py.

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

◆ getHandle()

def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1454 of file Configurable.py.

1454  def getHandle(self):
1455  return None
1456 

◆ getUsedInstance()

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

Definition at line 1555 of file Configurable.py.

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

◆ isApplicable()

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

Reimplemented from GaudiKernel.Configurable.Configurable.

Definition at line 1568 of file Configurable.py.

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

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

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

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

Member Data Documentation

◆ __queried_configurables__

GaudiKernel.Configurable.ConfigurableUser.__queried_configurables__
staticprivate

Definition at line 1377 of file Configurable.py.

◆ __slots__

GaudiKernel.Configurable.ConfigurableUser.__slots__
staticprivate

Definition at line 1360 of file Configurable.py.

◆ __used_configurables__

GaudiKernel.Configurable.ConfigurableUser.__used_configurables__
staticprivate

Definition at line 1374 of file Configurable.py.

◆ __used_instances__

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1393 of file Configurable.py.

◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1384 of file Configurable.py.

◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1385 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1383 of file Configurable.py.


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