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

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

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

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

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

928  def isApplicable(self):
929  '''
930  Return True is the instance can be "applied".
931  Always False for plain Configurable instances
932  (i.e. not ConfigurableUser).
933  '''
934  return False
935 
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 1503 of file Configurable.py.

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

1354  """
1355  Remove a callable from the list of post-config actions.
1356  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1357  """
1358  postConfigActions.remove(function)
1359 
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 16 of file Configurable.py.

GaudiKernel.Configurable._appliedConfigurableUsers_ = False

Definition at line 1360 of file Configurable.py.

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

Definition at line 27 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1341 of file Configurable.py.