The Gaudi Framework  v32r0 (3325bb39)
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 1489 of file Configurable.py.

1490  """
1491  Add a new callable ('function') to the list of post-configuration actions.
1492  If the callable is already in the list, it is moved to the end of the list.
1493  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1494  """
1495  try:
1496  postConfigActions.remove(function)
1497  except:
1498  pass
1499  postConfigActions.append(function)
1500 
1501 
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 1513 of file Configurable.py.

1514  """
1515  Call the apply method of all the ConfigurableUser instances respecting the
1516  dependencies. First the C.U.s that are not used by anybody, then the used
1517  ones, when they are not used anymore.
1518  """
1519  # Avoid double calls
1520  global _appliedConfigurableUsers_, postConfigActions
1521  if _appliedConfigurableUsers_:
1522  return
1523  _appliedConfigurableUsers_ = True
1524 
1525  def applicableConfUsers():
1526  '''
1527  Generator returning all the configurables that can be applied in the
1528  order in which they can be applied.
1529  '''
1530  # This is tricky...
1531  # We keep on looking for the first configurable that can be applied.
1532  # When we cannot find any, 'next()' raises a StopIteration that is
1533  # propagated outside of the infinite loop and the function, then handled
1534  # correctly from outside (it is the exception that is raised when you
1535  # exit from a generator).
1536  # Checking every time the full list is inefficient, but it is the
1537  # easiest way to fix bug #103803.
1538  # <https://savannah.cern.ch/bugs/?103803>
1539  while True:
1540  yield (c for c in Configurable.allConfigurables.values()
1541  if c.isApplicable()).next()
1542 
1543  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1544  for c in applicableConfUsers():
1545  if c._enabled:
1546  log.info("applying configuration of %s", c.name())
1547  if debugApplyOrder:
1548  sys.stderr.write('applying %r' % c)
1549  c.__apply_configuration__()
1550  log.info(c)
1551  else:
1552  log.info("skipping configuration of %s", c.name())
1553  c._applied = True # flag the instance as already applied
1554  if hasattr(c, "__detach_used__"):
1555  # tells the used configurables that they are not needed anymore
1556  c.__detach_used__()
1557 
1558  # check for dependency loops
1559  leftConfUsers = [
1560  c for c in Configurable.allConfigurables.values() if
1561  hasattr(c, '__apply_configuration__') and c._enabled and not c._applied
1562  ]
1563  # if an enabled configurable has not been applied, there must be a dependency loop
1564  if leftConfUsers:
1565  raise Error("Detected loop in the ConfigurableUser"
1566  " dependencies: %r" % [c.name() for c in leftConfUsers])
1567  # ensure that all the Handles have been triggered
1568  known = set()
1569  unknown = set(Configurable.allConfigurables)
1570  while unknown:
1571  for k in unknown:
1572  if not known: # do not print during the first iteration
1573  log.debug('new configurable created automatically: %s', k)
1574  # this trigger the instantiation from handles
1575  Configurable.allConfigurables[k].properties()
1576  known.add(k)
1577  unknown -= known
1578  # Call post-config actions
1579  for action in postConfigActions:
1580  action()
1581 
1582 
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 1583 of file Configurable.py.

