The Gaudi Framework  v37r1 (a7f61348)
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 appendPostConfigAction (function)
 
def removePostConfigAction (function)
 
def applyConfigurableUsers ()
 
def applyConfigurableUsers_old ()
 
def getNeededConfigurables ()
 
def purge ()
 
def makeSequences (expression)
 

Variables

 __all__
 
 log
 
 postConfigActions
 
 _appliedConfigurableUsers_
 

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

1577 def appendPostConfigAction(function):
1578  """
1579  Add a new callable ('function') to the list of post-configuration actions.
1580  If the callable is already in the list, it is moved to the end of the list.
1581  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1582  """
1583  try:
1584  postConfigActions.remove(function)
1585  except Exception:
1586  pass
1587  postConfigActions.append(function)
1588 
1589 

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

1602  """
1603  Call the apply method of all the ConfigurableUser instances respecting the
1604  dependencies. First the C.U.s that are not used by anybody, then the used
1605  ones, when they are not used anymore.
1606  """
1607  # Avoid double calls
1608  global _appliedConfigurableUsers_, postConfigActions
1609  if _appliedConfigurableUsers_:
1610  return
1611  _appliedConfigurableUsers_ = True
1612 
1613  def applicableConfUsers():
1614  """
1615  Generator returning all the configurables that can be applied in the
1616  order in which they can be applied.
1617  """
1618  # This is tricky...
1619  # We keep on looking for the first configurable that can be applied.
1620  # When we cannot find any, 'next()' raises a StopIteration that is
1621  # propagated outside of the infinite loop and the function, then handled
1622  # correctly from outside (it is the exception that is raised when you
1623  # exit from a generator).
1624  # Checking every time the full list is inefficient, but it is the
1625  # easiest way to fix bug #103803.
1626  # <https://savannah.cern.ch/bugs/?103803>
1627  while True:
1628  try:
1629  yield next(
1630  c
1631  for c in Configurable.allConfigurables.values()
1632  if c.isApplicable()
1633  )
1634  except StopIteration:
1635  break
1636 
1637  debugApplyOrder = "GAUDI_DUBUG_CONF_USER" in os.environ
1638  for c in applicableConfUsers():
1639  if c._enabled:
1640  log.info("applying configuration of %s", c.name())
1641  if debugApplyOrder:
1642  sys.stderr.write("applying %r" % c)
1643  c.__apply_configuration__()
1644  log.info(c)
1645  else:
1646  log.info("skipping configuration of %s", c.name())
1647  c._applied = True # flag the instance as already applied
1648  if hasattr(c, "__detach_used__"):
1649  # tells the used configurables that they are not needed anymore
1650  c.__detach_used__()
1651 
1652  # check for dependency loops
1653  leftConfUsers = [
1654  c
1655  for c in Configurable.allConfigurables.values()
1656  if hasattr(c, "__apply_configuration__") and c._enabled and not c._applied
1657  ]
1658  # if an enabled configurable has not been applied, there must be a dependency loop
1659  if leftConfUsers:
1660  raise Error(
1661  "Detected loop in the ConfigurableUser"
1662  " dependencies: %r" % [c.name() for c in leftConfUsers]
1663  )
1664  # ensure that all the Handles have been triggered
1665  known = set()
1666  unknown = set(Configurable.allConfigurables)
1667  while unknown:
1668  for k in unknown:
1669  if not known: # do not print during the first iteration
1670  log.debug("new configurable created automatically: %s", k)
1671  # this trigger the instantiation from handles
1672  Configurable.allConfigurables[k].properties()
1673  known.add(k)
1674  unknown -= known
1675  # Call post-config actions
1676  for action in postConfigActions:
1677  action()
1678 
1679 

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

