The Gaudi Framework  v36r1 (3e2fb5a8)
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

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
 
- Static Public Attributes inherited from GaudiKernel.ConfigurableMeta.ConfigurableMeta
def newclass = type.__new__(self, name, bases, dct)
 
 configurables
 
dictionary properties = {}
 
 slots = dct.get('__slots__')
 
list props = [x for x in slots if x[0] != '_']
 
 propDict = dct.get('_propertyDocDct')
 
 docString = propDict and propDict.get(prop)
 
 default = slots[prop]
 
 proxy
 
 bprops = base._properties.copy()
 
 properties = bprops
 

Detailed Description

Definition at line 1296 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1316 of file Configurable.py.

1316  def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1317  super(ConfigurableUser, self).__init__(name)
1318  for n, v in kwargs.items():
1319  setattr(self, n, v)
1320  self._enabled = _enabled
1321  self.__users__ = []
1322  self._applied = False
1323 
1324  # Needed to retrieve the actual class if the declaration in __used_configurables__
1325  # and __queried_configurables__ is done with strings.
1326  from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
1327 
1328  # Set the list of users of the used configurables
1329  #
1330  self.__used_instances__ = []
1331  for used in self.__used_configurables__:
1332  # By default we want to use the default name of the instances
1333  # for the used configurables
1334  used_name = Configurable.DefaultName
1335  # If the entry in the list is a tuple, we need a named instance
1336  if type(used) is tuple:
1337  used, used_name = used # we re-set used to re-use the code below
1338  if not used_name:
1339  used_name = self._instanceName(used)
1340  # Check is 'used' is a string or not
1341  if type(used) is str:
1342  used_class = confDbGetConfigurable(used)
1343  else:
1344  used_class = used
1345  # Instantiate the configurable that we are going to use
1346  try:
1347  inst = used_class(name=used_name, _enabled=False)
1348  except AttributeError:
1349  # This cover the case where the used configurable is not a
1350  # ConfigurableUser instance, i.e. id doesn't have the attribute
1351  # '_enabled'.
1352  inst = used_class(name=used_name)
1353  self.__addActiveUseOf(inst)
1354  for queried in self.__queried_configurables__:
1355  try:
1356  if type(queried) is str:
1357  queried = confDbGetConfigurable(used)
1358  inst = queried(_enabled=False)
1359  except AttributeError:
1360  inst = queried()
1361  self.__addPassiveUseOf(inst)
1362 

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

1363  def __addActiveUseOf(self, other):
1364  """
1365  Declare that we are going to modify the Configurable 'other' in our
1366  __apply_configuration__.
1367  """
1368  self.__used_instances__.append(other)
1369  if hasattr(other, "__users__"): # allow usage of plain Configurables
1370  other.__users__.append(self)
1371 

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

1372  def __addPassiveUseOf(self, other):
1373  """
1374  Declare that we are going to retrieve property values from the
1375  ConfigurableUser 'other' in our __apply_configuration__.
1376  """
1377  if not isinstance(other, ConfigurableUser):
1378  raise Error(
1379  "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser"
1380  % (self.name(), other.name()))
1381  other.__addActiveUseOf(self)
1382 

◆ __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 Gaudi.Configuration.GaudiPersistency, ConfigurableUser.ExampleApplication, ConfigurableUser.ExampleCommon, GaudiExamples.Configuration.GaudiExamplesCommonConf, and ConfigurableUser.ExampleIO.

Definition at line 1466 of file Configurable.py.

1466  def __apply_configuration__(self):
1467  """
1468  Function to be overridden to convert the high level configuration into a
1469  low level one.
1470  The default implementation calls applyConf, which is the method defined
1471  in some ConfigurableUser implementations.
1472  """
1473  return self.applyConf()
1474 

◆ __detach_used__()

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

Definition at line 1393 of file Configurable.py.

1393  def __detach_used__(self):
1394  """
1395  Remove this ConfigurableUser instance from the users list of the used
1396  instances.
1397  """
1398  for used in self.__used_instances__:
1399  if hasattr(used,
1400  "__users__"): # allow usage of plain Configurables
1401  used.__users__.remove(self)
1402 

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

1482  def _instanceName(self, cls):
1483  """
1484  Function used to define the name of the private instance of a given class
1485  name.
1486  This method is used when the __used_configurables_property__ declares the
1487  need of a private used configurable without specifying the name.
1488  """
1489  if type(cls) is str:
1490  clName = cls
1491  else:
1492  clName = cls.__name__
1493  return "%s_%s" % (self.name(), clName)
1494 

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

