The Gaudi Framework  v33r1 (b1225454)
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

◆ appendPostConfigAction()

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

1519 def appendPostConfigAction(function):
1520  """
1521  Add a new callable ('function') to the list of post-configuration actions.
1522  If the callable is already in the list, it is moved to the end of the list.
1523  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1524  """
1525  try:
1526  postConfigActions.remove(function)
1527  except:
1528  pass
1529  postConfigActions.append(function)
1530 
1531 
def appendPostConfigAction(function)

◆ applyConfigurableUsers()

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

1544  """
1545  Call the apply method of all the ConfigurableUser instances respecting the
1546  dependencies. First the C.U.s that are not used by anybody, then the used
1547  ones, when they are not used anymore.
1548  """
1549  # Avoid double calls
1550  global _appliedConfigurableUsers_, postConfigActions
1551  if _appliedConfigurableUsers_:
1552  return
1553  _appliedConfigurableUsers_ = True
1554 
1555  def applicableConfUsers():
1556  '''
1557  Generator returning all the configurables that can be applied in the
1558  order in which they can be applied.
1559  '''
1560  # This is tricky...
1561  # We keep on looking for the first configurable that can be applied.
1562  # When we cannot find any, 'next()' raises a StopIteration that is
1563  # propagated outside of the infinite loop and the function, then handled
1564  # correctly from outside (it is the exception that is raised when you
1565  # exit from a generator).
1566  # Checking every time the full list is inefficient, but it is the
1567  # easiest way to fix bug #103803.
1568  # <https://savannah.cern.ch/bugs/?103803>
1569  while True:
1570  yield next(c for c in Configurable.allConfigurables.values()
1571  if c.isApplicable())
1572 
1573  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1574  for c in applicableConfUsers():
1575  if c._enabled:
1576  log.info("applying configuration of %s", c.name())
1577  if debugApplyOrder:
1578  sys.stderr.write('applying %r' % c)
1579  c.__apply_configuration__()
1580  log.info(c)
1581  else:
1582  log.info("skipping configuration of %s", c.name())
1583  c._applied = True # flag the instance as already applied
1584  if hasattr(c, "__detach_used__"):
1585  # tells the used configurables that they are not needed anymore
1586  c.__detach_used__()
1587 
1588  # check for dependency loops
1589  leftConfUsers = [
1590  c for c in Configurable.allConfigurables.values() if
1591  hasattr(c, '__apply_configuration__') and c._enabled and not c._applied
1592  ]
1593  # if an enabled configurable has not been applied, there must be a dependency loop
1594  if leftConfUsers:
1595  raise Error("Detected loop in the ConfigurableUser"
1596  " dependencies: %r" % [c.name() for c in leftConfUsers])
1597  # ensure that all the Handles have been triggered
1598  known = set()
1599  unknown = set(Configurable.allConfigurables)
1600  while unknown:
1601  for k in unknown:
1602  if not known: # do not print during the first iteration
1603  log.debug('new configurable created automatically: %s', k)
1604  # this trigger the instantiation from handles
1605  Configurable.allConfigurables[k].properties()
1606  known.add(k)
1607  unknown -= known
1608  # Call post-config actions
1609  for action in postConfigActions:
1610  action()
1611 
1612 

◆ applyConfigurableUsers_old()

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

1614  """
1615  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1616  backward compatibility for configurations that where relying (implicitly) on
1617  bug #103803, or on a specific (non guaranteed) order of execution.
1618 
1619  @see applyConfigurableUsers()
1620  """
1621  # Avoid double calls
1622  global _appliedConfigurableUsers_, postConfigActions
1623  if _appliedConfigurableUsers_:
1624  return
1625  _appliedConfigurableUsers_ = True
1626 
1627  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1628  confUsers = [
1629  c for c in Configurable.allConfigurables.values()
1630  if hasattr(c, "__apply_configuration__")
1631  ]
1632  applied = True # needed to detect dependency loops
1633  while applied and confUsers:
1634  newConfUsers = [] # list of conf users that cannot be applied yet
1635  applied = False
1636  for c in confUsers:
1637  if hasattr(c, "__users__") and c.__users__:
1638  newConfUsers.append(c) # cannot use this one yet
1639  else: # it does not have users or the list is empty
1640  applied = True
1641  # the ConfigurableUser is enabled if it doesn't have an _enabled
1642  # property or its value is True
1643  enabled = (not hasattr(c, "_enabled")) or c._enabled
1644  if enabled:
1645  log.info("applying configuration of %s", c.name())
1646  if debugApplyOrder:
1647  sys.stderr.write('applying %r' % c)
1648  c.__apply_configuration__()
1649  log.info(c)
1650  else:
1651  log.info("skipping configuration of %s", c.name())
1652  if hasattr(c, "__detach_used__"):
1653  # tells the used configurables that they are not needed anymore
1654  c.__detach_used__()
1655  confUsers = newConfUsers # list of C.U.s still to go
1656  if confUsers:
1657  # this means that some C.U.s could not be applied because of a dependency loop
1658  raise Error("Detected loop in the ConfigurableUser "
1659  " dependencies: %r" % [c.name() for c in confUsers])
1660  # ensure that all the Handles have been triggered
1661  known = set()
1662  unknown = set(Configurable.allConfigurables)
1663  while unknown:
1664  for k in unknown:
1665  if not known: # do not print during the first iteration
1666  log.debug('new configurable created automatically: %s', k)
1667  # this trigger the instantiation from handles
1668  Configurable.allConfigurables[k].properties()
1669  known.add(k)
1670  unknown -= known
1671  # Call post-config actions
1672  for action in postConfigActions:
1673  action()
1674 
1675 

