10 from inspect
import isclass
13 VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL
19 InvertNode, ControlFlowLeaf,
20 ControlFlowNode, CFTrue, CFFalse)
24 'Configurable',
'ConfigurableAlgorithm',
'ConfigurableAlgTool',
25 'ConfigurableAuditor',
'ConfigurableService',
'ConfigurableUser',
26 'VERBOSE',
'DEBUG',
'INFO',
'WARNING',
'ERROR',
'FATAL',
27 'appendPostConfigAction',
'removePostConfigAction' 32 log = logging.getLogger(
'Configurable')
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). 44 return os.path.expandvars(data)
45 elif typ
in [list, tuple]:
60 Error occurred in the configuration process. 68 class PropertyReference(object):
73 return "@%s" % self.
name 78 refname, refprop = self.name.rsplit(
'.', 1)
79 if refname
in Configurable.allConfigurables:
80 conf = Configurable.allConfigurables[refname]
81 retval = getattr(conf, refprop)
82 if hasattr(retval,
"getFullName"):
83 retval = retval.getFullName()
86 "name '%s' not found resolving '%s'" % (refname, self))
90 """This function allow transparent integration with 91 Configurable.getValuedProperties. 98 except AttributeError:
107 """Base class for Gaudi components that implement the IProperty interface. 108 Provides most of the boilerplate code, but the actual useful classes 109 are its derived ConfigurableAlgorithm, ConfigurableService, and 110 ConfigurableAlgTool.""" 116 propertyNoValue =
'<no value>' 118 printHeaderWidth = 100
135 configurableServices = {
139 _configurationLocked =
False 142 """To Gaudi, any object with the same type/name is the same object. Hence, 143 this is mimicked in the configuration: instantiating a new Configurable 144 of a type with the same name will return the same instance.""" 150 name = kwargs[
'name']
151 elif 'name' in cls.__init__.func_code.co_varnames:
153 index = list(cls.__init__.func_code.co_varnames).index(
'name')
156 name = args[index - 1]
159 name = cls.__init__.func_defaults[index - (len(args) + 1)]
164 except (IndexError, TypeError):
165 raise TypeError(
'no "name" argument while instantiating "%s"' %
170 if hasattr(cls,
'DefaultedName'):
171 name = cls.DefaultedName
174 elif not name
or type(name) != str:
177 'could not retrieve name from %s.__init__ arguments' %
182 if issubclass(cls, ConfigurableAlgTool)
and '.' not in name:
183 name =
'ToolSvc.' + name
193 if name
in cls.configurables:
194 conf = cls.configurables[name]
196 cls.configurables[conf.getType()] = conf
198 for n, v
in kwargs.items():
202 conf, ConfigurableUser):
205 setattr(conf,
"_enabled",
True)
209 spos = name.find(
'/')
212 ti_name =
"%s/%s" % (name, name)
213 if ti_name
in cls.configurables:
215 return cls.configurables[ti_name]
220 if i_name == name[spos + 1:]
and i_name
in cls.configurables:
222 return cls.configurables[i_name]
225 conf = cls.allConfigurables.get(name,
None)
or\
226 (spos < 0
and cls.allConfigurables.get(ti_name,
None))
or\
227 (spos > 0
and i_name == name[spos + 1:]
228 and cls.allConfigurables.get(i_name,
None))
230 if conf.__class__
is ConfigurableGeneric:
234 newconf = object.__new__(cls)
235 cls.
__init__(newconf, *args, **kwargs)
240 for n
in newconf.__slots__:
242 for n
in conf._properties:
243 if names[n.lower()] != n:
245 "Option '%s' was used for %s, but the correct spelling is '%s'" 246 % (n, name, names[n.lower()]))
247 setattr(newconf, names[n.lower()], getattr(conf, n))
248 for n, v
in kwargs.items():
249 setattr(newconf, n, v)
250 cls.configurables[name] = newconf
256 'attempt to redefine type of "%s" (was: %s, new: %s)%s',
257 name, conf.__class__.__name__, cls.__name__,
263 for n, v
in kwargs.items():
268 conf = object.__new__(cls)
272 cls.configurables[name] = conf
274 for base
in cls.__bases__:
275 if base.__name__ ==
'ConfigurableService':
287 klass = self.__class__
290 if klass == Configurable:
291 raise TypeError,
"%s is an ABC and can not be instantiated" % str(
303 for meth, nArgs
in meths.items():
305 f = getattr(klass, meth).im_func
306 except AttributeError:
307 raise NotImplementedError,
"%s is missing in class %s" % (
311 nargcount = f.func_code.co_argcount
312 ndefaults = f.func_defaults
and len(f.func_defaults)
or 0
313 if not nargcount - ndefaults <= nArgs <= nargcount:
314 raise TypeError,
"%s.%s requires exactly %d arguments" % (
323 if hasattr(self.__class__,
'DefaultedName'):
324 self.
_name = self.__class__.DefaultedName
345 for name, proxy
in self._properties.items():
347 dict[name] = proxy.__get__(self)
348 except AttributeError:
351 dict[
'_Configurable__children'] = self.
__children 352 dict[
'_Configurable__tools'] = self.
__tools 353 dict[
'_name'] = self.
_name 357 return (self.
_name, )
361 from contextlib
import contextmanager
372 for n, v
in dict.items():
384 newconf = object.__new__(self.__class__)
385 self.__class__.__init__(newconf, self.
getName())
387 for proxy
in self._properties.values():
389 proxy.__set__(newconf, proxy.__get__(self))
390 except AttributeError:
400 if not type(configs)
in (list, tuple):
401 configs = (configs, )
407 if not isinstance(cfg, Configurable):
408 raise TypeError(
"'%s' is not a Configurable" % str(cfg))
413 ccjo = cc.getJobOptName()
415 if c.getJobOptName() == ccjo:
416 log.error(
'attempt to add a duplicate ... dupe ignored%s',
420 self.__children.append(cc)
424 descr.__set__(self, cc)
426 setattr(self, cc.getName(), cc)
427 except AttributeError:
437 if attr
in self._properties:
438 if isinstance(self._properties[attr].__get__(self),
439 DataObjectHandleBase):
440 return self._properties[attr].__get__(self)
443 if c.getName() == attr:
446 raise AttributeError(
447 "'%s' object has no attribute '%s'" % (self.__class__, attr))
452 "%s: Configuration cannot be modified after the ApplicationMgr has been started." 456 except AttributeError:
457 raise AttributeError(
458 "Configurable '%s' does not have property '%s'." %
459 (self.__class__.__name__, name))
465 prop = self._properties[attr]
466 prop.__delete__(self)
467 prop.__set__(self, prop.default)
477 if c.getName() == attr:
478 self.__children.remove(c)
482 del self.__dict__[attr]
483 except (AttributeError, KeyError):
490 if type(items) != list
and type(items) != tuple:
500 return copy.deepcopy(child)
514 if hasattr(cc,
'setParent')
and parent:
517 except RuntimeError, e:
519 log.error(str(e) +
'%s', error_explanation)
520 ccbd = cc.configurables[cc.getJobOptName()]
523 for proxy
in self._properties.values():
524 if proxy.history.has_key(cc):
525 proxy.__set__(ccbd, proxy.__get__(cc))
535 return self.__tools.values()
539 "children() is deprecated, use getChildren() instead for consistency" 542 "getChildren() returns a copy; to add a child, use 'parent += child'%s",
547 """Get all (private) configurable children, both explicit ones (added with +=) 548 and the ones in the private GaudiHandle properties""" 551 for proxy
in self._properties.values():
553 c = proxy.__get__(self)
554 except AttributeError:
557 if isinstance(c, Configurable)
and not c.isPublic():
559 elif isinstance(c, GaudiHandle):
561 conf = c.configurable
562 except AttributeError:
565 if not conf.isPublic():
567 elif isinstance(c, GaudiHandleArray):
571 if isinstance(ci, Configurable):
575 conf = ci.configurable
576 except AttributeError:
588 elems.append(c.getFullName())
593 if not hasattr(self,
'_initok')
or not self.
_initok:
596 "Configurable.__init__ not called in %s override" % self.__class__.__name__
610 handle = self.getHandle()
612 log.debug(
'no handle for %s: not transporting properties',
617 for name
in self._properties.keys():
620 setattr(handle, name, getattr(self, name))
627 for name, proxy
in self._properties.items():
629 props[name] = proxy.__get__(self)
630 except AttributeError:
631 props[name] = Configurable.propertyNoValue
636 """Get all properties with their description string as { name : (value, desc) }.""" 638 for name, proxy
in self._properties.items():
640 props[name] = (proxy.__get__(self), proxy.__doc__)
641 except AttributeError:
642 props[name] = (Configurable.propertyNoValue, proxy.__doc__)
647 for name, proxy
in self._properties.items():
649 value = proxy.__get__(self)
650 if hasattr(value,
'getFullName'):
651 value = value.getFullName()
652 elif type(value)
in [list, tuple]:
655 if hasattr(i,
'getFullName'):
656 new_value.append(i.getFullName())
659 value =
type(value)(new_value)
660 elif type(value)
is dict:
663 if hasattr(value[i],
'getFullName'):
666 new_value[i] = value[i]
685 for k, v
in cls._properties.items():
686 if not k
in c.__dict__
and hasattr(v,
'default'):
687 c.__dict__[k] = v.default
700 if name
in c.__dict__:
701 return c.__dict__[name]
705 v = cls._properties[name]
706 if hasattr(v,
'default'):
714 """Returns the value of the given property. 716 if hasattr(self, name):
717 return getattr(self, name)
722 """Set the value of a given property 724 return setattr(self, name, value)
727 """Tell if the property 'name' has been set or not. 729 Because of a problem with list and dictionary properties, in those cases 730 if the value is equal to the default, the property is considered as not 733 if not hasattr(self, name):
736 if isinstance(default, (list, dict, DataObjectHandleBase)):
737 value = getattr(self, name)
738 return value != default
759 "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
774 if log.isEnabledFor(logging.DEBUG):
782 def clone(self, name=None, **kwargs):
784 if hasattr(self,
'DefaultedName'):
785 name = self.DefaultedName
787 name = self.getType()
789 newconf = Configurable.__new__(self.__class__, name)
790 self.__class__.__init__(newconf, name)
792 for proxy
in self._properties.values():
794 value = proxy.__get__(self)
795 if type(value)
in [str, list, dict, tuple]:
797 value =
type(value)(value)
798 proxy.__set__(newconf, value)
799 except AttributeError:
802 for c
in self.__children:
805 for n, t
in self.__tools.items():
806 newconf.addTool(t, n)
808 for name, value
in kwargs.items():
809 setattr(newconf, name, value)
815 dot = fullname.find(
'.')
817 parentname = fullname[:dot]
818 longname = fullname[dot + 1:]
822 dot = longname.find(
'.')
824 name = longname[:dot]
827 return parentname, name, longname
830 if isclass(tool)
and issubclass(tool, ConfigurableAlgTool):
833 priv_tool = tool(self.
getName() +
'.' + name)
834 elif isinstance(tool, ConfigurableAlgTool):
836 name = tool.splitName()[1]
837 priv_tool = tool.clone(self.
getName() +
'.' + name)
840 classname = tool.__name__
842 classname =
type(tool).__name__
843 raise TypeError,
"addTool requires AlgTool configurable. Got %s type" % classname
847 setattr(self, name, self.
__tools[name])
862 handle = __main__.Service(svc)
867 if hasattr(self,
'configure' + svc):
868 eval(
'self.configure' + svc +
'( handle )')
871 dlls = self.getDlls()
874 elif type(dlls) == types.StringType:
877 from __main__
import theApp
878 dlls = filter(
lambda d: d
not in theApp.Dlls, dlls)
891 preLen = Configurable.printHeaderPre
892 postLen = Configurable.printHeaderWidth - \
893 preLen - 3 - len(title)
894 postLen =
max(preLen, postLen)
895 return indentStr +
'/%s %s %s' % (preLen *
'*', title, postLen *
'*')
899 preLen = Configurable.printHeaderPre
900 postLen = Configurable.printHeaderWidth - \
901 preLen - 12 - len(title)
902 postLen =
max(preLen, postLen)
903 return indentStr +
'\\%s (End of %s) %s' % (preLen *
'-', title,
907 return '{0}({1!r})'.
format(self.__class__.__name__, self.
name())
909 def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
911 indentStr = indent * Configurable.indentUnit
916 headerIndent = (indent - 1) * \
917 Configurable.indentUnit + headerLastIndentUnit
920 rep = Configurable._printHeader(headerIndent, title)
926 rep += indentStr +
'|-<no properties>' + os.linesep
930 for p
in props.keys():
931 nameWidth =
max(nameWidth, len(p))
932 for p, v
in props.items():
934 prefix = indentStr +
'|-%-*s' % (nameWidth, p)
936 if log.isEnabledFor(logging.DEBUG):
937 if v != Configurable.propertyNoValue:
938 address =
' @%11s' %
hex(id(v))
943 default = defs.get(p)
944 if v == Configurable.propertyNoValue:
946 strVal = repr(default)
950 if hasattr(v,
"getGaudiHandle"):
951 vv = v.getGaudiHandle()
954 if isinstance(vv, GaudiHandle)
or isinstance(
955 vv, GaudiHandleArray):
958 if hasattr(default,
"toStringProperty"):
959 strDef = repr(default.toStringProperty())
961 strDef = repr(default)
962 if strDef == repr(vv.toStringProperty()):
966 strDef = repr(default)
968 line = prefix +
' = ' + strVal
970 if strDef
is not None:
972 if len(line) + len(strDef) > Configurable.printHeaderWidth:
973 line += os.linesep + indentStr +
'| ' + \
974 (len(prefix) - len(indentStr) - 3) *
' ' 975 line +=
' (default: %s)' % (strDef, )
977 rep += line + os.linesep
989 rep += cfg.__str__(indent + 1,
'|=') + os.linesep
992 rep += Configurable._printFooter(indentStr, title)
997 Return True is the instance can be "applied". 998 Always False for plain Configurable instances 999 (i.e. not ConfigurableUser). 1015 object.__setattr__(obj, self.
__name__, value)
1022 Configurable.__init__(self, name)
1030 return 'GenericComponent' 1041 super(ConfigurableGeneric, self).
__setattr__(name, value)
1045 if isinstance(value, Configurable):
1046 self.__dict__[name] = value
1050 if not name
in self._properties:
1052 self._properties[name].__set__(self, value)
1066 'AuditAlgorithms': 0,
1067 'AuditInitialize': 0,
1068 'AuditReinitialize': 0,
1076 super(ConfigurableAlgorithm, self).
__init__(name)
1096 elif rhs
is CFFalse:
1098 return AndNode(self, rhs)
1105 return OrNode(self, rhs)
1108 return InvertNode(self)
1111 return OrderedNode(self, rhs)
1122 return (repr(self) == repr(other))
1129 'AuditInitialize': 0,
1140 return iService(self.
_name)
1158 'AuditInitialize': 0,
1163 super(ConfigurableAlgTool, self).
__init__(name)
1164 if '.' not in self.
_name:
1168 name = name[name.find(
'/') + 1:]
1189 return pop + Configurable.getPrintTitle(self)
1198 if isinstance(c, ConfigurableAlgTool):
1199 c.setParent(parentName)
1203 name = name[name.rfind(
'.') + 1:]
1207 dot = self._jobOptName.rfind(
'.')
1214 return self._jobOptName.startswith(parent +
'.')
1223 return self._jobOptName.startswith(
'ToolSvc.')
1234 name = name[name.rfind(
'.') + 1:]
1235 return str(self.
getType() +
'/' + name)
1242 __slots__ = {
'_jobOptName': 0,
'OutputLevel': 0,
'Enable': 1}
1245 super(ConfigurableAuditor, self).
__init__(name)
1247 name = name[name.find(
'/') + 1:]
1268 "__used_instances__": [],
1280 __used_configurables__ = []
1283 __queried_configurables__ = []
1285 def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1286 super(ConfigurableUser, self).
__init__(name)
1287 for n, v
in kwargs.items():
1305 if type(used)
is tuple:
1306 used, used_name = used
1310 if type(used)
is str:
1311 used_class = confDbGetConfigurable(used)
1316 inst = used_class(name=used_name, _enabled=
False)
1317 except AttributeError:
1321 inst = used_class(name=used_name)
1325 if type(queried)
is str:
1326 queried = confDbGetConfigurable(used)
1327 inst = queried(_enabled=
False)
1328 except AttributeError:
1334 Declare that we are going to modify the Configurable 'other' in our 1335 __apply_configuration__. 1337 self.__used_instances__.append(other)
1338 if hasattr(other,
"__users__"):
1339 other.__users__.append(self)
1343 Declare that we are going to retrieve property values from the 1344 ConfigurableUser 'other' in our __apply_configuration__. 1346 if not isinstance(other, ConfigurableUser):
1348 "'%s': Cannot make passive use of '%s', it is not a ConfigurableUser" 1349 % (self.
name(), other.name()))
1350 other.__addActiveUseOf(self)
1363 Remove this ConfigurableUser instance from the users list of the used 1369 used.__users__.remove(self)
1373 Propagate the property 'name' (if set) to other configurables (if possible). 1376 propagate to all the entries in __used_configurables__ 1377 a configurable instance: 1378 propagate only to it 1379 list of configurable instances: 1380 propagate to all of them. 1384 - if the local property is set, the other property will be overwritten 1385 - local property not set and other set => keep other 1386 - local property not set and other not set => overwrite the default for 1387 ConfigurableUser instances and set the property for Configurables 1392 elif type(others)
not in [list, tuple]:
1398 for other
in [o
for o
in others
if name
in o.__slots__]:
1401 if other.isPropertySet(name):
1403 "Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'" 1405 "self": self.
name(),
1406 "other": other.name(),
1409 other.setProp(name, value)
1411 elif not other.isPropertySet(name):
1412 if isinstance(other, ConfigurableUser):
1413 otherType =
type(other._properties[name].getDefault())
1414 other._properties[name].setDefault(value)
1415 if otherType
in [list, dict]:
1418 other.setProp(name, otherType(value))
1420 other.setProp(name, value)
1425 Call propagateProperty for each property listed in 'names'. 1426 If 'names' is None, all the properties are propagated. 1430 names = [p
for p
in self.
__slots__ if not p.startswith(
"_")]
1436 Function to be overridden to convert the high level configuration into a 1438 The default implementation calls applyConf, which is the method defined 1439 in some ConfigurableUser implementations. 1445 Function to be overridden to convert the high level configuration into a 1452 Function used to define the name of the private instance of a given class 1454 This method is used when the __used_configurables_property__ declares the 1455 need of a private used configurable without specifying the name. 1457 if type(cls)
is str:
1460 clName = cls.__name__
1461 return "%s_%s" % (self.name(), clName)
1465 Return the used instance with a given name. 1468 if i.name() == name:
1469 if hasattr(i,
"_enabled"):
1474 raise KeyError(name)
1478 Return True is the instance can be "applied". 1484 postConfigActions = []
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'. 1494 postConfigActions.remove(function)
1497 postConfigActions.append(function)
1502 Remove a callable from the list of post-config actions. 1503 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'. 1505 postConfigActions.remove(function)
1508 _appliedConfigurableUsers_ =
False 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. 1518 global _appliedConfigurableUsers_, postConfigActions
1519 if _appliedConfigurableUsers_:
1521 _appliedConfigurableUsers_ =
True 1523 def applicableConfUsers():
1525 Generator returning all the configurables that can be applied in the 1526 order in which they can be applied. 1538 yield (c
for c
in Configurable.allConfigurables.values()
1539 if c.isApplicable()).next()
1541 debugApplyOrder =
'GAUDI_DUBUG_CONF_USER' in os.environ
1542 for c
in applicableConfUsers():
1544 log.info(
"applying configuration of %s", c.name())
1546 sys.stderr.write(
'applying %r' % c)
1547 c.__apply_configuration__()
1550 log.info(
"skipping configuration of %s", c.name())
1552 if hasattr(c,
"__detach_used__"):
1558 c
for c
in Configurable.allConfigurables.values()
if 1559 hasattr(c,
'__apply_configuration__')
and c._enabled
and not c._applied
1563 raise Error(
"Detected loop in the ConfigurableUser" 1564 " dependencies: %r" % [c.name()
for c
in leftConfUsers])
1567 unknown = set(Configurable.allConfigurables)
1571 log.debug(
'new configurable created automatically: %s', k)
1573 Configurable.allConfigurables[k].
properties()
1577 for action
in postConfigActions:
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. 1587 @see applyConfigurableUsers() 1590 global _appliedConfigurableUsers_, postConfigActions
1591 if _appliedConfigurableUsers_:
1593 _appliedConfigurableUsers_ =
True 1595 debugApplyOrder =
'GAUDI_DUBUG_CONF_USER' in os.environ
1597 c
for c
in Configurable.allConfigurables.values()
1598 if hasattr(c,
"__apply_configuration__")
1601 while applied
and confUsers:
1605 if hasattr(c,
"__users__")
and c.__users__:
1606 newConfUsers.append(c)
1611 enabled = (
not hasattr(c,
"_enabled"))
or c._enabled
1613 log.info(
"applying configuration of %s", c.name())
1615 sys.stderr.write(
'applying %r' % c)
1616 c.__apply_configuration__()
1619 log.info(
"skipping configuration of %s", c.name())
1620 if hasattr(c,
"__detach_used__"):
1623 confUsers = newConfUsers
1626 raise Error(
"Detected loop in the ConfigurableUser " 1627 " dependencies: %r" % [c.name()
for c
in confUsers])
1630 unknown = set(Configurable.allConfigurables)
1634 log.debug(
'new configurable created automatically: %s', k)
1636 Configurable.allConfigurables[k].
properties()
1640 for action
in postConfigActions:
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). 1652 k
for k, v
in Configurable.allConfigurables.items()
1653 if v.getGaudiType() !=
"User" 1659 Clean up all configurations and configurables. 1661 for c
in Configurable.allConfigurables.values():
1662 c.__class__.configurables.clear()
1663 Configurable.allConfigurables.clear()
1666 ConfigurableGeneric.configurables.clear()
1667 from ProcessJobOptions
import _included_files
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()
1684 return self.
stack[-1]
1692 name = prefix + str(cnt)
1693 while name
in allConfigurables:
1695 name = prefix + str(cnt)
1699 from Configurables
import GaudiSequencer
1704 if visitee
in (CFTrue, CFFalse):
1705 stack.append(self.
_newSeq(Invert=visitee
is CFFalse))
1706 elif isinstance(visitee, (ControlFlowLeaf, ConfigurableAlgorithm)):
1707 stack.append(visitee)
1708 elif isinstance(visitee, (OrNode, AndNode, OrderedNode)):
1713 ModeOR=isinstance(visitee, OrNode),
1714 ShortCircuit=
not isinstance(visitee, OrderedNode),
1717 elif isinstance(visitee, ignore):
1718 if hasattr(stack[-1],
'IgnoreFilterPassed'):
1719 stack[-1].IgnoreFilterPassed =
True 1723 Members=[stack.pop()], IgnoreFilterPassed=
True))
1724 elif isinstance(visitee, InvertNode):
1725 if hasattr(stack[-1],
'Invert'):
1726 stack[-1].Invert =
True 1728 stack.append(self.
_newSeq(Members=[stack.pop()], Invert=
True))
1733 Convert a control flow expression to nested GaudiSequencers. 1735 if not isinstance(expression, ControlFlowNode):
1736 raise ValueError(
'ControlFlowNode instance expected, got %s' %
1737 type(expression).__name__)
1739 expression.visitNode(visitor)
1740 return visitor.sequence
1745 Helper class to use a ControlFlowNode as an algorithm configurable 1752 if name
in Configurable.allConfigurables:
1753 instance = Configurable.allConfigurables[name]
1754 assert type(instance)
is cls, \
1755 (
'trying to reuse {0!r} as name of a {1} instance while it''s ' 1756 'already used for an instance of {2}').
format(
1759 type(instance).__name__)
1762 instance = super(SuperAlgorithm, cls).
__new__(cls, name, **kwargs)
1763 Configurable.allConfigurables[name] = instance
1770 setattr(self, key, kwargs[key])
1794 Instantiate and algorithm of type 'typ' with a name suitable for use 1795 inside a SuperAlgorithm. 1797 name =
'{0}_{1}'.
format(self.
name, kwargs.pop(
'name', typ.getType()))
1798 return typ(name, **kwargs)
1801 raise NotImplementedError()
1808 self.graph.visitNode(visitor)
1811 super(SuperAlgorithm, self).
__setattr__(name, value)
1812 if name
in (
'_name',
'graph'):
1816 class PropSetter(object):
1817 def enter(self, node):
1819 setattr(node, name, value)
1820 except (ValueError, AttributeError):
1824 def leave(self, node):
1827 self._visitSubNodes(PropSetter())
def getNeededConfigurables()
def __deepcopy__(self, memo)
def propagateProperty(self, name, others=None, force=True)
def setParent(self, parentName)
def __apply_configuration__(self)
dictionary allConfigurables
def _newSeq(self, prefix='seq_', kwargs)
def __deepcopy__(self, memo)
def __detach_used__(self)
def __setstate__(self, dict)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
list __queried_configurables__
def _printHeader(indentStr, title)
def _getUniqueName(self, prefix)
def __init__(self, name=Configurable.DefaultName, _enabled=True, kwargs)
dictionary configurableServices
def __addPassiveUseOf(self, other)
def __new__(cls, args, kwargs)
def hasParent(self, parent)
def __init__(self, name=None, kwargs)
def appendPostConfigAction(function)
Sequencer for executing several algorithms, stopping when one is faulty.
def __init__(self, name=DefaultName)
def getPropertiesWithDescription(self)
def addTool(self, tool, name=None)
def __setupDefaults(self)
def makeSequences(expression)
def _printFooter(indentStr, title)
def _makeAlg(self, typ, kwargs)
def _visitSubNodes(self, visitor)
def applyConfigurableUsers()
def clone(self, name=None, kwargs)
def _instanceName(self, cls)
def setProp(self, name, value)
list __used_configurables__
def __deepcopy__(self, memo)
MsgStream & hex(MsgStream &log)
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
def __init__(self, name=Configurable.DefaultName)
def __getattr__(self, attr)
def __init__(self, name=Configurable.DefaultName)
def __init__(self, propname)
def __deepcopy__(self, memo)
def copyChildAndSetParent(self, cfg, parent)
def __setattr__(self, name, value)
def __addActiveUseOf(self, other)
def setDefaults(cls, handle)
def __iadd__(self, configs, descr=None)
def isPropertySet(self, name)
def toStringProperty(self)
def __new__(cls, name=None, kwargs)
def getDefaultProperties(cls)
def __rshift__(self, rhs)
def __delattr__(self, attr)
def getUsedInstance(self, name)
def copyChild(self, child)
def applyConfigurableUsers_old()
def __setattr__(self, name, value)
def getFullJobOptName(self)
def __set__(self, obj, value)
def removePostConfigAction(function)
def __str__(self, indent=0, headerLastIndentUnit=indentUnit)
bool _configurationLocked
def __setupServices(self)
def _isInSetDefaults(self)
def __init__(self, name=Configurable.DefaultName)
def getDefaultProperty(cls, name)
def toStringProperty(self)
def propagateProperties(self, names=None, others=None, force=True)
def __get__(self, obj, type=None)
def _visitSubNodes(self, visitor)
def copyChild(self, child)
def getValuedProperties(self)
def __setattr__(self, name, value)
def isApplicable(self)
rep += v.__str__( indent + 1 ) + os.linesep elif isinstance(v,GaudiHandleArray): for vi in v: if isin...
def visitNode(self, visitor)