The Gaudi Framework  v36r16 (ea80daf8)
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 1579 of file Configurable.py.

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

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

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

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

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

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

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

◆ makeSequences()

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

Definition at line 1841 of file Configurable.py.

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

◆ purge()

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

Definition at line 1762 of file Configurable.py.

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

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

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

Variable Documentation

◆ __all__

GaudiKernel.Configurable.__all__
private

Definition at line 55 of file Configurable.py.

◆ _appliedConfigurableUsers_

GaudiKernel.Configurable._appliedConfigurableUsers_
private

Definition at line 1600 of file Configurable.py.

◆ log

GaudiKernel.Configurable.log

Definition at line 75 of file Configurable.py.

◆ postConfigActions

GaudiKernel.Configurable.postConfigActions

Definition at line 1576 of file Configurable.py.

GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1682
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1841
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1579
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:69
gaudirun.type
type
Definition: gaudirun.py:162
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1592
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1748
gaudirun.action
action
Definition: gaudirun.py:155
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1762
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:78
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1603