◆ expandvars()

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

47 def expandvars(data):
48  """
49  Expand environment variables "data".
50  Data can be string, list, tuple and dictionary. For collection, all the
51  contained strings will be manipulated (recursively).
52  """
53  import os.path
54  typ = type(data)
55  if typ is str:
56  return os.path.expandvars(data)
57  elif typ in [list, tuple]:
58  collect = []
59  for i in data:
60  collect.append(expandvars(i))
61  return typ(collect)
62  elif typ is dict:
63  collect = {}
64  for k in data:
65  collect[expandvars(k)] = expandvars(data[k])
66  return collect
67  return data
68 
69 

◆ getNeededConfigurables()

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

1677  """
1678  Function to select all and only the configurables that have to be used in
1679  GaudiPython.AppMgr constructor.
1680  This is needed because in Athena the implementation have to be different (the
1681  configuration is used in a different moment).
1682  """
1683  return sorted(
1684  k for k, v in Configurable.allConfigurables.items()
1685  if v.getGaudiType() != "User") # Exclude ConfigurableUser instances
1686 
1687 

◆ isApplicable()

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

1014  def isApplicable(self):
1015  '''
1016  Return True is the instance can be "applied".
1017  Always False for plain Configurable instances
1018  (i.e. not ConfigurableUser).
1019  '''
1020  return False
1021 
1022 
1023 # classes for generic Gaudi component ===========
1024 
1025 
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...

◆ makeSequences()

def GaudiKernel.Configurable.makeSequences (   expression)
Convert a control flow expression to nested GaudiSequencers.

Definition at line 1762 of file Configurable.py.

1762 def makeSequences(expression):
1763  '''
1764  Convert a control flow expression to nested GaudiSequencers.
1765  '''
1766  if not isinstance(expression, ControlFlowNode):
1767  raise ValueError('ControlFlowNode instance expected, got %s' %
1768  type(expression).__name__)
1769  visitor = CreateSequencesVisitor()
1770  expression.visitNode(visitor)
1771  return visitor.sequence
1772 
1773 
def makeSequences(expression)

◆ purge()

def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1688 of file Configurable.py.

1688 def purge():
1689  """
1690  Clean up all configurations and configurables.
1691  """
1692  for c in Configurable.allConfigurables.values():
1693  c.__class__.configurables.clear()
1694  Configurable.allConfigurables.clear()
1695  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1696  # migrated to the correct class when this is known.
1697  ConfigurableGeneric.configurables.clear()
1698  from .ProcessJobOptions import _included_files
1699  import os.path
1700  import sys
1701  for file in _included_files:
1702  dirname, basname = os.path.split(file)
1703  basname, ext = os.path.splitext(basname)
1704  if basname in sys.modules:
1705  del sys.modules[basname]
1706  _included_files.clear()
1707 
1708 

◆ removePostConfigAction()

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

1532 def removePostConfigAction(function):
1533  """
1534  Remove a callable from the list of post-config actions.
1535  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1536  """
1537  postConfigActions.remove(function)
1538 
1539 
def removePostConfigAction(function)

Variable Documentation

◆ __all__

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

◆ _appliedConfigurableUsers_

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1540 of file Configurable.py.

◆ log

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

Definition at line 44 of file Configurable.py.

◆ postConfigActions

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1516 of file Configurable.py.