| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

Classes | Functions | Variables
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 1424 of file Configurable.py.

1424 def appendPostConfigAction(function):
1425 """
1426 Add a new callable ('function') to the list of post-configuration actions.
1427 If the callable is already in the list, it is moved to the end of the list.
1428 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1429 """
1430 try:
1431 postConfigActions.remove(function)
1432 except:
1433 pass
1434 postConfigActions.append(function)
1435
1436
GaudiKernel.Configurable.appendPostConfigAction
def appendPostConfigAction(function)
Definition: Configurable.py:1424

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

1448 def applyConfigurableUsers():
1449 """
1450 Call the apply method of all the ConfigurableUser instances respecting the
1451 dependencies. First the C.U.s that are not used by anybody, then the used
1452 ones, when they are not used anymore.
1453 """
1454 # Avoid double calls
1455 global _appliedConfigurableUsers_, postConfigActions
1456 if _appliedConfigurableUsers_:
1457 return
1458 _appliedConfigurableUsers_ = True
1459
1460 def applicableConfUsers():
1461 '''
1462 Generator returning all the configurables that can be applied in the
1463 order in which they can be applied.
1464 '''
1465 # This is tricky...
1466 # We keep on looking for the first configurable that can be applied.
1467 # When we cannot find any, 'next()' raises a StopIteration that is
1468 # propagated outside of the infinite loop and the function, then handled
1469 # correctly from outside (it is the exception that is raised when you
1470 # exit from a generator).
1471 # Checking every time the full list is inefficient, but it is the
1472 # easiest way to fix bug #103803.
1473 # <https://savannah.cern.ch/bugs/?103803>
1474 while True:
1475 yield (c for c in Configurable.allConfigurables.values()
1476 if c.isApplicable()).next()
1477
1478 debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1479 for c in applicableConfUsers():
1480 if c._enabled:
1481 log.info("applying configuration of %s", c.name())
1482 if debugApplyOrder:
1483 sys.stderr.write('applying %r' % c)
1484 c.__apply_configuration__()
1485 log.info(c)
1486 else:
1487 log.info("skipping configuration of %s", c.name())
1488 c._applied = True # flag the instance as already applied
1489 if hasattr(c, "__detach_used__"):
1490 # tells the used configurables that they are not needed anymore
1491 c.__detach_used__()
1492
1493 # check for dependency loops
1494 leftConfUsers = [c for c in Configurable.allConfigurables.values()
1495 if hasattr(c, '__apply_configuration__') and
1496 c._enabled and not c._applied]
1497 # if an enabled configurable has not been applied, there must be a dependency loop
1498 if leftConfUsers:
1499 raise Error("Detected loop in the ConfigurableUser"
1500 " dependencies: %r" % [c.name()
1501 for c in leftConfUsers])
1502 # ensure that all the Handles have been triggered
1503 known = set()
1504 unknown = set(Configurable.allConfigurables)
1505 while unknown:
1506 for k in unknown:
1507 if not known: # do not print during the first iteration
1508 log.debug('new configurable created automatically: %s', k)
1509 # this trigger the instantiation from handles
1510 Configurable.allConfigurables[k].properties()
1511 known.add(k)
1512 unknown -= known
1513 # Call post-config actions
1514 for action in postConfigActions:
1515 action()
1516
1517
std::function< StatusCode()>
GaudiKernel.Configurable.applyConfigurableUsers
def applyConfigurableUsers()
Definition: Configurable.py:1448
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:41
GaudiKernel.Configurable.Error
Definition: Configurable.py:61

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

