The Gaudi Framework  v36r9p1 (5c15b2bb)
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

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

1567 def appendPostConfigAction(function):
1568  """
1569  Add a new callable ('function') to the list of post-configuration actions.
1570  If the callable is already in the list, it is moved to the end of the list.
1571  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1572  """
1573  try:
1574  postConfigActions.remove(function)
1575  except:
1576  pass
1577  postConfigActions.append(function)
1578 
1579 

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

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

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

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

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

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

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

1737  """
1738  Function to select all and only the configurables that have to be used in
1739  GaudiPython.AppMgr constructor.
1740  This is needed because in Athena the implementation have to be different (the
1741  configuration is used in a different moment).
1742  """
1743  return sorted(
1744  k
1745  for k, v in Configurable.allConfigurables.items()
1746  if v.getGaudiType() != "User"
1747  ) # Exclude ConfigurableUser instances
1748 
1749 

◆ makeSequences()

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

Definition at line 1829 of file Configurable.py.

1829 def makeSequences(expression):
1830  """
1831  Convert a control flow expression to nested GaudiSequencers.
1832  """
1833  if not isinstance(expression, ControlFlowNode):
1834  raise ValueError(
1835  "ControlFlowNode instance expected, got %s" % type(expression).__name__
1836  )
1837  visitor = CreateSequencesVisitor()
1838  expression.visitNode(visitor)
1839  return visitor.sequence
1840 
1841 

◆ purge()

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

Definition at line 1750 of file Configurable.py.

1750 def purge():
1751  """
1752  Clean up all configurations and configurables.
1753  """
1754  for c in Configurable.allConfigurables.values():
1755  c.__class__.configurables.clear()
1756  Configurable.allConfigurables.clear()
1757  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1758  # migrated to the correct class when this is known.
1759  ConfigurableGeneric.configurables.clear()
1760  import os.path
1761  import sys
1762 
1763  from .ProcessJobOptions import _included_files
1764 
1765  for file in _included_files:
1766  dirname, basname = os.path.split(file)
1767  basname, ext = os.path.splitext(basname)
1768  if basname in sys.modules:
1769  del sys.modules[basname]
1770  _included_files.clear()
1771 
1772 

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

1580 def removePostConfigAction(function):
1581  """
1582  Remove a callable from the list of post-config actions.
1583  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1584  """
1585  postConfigActions.remove(function)
1586 
1587 

Variable Documentation

◆ __all__

list GaudiKernel.Configurable.__all__
private
Initial value:
1 = [
2  "Configurable",
3  "ConfigurableAlgorithm",
4  "ConfigurableAlgTool",
5  "ConfigurableAuditor",
6  "ConfigurableService",
7  "ConfigurableUser",
8  "VERBOSE",
9  "DEBUG",
10  "INFO",
11  "WARNING",
12  "ERROR",
13  "FATAL",
14  "appendPostConfigAction",
15  "removePostConfigAction",
16 ]

Definition at line 50 of file Configurable.py.

◆ _appliedConfigurableUsers_

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1588 of file Configurable.py.

◆ log

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

Definition at line 70 of file Configurable.py.

◆ postConfigActions

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1564 of file Configurable.py.

GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1670
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1829
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1567
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:69
gaudirun.type
type
Definition: gaudirun.py:160
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1580
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1736
gaudirun.action
action
Definition: gaudirun.py:153
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1750
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:73
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1591