Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 1581 of file Configurable.py.

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

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

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

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

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

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

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

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

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

◆ makeSequences()

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

Definition at line 1842 of file Configurable.py.

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

◆ purge()

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

Definition at line 1764 of file Configurable.py.

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

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

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

Variable Documentation

◆ __all__

GaudiKernel.Configurable.__all__
private

Definition at line 54 of file Configurable.py.

◆ _appliedConfigurableUsers_

GaudiKernel.Configurable._appliedConfigurableUsers_
private

Definition at line 1602 of file Configurable.py.

◆ log

GaudiKernel.Configurable.log

Definition at line 74 of file Configurable.py.

◆ postConfigActions

GaudiKernel.Configurable.postConfigActions

Definition at line 1578 of file Configurable.py.

GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1684
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1842
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1581
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:68
gaudirun.type
type
Definition: gaudirun.py:160
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1594
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1750
gaudirun.action
action
Definition: gaudirun.py:153
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1764
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:77
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1605