The Gaudi Framework  v30r4 (9b837755)
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 1222 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 1240 of file Configurable.py.

1240  def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1241  super(ConfigurableUser, self).__init__(name)
1242  for n, v in kwargs.items():
1243  setattr(self, n, v)
1244  self._enabled = _enabled
1245  self.__users__ = []
1246  self._applied = False
1247 
1248  # Needed to retrieve the actual class if the declaration in __used_configurables__
1249  # and __queried_configurables__ is done with strings.
1250  from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
1251 
1252  # Set the list of users of the used configurables
1253  #
1255  for used in self.__used_configurables__:
1256  # By default we want to use the default name of the instances
1257  # for the used configurables
1258  used_name = Configurable.DefaultName
1259  # If the entry in the list is a tuple, we need a named instance
1260  if type(used) is tuple:
1261  used, used_name = used # we re-set used to re-use the code below
1262  if not used_name:
1263  used_name = self._instanceName(used)
1264  # Check is 'used' is a string or not
1265  if type(used) is str:
1266  used_class = confDbGetConfigurable(used)
1267  else:
1268  used_class = used
1269  # Instantiate the configurable that we are going to use
1270  try:
1271  inst = used_class(name=used_name, _enabled=False)
1272  except AttributeError:
1273  # This cover the case where the used configurable is not a
1274  # ConfigurableUser instance, i.e. id doesn't have the attribute
1275  # '_enabled'.
1276  inst = used_class(name=used_name)
1277  self.__addActiveUseOf(inst)
1278  for queried in self.__queried_configurables__:
1279  try:
1280  if type(queried) is str:
1281  queried = confDbGetConfigurable(used)
1282  inst = queried(_enabled=False)
1283  except AttributeError:
1284  inst = queried()
1285  self.__addPassiveUseOf(inst)
1286 
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 1287 of file Configurable.py.

1287  def __addActiveUseOf(self, other):
1288  """
1289  Declare that we are going to modify the Configurable 'other' in our
1290  __apply_configuration__.
1291  """
1292  self.__used_instances__.append(other)
1293  if hasattr(other, "__users__"): # allow usage of plain Configurables
1294  other.__users__.append(self)
1295 
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 1296 of file Configurable.py.

1296  def __addPassiveUseOf(self, other):
1297  """
1298  Declare that we are going to retrieve property values from the
1299  ConfigurableUser 'other' in our __apply_configuration__.
1300  """
1301  if not isinstance(other, ConfigurableUser):
1302  raise Error("'%s': Cannot make passive use of '%s', it is not a ConfigurableUser" % (
1303  self.name(), other.name()))
1304  other.__addActiveUseOf(self)
1305 
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 1384 of file Configurable.py.

1385  """
1386  Function to be overridden to convert the high level configuration into a
1387  low level one.
1388  The default implementation calls applyConf, which is the method defined
1389  in some ConfigurableUser implementations.
1390  """
1391  return self.applyConf()
1392 
def GaudiKernel.Configurable.ConfigurableUser.__detach_used__ (   self)
Remove this ConfigurableUser instance from the users list of the used
instances.

Definition at line 1315 of file Configurable.py.

1315  def __detach_used__(self):
1316  """
1317  Remove this ConfigurableUser instance from the users list of the used
1318  instances.
1319  """
1320  for used in self.__used_instances__:
1321  if hasattr(used, "__users__"): # allow usage of plain Configurables
1322  used.__users__.remove(self)
1323 
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 1400 of file Configurable.py.

1400  def _instanceName(self, cls):
1401  """
1402  Function used to define the name of the private instance of a given class
1403  name.
1404  This method is used when the __used_configurables_property__ declares the
1405  need of a private used configurable without specifying the name.
1406  """
1407  if type(cls) is str:
1408  clName = cls
1409  else:
1410  clName = cls.__name__
1411  return "%s_%s" % (self.name(), clName)
1412 
def GaudiKernel.Configurable.ConfigurableUser.applyConf (   self)
Function to be overridden to convert the high level configuration into a
low level one.

Definition at line 1393 of file Configurable.py.

1393  def applyConf(self):
1394  """
1395  Function to be overridden to convert the high level configuration into a
1396  low level one.
1397  """
1398  pass
1399 
def GaudiKernel.Configurable.ConfigurableUser.getDlls (   self)

