The Gaudi Framework  v30r3 (a5ef0a68)
GaudiKernel.Configurable Namespace Reference

Classes

class  Configurable
 
class  ConfigurableAlgorithm
 
class  ConfigurableAlgTool
 
class  ConfigurableAuditor
 
class  ConfigurableGeneric
 
class  ConfigurableService
 
class  ConfigurableUser
 
class  CreateSequencesVisitor
 
class  DummyDescriptor
 
class  Error
 
class  PropertyReference
 
class  SuperAlgorithm
 

Functions

def expandvars (data)
 
def isApplicable (self)
 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 ()
 
def makeSequences (expression)
 

Variables

list __all__
 
 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 1437 of file Configurable.py.

1438  """
1439  Add a new callable ('function') to the list of post-configuration actions.
1440  If the callable is already in the list, it is moved to the end of the list.
1441  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1442  """
1443  try:
1444  postConfigActions.remove(function)
1445  except:
1446  pass
1447  postConfigActions.append(function)
1448 
1449 
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 1461 of file Configurable.py.

1462  """
1463  Call the apply method of all the ConfigurableUser instances respecting the
1464  dependencies. First the C.U.s that are not used by anybody, then the used
1465  ones, when they are not used anymore.
1466  """
1467  # Avoid double calls
1468  global _appliedConfigurableUsers_, postConfigActions
1469  if _appliedConfigurableUsers_:
1470  return
1471  _appliedConfigurableUsers_ = True
1472 
1473  def applicableConfUsers():
1474  '''
1475  Generator returning all the configurables that can be applied in the
1476  order in which they can be applied.
1477  '''
1478  # This is tricky...
1479  # We keep on looking for the first configurable that can be applied.
1480  # When we cannot find any, 'next()' raises a StopIteration that is
1481  # propagated outside of the infinite loop and the function, then handled
1482  # correctly from outside (it is the exception that is raised when you
1483  # exit from a generator).
1484  # Checking every time the full list is inefficient, but it is the
1485  # easiest way to fix bug #103803.
1486  # <https://savannah.cern.ch/bugs/?103803>
1487  while True:
1488  yield (c for c in Configurable.allConfigurables.values()
1489  if c.isApplicable()).next()
1490 
1491  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1492  for c in applicableConfUsers():
1493  if c._enabled:
1494  log.info("applying configuration of %s", c.name())
1495  if debugApplyOrder:
1496  sys.stderr.write('applying %r' % c)
1497  c.__apply_configuration__()
1498  log.info(c)
1499  else:
1500  log.info("skipping configuration of %s", c.name())
1501  c._applied = True # flag the instance as already applied
1502  if hasattr(c, "__detach_used__"):
1503  # tells the used configurables that they are not needed anymore
1504  c.__detach_used__()
1505 
1506  # check for dependency loops
1507  leftConfUsers = [c for c in Configurable.allConfigurables.values()
1508  if hasattr(c, '__apply_configuration__') and
1509  c._enabled and not c._applied]
1510  # if an enabled configurable has not been applied, there must be a dependency loop
1511  if leftConfUsers:
1512  raise Error("Detected loop in the ConfigurableUser"
1513  " dependencies: %r" % [c.name()
1514  for c in leftConfUsers])
1515  # ensure that all the Handles have been triggered
1516  known = set()
1517  unknown = set(Configurable.allConfigurables)
1518  while unknown:
1519  for k in unknown:
1520  if not known: # do not print during the first iteration
1521  log.debug('new configurable created automatically: %s', k)
1522  # this trigger the instantiation from handles
1523  Configurable.allConfigurables[k].properties()
1524  known.add(k)
1525  unknown -= known
1526  # Call post-config actions
1527  for action in postConfigActions:
1528  action()
1529 
1530 
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 1531 of file Configurable.py.