1584  """
1585  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1586  backward compatibility for configurations that where relying (implicitly) on
1587  bug #103803, or on a specific (non guaranteed) order of execution.
1588 
1589  @see applyConfigurableUsers()
1590  """
1591  # Avoid double calls
1592  global _appliedConfigurableUsers_, postConfigActions
1593  if _appliedConfigurableUsers_:
1594  return
1595  _appliedConfigurableUsers_ = True
1596 
1597  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1598  confUsers = [
1599  c for c in Configurable.allConfigurables.values()
1600  if hasattr(c, "__apply_configuration__")
1601  ]
1602  applied = True # needed to detect dependency loops
1603  while applied and confUsers:
1604  newConfUsers = [] # list of conf users that cannot be applied yet
1605  applied = False
1606  for c in confUsers:
1607  if hasattr(c, "__users__") and c.__users__:
1608  newConfUsers.append(c) # cannot use this one yet
1609  else: # it does not have users or the list is empty
1610  applied = True
1611  # the ConfigurableUser is enabled if it doesn't have an _enabled
1612  # property or its value is True
1613  enabled = (not hasattr(c, "_enabled")) or c._enabled
1614  if enabled:
1615  log.info("applying configuration of %s", c.name())
1616  if debugApplyOrder:
1617  sys.stderr.write('applying %r' % c)
1618  c.__apply_configuration__()
1619  log.info(c)
1620  else:
1621  log.info("skipping configuration of %s", c.name())
1622  if hasattr(c, "__detach_used__"):
1623  # tells the used configurables that they are not needed anymore
1624  c.__detach_used__()
1625  confUsers = newConfUsers # list of C.U.s still to go
1626  if confUsers:
1627  # this means that some C.U.s could not be applied because of a dependency loop
1628  raise Error("Detected loop in the ConfigurableUser "
1629  " dependencies: %r" % [c.name() for c in confUsers])
1630  # ensure that all the Handles have been triggered
1631  known = set()
1632  unknown = set(Configurable.allConfigurables)
1633  while unknown:
1634  for k in unknown:
1635  if not known: # do not print during the first iteration
1636  log.debug('new configurable created automatically: %s', k)
1637  # this trigger the instantiation from handles
1638  Configurable.allConfigurables[k].properties()
1639  known.add(k)
1640  unknown -= known
1641  # Call post-config actions
1642  for action in postConfigActions:
1643  action()
1644 
1645 
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 35 of file Configurable.py.

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

1647  """
1648  Function to select all and only the configurables that have to be used in
1649  GaudiPython.AppMgr constructor.
1650  This is needed because in Athena the implementation have to be different (the
1651  configuration is used in a different moment).
1652  """
1653  return [
1654  k for k, v in Configurable.allConfigurables.items()
1655  if v.getGaudiType() != "User"
1656  ] # Exclude ConfigurableUser instances
1657 
1658 
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 997 of file Configurable.py.

997  def isApplicable(self):
998  '''
999  Return True is the instance can be "applied".
1000  Always False for plain Configurable instances
1001  (i.e. not ConfigurableUser).
1002  '''
1003  return False
1004 
1005 
1006 # classes for generic Gaudi component ===========
1007 
1008 
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 1733 of file Configurable.py.

1733 def makeSequences(expression):
1734  '''
1735  Convert a control flow expression to nested GaudiSequencers.
1736  '''
1737  if not isinstance(expression, ControlFlowNode):
1738  raise ValueError('ControlFlowNode instance expected, got %s' %
1739  type(expression).__name__)
1740  visitor = CreateSequencesVisitor()
1741  expression.visitNode(visitor)
1742  return visitor.sequence
1743 
1744 
def makeSequences(expression)
def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1659 of file Configurable.py.

1659 def purge():
1660  """
1661  Clean up all configurations and configurables.
1662  """
1663  for c in Configurable.allConfigurables.values():
1664  c.__class__.configurables.clear()
1665  Configurable.allConfigurables.clear()
1666  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1667  # migrated to the correct class when this is known.
1668  ConfigurableGeneric.configurables.clear()
1669  from ProcessJobOptions import _included_files
1670  import os.path
1671  import sys
1672  for file in _included_files:
1673  dirname, basname = os.path.split(file)
1674  basname, ext = os.path.splitext(basname)
1675  if basname in sys.modules:
1676  del sys.modules[basname]
1677  _included_files.clear()
1678 
1679 
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 1502 of file Configurable.py.

1503  """
1504  Remove a callable from the list of post-config actions.
1505  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1506  """
1507  postConfigActions.remove(function)
1508 
1509 
def removePostConfigAction(function)

Variable Documentation

list GaudiKernel.Configurable.__all__
private
Initial value:
1 = [
2  'Configurable', 'ConfigurableAlgorithm', 'ConfigurableAlgTool',
3  'ConfigurableAuditor', 'ConfigurableService', 'ConfigurableUser',
4  'VERBOSE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL',
5  'appendPostConfigAction', 'removePostConfigAction'
6 ]

Definition at line 23 of file Configurable.py.

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1510 of file Configurable.py.

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

Definition at line 32 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1486 of file Configurable.py.