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

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

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

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

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
49 
string type
Definition: gaudirun.py:151
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 1487 of file Configurable.py.

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

923  def isApplicable(self):
924  '''
925  Return True is the instance can be "applied".
926  Always False for plain Configurable instances
927  (i.e. not ConfigurableUser).
928  '''
929  return False
930 
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 1498 of file Configurable.py.

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

1349  """
1350  Remove a callable from the list of post-config actions.
1351  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1352  """
1353  postConfigActions.remove(function)
1354 
def removePostConfigAction(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 15 of file Configurable.py.

GaudiKernel.Configurable._appliedConfigurableUsers_ = False

Definition at line 1355 of file Configurable.py.

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

Definition at line 26 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1336 of file Configurable.py.