The Gaudi Framework  v32r2 (46d42edc)
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 1511 of file Configurable.py.

1511 def appendPostConfigAction(function):
1512  """
1513  Add a new callable ('function') to the list of post-configuration actions.
1514  If the callable is already in the list, it is moved to the end of the list.
1515  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1516  """
1517  try:
1518  postConfigActions.remove(function)
1519  except:
1520  pass
1521  postConfigActions.append(function)
1522 
1523 
def appendPostConfigAction(function)

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

1536  """
1537  Call the apply method of all the ConfigurableUser instances respecting the
1538  dependencies. First the C.U.s that are not used by anybody, then the used
1539  ones, when they are not used anymore.
1540  """
1541  # Avoid double calls
1542  global _appliedConfigurableUsers_, postConfigActions
1543  if _appliedConfigurableUsers_:
1544  return
1545  _appliedConfigurableUsers_ = True
1546 
1547  def applicableConfUsers():
1548  '''
1549  Generator returning all the configurables that can be applied in the
1550  order in which they can be applied.
1551  '''
1552  # This is tricky...
1553  # We keep on looking for the first configurable that can be applied.
1554  # When we cannot find any, 'next()' raises a StopIteration that is
1555  # propagated outside of the infinite loop and the function, then handled
1556  # correctly from outside (it is the exception that is raised when you
1557  # exit from a generator).
1558  # Checking every time the full list is inefficient, but it is the
1559  # easiest way to fix bug #103803.
1560  # <https://savannah.cern.ch/bugs/?103803>
1561  while True:
1562  yield next(c for c in Configurable.allConfigurables.values()
1563  if c.isApplicable())
1564 
1565  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1566  for c in applicableConfUsers():
1567  if c._enabled:
1568  log.info("applying configuration of %s", c.name())
1569  if debugApplyOrder:
1570  sys.stderr.write('applying %r' % c)
1571  c.__apply_configuration__()
1572  log.info(c)
1573  else:
1574  log.info("skipping configuration of %s", c.name())
1575  c._applied = True # flag the instance as already applied
1576  if hasattr(c, "__detach_used__"):
1577  # tells the used configurables that they are not needed anymore
1578  c.__detach_used__()
1579 
1580  # check for dependency loops
1581  leftConfUsers = [
1582  c for c in Configurable.allConfigurables.values() if
1583  hasattr(c, '__apply_configuration__') and c._enabled and not c._applied
1584  ]
1585  # if an enabled configurable has not been applied, there must be a dependency loop
1586  if leftConfUsers:
1587  raise Error("Detected loop in the ConfigurableUser"
1588  " dependencies: %r" % [c.name() for c in leftConfUsers])
1589  # ensure that all the Handles have been triggered
1590  known = set()
1591  unknown = set(Configurable.allConfigurables)
1592  while unknown:
1593  for k in unknown:
1594  if not known: # do not print during the first iteration
1595  log.debug('new configurable created automatically: %s', k)
1596  # this trigger the instantiation from handles
1597  Configurable.allConfigurables[k].properties()
1598  known.add(k)
1599  unknown -= known
1600  # Call post-config actions
1601  for action in postConfigActions:
1602  action()
1603 
1604 

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

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

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

37 def expandvars(data):
38  """
39  Expand environment variables "data".
40  Data can be string, list, tuple and dictionary. For collection, all the
41  contained strings will be manipulated (recursively).
42  """
43  import os.path
44  typ = type(data)
45  if typ is str:
46  return os.path.expandvars(data)
47  elif typ in [list, tuple]:
48  collect = []
49  for i in data:
50  collect.append(expandvars(i))
51  return typ(collect)
52  elif typ is dict:
53  collect = {}
54  for k in data:
55  collect[expandvars(k)] = expandvars(data[k])
56  return collect
57  return data
58 
59 

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

1669  """
1670  Function to select all and only the configurables that have to be used in
1671  GaudiPython.AppMgr constructor.
1672  This is needed because in Athena the implementation have to be different (the
1673  configuration is used in a different moment).
1674  """
1675  return sorted(
1676  k for k, v in Configurable.allConfigurables.items()
1677  if v.getGaudiType() != "User") # Exclude ConfigurableUser instances
1678 
1679 

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

1004  def isApplicable(self):
1005  '''
1006  Return True is the instance can be "applied".
1007  Always False for plain Configurable instances
1008  (i.e. not ConfigurableUser).
1009  '''
1010  return False
1011 
1012 
1013 # classes for generic Gaudi component ===========
1014 
1015 
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...

◆ makeSequences()

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

Definition at line 1754 of file Configurable.py.

1754 def makeSequences(expression):
1755  '''
1756  Convert a control flow expression to nested GaudiSequencers.
1757  '''
1758  if not isinstance(expression, ControlFlowNode):
1759  raise ValueError('ControlFlowNode instance expected, got %s' %
1760  type(expression).__name__)
1761  visitor = CreateSequencesVisitor()
1762  expression.visitNode(visitor)
1763  return visitor.sequence
1764 
1765 
def makeSequences(expression)

◆ purge()

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

Definition at line 1680 of file Configurable.py.

1680 def purge():
1681  """
1682  Clean up all configurations and configurables.
1683  """
1684  for c in Configurable.allConfigurables.values():
1685  c.__class__.configurables.clear()
1686  Configurable.allConfigurables.clear()
1687  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1688  # migrated to the correct class when this is known.
1689  ConfigurableGeneric.configurables.clear()
1690  from .ProcessJobOptions import _included_files
1691  import os.path
1692  import sys
1693  for file in _included_files:
1694  dirname, basname = os.path.split(file)
1695  basname, ext = os.path.splitext(basname)
1696  if basname in sys.modules:
1697  del sys.modules[basname]
1698  _included_files.clear()
1699 
1700 

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

1524 def removePostConfigAction(function):
1525  """
1526  Remove a callable from the list of post-config actions.
1527  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1528  """
1529  postConfigActions.remove(function)
1530 
1531 
def removePostConfigAction(function)

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

◆ _appliedConfigurableUsers_

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1532 of file Configurable.py.

◆ log

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

Definition at line 34 of file Configurable.py.

◆ postConfigActions

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1508 of file Configurable.py.