10 from inspect
import isclass
13 VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL
20 ControlFlowLeaf, ControlFlowNode,
24 __all__ = [
'Configurable',
25 'ConfigurableAlgorithm',
26 'ConfigurableAlgTool',
27 'ConfigurableAuditor',
28 'ConfigurableService',
30 'VERBOSE',
'DEBUG',
'INFO',
'WARNING',
'ERROR',
'FATAL',
31 'appendPostConfigAction',
'removePostConfigAction']
35 log = logging.getLogger(
'Configurable')
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). 47 return os.path.expandvars(data)
48 elif typ
in [list, tuple]:
63 Error occurred in the configuration process. 70 class PropertyReference(object):
75 return "@%s" % self.
name 80 refname, refprop = self.name.rsplit(
'.', 1)
81 if refname
in Configurable.allConfigurables:
82 conf = Configurable.allConfigurables[refname]
83 retval = getattr(conf, refprop)
84 if hasattr(retval,
"getFullName"):
85 retval = retval.getFullName()
87 raise NameError(
"name '%s' not found resolving '%s'" %
92 """This function allow transparent integration with 93 Configurable.getValuedProperties. 100 except AttributeError:
108 """Base class for Gaudi components that implement the IProperty interface. 109 Provides most of the boilerplate code, but the actual useful classes 110 are its derived ConfigurableAlgorithm, ConfigurableService, and 111 ConfigurableAlgTool.""" 117 propertyNoValue =
'<no value>' 119 printHeaderWidth = 100
133 allConfigurables = {}
134 configurableServices = {}
137 _configurationLocked =
False 140 """To Gaudi, any object with the same type/name is the same object. Hence, 141 this is mimicked in the configuration: instantiating a new Configurable 142 of a type with the same name will return the same instance.""" 148 name = kwargs[
'name']
149 elif 'name' in cls.__init__.func_code.co_varnames:
151 index = list(cls.__init__.func_code.co_varnames).index(
'name')
154 name = args[index - 1]
157 name = cls.__init__.func_defaults[index - (len(args) + 1)]
162 except (IndexError, TypeError):
164 'no "name" argument while instantiating "%s"' % cls.__name__)
168 if hasattr(cls,
'DefaultedName'):
169 name = cls.DefaultedName
172 elif not name
or type(name) != str:
175 'could not retrieve name from %s.__init__ arguments' % cls.__name__)
179 if issubclass(cls, ConfigurableAlgTool)
and '.' not in name:
180 name =
'ToolSvc.' + name
190 if name
in cls.configurables:
191 conf = cls.configurables[name]
193 cls.configurables[conf.getType()] = conf
195 for n, v
in kwargs.items():
198 if not cls.
_configurationLocked and not "_enabled" in kwargs
and isinstance(conf, ConfigurableUser):
201 setattr(conf,
"_enabled",
True)
205 spos = name.find(
'/')
208 ti_name =
"%s/%s" % (name, name)
209 if ti_name
in cls.configurables:
211 return cls.configurables[ti_name]
216 if i_name == name[spos + 1:]
and i_name
in cls.configurables:
218 return cls.configurables[i_name]
221 conf = cls.allConfigurables.get(name,
None)
or\
222 (spos < 0
and cls.allConfigurables.get(ti_name,
None))
or\
223 (spos > 0
and i_name == name[spos + 1:]
224 and cls.allConfigurables.get(i_name,
None))
226 if conf.__class__
is ConfigurableGeneric:
230 newconf = object.__new__(cls)
231 cls.
__init__(newconf, *args, **kwargs)
236 for n
in newconf.__slots__:
238 for n
in conf._properties:
239 if names[n.lower()] != n:
240 log.warning(
"Option '%s' was used for %s, but the correct spelling is '%s'" % (
241 n, name, names[n.lower()]))
242 setattr(newconf, names[n.lower()], getattr(conf, n))
243 for n, v
in kwargs.items():
244 setattr(newconf, n, v)
245 cls.configurables[name] = newconf
250 log.error(
'attempt to redefine type of "%s" (was: %s, new: %s)%s',
251 name, conf.__class__.__name__, cls.__name__, error_explanation)
256 for n, v
in kwargs.items():
261 conf = object.__new__(cls)
265 cls.configurables[name] = conf
267 for base
in cls.__bases__:
268 if base.__name__ ==
'ConfigurableService':
280 klass = self.__class__
283 if klass == Configurable:
284 raise TypeError,
"%s is an ABC and can not be instantiated" % str(
289 meths = {
'getDlls': 1,
294 for meth, nArgs
in meths.items():
296 f = getattr(klass, meth).im_func
297 except AttributeError:
298 raise NotImplementedError,
"%s is missing in class %s" % (
302 nargcount = f.func_code.co_argcount
303 ndefaults = f.func_defaults
and len(f.func_defaults)
or 0
304 if not nargcount - ndefaults <= nArgs <= nargcount:
305 raise TypeError,
"%s.%s requires exactly %d arguments" % (
314 if hasattr(self.__class__,
'DefaultedName'):
315 self.
_name = self.__class__.DefaultedName
333 for name, proxy
in self._properties.items():
335 dict[name] = proxy.__get__(self)
336 except AttributeError:
339 dict[
'_Configurable__children'] = self.
__children 340 dict[
'_Configurable__tools'] = self.
__tools 341 dict[
'_name'] = self.
_name 349 for n, v
in dict.items():
362 newconf = object.__new__(self.__class__)
363 self.__class__.__init__(newconf, self.
getName())
365 for proxy
in self._properties.values():
367 proxy.__set__(newconf, proxy.__get__(self))
368 except AttributeError:
378 if not type(configs)
in (list, tuple):
379 configs = (configs, )
385 if not isinstance(cfg, Configurable):
386 raise TypeError(
"'%s' is not a Configurable" % str(cfg))
391 ccjo = cc.getJobOptName()
393 if c.getJobOptName() == ccjo:
395 'attempt to add a duplicate ... dupe ignored%s', error_explanation)
398 self.__children.append(cc)
402 descr.__set__(self, cc)
404 setattr(self, cc.getName(), cc)
405 except AttributeError:
415 if attr
in self._properties:
416 if isinstance(self._properties[attr].__get__(self), DataObjectHandleBase):
417 return self._properties[attr].__get__(self)
420 if c.getName() == attr:
423 raise AttributeError(
424 "'%s' object has no attribute '%s'" % (self.__class__, attr))
429 "%s: Configuration cannot be modified after the ApplicationMgr has been started." % self.
name())
432 except AttributeError:
433 raise AttributeError(
"Configurable '%s' does not have property '%s'." 434 % (self.__class__.__name__, name))
440 prop = self._properties[attr]
441 prop.__delete__(self)
442 prop.__set__(self, prop.default)
452 if c.getName() == attr:
453 self.__children.remove(c)
457 del self.__dict__[attr]
458 except (AttributeError, KeyError):
465 if type(items) != list
and type(items) != tuple:
475 return copy.deepcopy(child)
489 if hasattr(cc,
'setParent')
and parent:
492 except RuntimeError, e:
494 log.error(str(e) +
'%s', error_explanation)
495 ccbd = cc.configurables[cc.getJobOptName()]
498 for proxy
in self._properties.values():
499 if proxy.history.has_key(cc):
500 proxy.__set__(ccbd, proxy.__get__(cc))
510 return self.__tools.values()
514 "children() is deprecated, use getChildren() instead for consistency")
515 log.error(
"getChildren() returns a copy; to add a child, use 'parent += child'%s",
520 """Get all (private) configurable children, both explicit ones (added with +=) 521 and the ones in the private GaudiHandle properties""" 524 for proxy
in self._properties.values():
526 c = proxy.__get__(self)
527 except AttributeError:
530 if isinstance(c, Configurable)
and not c.isPublic():
532 elif isinstance(c, GaudiHandle):
534 conf = c.configurable
535 except AttributeError:
538 if not conf.isPublic():
540 elif isinstance(c, GaudiHandleArray):
544 if isinstance(ci, Configurable):
548 conf = ci.configurable
549 except AttributeError:
561 elems.append(c.getFullName())
566 if not hasattr(self,
'_initok')
or not self.
_initok:
569 "Configurable.__init__ not called in %s override" % self.__class__.__name__
583 handle = self.getHandle()
585 log.debug(
'no handle for %s: not transporting properties', self.
_name)
589 for name
in self._properties.keys():
590 if hasattr(self, name):
591 setattr(handle, name, getattr(self, name))
598 for name, proxy
in self._properties.items():
600 props[name] = proxy.__get__(self)
601 except AttributeError:
602 props[name] = Configurable.propertyNoValue
607 """Get all properties with their description string as { name : (value, desc) }.""" 609 for name, proxy
in self._properties.items():
611 props[name] = (proxy.__get__(self), proxy.__doc__)
612 except AttributeError:
613 props[name] = (Configurable.propertyNoValue, proxy.__doc__)
618 for name, proxy
in self._properties.items():
620 value = proxy.__get__(self)
621 if hasattr(value,
'getFullName'):
622 value = value.getFullName()
623 elif type(value)
in [list, tuple]:
626 if hasattr(i,
'getFullName'):
627 new_value.append(i.getFullName())
630 value =
type(value)(new_value)
631 elif type(value)
is dict:
634 if hasattr(value[i],
'getFullName'):
637 new_value[i] = value[i]
656 for k, v
in cls._properties.items():
657 if not k
in c.__dict__
and hasattr(v,
'default'):
658 c.__dict__[k] = v.default
671 if name
in c.__dict__:
672 return c.__dict__[name]
676 v = cls._properties[name]
677 if hasattr(v,
'default'):
685 """Returns the value of the given property. 687 if hasattr(self, name):
688 return getattr(self, name)
693 """Set the value of a given property 695 return setattr(self, name, value)
698 """Tell if the property 'name' has been set or not. 700 Because of a problem with list and dictionary properties, in those cases 701 if the value is equal to the default, the property is considered as not 704 if not hasattr(self, name):
707 if isinstance(default, (list, dict, DataObjectHandleBase)):
708 value = getattr(self, name)
709 return value != default
729 log.error(
"jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
743 if log.isEnabledFor(logging.DEBUG):
751 def clone(self, name=None, **kwargs):
753 if hasattr(self,
'DefaultedName'):
754 name = self.DefaultedName
756 name = self.getType()
758 newconf = Configurable.__new__(self.__class__, name)
759 self.__class__.__init__(newconf, name)
761 for proxy
in self._properties.values():
763 value = proxy.__get__(self)
764 if type(value)
in [str, list, dict, tuple]:
766 value =
type(value)(value)
767 proxy.__set__(newconf, value)
768 except AttributeError:
771 for c
in self.__children:
774 for n, t
in self.__tools.items():
775 newconf.addTool(t, n)
777 for name, value
in kwargs.items():
778 setattr(newconf, name, value)
784 dot = fullname.find(
'.')
786 parentname = fullname[:dot]
787 longname = fullname[dot + 1:]
791 dot = longname.find(
'.')
793 name = longname[:dot]
796 return parentname, name, longname
799 if isclass(tool)
and issubclass(tool, ConfigurableAlgTool):
802 priv_tool = tool(self.
getName() +
'.' + name)
803 elif isinstance(tool, ConfigurableAlgTool):
805 name = tool.splitName()[1]
806 priv_tool = tool.clone(self.
getName() +
'.' + name)
809 classname = tool.__name__
811 classname =
type(tool).__name__
812 raise TypeError,
"addTool requires AlgTool configurable. Got %s type" % classname
816 setattr(self, name, self.
__tools[name])
831 handle = __main__.Service(svc)
836 if hasattr(self,
'configure' + svc):
837 eval(
'self.configure' + svc +
'( handle )')
840 dlls = self.getDlls()
843 elif type(dlls) == types.StringType:
846 from __main__
import theApp
847 dlls = filter(
lambda d: d
not in theApp.Dlls, dlls)
860 preLen = Configurable.printHeaderPre
861 postLen = Configurable.printHeaderWidth - \
862 preLen - 3 - len(title)
863 postLen = max(preLen, postLen)
864 return indentStr +
'/%s %s %s' % (preLen *
'*', title, postLen *
'*')
868 preLen = Configurable.printHeaderPre
869 postLen = Configurable.printHeaderWidth - \
870 preLen - 12 - len(title)
871 postLen = max(preLen, postLen)
872 return indentStr +
'\\%s (End of %s) %s' % (preLen *
'-', title, postLen *
'-')
875 return '{0}({1!r})'.
format(self.__class__.__name__, self.
name())
877 def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
879 indentStr = indent * Configurable.indentUnit
884 headerIndent = (indent - 1) * \
885 Configurable.indentUnit + headerLastIndentUnit
888 rep = Configurable._printHeader(headerIndent, title)
894 rep += indentStr +
'|-<no properties>' + os.linesep
898 for p
in props.keys():
899 nameWidth = max(nameWidth, len(p))
900 for p, v
in props.items():
902 prefix = indentStr +
'|-%-*s' % (nameWidth, p)
904 if log.isEnabledFor(logging.DEBUG):
905 if v != Configurable.propertyNoValue:
906 address =
' @%11s' %
hex(id(v))
911 default = defs.get(p)
912 if v == Configurable.propertyNoValue:
914 strVal = repr(default)
918 if hasattr(v,
"getGaudiHandle"):
919 vv = v.getGaudiHandle()
922 if isinstance(vv, GaudiHandle)
or isinstance(vv, GaudiHandleArray):
925 if hasattr(default,
"toStringProperty"):
926 strDef = repr(default.toStringProperty())
928 strDef = repr(default)
929 if strDef == repr(vv.toStringProperty()):
933 strDef = repr(default)
935 line = prefix +
' = ' + strVal
937 if strDef
is not None:
939 if len(line) + len(strDef) > Configurable.printHeaderWidth:
940 line += os.linesep + indentStr +
'| ' + \
941 (len(prefix) - len(indentStr) - 3) *
' ' 942 line +=
' (default: %s)' % (strDef,)
944 rep += line + os.linesep
956 rep += cfg.__str__(indent + 1,
'|=') + os.linesep
959 rep += Configurable._printFooter(indentStr, title)
964 Return True is the instance can be "applied". 965 Always False for plain Configurable instances 966 (i.e. not ConfigurableUser). 981 object.__setattr__(obj, self.
__name__, value)
988 Configurable.__init__(self, name)
997 def getDlls(self):
pass 1004 super(ConfigurableGeneric, self).
__setattr__(name, value)
1008 if isinstance(value, Configurable):
1009 self.__dict__[name] = value
1021 class ConfigurableAlgorithm(Configurable):
1022 __slots__ = {
'_jobOptName': 0,
'OutputLevel': 0,
1023 'Enable': 1,
'ErrorMax': 1,
'ErrorCount': 0,
'AuditAlgorithms': 0,
1024 'AuditInitialize': 0,
'AuditReinitialize': 0,
'AuditExecute': 0,
1025 'AuditFinalize': 0,
'AuditBeginRun': 0,
'AuditEndRun': 0}
1028 super(ConfigurableAlgorithm, self).
__init__(name)
1048 elif rhs
is CFFalse:
1050 return AndNode(self, rhs)
1057 return OrNode(self, rhs)
1060 return InvertNode(self)
1063 return OrderedNode(self, rhs)
1074 return (repr(self) == repr(other))
1078 __slots__ = {
'OutputLevel': 0,
1079 'AuditServices': 0,
'AuditInitialize': 0,
'AuditFinalize': 0}
1088 return iService(self.
_name)
1102 __slots__ = {
'_jobOptName':
'',
'OutputLevel': 0,
1103 'AuditTools': 0,
'AuditInitialize': 0,
'AuditFinalize': 0}
1106 super(ConfigurableAlgTool, self).
__init__(name)
1107 if '.' not in self.
_name:
1111 name = name[name.find(
'/') + 1:]
1132 return pop + Configurable.getPrintTitle(self)
1141 if isinstance(c, ConfigurableAlgTool):
1142 c.setParent(parentName)
1146 name = name[name.rfind(
'.') + 1:]
1150 dot = self._jobOptName.rfind(
'.')
1157 return self._jobOptName.startswith(parent +
'.')
1166 return self._jobOptName.startswith(
'ToolSvc.')
1177 name = name[name.rfind(
'.') + 1:]
1178 return str(self.
getType() +
'/' + name)
1185 __slots__ = {
'_jobOptName': 0,
'OutputLevel': 0,
1189 super(ConfigurableAuditor, self).
__init__(name)
1191 name = name[name.find(
'/') + 1:]
1210 __slots__ = {
"__users__": [],
1211 "__used_instances__": [],
1222 __used_configurables__ = []
1225 __queried_configurables__ = []
1227 def __init__(self, name=Configurable.DefaultName, _enabled=True, **kwargs):
1228 super(ConfigurableUser, self).
__init__(name)
1229 for n, v
in kwargs.items():
1247 if type(used)
is tuple:
1248 used, used_name = used
1252 if type(used)
is str:
1253 used_class = confDbGetConfigurable(used)
1258 inst = used_class(name=used_name, _enabled=
False)
1259 except AttributeError:
1263 inst = used_class(name=used_name)
1267 if type(queried)
is str:
1268 queried = confDbGetConfigurable(used)
1269 inst = queried(_enabled=
False)
1270 except AttributeError:
1276 Declare that we are going to modify the Configurable 'other' in our 1277 __apply_configuration__. 1279 self.__used_instances__.append(other)
1280 if hasattr(other,
"__users__"):
1281 other.__users__.append(self)
1285 Declare that we are going to retrieve property values from the 1286 ConfigurableUser 'other' in our __apply_configuration__. 1288 if not isinstance(other, ConfigurableUser):
1289 raise Error(
"'%s': Cannot make passive use of '%s', it is not a ConfigurableUser" % (
1290 self.
name(), other.name()))
1291 other.__addActiveUseOf(self)
1304 Remove this ConfigurableUser instance from the users list of the used 1308 if hasattr(used,
"__users__"):
1309 used.__users__.remove(self)
1313 Propagate the property 'name' (if set) to other configurables (if possible). 1316 propagate to all the entries in __used_configurables__ 1317 a configurable instance: 1318 propagate only to it 1319 list of configurable instances: 1320 propagate to all of them. 1324 - if the local property is set, the other property will be overwritten 1325 - local property not set and other set => keep other 1326 - local property not set and other not set => overwrite the default for 1327 ConfigurableUser instances and set the property for Configurables 1332 elif type(others)
not in [list, tuple]:
1338 for other
in [o
for o
in others
if name
in o.__slots__]:
1341 if other.isPropertySet(name):
1342 log.warning(
"Property '%(prop)s' is set in both '%(self)s' and '%(other)s', using '%(self)s.%(prop)s'" %
1343 {
"self": self.
name(),
1344 "other": other.name(),
1346 other.setProp(name, value)
1348 elif not other.isPropertySet(name):
1349 if isinstance(other, ConfigurableUser):
1350 otherType =
type(other._properties[name].getDefault())
1351 other._properties[name].setDefault(value)
1352 if otherType
in [list, dict]:
1355 other.setProp(name, otherType(value))
1357 other.setProp(name, value)
1362 Call propagateProperty for each property listed in 'names'. 1363 If 'names' is None, all the properties are propagated. 1367 names = [p
for p
in self.
__slots__ if not p.startswith(
"_")]
1373 Function to be overridden to convert the high level configuration into a 1375 The default implementation calls applyConf, which is the method defined 1376 in some ConfigurableUser implementations. 1382 Function to be overridden to convert the high level configuration into a 1389 Function used to define the name of the private instance of a given class 1391 This method is used when the __used_configurables_property__ declares the 1392 need of a private used configurable without specifying the name. 1394 if type(cls)
is str:
1397 clName = cls.__name__
1398 return "%s_%s" % (self.name(), clName)
1402 Return the used instance with a given name. 1405 if i.name() == name:
1406 if hasattr(i,
"_enabled"):
1411 raise KeyError(name)
1415 Return True is the instance can be "applied". 1421 postConfigActions = []
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'. 1431 postConfigActions.remove(function)
1434 postConfigActions.append(function)
1439 Remove a callable from the list of post-config actions. 1440 The list is directly accessible as 'GaudiKernel.Configurable.postConfigActions'. 1442 postConfigActions.remove(function)
1445 _appliedConfigurableUsers_ =
False 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. 1455 global _appliedConfigurableUsers_, postConfigActions
1456 if _appliedConfigurableUsers_:
1458 _appliedConfigurableUsers_ =
True 1460 def applicableConfUsers():
1462 Generator returning all the configurables that can be applied in the 1463 order in which they can be applied. 1475 yield (c
for c
in Configurable.allConfigurables.values()
1476 if c.isApplicable()).next()
1478 debugApplyOrder =
'GAUDI_DUBUG_CONF_USER' in os.environ
1479 for c
in applicableConfUsers():
1481 log.info(
"applying configuration of %s", c.name())
1483 sys.stderr.write(
'applying %r' % c)
1484 c.__apply_configuration__()
1487 log.info(
"skipping configuration of %s", c.name())
1489 if hasattr(c,
"__detach_used__"):
1494 leftConfUsers = [c
for c
in Configurable.allConfigurables.values()
1495 if hasattr(c,
'__apply_configuration__')
and 1496 c._enabled
and not c._applied]
1499 raise Error(
"Detected loop in the ConfigurableUser" 1500 " dependencies: %r" % [c.name()
1501 for c
in leftConfUsers])
1504 unknown = set(Configurable.allConfigurables)
1508 log.debug(
'new configurable created automatically: %s', k)
1510 Configurable.allConfigurables[k].
properties()
1514 for action
in postConfigActions:
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. 1524 @see applyConfigurableUsers() 1527 global _appliedConfigurableUsers_, postConfigActions
1528 if _appliedConfigurableUsers_:
1530 _appliedConfigurableUsers_ =
True 1532 debugApplyOrder =
'GAUDI_DUBUG_CONF_USER' in os.environ
1534 for c
in Configurable.allConfigurables.values()
1535 if hasattr(c,
"__apply_configuration__")]
1537 while applied
and confUsers:
1541 if hasattr(c,
"__users__")
and c.__users__:
1542 newConfUsers.append(c)
1547 enabled = (
not hasattr(c,
"_enabled"))
or c._enabled
1549 log.info(
"applying configuration of %s", c.name())
1551 sys.stderr.write(
'applying %r' % c)
1552 c.__apply_configuration__()
1555 log.info(
"skipping configuration of %s", c.name())
1556 if hasattr(c,
"__detach_used__"):
1559 confUsers = newConfUsers
1562 raise Error(
"Detected loop in the ConfigurableUser " 1563 " dependencies: %r" % [c.name()
1564 for c
in confUsers])
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 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). 1589 for k, v
in Configurable.allConfigurables.items()
1590 if v.getGaudiType() !=
"User"]
1595 Clean up all configurations and configurables. 1597 for c
in Configurable.allConfigurables.values():
1598 c.__class__.configurables.clear()
1599 Configurable.allConfigurables.clear()
1602 ConfigurableGeneric.configurables.clear()
1603 from ProcessJobOptions
import _included_files
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()
1620 return self.
stack[-1]
1628 name = prefix + str(cnt)
1629 while name
in allConfigurables:
1631 name = prefix + str(cnt)
1635 from Configurables
import GaudiSequencer
1641 if visitee
in (CFTrue, CFFalse):
1642 stack.append(self.
_newSeq(Invert=visitee
is CFFalse))
1643 elif isinstance(visitee, (ControlFlowLeaf, ConfigurableAlgorithm)):
1644 stack.append(visitee)
1645 elif isinstance(visitee, (OrNode, AndNode, OrderedNode)):
1648 seq = self.
_newSeq(Members=[a, b],
1649 ModeOR=isinstance(visitee, OrNode),
1650 ShortCircuit=
not isinstance(
1651 visitee, OrderedNode),
1654 elif isinstance(visitee, ignore):
1655 if hasattr(stack[-1],
'IgnoreFilterPassed'):
1656 stack[-1].IgnoreFilterPassed =
True 1658 stack.append(self.
_newSeq(Members=[stack.pop()],
1659 IgnoreFilterPassed=
True))
1660 elif isinstance(visitee, InvertNode):
1661 if hasattr(stack[-1],
'Invert'):
1662 stack[-1].Invert =
True 1664 stack.append(self.
_newSeq(Members=[stack.pop()],
1670 Convert a control flow expression to nested GaudiSequencers. 1672 if not isinstance(expression, ControlFlowNode):
1673 raise ValueError(
'ControlFlowNode instance expected, got %s' %
1674 type(expression).__name__)
1676 expression.visitNode(visitor)
1677 return visitor.sequence
1682 Helper class to use a ControlFlowNode as an algorithm configurable 1688 if name
in Configurable.allConfigurables:
1689 instance = Configurable.allConfigurables[name]
1690 assert type(instance)
is cls, \
1691 (
'trying to reuse {0!r} as name of a {1} instance while it''s ' 1692 'already used for an instance of {2}').
format(
1695 type(instance).__name__)
1698 instance = super(SuperAlgorithm, cls).
__new__(cls, name, **kwargs)
1699 Configurable.allConfigurables[name] = instance
1706 setattr(self, key, kwargs[key])
1730 Instantiate and algorithm of type 'typ' with a name suitable for use 1731 inside a SuperAlgorithm. 1733 name =
'{0}_{1}'.
format(self.
name, kwargs.pop(
'name', typ.getType()))
1734 return typ(name, **kwargs)
1737 raise NotImplementedError()
1744 self.graph.visitNode(visitor)
1747 super(SuperAlgorithm, self).
__setattr__(name, value)
1748 if name
in (
'_name',
'graph'):
1752 class PropSetter(object):
1753 def enter(self, node):
1755 setattr(node, name, value)
1756 except (ValueError, AttributeError):
1760 def leave(self, node):
1763 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)
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)