| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
GaudiKernel.Configurable Namespace Reference

## Classes
class | Error
class | PropertyReference
| Allow references to options as in old style. More...
class | Configurable
class | DummyDescriptor
| classes for generic Gaudi component =========== More...
class | ConfigurableGeneric
class | ConfigurableAlgorithm
class | ConfigurableService
class | ConfigurableAlgTool
class | ConfigurableAuditor
class | ConfigurableUser

## Functions
def | expandvars
def | isApplicable
| if isinstance(v,Configurable) and not v.isPublic(): rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isinstance(vi,Configurable) and not vi.isPublic(): rep += vi.__str__( indent + 1 ) + os.linesep
def | appendPostConfigAction
def | removePostConfigAction
def | applyConfigurableUsers
def | applyConfigurableUsers_old
def | getNeededConfigurables
def | purge

## Variables
list | __all__
| data ------------------------------------------------------------------—
tuple | log logging.getLogger( 'Configurable' )
list | postConfigActions []
| _appliedConfigurableUsers_ False

## Function Documentation

def GaudiKernel.Configurable.appendPostConfigAction | ( |  | function | ) |

    Add a new callable ('function') to the list of post-configuration actions.
    If the callable is already in the list, it is moved to the end of the list.
    The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.

Definition at line 1326 of file Configurable.py.

1326
1327 def appendPostConfigAction(function):
1328 """
1329 Add a new callable ('function') to the list of post-configuration actions.
1330 If the callable is already in the list, it is moved to the end of the list.
1331 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1332 """
1333 try:
1334 postConfigActions.remove(function)
1335 except:
1336 pass
postConfigActions.append(function)

def GaudiKernel.Configurable.applyConfigurableUsers | ( |  | ) |

    Call the apply method of all the ConfigurableUser instances respecting the
    dependencies. First the C.U.s that are not used by anybody, then the used
    ones, when they are not used anymore.

Definition at line 1345 of file Configurable.py.

1345
1346 def applyConfigurableUsers():
1347 """
1348 Call the apply method of all the ConfigurableUser instances respecting the
1349 dependencies. First the C.U.s that are not used by anybody, then the used
1350 ones, when they are not used anymore.
1351 """
1352 # Avoid double calls
1353 global _appliedConfigurableUsers_, postConfigActions
1354 if _appliedConfigurableUsers_:
1355 return
1356 _appliedConfigurableUsers_ = True
1357
1358 def applicableConfUsers():
1359 '''
1360 Generator returning all the configurables that can be applied in the
1361 order in which they can be applied.
1362 '''
1363 # This is tricky...
1364 # We keep on looking for the first configurable that can be applied.
1365 # When we cannot find any, 'next()' raises a StopIteration that is
1366 # propagated outside of the infinite loop and the function, then handled
1367 # correctly from outside (it is the exception that is raised when you
1368 # exit from a generator).
1369 # Checking every time the full list is inefficient, but it is the
1370 # easiest way to fix bug #103803.
1371 # <https://savannah.cern.ch/bugs/?103803>
1372 while True:
1373 yield (c for c in Configurable.allConfigurables.values()
1374 if c.isApplicable()).next()
1375
1376 debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1377 for c in applicableConfUsers():
1378 if c._enabled:
1379 log.info("applying configuration of %s", c.name())
1380 if debugApplyOrder:
1381 sys.stderr.write('applying %r' % c)
1382 c.__apply_configuration__()
1383 log.info(c)
1384 else:
1385 log.info("skipping configuration of %s", c.name())
1386 c._applied = True # flag the instance as already applied
1387 if hasattr(c, "__detach_used__"):
1388 # tells the used configurables that they are not needed anymore
1389 c.__detach_used__()
1390
1391 # check for dependency loops
1392 leftConfUsers = [c for c in Configurable.allConfigurables.values()
1393 if hasattr(c, '__apply_configuration__') and
1394 c._enabled and not c._applied]
1395 # if an enabled configurable has not been applied, there must be a dependency loop
1396 if leftConfUsers:
1397 raise Error("Detected loop in the ConfigurableUser"
1398 " dependencies: %r" % [ c.name()
1399 for c in leftConfUsers ])
1400 # ensure that all the Handles have been triggered
1401 known = set()
1402 unknown = set(Configurable.allConfigurables)
1403 while unknown:
1404 for k in unknown:
1405 if not known: # do not print during the first iteration
1406 log.debug('new configurable created automatically: %s', k)
1407 # this trigger the instantiation from handles
1408 Configurable.allConfigurables[k].properties()
1409 known.add(k)
1410 unknown -= known
1411 # Call post-config actions
1412 for action in postConfigActions:
1413 action()

