GaudiKernel.Configurable Namespace Reference

Classes

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

Functions

def expandvars (data)
 
def 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 More...
 
def appendPostConfigAction (function)
 
def removePostConfigAction (function)
 
def applyConfigurableUsers ()
 
def applyConfigurableUsers_old ()
 
def getNeededConfigurables ()
 
def purge ()
 

Variables

list __all__
 data ------------------------------------------------------------------— More...
 
 log = logging.getLogger( 'Configurable' )
 
list postConfigActions = []
 
bool _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 1340 of file Configurable.py.

1341  """
1342  Add a new callable ('function') to the list of post-configuration actions.
1343  If the callable is already in the list, it is moved to the end of the list.
1344  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1345  """
1346  try:
1347  postConfigActions.remove(function)
1348  except:
1349  pass
1350  postConfigActions.append(function)
def appendPostConfigAction(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 1359 of file Configurable.py.

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

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

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

1491  """
1492  Function to select all and only the configurables that have to be used in
1493  GaudiPython.AppMgr constructor.
1494  This is needed because in Athena the implementation have to be different (the
1495  configuration is used in a different moment).
1496  """
1497  return [ k
1498  for k, v in Configurable.allConfigurables.items()
1499  if v.getGaudiType() != "User" ] # Exclude ConfigurableUser instances
1500 
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:

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

Definition at line 926 of file Configurable.py.

926  def isApplicable(self):
927  '''
928  Return True is the instance can be "applied".
929  Always False for plain Configurable instances
930  (i.e. not ConfigurableUser).
931  '''
932  return False
933 
def isApplicable(self)
if isinstance(v,Configurable) and not v.isPublic(): rep += v.__str__( indent + 1 ) + os...
def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1501 of file Configurable.py.

1501 def purge():
1502  """
1503  Clean up all configurations and configurables.
1504  """
1505  for c in Configurable.allConfigurables.values():
1506  c.__class__.configurables.clear()
1507  Configurable.allConfigurables.clear()
1508  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1509  # migrated to the correct class when this is known.
1510  ConfigurableGeneric.configurables.clear()
1511  from ProcessJobOptions import _included_files
1512  import os.path, sys
1513  for file in _included_files:
1514  dirname, basname = os.path.split(file)
1515  basname, ext = os.path.splitext(basname)
1516  if basname in sys.modules:
1517  del sys.modules[basname]
1518  _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 1351 of file Configurable.py.

1352  """
1353  Remove a callable from the list of post-config actions.
1354  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1355  """
1356  postConfigActions.remove(function)
1357 
def removePostConfigAction(function)

Variable Documentation

list GaudiKernel.Configurable.__all__
private
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 16 of file Configurable.py.

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1358 of file Configurable.py.

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

Definition at line 27 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1339 of file Configurable.py.