All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiKernel.Configurable Namespace Reference

Classes

class  Configurable
 
class  ConfigurableAlgorithm
 
class  ConfigurableAlgTool
 
class  ConfigurableAuditor
 
class  ConfigurableGeneric
 
class  ConfigurableService
 
class  ConfigurableUser
 
class  DummyDescriptor
 classes for generic Gaudi component =========== More...
 
class  Error
 
class  PropertyReference
 Allow references to options as in old style. More...
 

Functions

def expandvars
 
def isApplicable
 if isinstance(v,Configurable) and not v.isPublic(): 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
 
def removePostConfigAction
 
def applyConfigurableUsers
 
def applyConfigurableUsers_old
 
def getNeededConfigurables
 
def purge
 

Variables

list __all__
 data ------------------------------------------------------------------— More...
 
tuple log = logging.getLogger( 'Configurable' )
 
list postConfigActions = []
 
 _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 1327 of file Configurable.py.

1328 def appendPostConfigAction(function):
1329  """
1330  Add a new callable ('function') to the list of post-configuration actions.
1331  If the callable is already in the list, it is moved to the end of the list.
1332  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1333  """
1334  try:
1335  postConfigActions.remove(function)
1336  except:
1337  pass
postConfigActions.append(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 1346 of file Configurable.py.

1348  """
1349  Call the apply method of all the ConfigurableUser instances respecting the
1350  dependencies. First the C.U.s that are not used by anybody, then the used
1351  ones, when they are not used anymore.
1352  """
1353  # Avoid double calls
1354  global _appliedConfigurableUsers_, postConfigActions
1355  if _appliedConfigurableUsers_:
1356  return
1357  _appliedConfigurableUsers_ = True
1358 
1359  def applicableConfUsers():
1360  '''
1361  Generator returning all the configurables that can be applied in the
1362  order in which they can be applied.
1363  '''
1364  # This is tricky...
1365  # We keep on looking for the first configurable that can be applied.
1366  # When we cannot find any, 'next()' raises a StopIteration that is
1367  # propagated outside of the infinite loop and the function, then handled
1368  # correctly from outside (it is the exception that is raised when you
1369  # exit from a generator).
1370  # Checking every time the full list is inefficient, but it is the
1371  # easiest way to fix bug #103803.
1372  # <https://savannah.cern.ch/bugs/?103803>
1373  while True:
1374  yield (c for c in Configurable.allConfigurables.values()
1375  if c.isApplicable()).next()
1376 
1377  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1378  for c in applicableConfUsers():
1379  if c._enabled:
1380  log.info("applying configuration of %s", c.name())
1381  if debugApplyOrder:
1382  sys.stderr.write('applying %r' % c)
1383  c.__apply_configuration__()
1384  log.info(c)
1385  else:
1386  log.info("skipping configuration of %s", c.name())
1387  c._applied = True # flag the instance as already applied
1388  if hasattr(c, "__detach_used__"):
1389  # tells the used configurables that they are not needed anymore
1390  c.__detach_used__()
1391 
1392  # check for dependency loops
1393  leftConfUsers = [c for c in Configurable.allConfigurables.values()
1394  if hasattr(c, '__apply_configuration__') and
1395  c._enabled and not c._applied]
1396  # if an enabled configurable has not been applied, there must be a dependency loop
1397  if leftConfUsers:
1398  raise Error("Detected loop in the ConfigurableUser"
1399  " dependencies: %r" % [ c.name()
1400  for c in leftConfUsers ])
1401  # ensure that all the Handles have been triggered
1402  known = set()
1403  unknown = set(Configurable.allConfigurables)
1404  while unknown:
1405  for k in unknown:
1406  if not known: # do not print during the first iteration
1407  log.debug('new configurable created automatically: %s', k)
1408  # this trigger the instantiation from handles
1409  Configurable.allConfigurables[k].properties()
1410  known.add(k)
1411  unknown -= known
1412  # Call post-config actions
1413  for action in postConfigActions:
1414  action()
string action
Definition: merge_files.py:89
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 1415 of file Configurable.py.

1417  """
1418  Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1419  backward compatibility for configurations that where relying (implicitly) on
1420  bug #103803, or on a specific (non guaranteed) order of execution.
1421 
1422  @see applyConfigurableUsers()
1423  """
1424  # Avoid double calls
1425  global _appliedConfigurableUsers_, postConfigActions
1426  if _appliedConfigurableUsers_:
1427  return
1428  _appliedConfigurableUsers_ = True
1429 
1430  debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1431  confUsers = [ c
1432  for c in Configurable.allConfigurables.values()
1433  if hasattr(c,"__apply_configuration__") ]
1434  applied = True # needed to detect dependency loops
1435  while applied and confUsers:
1436  newConfUsers = [] # list of conf users that cannot be applied yet
1437  applied = False
1438  for c in confUsers:
1439  if hasattr(c,"__users__") and c.__users__:
1440  newConfUsers.append(c) # cannot use this one yet
1441  else: # it does not have users or the list is empty
1442  applied = True
1443  # the ConfigurableUser is enabled if it doesn't have an _enabled
1444  # property or its value is True
1445  enabled = (not hasattr(c, "_enabled")) or c._enabled
1446  if enabled:
1447  log.info("applying configuration of %s", c.name())
1448  if debugApplyOrder:
1449  sys.stderr.write('applying %r' % c)
1450  c.__apply_configuration__()
1451  log.info(c)
1452  else:
1453  log.info("skipping configuration of %s", c.name())
1454  if hasattr(c, "__detach_used__"):
1455  # tells the used configurables that they are not needed anymore
1456  c.__detach_used__()
1457  confUsers = newConfUsers # list of C.U.s still to go
1458  if confUsers:
1459  # this means that some C.U.s could not be applied because of a dependency loop
1460  raise Error("Detected loop in the ConfigurableUser "
1461  " dependencies: %r" % [ c.name()
1462  for c in confUsers ])
1463  # ensure that all the Handles have been triggered
1464  known = set()
1465  unknown = set(Configurable.allConfigurables)
1466  while unknown:
1467  for k in unknown:
1468  if not known: # do not print during the first iteration
1469  log.debug('new configurable created automatically: %s', k)
1470  # this trigger the instantiation from handles
1471  Configurable.allConfigurables[k].properties()
1472  known.add(k)
1473  unknown -= known
1474  # Call post-config actions
1475  for action in postConfigActions:
1476  action()
string action
Definition: merge_files.py:89
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 28 of file Configurable.py.

28 
29 def expandvars(data):
30  """
31  Expand environment variables "data".
32  Data can be string, list, tuple and dictionary. For collection, all the
33  contained strings will be manipulated (recursively).
34  """
35  import os.path
36  typ = type(data)
37  if typ is str:
38  return os.path.expandvars(data)
39  elif typ in [list, tuple]:
40  collect = []
41  for i in data:
42  collect.append(expandvars(i))
43  return typ(collect)
44  elif typ is dict:
45  collect = {}
46  for k in data:
47  collect[expandvars(k)] = expandvars(data[k])
48  return collect
49  return data
string type
Definition: gaudirun.py:126
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 1477 of file Configurable.py.

1479  """
1480  Function to select all and only the configurables that have to be used in
1481  GaudiPython.AppMgr constructor.
1482  This is needed because in Athena the implementation have to be different (the
1483  configuration is used in a different moment).
1484  """
1485  return [ k
1486  for k, v in Configurable.allConfigurables.items()
1487  if v.getGaudiType() != "User" ] # Exclude ConfigurableUser instances
def GaudiKernel.Configurable.isApplicable (   self)

if isinstance(v,Configurable) and not v.isPublic(): 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

for cfg in self.__children:

Return True is the instance can be "applied".
Always False for plain Configurable instances
(i.e. not ConfigurableUser).

Definition at line 913 of file Configurable.py.

914  def isApplicable(self):
915  '''
916  Return True is the instance can be "applied".
917  Always False for plain Configurable instances
918  (i.e. not ConfigurableUser).
919  '''
920  return False
def isApplicable
if isinstance(v,Configurable) and not v.isPublic(): rep += v.__str__( indent + 1 ) + os...
def GaudiKernel.Configurable.purge ( )
Clean up all configurations and configurables.

Definition at line 1488 of file Configurable.py.

1489 def purge():
1490  """
1491  Clean up all configurations and configurables.
1492  """
1493  for c in Configurable.allConfigurables.values():
1494  c.__class__.configurables.clear()
1495  Configurable.allConfigurables.clear()
1496  # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1497  # migrated to the correct class when this is known.
1498  ConfigurableGeneric.configurables.clear()
1499  from ProcessJobOptions import _included_files
1500  import os.path, sys
1501  for file in _included_files:
1502  dirname, basname = os.path.split(file)
1503  basname, ext = os.path.splitext(basname)
1504  if basname in sys.modules:
1505  del sys.modules[basname]
1506  _included_files.clear()
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 1338 of file Configurable.py.

1339 def removePostConfigAction(function):
1340  """
1341  Remove a callable from the list of post-config actions.
1342  The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1343  """
1344  postConfigActions.remove(function)

Variable Documentation

list GaudiKernel.Configurable.__all__
Initial value:
1 = [ 'Configurable',
2  'ConfigurableAlgorithm',
3  'ConfigurableAlgTool',
4  'ConfigurableAuditor',
5  'ConfigurableService',
6  'ConfigurableUser',
7  'VERBOSE','DEBUG','INFO', 'WARNING', 'ERROR', 'FATAL',
8  'appendPostConfigAction', 'removePostConfigAction' ]

data ------------------------------------------------------------------—

Definition at line 15 of file Configurable.py.

GaudiKernel.Configurable._appliedConfigurableUsers_ = False

Definition at line 1345 of file Configurable.py.

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

Definition at line 26 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1326 of file Configurable.py.