1518 def applyConfigurableUsers_old():
1519 """
1520 Obsolete (buggy) implementation of applyConfigurableUsers(), kept to provide
1521 backward compatibility for configurations that where relying (implicitly) on
1522 bug #103803, or on a specific (non guaranteed) order of execution.
1523
1524 @see applyConfigurableUsers()
1525 """
1526 # Avoid double calls
1527 global _appliedConfigurableUsers_, postConfigActions
1528 if _appliedConfigurableUsers_:
1529 return
1530 _appliedConfigurableUsers_ = True
1531
1532 debugApplyOrder = 'GAUDI_DUBUG_CONF_USER' in os.environ
1533 confUsers = [c
1534 for c in Configurable.allConfigurables.values()
1535 if hasattr(c, "__apply_configuration__")]
1536 applied = True # needed to detect dependency loops
1537 while applied and confUsers:
1538 newConfUsers = [] # list of conf users that cannot be applied yet
1539 applied = False
1540 for c in confUsers:
1541 if hasattr(c, "__users__") and c.__users__:
1542 newConfUsers.append(c) # cannot use this one yet
1543 else: # it does not have users or the list is empty
1544 applied = True
1545 # the ConfigurableUser is enabled if it doesn't have an _enabled
1546 # property or its value is True
1547 enabled = (not hasattr(c, "_enabled")) or c._enabled
1548 if enabled:
1549 log.info("applying configuration of %s", c.name())
1550 if debugApplyOrder:
1551 sys.stderr.write('applying %r' % c)
1552 c.__apply_configuration__()
1553 log.info(c)
1554 else:
1555 log.info("skipping configuration of %s", c.name())
1556 if hasattr(c, "__detach_used__"):
1557 # tells the used configurables that they are not needed anymore
1558 c.__detach_used__()
1559 confUsers = newConfUsers # list of C.U.s still to go
1560 if confUsers:
1561 # this means that some C.U.s could not be applied because of a dependency loop
1562 raise Error("Detected loop in the ConfigurableUser "
1563 " dependencies: %r" % [c.name()
1564 for c in confUsers])
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
std::function< StatusCode()>
GaudiKernel.Configurable.applyConfigurableUsers_old
def applyConfigurableUsers_old()
Definition: Configurable.py:1518
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:41
GaudiKernel.Configurable.Error
Definition: Configurable.py:61

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

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

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

1581 def getNeededConfigurables():
1582 """
1583 Function to select all and only the configurables that have to be used in
1584 GaudiPython.AppMgr constructor.
1585 This is needed because in Athena the implementation have to be different (the
1586 configuration is used in a different moment).
1587 """
1588 return [k
1589 for k, v in Configurable.allConfigurables.items()
1590 if v.getGaudiType() != "User"] # Exclude ConfigurableUser instances
1591
1592
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1581

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

962 def isApplicable(self):
963 '''
964 Return True is the instance can be "applied".
965 Always False for plain Configurable instances
966 (i.e. not ConfigurableUser).
967 '''
968 return False
969
970 # classes for generic Gaudi component ===========
971
972
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:962

def GaudiKernel.Configurable.makeSequences | ( |  | expression | ) |

    Convert a control flow expression to nested GaudiSequencers.

Definition at line 1668 of file Configurable.py.

1668 def makeSequences(expression):
1669 '''
1670 Convert a control flow expression to nested GaudiSequencers.
1671 '''
1672 if not isinstance(expression, ControlFlowNode):
1673 raise ValueError('ControlFlowNode instance expected, got %s' %
1674 type(expression).__name__)
1675 visitor = CreateSequencesVisitor()
1676 expression.visitNode(visitor)
1677 return visitor.sequence
1678
1679
GaudiKernel.Configurable.CreateSequencesVisitor
Definition: Configurable.py:1614
GaudiKernel.Configurable.makeSequences
def makeSequences(expression)
Definition: Configurable.py:1668
gaudirun.type
type
Definition: gaudirun.py:133

def GaudiKernel.Configurable.purge | ( |  | ) |

    Clean up all configurations and configurables.

Definition at line 1593 of file Configurable.py.

1593 def purge():
1594 """
1595 Clean up all configurations and configurables.
1596 """
1597 for c in Configurable.allConfigurables.values():
1598 c.__class__.configurables.clear()
1599 Configurable.allConfigurables.clear()
1600 # FIXME: (MCl) this is needed because instances of ConfigurableGeneric are not
1601 # migrated to the correct class when this is known.
1602 ConfigurableGeneric.configurables.clear()
1603 from ProcessJobOptions import _included_files
1604 import os.path
1605 import sys
1606 for file in _included_files:
1607 dirname, basname = os.path.split(file)
1608 basname, ext = os.path.splitext(basname)
1609 if basname in sys.modules:
1610 del sys.modules[basname]
1611 _included_files.clear()
1612
1613
GaudiKernel.Configurable.purge
def purge()
Definition: Configurable.py:1593

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

1437 def removePostConfigAction(function):
1438 """
1439 Remove a callable from the list of post-config actions.
1440 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'.
1441 """
1442 postConfigActions.remove(function)
1443
1444
GaudiKernel.Configurable.removePostConfigAction
def removePostConfigAction(function)
Definition: Configurable.py:1437

## Variable Documentation

list GaudiKernel.Configurable.__all__
| private

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

Definition at line 24 of file Configurable.py.

bool GaudiKernel.Configurable._appliedConfigurableUsers_ = False
| private

Definition at line 1445 of file Configurable.py.

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

Definition at line 35 of file Configurable.py.

list GaudiKernel.Configurable.postConfigActions = []

Definition at line 1421 of file Configurable.py.