The Gaudi Framework  v31r0 (aeb156f0)
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 (self)
 
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 __nonzero__ (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)
 

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

dictionary __slots__
 
list __used_configurables__ = []
 
list __queried_configurables__ = []
 

Additional Inherited Members

- Static Public Attributes inherited from GaudiKernel.Configurable.Configurable
 propertyNoValue
 
string indentUnit = '| '
 
int printHeaderWidth = 100
 
int printHeaderPre = 5
 
dictionary allConfigurables
 
dictionary configurableServices
 

Detailed Description

Definition at line 1265 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 1285 of file Configurable.py.

1285  def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1286  super(ConfigurableUser, self).__init__(name)
1287  for n, v in kwargs.items():
1288  setattr(self, n, v)
1289  self._enabled = _enabled
1290  self.__users__ = []
1291  self._applied = False
1292 
1293  # Needed to retrieve the actual class if the declaration in __used_configurables__
1294  # and __queried_configurables__ is done with strings.
1295  from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
1296 
1297  # Set the list of users of the used configurables
1298  #
1300  for used in self.__used_configurables__:
1301  # By default we want to use the default name of the instances
1302  # for the used configurables
1303  used_name = Configurable.DefaultName
1304  # If the entry in the list is a tuple, we need a named instance
1305  if type(used) is tuple:
1306  used, used_name = used # we re-set used to re-use the code below
1307  if not used_name:
1308  used_name = self._instanceName(used)
1309  # Check is 'used' is a string or not
1310  if type(used) is str:
1311  used_class = confDbGetConfigurable(used)
1312  else:
1313  used_class = used
1314  # Instantiate the configurable that we are going to use
1315  try:
1316  inst = used_class(name=used_name, _enabled=False)
1317  except AttributeError:
1318  # This cover the case where the used configurable is not a
1319  # ConfigurableUser instance, i.e. id doesn't have the attribute
1320  # '_enabled'.
1321  inst = used_class(name=used_name)
1322  self.__addActiveUseOf(inst)
1323  for queried in self.__queried_configurables__:
1324  try:
1325  if type(queried) is str:
1326  queried = confDbGetConfigurable(used)
1327  inst = queried(_enabled=False)
1328  except AttributeError:
1329  inst = queried()
1330  self.__addPassiveUseOf(inst)
1331 
def __init__(self, name=Configurable.DefaultName, _enabled=True, kwargs)

Member Function Documentation

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

1332  def __addActiveUseOf(self, other):
1333  """
1334  Declare that we are going to modify the Configurable 'other' in our
1335  __apply_configuration__.
1336  """
1337  self.__used_instances__.append(other)
1338  if hasattr(other, "__users__"): # allow usage of plain Configurables
1339  other.__users__.append(self)
1340 
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 1341 of file Configurable.py.

1341  def __addPassiveUseOf(self, other):
1342  """
1343  Declare that we are going to retrieve property values from the
1344  ConfigurableUser 'other' in our __apply_configuration__.
1345  """
1346  if not isinstance(other, ConfigurableUser):
1347  raise Error(
1348  "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser"
1349  % (self.name(), other.name()))
1350  other.__addActiveUseOf(self)
1351 
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.

Definition at line 1434 of file Configurable.py.

1435  """
1436  Function to be overridden to convert the high level configuration into a
1437  low level one.
1438  The default implementation calls applyConf, which is the method defined
1439  in some ConfigurableUser implementations.
1440  """
1441  return self.applyConf()
1442 
def GaudiKernel.Configurable.ConfigurableUser.__detach_used__ (   self)
Remove this ConfigurableUser instance from the users list of the used
instances.

Definition at line 1361 of file Configurable.py.

1361  def __detach_used__(self):
1362  """
1363  Remove this ConfigurableUser instance from the users list of the used
1364  instances.
1365  """
1366  for used in self.__used_instances__:
1367  if hasattr(used,
1368  "__users__"): # allow usage of plain Configurables
1369  used.__users__.remove(self)
1370 
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 1450 of file Configurable.py.

1450  def _instanceName(self, cls):
1451  """
1452  Function used to define the name of the private instance of a given class
1453  name.
1454  This method is used when the __used_configurables_property__ declares the
1455  need of a private used configurable without specifying the name.
1456  """
1457  if type(cls) is str:
1458  clName = cls
1459  else:
1460  clName = cls.__name__
1461  return "%s_%s" % (self.name(), clName)
1462 
def GaudiKernel.Configurable.ConfigurableUser.applyConf (   self)
Function to be overridden to convert the high level configuration into a
low level one.