1475  def applyConf(self):
1476  """
1477  Function to be overridden to convert the high level configuration into a
1478  low level one.
1479  """
1480  pass
1481 

◆ getDlls()

def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1387 of file Configurable.py.

1387  def getDlls(self):
1388  return None
1389 

◆ getGaudiType()

def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   cls)

Definition at line 1384 of file Configurable.py.

1384  def getGaudiType(cls):
1385  return 'User'
1386 

◆ getHandle()

def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1390 of file Configurable.py.

1390  def getHandle(self):
1391  return None
1392 

◆ getUsedInstance()

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

Definition at line 1495 of file Configurable.py.

1495  def getUsedInstance(self, name):
1496  """
1497  Return the used instance with a given name.
1498  """
1499  for i in self.__used_instances__:
1500  if i.name() == name:
1501  if hasattr(i, "_enabled"):
1502  # ensure that the instances retrieved through the method are
1503  # enabled
1504  i._enabled = True
1505  return i
1506  raise KeyError(name)
1507 

◆ isApplicable()

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

Definition at line 1508 of file Configurable.py.

1508  def isApplicable(self):
1509  '''
1510  Return True is the instance can be "applied".
1511  '''
1512  return (not self.__users__) and (not self._applied)
1513 
1514 
1515 # 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 1455 of file Configurable.py.

1455  def propagateProperties(self, names=None, others=None, force=True):
1456  """
1457  Call propagateProperty for each property listed in 'names'.
1458  If 'names' is None, all the properties are propagated.
1459  """
1460  if names is None:
1461  # use all the non-private slots
1462  names = [p for p in self.__slots__ if not p.startswith("_")]
1463  for n in names:
1464  self.propagateProperty(n, others, force)
1465 

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

1403  def propagateProperty(self, name, others=None, force=True):
1404  """
1405  Propagate the property 'name' (if set) to other configurables (if possible).
1406  'others' can be:
1407  None:
1408  propagate to all the entries in __used_configurables__
1409  a configurable instance:
1410  propagate only to it
1411  list of configurable instances:
1412  propagate to all of them.
1413 
1414 
1415  The logic is:
1416  - if the local property is set, the other property will be overwritten
1417  - local property not set and other set => keep other
1418  - local property not set and other not set => overwrite the default for
1419  ConfigurableUser instances and set the property for Configurables
1420  """
1421  # transform 'others' to a list of configurable instances
1422  if others is None:
1423  others = self.__used_instances__
1424  elif type(others) not in [list, tuple]:
1425  others = [others]
1426  # these can be computed before the loop
1427  local_is_set = self.isPropertySet(name)
1428  value = self.getProp(name)
1429  # loop over the others that do have 'name' in their slots
1430  for other in [o for o in others if name in o.__slots__]:
1431  # If self property is set, use it
1432  if local_is_set:
1433  if other.isPropertySet(name):
1434  log.warning(
1435  "Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'"
1436  % {
1437  "self": self.name(),
1438  "other": other.name(),
1439  "prop": name
1440  })
1441  other.setProp(name, value)
1442  # If not, and other property also not set, propagate the default
1443  elif not other.isPropertySet(name):
1444  if isinstance(other, ConfigurableUser):
1445  otherType = type(other._properties[name].getDefault())
1446  other._properties[name].setDefault(value)
1447  if otherType in [list, dict]:
1448  # Special case for list and dictionaries:
1449  # also set the property to the same value of the default (copy)
1450  other.setProp(name, otherType(value))
1451  else:
1452  other.setProp(name, value)
1453  # If not set and other set, do nothing
1454 

Member Data Documentation

◆ __queried_configurables__

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

Definition at line 1314 of file Configurable.py.

◆ __slots__

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

Definition at line 1297 of file Configurable.py.

◆ __used_configurables__

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

Definition at line 1311 of file Configurable.py.

◆ __used_instances__

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1330 of file Configurable.py.

◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1321 of file Configurable.py.

◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1322 of file Configurable.py.

◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1320 of file Configurable.py.


The documentation for this class was generated from the following file:
GaudiKernel.Configurable.isApplicable
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...
Definition: Configurable.py:1013
gaudirun.type
type
Definition: gaudirun.py:154
GaudiKernel.ConfigurableDb
Definition: ConfigurableDb.py:1