The Gaudi Framework  v32r0 (3325bb39)
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 1267 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 1287 of file Configurable.py.

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

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

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

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

Definition at line 1363 of file Configurable.py.

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

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

Definition at line 1445 of file Configurable.py.

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

Definition at line 1357 of file Configurable.py.

1357  def getDlls(self):
1358  return None
1359 
def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   self)

Definition at line 1354 of file Configurable.py.

1354  def getGaudiType(self):
1355  return 'User'
1356 
def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1360 of file Configurable.py.

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

Definition at line 1465 of file Configurable.py.

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

Definition at line 1478 of file Configurable.py.

1478  def isApplicable(self):
1479  '''
1480  Return True is the instance can be "applied".
1481  '''
1482  return (not self.__users__) and (not self._applied)
1483 
1484 
1485 # 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 1425 of file Configurable.py.

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

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

Member Data Documentation

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

Definition at line 1285 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 1268 of file Configurable.py.

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

Definition at line 1282 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1301 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1292 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1293 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1291 of file Configurable.py.


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