The Gaudi Framework  v36r1 (3e2fb5a8)
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 

◆ 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  try:
1571  yield next(c for c in Configurable.allConfigurables.values()
1572  if c.isApplicable())
1573  except StopIteration:
1574  break
1575 
1576  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1577  for c in applicableConfUsers():
1578  if c._enabled:
1579  log.info("applying configuration of %s", c.name())
1580  if debugApplyOrder:
1581  sys.stderr.write('applying %r' % c)
1582  c.__apply_configuration__()
1583  log.info(c)
1584  else:
1585  log.info("skipping configuration of %s", c.name())
1586  c._applied = True # flag the instance as already applied
1587  if hasattr(c, "__detach_used__"):
1588  # tells the used configurables that they are not needed anymore
1589  c.__detach_used__()
1590 
1591  # check for dependency loops
1592  leftConfUsers = [
1593  c for c in Configurable.allConfigurables.values() if
1594  hasattr(c, '__apply_configuration__') and c._enabled and not c._applied
1595  ]
1596  # if an enabled configurable has not been applied, there must be a dependency loop
1597  if leftConfUsers:
1598  raise Error("Detected loop in the ConfigurableUser"
1599  " dependencies: %r" % [c.name() for c in leftConfUsers])
1600  # ensure that all the Handles have been triggered
1601  known = set()
1602  unknown = set(Configurable.allConfigurables)
1603  while unknown:
1604  for k in unknown:
1605  if not known: # do not print during the first iteration
1606  log.debug('new configurable created automatically: %s', k)
1607  # this trigger the instantiation from handles
1608  Configurable.allConfigurables[k].properties()
1609  known.add(k)
1610  unknown -= known
1611  # Call post-config actions
1612  for action in postConfigActions:
1613  action()
1614 
1615 

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

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

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

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

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

1013  def isApplicable(self):
1014  '''
1015  Return True is the instance can be "applied".
1016  Always False for plain Configurable instances
1017  (i.e. not ConfigurableUser).
1018  '''
1019  return False
1020 
1021 
1022 # classes for generic Gaudi component ===========
1023 
1024 

◆ makeSequences()

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

Definition at line 1765 of file Configurable.py.

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

◆ purge()

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

Definition at line 1691 of file Configurable.py.

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

◆ 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 

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.

GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1616
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1765
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1519
GaudiKernel.Configurable.isApplicable
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...
Definition: Configurable.py:1013
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:62
gaudirun.type
type
Definition: gaudirun.py:154
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1532
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1679
gaudirun.action
action
Definition: gaudirun.py:148
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1691
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:47
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1543