The Gaudi Framework  v31r0 (aeb156f0)
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

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

1488  """
1489  Add a new callable ('function') to the list of post-configuration actions.
1490  If the callable is already in the list, it is moved to the end of the list.
1491  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1492  """
1493  try:
1494  postConfigActions.remove(function)
1495  except:
1496  pass
1497  postConfigActions.append(function)
1498 
1499 
def appendPostConfigAction(function)
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 1511 of file Configurable.py.

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

1582  """
1583  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1584  backward compatibility for configurations that where relying (implicitly) on
1585  bug #103803, or on a specific (non guaranteed) order of execution.
1586 
1587  @see applyConfigurableUsers()
1588  """
1589  # Avoid double calls
1590  global _appliedConfigurableUsers_, postConfigActions
1591  if _appliedConfigurableUsers_:
1592  return
1593  _appliedConfigurableUsers_ = True
1594 
1595  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1596  confUsers = [
1597  c for c in Configurable.allConfigurables.values()
1598  if hasattr(c, "__apply_configuration__")
1599  ]
1600  applied = True # needed to detect dependency loops
1601  while applied and confUsers:
1602  newConfUsers = [] # list of conf users that cannot be applied yet
1603  applied = False
1604  for c in confUsers:
1605  if hasattr(c, "__users__") and c.__users__:
1606  newConfUsers.append(c) # cannot use this one yet
1607  else: # it does not have users or the list is empty
1608  applied = True
1609  # the ConfigurableUser is enabled if it doesn't have an _enabled
1610  # property or its value is True
1611  enabled = (not hasattr(c, "_enabled")) or c._enabled
1612  if enabled:
1613  log.info("applying configuration of %s", c.name())
1614  if debugApplyOrder:
1615  sys.stderr.write('applying %r' % c)
1616  c.__apply_configuration__()
1617  log.info(c)
1618  else:
1619  log.info("skipping configuration of %s", c.name())
1620  if hasattr(c, "__detach_used__"):
1621  # tells the used configurables that they are not needed anymore
1622  c.__detach_used__()
1623  confUsers = newConfUsers # list of C.U.s still to go
1624  if confUsers:
1625  # this means that some C.U.s could not be applied because of a dependency loop
1626  raise Error("Detected loop in the ConfigurableUser "
1627  " dependencies: %r" % [c.name() for c in confUsers])
1628  # ensure that all the Handles have been triggered
1629  known = set()
1630  unknown = set(Configurable.allConfigurables)
1631  while unknown:
1632  for k in unknown:
1633  if not known: # do not print during the first iteration
1634  log.debug('new configurable created automatically: %s', k)
1635  # this trigger the instantiation from handles
1636  Configurable.allConfigurables[k].properties()
1637  known.add(k)
1638  unknown -= known
1639  # Call post-config actions
1640  for action in postConfigActions:
1641  action()
1642 
1643 
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 35 of file Configurable.py.

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

1645  """
1646  Function to select all and only the configurables that have to be used in
1647  GaudiPython.AppMgr constructor.
1648  This is needed because in Athena the implementation have to be different (the
1649  configuration is used in a different moment).
1650  """
1651  return [
1652  k for k, v in Configurable.allConfigurables.items()
1653  if v.getGaudiType() != "User"
1654  ] # Exclude ConfigurableUser instances
1655 
1656 
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 995 of file Configurable.py.

995  def isApplicable(self):
996  '''
997  Return True is the instance can be "applied".
998  Always False for plain Configurable instances
999  (i.e. not ConfigurableUser).
1000  '''
1001  return False
1002 
1003 
1004 # classes for generic Gaudi component ===========
1005 
1006 
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...
def GaudiKernel.Configurable.makeSequences (   expression)
Convert a control flow expression to nested GaudiSequencers.

Definition at line 1731 of file Configurable.py.

1731 def makeSequences(expression):
1732  '''
1733  Convert a control flow expression to nested GaudiSequencers.
1734  '''
1735  if not isinstance(expression, ControlFlowNode):
1736  raise ValueError('ControlFlowNode instance expected, got %s' %
1737  type(expression).__name__)
1738  visitor = CreateSequencesVisitor()
1739  expression.visitNode(visitor)
1740  return visitor.sequence
1741 
1742 
def makeSequences(expression)
def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1657 of file Configurable.py.

1657 def purge():
1658  """
1659  Clean up all configurations and configurables.
1660  """
1661  for c in Configurable.allConfigurables.values():
1662  c.__class__.configurables.clear()
1663  Configurable.allConfigurables.clear()
1664  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1665  # migrated to the correct class when this is known.
1666  ConfigurableGeneric.configurables.clear()
1667  from ProcessJobOptions import _included_files
1668  import os.path
1669  import sys
1670  for file in _included_files:
1671  dirname, basname = os.path.split(file)
1672  basname, ext = os.path.splitext(basname)
1673  if basname in sys.modules:
1674  del sys.modules[basname]
1675  _included_files.clear()
1676 
1677 
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 1500 of file Configurable.py.

1501  """
1502  Remove a callable from the list of post-config actions.
1503  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1504  """
1505  postConfigActions.remove(function)
1506 
1507 
def removePostConfigAction(function)

Variable Documentation

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

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
private

Definition at line 1508 of file Configurable.py.

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

Definition at line 32 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1484 of file Configurable.py.