def GaudiKernel.Configurable.applyConfigurableUsers_old | ( |  | ) |

    Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
    backward compatibility for configurations that where relying (implicitly) on
    bug #103803, or on a specific (non guaranteed) order of execution.

    @see applyConfigurableUsers()

Definition at line 1414 of file Configurable.py.

1414
1415 def applyConfigurableUsers_old():
1416 """
1417 Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1418 backward compatibility for configurations that where relying (implicitly) on
1419 bug #103803, or on a specific (non guaranteed) order of execution.
1420
1421 @see applyConfigurableUsers()
1422 """
1423 # Avoid double calls
1424 global _appliedConfigurableUsers_, postConfigActions
1425 if _appliedConfigurableUsers_:
1426 return
1427 _appliedConfigurableUsers_ = True
1428
1429 debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1430 confUsers = [ c
1431 for c in Configurable.allConfigurables.values()
1432 if hasattr(c,"__apply_configuration__") ]
1433 applied = True # needed to detect dependency loops
1434 while applied and confUsers:
1435 newConfUsers = [] # list of conf users that cannot be applied yet
1436 applied = False
1437 for c in confUsers:
1438 if hasattr(c,"__users__") and c.__users__:
1439 newConfUsers.append(c) # cannot use this one yet
1440 else: # it does not have users or the list is empty
1441 applied = True
1442 # the ConfigurableUser is enabled if it doesn't have an _enabled
1443 # property or its value is True
1444 enabled = (not hasattr(c, "_enabled")) or c._enabled
1445 if enabled:
1446 log.info("applying configuration of %s", c.name())
1447 if debugApplyOrder:
1448 sys.stderr.write('applying %r' % c)
1449 c.__apply_configuration__()
1450 log.info(c)
1451 else:
1452 log.info("skipping configuration of %s", c.name())
1453 if hasattr(c, "__detach_used__"):
1454 # tells the used configurables that they are not needed anymore
1455 c.__detach_used__()
1456 confUsers = newConfUsers # list of C.U.s still to go
1457 if confUsers:
1458 # this means that some C.U.s could not be applied because of a dependency loop
1459 raise Error("Detected loop in the ConfigurableUser "
1460 " dependencies: %r" % [ c.name()
1461 for c in confUsers ])
1462 # ensure that all the Handles have been triggered
1463 known = set()
1464 unknown = set(Configurable.allConfigurables)
1465 while unknown:
1466 for k in unknown:
1467 if not known: # do not print during the first iteration
1468 log.debug('new configurable created automatically: %s', k)
1469 # this trigger the instantiation from handles
1470 Configurable.allConfigurables[k].properties()
1471 known.add(k)
1472 unknown -= known
1473 # Call post-config actions
1474 for action in postConfigActions:
1475 action()

def GaudiKernel.Configurable.expandvars | ( |  | data | ) |

    Expand environment variables "data".
    Data can be string, list, tuple and dictionary. For collection, all the
    contained strings will be manipulated (recursively).

Definition at line 27 of file Configurable.py.