Definition at line 1309 of file Configurable.py.

1309  def getDlls(self):
1310  return None
1311 
def GaudiKernel.Configurable.ConfigurableUser.getGaudiType (   self)

Definition at line 1306 of file Configurable.py.

1306  def getGaudiType(self):
1307  return 'User'
1308 
def GaudiKernel.Configurable.ConfigurableUser.getHandle (   self)

Definition at line 1312 of file Configurable.py.

1312  def getHandle(self):
1313  return None
1314 
def GaudiKernel.Configurable.ConfigurableUser.getUsedInstance (   self,
  name 
)
Return the used instance with a given name.

Definition at line 1413 of file Configurable.py.

1413  def getUsedInstance(self, name):
1414  """
1415  Return the used instance with a given name.
1416  """
1417  for i in self.__used_instances__:
1418  if i.name() == name:
1419  if hasattr(i, "_enabled"):
1420  # ensure that the instances retrieved through the method are
1421  # enabled
1422  i._enabled = True
1423  return i
1424  raise KeyError(name)
1425 
def GaudiKernel.Configurable.ConfigurableUser.isApplicable (   self)
Return True is the instance can be "applied".

Definition at line 1426 of file Configurable.py.

1426  def isApplicable(self):
1427  '''
1428  Return True is the instance can be "applied".
1429  '''
1430  return (not self.__users__) and (not self._applied)
1431 
1432 
1433 # 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 1373 of file Configurable.py.

1373  def propagateProperties(self, names=None, others=None, force=True):
1374  """
1375  Call propagateProperty for each property listed in 'names'.
1376  If 'names' is None, all the properties are propagated.
1377  """
1378  if names is None:
1379  # use all the non-private slots
1380  names = [p for p in self.__slots__ if not p.startswith("_")]
1381  for n in names:
1382  self.propagateProperty(n, others, force)
1383 
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 1324 of file Configurable.py.

1324  def propagateProperty(self, name, others=None, force=True):
1325  """
1326  Propagate the property 'name' (if set) to other configurables (if possible).
1327  'others' can be:
1328  None:
1329  propagate to all the entries in __used_configurables__
1330  a configurable instance:
1331  propagate only to it
1332  list of configurable instances:
1333  propagate to all of them.
1334 
1335 
1336  The logic is:
1337  - if the local property is set, the other property will be overwritten
1338  - local property not set and other set => keep other
1339  - local property not set and other not set => overwrite the default for
1340  ConfigurableUser instances and set the property for Configurables
1341  """
1342  # transform 'others' to a list of configurable instances
1343  if others is None:
1344  others = self.__used_instances__
1345  elif type(others) not in [list, tuple]:
1346  others = [others]
1347  # these can be computed before the loop
1348  local_is_set = self.isPropertySet(name)
1349  value = self.getProp(name)
1350  # loop over the others that do have 'name' in their slots
1351  for other in [o for o in others if name in o.__slots__]:
1352  # If self property is set, use it
1353  if local_is_set:
1354  if other.isPropertySet(name):
1355  log.warning("Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'" %
1356  {"self": self.name(),
1357  "other": other.name(),
1358  "prop": name})
1359  other.setProp(name, value)
1360  # If not, and other property also not set, propagate the default
1361  elif not other.isPropertySet(name):
1362  if isinstance(other, ConfigurableUser):
1363  otherType = type(other._properties[name].getDefault())
1364  other._properties[name].setDefault(value)
1365  if otherType in [list, dict]:
1366  # Special case for list and dictionaries:
1367  # also set the property to the same value of the default (copy)
1368  other.setProp(name, otherType(value))
1369  else:
1370  other.setProp(name, value)
1371  # If not set and other set, do nothing
1372 
def propagateProperty(self, name, others=None, force=True)

Member Data Documentation

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

Definition at line 1238 of file Configurable.py.

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

Definition at line 1223 of file Configurable.py.

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

Definition at line 1235 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
private

Definition at line 1254 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser.__users__
private

Definition at line 1245 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._applied
private

Definition at line 1246 of file Configurable.py.

GaudiKernel.Configurable.ConfigurableUser._enabled
private

Definition at line 1244 of file Configurable.py.


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