1681  """
1682  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1683  backward compatibility for configurations that where relying (implicitly) on
1684  bug #103803, or on a specific (non guaranteed) order of execution.
1685 
1686  @see applyConfigurableUsers()
1687  """
1688  # Avoid double calls
1689  global _appliedConfigurableUsers_, postConfigActions
1690  if _appliedConfigurableUsers_:
1691  return
1692  _appliedConfigurableUsers_ = True
1693 
1694  debugApplyOrder = "GAUDI_DUBUG_CONF_USER" in os.environ
1695  confUsers = [
1696  c
1697  for c in Configurable.allConfigurables.values()
1698  if hasattr(c, "__apply_configuration__")
1699  ]
1700  applied = True # needed to detect dependency loops
1701  while applied and confUsers:
1702  newConfUsers = [] # list of conf users that cannot be applied yet
1703  applied = False
1704  for c in confUsers:
1705  if hasattr(c, "__users__") and c.__users__:
1706  newConfUsers.append(c) # cannot use this one yet
1707  else: # it does not have users or the list is empty
1708  applied = True
1709  # the ConfigurableUser is enabled if it doesn't have an _enabled
1710  # property or its value is True
1711  enabled = (not hasattr(c, "_enabled")) or c._enabled
1712  if enabled:
1713  log.info("applying configuration of %s", c.name())
1714  if debugApplyOrder:
1715  sys.stderr.write("applying %r" % c)
1716  c.__apply_configuration__()
1717  log.info(c)
1718  else:
1719  log.info("skipping configuration of %s", c.name())
1720  if hasattr(c, "__detach_used__"):
1721  # tells the used configurables that they are not needed anymore
1722  c.__detach_used__()
1723  confUsers = newConfUsers # list of C.U.s still to go
1724  if confUsers:
1725  # this means that some C.U.s could not be applied because of a dependency loop
1726  raise Error(
1727  "Detected loop in the ConfigurableUser "
1728  " dependencies: %r" % [c.name() for c in confUsers]
1729  )
1730  # ensure that all the Handles have been triggered
1731  known = set()
1732  unknown = set(Configurable.allConfigurables)
1733  while unknown:
1734  for k in unknown:
1735  if not known: # do not print during the first iteration
1736  log.debug("new configurable created automatically: %s", k)
1737  # this trigger the instantiation from handles
1738  Configurable.allConfigurables[k].properties()
1739  known.add(k)
1740  unknown -= known
1741  # Call post-config actions
1742  for action in postConfigActions:
1743  action()
1744 
1745 

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

78 def expandvars(data):
79  """
80  Expand environment variables "data".
81  Data can be string, list, tuple and dictionary. For collection, all the
82  contained strings will be manipulated (recursively).
83  """
84  import os.path
85 
86  typ = type(data)
87  if typ is str:
88  return os.path.expandvars(data)
89  elif typ in [list, tuple]:
90  collect = []
91  for i in data:
92  collect.append(expandvars(i))
93  return typ(collect)
94  elif typ is dict:
95  collect = {}
96  for k in data:
97  collect[expandvars(k)] = expandvars(data[k])
98  return collect
99  return data
100 
101 

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

1747  """
1748  Function to select all and only the configurables that have to be used in
1749  GaudiPython.AppMgr constructor.
1750  This is needed because in Athena the implementation have to be different (the
1751  configuration is used in a different moment).
1752  """
1753  return sorted(
1754  k
1755  for k, v in Configurable.allConfigurables.items()
1756  if v.getGaudiType() != "User"
1757  ) # Exclude ConfigurableUser instances
1758 
1759 

◆ makeSequences()

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

Definition at line 1838 of file Configurable.py.

1838 def makeSequences(expression):
1839  """
1840  Convert a control flow expression to nested GaudiSequencers.
1841  """
1842  if not isinstance(expression, ControlFlowNode):
1843  raise ValueError(
1844  "ControlFlowNode instance expected, got %s" % type(expression).__name__
1845  )
1846  visitor = CreateSequencesVisitor()
1847  expression.visitNode(visitor)
1848  return visitor.sequence
1849 
1850 

◆ purge()

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

Definition at line 1760 of file Configurable.py.

1760 def purge():
1761  """
1762  Clean up all configurations and configurables.
1763  """
1764  for c in Configurable.allConfigurables.values():
1765  c.__class__.configurables.clear()
1766  Configurable.allConfigurables.clear()
1767  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1768  # migrated to the correct class when this is known.
1769  ConfigurableGeneric.configurables.clear()
1770  import os.path
1771  import sys
1772 
1773  from .ProcessJobOptions import _included_files
1774 
1775  for file in _included_files:
1776  dirname, basname = os.path.split(file)
1777  basname, ext = os.path.splitext(basname)
1778  if basname in sys.modules:
1779  del sys.modules[basname]
1780  _included_files.clear()
1781 
1782 

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

1590 def removePostConfigAction(function):
1591  """
1592  Remove a callable from the list of post-config actions.
1593  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1594  """
1595  postConfigActions.remove(function)
1596 
1597 

Variable Documentation

◆ __all__

GaudiKernel.Configurable.__all__
private

Definition at line 55 of file Configurable.py.

◆ _appliedConfigurableUsers_

GaudiKernel.Configurable._appliedConfigurableUsers_
private

Definition at line 1598 of file Configurable.py.

◆ log

GaudiKernel.Configurable.log

Definition at line 75 of file Configurable.py.

◆ postConfigActions

GaudiKernel.Configurable.postConfigActions

Definition at line 1574 of file Configurable.py.

GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1680
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1838
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1577
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:69
gaudirun.type
type
Definition: gaudirun.py:162
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1590
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1746
gaudirun.action
action
Definition: gaudirun.py:155
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1760
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:78
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1601