Definition at line 1443 of file Configurable.py.

1443  def applyConf(self):
1444  """
1445  Function to be overridden to convert the high level configuration into a
1446  low level one.
1447  """
1448  pass
1449 
def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1355 of file Configurable.py.

1355  def getDlls(self):
1356  return None
1357 
def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   self)

Definition at line 1352 of file Configurable.py.

1352  def getGaudiType(self):
1353  return 'User'
1354 
def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1358 of file Configurable.py.

1358  def getHandle(self):
1359  return None
1360 
def GaudiKernel.Configurable.ConfigurableUser.getUsedInstance (   self,
  name 
)
Return the used instance with a given name.

Definition at line 1463 of file Configurable.py.

1463  def getUsedInstance(self, name):
1464  """
1465  Return the used instance with a given name.
1466  """
1467  for i in self.__used_instances__:
1468  if i.name() == name:
1469  if hasattr(i, "_enabled"):
1470  # ensure that the instances retrieved through the method are
1471  # enabled
1472  i._enabled = True
1473  return i
1474  raise KeyError(name)
1475 
def GaudiKernel.Configurable.ConfigurableUser.isApplicable (   self)
Return True is the instance can be "applied".

Definition at line 1476 of file Configurable.py.

1476  def isApplicable(self):
1477  '''
1478  Return True is the instance can be "applied".
1479  '''
1480  return (not self.__users__) and (not self._applied)
1481 
1482 
1483 # list of callables to be called after all the __apply_configuration__ are called.
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 1423 of file Configurable.py.

1423  def propagateProperties(self, names=None, others=None, force=True):
1424  """
1425  Call propagateProperty for each property listed in 'names'.
1426  If 'names' is None, all the properties are propagated.
1427  """
1428  if names is None:
1429  # use all the non-private slots
1430  names = [p for p in self.__slots__ if not p.startswith("_")]
1431  for n in names:
1432  self.propagateProperty(n, others, force)
1433 
def propagateProperty(self, name, others=None, force=True)
def propagateProperties(self, names=None, others=None, force=True)
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 1371 of file Configurable.py.

1371  def propagateProperty(self, name, others=None, force=True):
1372  """
1373  Propagate the property 'name' (if set) to other configurables (if possible).
1374  'others' can be:
1375  None:
1376  propagate to all the entries in __used_configurables__
1377  a configurable instance:
1378  propagate only to it
1379  list of configurable instances:
1380  propagate to all of them.
1381 
1382 
1383  The logic is:
1384  - if the local property is set, the other property will be overwritten
1385  - local property not set and other set => keep other
1386  - local property not set and other not set => overwrite the default for
1387  ConfigurableUser instances and set the property for Configurables
1388  """
1389  # transform 'others' to a list of configurable instances
1390  if others is None:
1391  others = self.__used_instances__
1392  elif type(others) not in [list, tuple]:
1393  others = [others]
1394  # these can be computed before the loop
1395  local_is_set = self.isPropertySet(name)
1396  value = self.getProp(name)
1397  # loop over the others that do have 'name' in their slots
1398  for other in [o for o in others if name in o.__slots__]:
1399  # If self property is set, use it
1400  if local_is_set:
1401  if other.isPropertySet(name):
1402  log.warning(
1403  "Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'"
1404  % {
1405  "self": self.name(),
1406  "other": other.name(),
1407  "prop": name
1408  })
1409  other.setProp(name, value)
1410  # If not, and other property also not set, propagate the default
1411  elif not other.isPropertySet(name):
1412  if isinstance(other, ConfigurableUser):
1413  otherType = type(other._properties[name].getDefault())
1414  other._properties[name].setDefault(value)
1415  if otherType in [list, dict]:
1416  # Special case for list and dictionaries:
1417  # also set the property to the same value of the default (copy)
1418  other.setProp(name, otherType(value))
1419  else:
1420  other.setProp(name, value)
1421  # If not set and other set, do nothing
1422 
def propagateProperty(self, name, others=None, force=True)

Member Data Documentation

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

Definition at line 1283 of file Configurable.py.

dictionary GaudiKernel.Configurable.ConfigurableUser.__slots__
staticprivate
Initial value:
1 = {
2  "__users__": [],
3  "__used_instances__": [],
4  "_enabled": True,
5  "_applied": False
6  }

Definition at line 1266 of file Configurable.py.

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

Definition at line 1280 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1299 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1290 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1291 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1289 of file Configurable.py.


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