1532  """
1533  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1534  backward compatibility for configurations that where relying (implicitly) on
1535  bug #103803, or on a specific (non guaranteed) order of execution.
1536 
1537  @see applyConfigurableUsers()
1538  """
1539  # Avoid double calls
1540  global _appliedConfigurableUsers_, postConfigActions
1541  if _appliedConfigurableUsers_:
1542  return
1543  _appliedConfigurableUsers_ = True
1544 
1545  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1546  confUsers = [c
1547  for c in Configurable.allConfigurables.values()
1548  if hasattr(c, "__apply_configuration__")]
1549  applied = True # needed to detect dependency loops
1550  while applied and confUsers:
1551  newConfUsers = [] # list of conf users that cannot be applied yet
1552  applied = False
1553  for c in confUsers:
1554  if hasattr(c, "__users__") and c.__users__:
1555  newConfUsers.append(c) # cannot use this one yet
1556  else: # it does not have users or the list is empty
1557  applied = True
1558  # the ConfigurableUser is enabled if it doesn't have an _enabled
1559  # property or its value is True
1560  enabled = (not hasattr(c, "_enabled")) or c._enabled
1561  if enabled:
1562  log.info("applying configuration of %s", c.name())
1563  if debugApplyOrder:
1564  sys.stderr.write('applying %r' % c)
1565  c.__apply_configuration__()
1566  log.info(c)
1567  else:
1568  log.info("skipping configuration of %s", c.name())
1569  if hasattr(c, "__detach_used__"):
1570  # tells the used configurables that they are not needed anymore
1571  c.__detach_used__()
1572  confUsers = newConfUsers # list of C.U.s still to go
1573  if confUsers:
1574  # this means that some C.U.s could not be applied because of a dependency loop
1575  raise Error("Detected loop in the ConfigurableUser "
1576  " dependencies: %r" % [c.name()
1577  for c in confUsers])
1578  # ensure that all the Handles have been triggered
1579  known = set()
1580  unknown = set(Configurable.allConfigurables)
1581  while unknown:
1582  for k in unknown:
1583  if not known: # do not print during the first iteration
1584  log.debug('new configurable created automatically: %s', k)
1585  # this trigger the instantiation from handles
1586  Configurable.allConfigurables[k].properties()
1587  known.add(k)
1588  unknown -= known
1589  # Call post-config actions
1590  for action in postConfigActions:
1591  action()
1592 
1593 
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 38 of file Configurable.py.

38 def expandvars(data):
39  """
40  Expand environment variables "data".
41  Data can be string, list, tuple and dictionary. For collection, all the
42  contained strings will be manipulated (recursively).
43  """
44  import os.path
45  typ = type(data)
46  if typ is str:
47  return os.path.expandvars(data)
48  elif typ in [list, tuple]:
49  collect = []
50  for i in data:
51  collect.append(expandvars(i))
52  return typ(collect)
53  elif typ is dict:
54  collect = {}
55  for k in data:
56  collect[expandvars(k)] = expandvars(data[k])
57  return collect
58  return data
59 
60 
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 1594 of file Configurable.py.

1595  """
1596  Function to select all and only the configurables that have to be used in
1597  GaudiPython.AppMgr constructor.
1598  This is needed because in Athena the implementation have to be different (the
1599  configuration is used in a different moment).
1600  """
1601  return [k
1602  for k, v in Configurable.allConfigurables.items()
1603  if v.getGaudiType() != "User"] # Exclude ConfigurableUser instances
1604 
1605 
def GaudiKernel.Configurable.isApplicable (   self)

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

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

Definition at line 975 of file Configurable.py.

975  def isApplicable(self):
976  '''
977  Return True is the instance can be "applied".
978  Always False for plain Configurable instances
979  (i.e. not ConfigurableUser).
980  '''
981  return False
982 
983 # classes for generic Gaudi component ===========
984 
985 
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...
def GaudiKernel.Configurable.makeSequences (   expression)
Convert a control flow expression to nested GaudiSequencers.

Definition at line 1681 of file Configurable.py.

1681 def makeSequences(expression):
1682  '''
1683  Convert a control flow expression to nested GaudiSequencers.
1684  '''
1685  if not isinstance(expression, ControlFlowNode):
1686  raise ValueError('ControlFlowNode instance expected, got %s' %
1687  type(expression).__name__)
1688  visitor = CreateSequencesVisitor()
1689  expression.visitNode(visitor)
1690  return visitor.sequence
1691 
1692 
def makeSequences(expression)
def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1606 of file Configurable.py.

1606 def purge():
1607  """
1608  Clean up all configurations and configurables.
1609  """
1610  for c in Configurable.allConfigurables.values():
1611  c.__class__.configurables.clear()
1612  Configurable.allConfigurables.clear()
1613  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1614  # migrated to the correct class when this is known.
1615  ConfigurableGeneric.configurables.clear()
1616  from ProcessJobOptions import _included_files
1617  import os.path
1618  import sys
1619  for file in _included_files:
1620  dirname, basname = os.path.split(file)
1621  basname, ext = os.path.splitext(basname)
1622  if basname in sys.modules:
1623  del sys.modules[basname]
1624  _included_files.clear()
1625 
1626 
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 1450 of file Configurable.py.

1451  """
1452  Remove a callable from the list of post-config actions.
1453  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1454  """
1455  postConfigActions.remove(function)
1456 
1457 
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']

Definition at line 24 of file Configurable.py.

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1458 of file Configurable.py.

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

Definition at line 35 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1434 of file Configurable.py.