27
28 def expandvars(data):
29 """
30 Expand environment variables "data".
31 Data can be string, list, tuple and dictionary. For collection, all the
32 contained strings will be manipulated (recursively).
33 """
34 import os.path
35 typ = type(data)
36 if typ is str:
37 return os.path.expandvars(data)
38 elif typ in [list, tuple]:
39 collect = []
40 for i in data:
41 collect.append(expandvars(i))
42 return typ(collect)
43 elif typ is dict:
44 collect = {}
45 for k in data:
46 collect[expandvars(k)] = expandvars(data[k])
47 return collect
48 return data

def GaudiKernel.Configurable.getNeededConfigurables | ( |  | ) |

    Function to select all and only the configurables that have to be used in
    GaudiPython.AppMgr constructor.
    This is needed because in Athena the implementation have to be different (the
    configuration is used in a different moment).

Definition at line 1476 of file Configurable.py.

1476
1477 def getNeededConfigurables():
1478 """
1479 Function to select all and only the configurables that have to be used in
1480 GaudiPython.AppMgr constructor.
1481 This is needed because in Athena the implementation have to be different (the
1482 configuration is used in a different moment).
1483 """
1484 return [ k
1485 for k, v in Configurable.allConfigurables.items()
1486 if v.getGaudiType() != "User" ] # Exclude ConfigurableUser instances

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

if isinstance(v,Configurable) and not v.isPublic(): rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isinstance(vi,Configurable) and not vi.isPublic(): rep += vi.__str__( indent + 1 ) + os.linesep

      for cfg in self.__children: @verbatim

Return True is the instance can be "applied". Always False for plain Configurable instances (i.e. not ConfigurableUser).

Definition at line 912 of file Configurable.py.

912
913 def isApplicable(self):
914 '''
915 Return True is the instance can be "applied".
916 Always False for plain Configurable instances
917 (i.e. not ConfigurableUser).
918 '''
919 return False

def GaudiKernel.Configurable.purge | ( |  | ) |

    Clean up all configurations and configurables.

Definition at line 1487 of file Configurable.py.

1487
1488 def purge():
1489 """
1490 Clean up all configurations and configurables.
1491 """
1492 for c in Configurable.allConfigurables.values():
1493 c.__class__.configurables.clear()
1494 Configurable.allConfigurables.clear()
1495 # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1496 # migrated to the correct class when this is known.
1497 ConfigurableGeneric.configurables.clear()
1498 from ProcessJobOptions import _included_files
1499 import os.path, sys
1500 for file in _included_files:
1501 dirname, basname = os.path.split(file)
1502 basname, ext = os.path.splitext(basname)
1503 if basname in sys.modules:
1504 del sys.modules[basname]
1505 _included_files.clear()

def GaudiKernel.Configurable.removePostConfigAction | ( |  | function | ) |

    Remove a callable from the list of post-config actions.
    The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.

Definition at line 1337 of file Configurable.py.

1337
1338 def removePostConfigAction(function):
1339 """
1340 Remove a callable from the list of post-config actions.
1341 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1342 """
1343 postConfigActions.remove(function)

## Variable Documentation

list GaudiKernel.Configurable.__all__

Initial value:
1 [ 'Configurable',
2 'ConfigurableAlgorithm',
3 'ConfigurableAlgTool',
4 'ConfigurableAuditor',
5 'ConfigurableService',
6 'ConfigurableUser',
7 'VERBOSE','DEBUG','INFO', 'WARNING', 'ERROR', 'FATAL',
8 'appendPostConfigAction', 'removePostConfigAction' ]

data ------------------------------------------------------------------—

Definition at line 14 of file Configurable.py.

GaudiKernel.Configurable._appliedConfigurableUsers_ False

Definition at line 1344 of file Configurable.py.

tuple GaudiKernel.Configurable.log logging.getLogger( 'Configurable' )

Definition at line 25 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions []

Definition at line 1325 of file Configurable.py.