| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GaudiKernel.Configurable.ConfigurableUser Class Reference
Inheritance diagram for GaudiKernel.Configurable.ConfigurableUser:
[legend]
Collaboration diagram for GaudiKernel.Configurable.ConfigurableUser:
[legend]

## 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 | __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 1272 of file Configurable.py.

## Constructor & Destructor Documentation

## ◆ __init__()

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

Definition at line 1292 of file Configurable.py.

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

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

1339 def __addActiveUseOf(self, other):
1340 """
1341 Declare that we are going to modify the Configurable 'other' in our
1342 __apply_configuration__.
1343 """
1344 self.__used_instances__.append(other)
1345 if hasattr(other, "__users__"): # allow usage of plain Configurables
1346 other.__users__.append(self)
1347

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

1348 def __addPassiveUseOf(self, other):
1349 """
1350 Declare that we are going to retrieve property values from the
1351 ConfigurableUser 'other' in our __apply_configuration__.
1352 """
1353 if not isinstance(other, ConfigurableUser):
1354 raise Error(
1355 "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser"
1356 % (self.name(), other.name()))
1357 other.__addActiveUseOf(self)
1358

## ◆ __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.

Definition at line 1442 of file Configurable.py.

1442 def __apply_configuration__(self):
1443 """
1444 Function to be overridden to convert the high level configuration into a
1445 low level one.
1446 The default implementation calls applyConf, which is the method defined
1447 in some ConfigurableUser implementations.
1448 """
1449 return self.applyConf()
1450

## ◆ __detach_used__()

def GaudiKernel.Configurable.ConfigurableUser.__detach_used__ | ( |  | self | ) |

    Remove this ConfigurableUser instance from the users list of the used
    instances.

Definition at line 1369 of file Configurable.py.

1369 def __detach_used__(self):
1370 """
1371 Remove this ConfigurableUser instance from the users list of the used
1372 instances.
1373 """
1374 for used in self.__used_instances__:
1375 if hasattr(used,
1376 "__users__"): # allow usage of plain Configurables
1377 used.__users__.remove(self)
1378

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

1458 def _instanceName(self, cls):
1459 """
1460 Function used to define the name of the private instance of a given class
1461 name.
1462 This method is used when the __used_configurables_property__ declares the
1463 need of a private used configurable without specifying the name.
1464 """
1465 if type(cls) is str:
1466 clName = cls
1467 else:
1468 clName = cls.__name__
1469 return "%s_%s" % (self.name(), clName)
1470
gaudirun.type
type
Definition: gaudirun.py:142

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

1451 def applyConf(self):
1452 """
1453 Function to be overridden to convert the high level configuration into a
1454 low level one.
1455 """
1456 pass
1457

## ◆ getDlls()

def GaudiKernel.Configurable.ConfigurableUser.getDlls | ( |  | self | ) |

Definition at line 1363 of file Configurable.py.

1363 def getDlls(self):
1364 return None
1365

## ◆ getGaudiType()

def GaudiKernel.Configurable.ConfigurableUser.getGaudiType | ( |  | cls | ) |

Definition at line 1360 of file Configurable.py.

1360 def getGaudiType(cls):
1361 return 'User'
1362

## ◆ getHandle()

def GaudiKernel.Configurable.ConfigurableUser.getHandle | ( |  | self | ) |

Definition at line 1366 of file Configurable.py.

1366 def getHandle(self):
1367 return None
1368

## ◆ getUsedInstance()

def GaudiKernel.Configurable.ConfigurableUser.getUsedInstance | ( |  | self,
|  |  | name
| ) |  |

    Return the used instance with a given name.

Definition at line 1471 of file Configurable.py.

1471 def getUsedInstance(self, name):
1472 """
1473 Return the used instance with a given name.
1474 """
1475 for i in self.__used_instances__:
1476 if i.name() == name:
1477 if hasattr(i, "_enabled"):
1478 # ensure that the instances retrieved through the method are
1479 # enabled
1480 i._enabled = True
1481 return i
1482 raise KeyError(name)
1483

## ◆ isApplicable()

def GaudiKernel.Configurable.ConfigurableUser.isApplicable | ( |  | self | ) |

    Return True is the instance can be "applied".

Definition at line 1484 of file Configurable.py.

1484 def isApplicable(self):
1485 '''
1486 Return True is the instance can be "applied".
1487 '''
1488 return (not self.__users__) and (not self._applied)
1489
1490
1491 # list of callables to be called after all the __apply_configuration__ are called.
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:997

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

1431 def propagateProperties(self, names=None, others=None, force=True):
1432 """
1433 Call propagateProperty for each property listed in 'names'.
1434 If 'names' is None, all the properties are propagated.
1435 """
1436 if names is None:
1437 # use all the non-private slots
1438 names = [p for p in self.__slots__ if not p.startswith("_")]
1439 for n in names:
1440 self.propagateProperty(n, others, force)
1441

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

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

## Member Data Documentation

## ◆ __queried_configurables__

list GaudiKernel.Configurable.ConfigurableUser.__queried_configurables__ = []
| static private

Definition at line 1290 of file Configurable.py.

## ◆ __slots__

dictionary GaudiKernel.Configurable.ConfigurableUser.__slots__
| static private

Initial value:
= {
"__users__": [],
"__used_instances__": [],
"_enabled": True,
"_applied": False
}

Definition at line 1273 of file Configurable.py.

## ◆ __used_configurables__

list GaudiKernel.Configurable.ConfigurableUser.__used_configurables__ = []
| static private

Definition at line 1287 of file Configurable.py.

## ◆ __used_instances__

GaudiKernel.Configurable.ConfigurableUser.__used_instances__
| private

Definition at line 1306 of file Configurable.py.

## ◆ __users__

GaudiKernel.Configurable.ConfigurableUser.__users__
| private

Definition at line 1297 of file Configurable.py.

## ◆ _applied

GaudiKernel.Configurable.ConfigurableUser._applied
| private

Definition at line 1298 of file Configurable.py.

## ◆ _enabled

GaudiKernel.Configurable.ConfigurableUser._enabled
| private

Definition at line 1296 of file Configurable.py.

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

- GaudiKernel/python/GaudiKernel/Configurable.py