The Gaudi Framework  v40r0 (475e45c1)
GaudiKernel.Configurable.Configurable Class Reference
Inheritance diagram for GaudiKernel.Configurable.Configurable:
Collaboration diagram for GaudiKernel.Configurable.Configurable:

Classes

class  DefaultName
 

Public Member Functions

def __new__ (cls, *args, **kwargs)
 
def __init__ (self, name=DefaultName)
 
def __getstate__ (self)
 
def __getnewargs__ (self)
 
def __setstate__ (self, dict)
 
def __len__ (self)
 
def __iter__ (self)
 
def __deepcopy__ (self, memo)
 
def __iadd__ (self, configs, descr=None)
 
def __getattr__ (self, attr)
 
def __setattr__ (self, name, value)
 
def __delattr__ (self, attr)
 
def __bool__ (self)
 
def remove (self, items)
 
def removeAll (self)
 
def copyChild (self, child)
 
def setParent (self, parentName)
 
def getParent (self)
 
def hasParent (self, parent)
 
def copyChildAndSetParent (self, cfg, parent)
 
def getChildren (self)
 
def getTools (self)
 
def children (self)
 
def getAllChildren (self)
 
def getSequence (self)
 
def setup (self)
 
def getProperties (self)
 
def getPropertiesWithDescription (self)
 
def getValuedProperties (self)
 
def properties (self)
 
def getDefaultProperties (cls)
 
def getDefaultProperty (cls, name)
 
def getProp (self, name)
 
def setProp (self, name, value)
 
def isPropertySet (self, name)
 
def getType (cls)
 
def getName (self)
 
def name (self)
 
def getJobOptName (self)
 
def isPublic (self)
 
def jobOptName (self)
 
def getFullName (self)
 
def getFullJobOptName (self)
 
def getPrintTitle (self)
 
def getTitleName (self)
 
def setDefaults (cls, handle)
 
def clone (self, name=None, **kwargs)
 
def splitName (self)
 
def addTool (self, tool, name=None)
 
def __repr__ (self)
 
def __str__ (self, indent=0, headerLastIndentUnit=indentUnit)
 
def isApplicable (self)
 
- Public Member Functions inherited from GaudiKernel.ConfigurableMeta.ConfigurableMeta
def __new__ (self, name, bases, dct)
 
def __call__ (cls, *args, **kwargs)
 

Static Public Attributes

 propertyNoValue
 
 indentUnit
 
 printHeaderWidth
 
 printHeaderPre
 
 allConfigurables
 
 configurableServices
 

Private Member Functions

def _isInSetDefaults (self)
 
def __setupServices (self)
 
def __setupDlls (self)
 
def __setupDefaults (self)
 

Static Private Member Functions

def _printHeader (indentStr, title)
 
def _printFooter (indentStr, title)
 

Private Attributes

 __children
 
 __tools
 
 _name
 
 _inSetDefaults
 
 _initok
 
 _setupok
 
 _unpickling
 

Static Private Attributes

 __slots__
 
 _configurationLocked
 

Detailed Description

Base class for Gaudi components that implement the IProperty interface.
Provides most of the boilerplate code, but the actual useful classes
are its derived ConfigurableAlgorithm, ConfigurableService, and
ConfigurableAlgTool.

Definition at line 154 of file Configurable.py.

Constructor & Destructor Documentation

◆ __init__()

def GaudiKernel.Configurable.Configurable.__init__ (   self,
  name = DefaultName 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableAuditor, GaudiKernel.Configurable.ConfigurableAlgTool, GaudiKernel.Configurable.ConfigurableAlgorithm, and GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 344 of file Configurable.py.

344  def __init__(self, name=DefaultName):
345  # check class readiness, all required overloads should be there now
346  klass = self.__class__
347 
348  # this is an abstract class
349  if klass == Configurable:
350  raise TypeError(
351  "%s is an ABC and can not be instantiated" % str(Configurable)
352  )
353 
354  # the following methods require overloading
355  # NOT YET meths = { 'getServices' : 1, # retrieve list of services to configure
356  meths = {
357  "getDlls": 1, # provide list of Dlls to load
358  "getGaudiType": 1, # return string describing component class
359  "getHandle": 1,
360  } # provide access to C++ side component instance
361  # 'getType' : 1 } # return the type of the actual C++ component
362 
363  for meth, nArgs in meths.items():
364  try:
365  f = getattr(klass, meth)
366  except AttributeError:
367  raise NotImplementedError(
368  "%s is missing in class %s" % (meth, str(klass))
369  )
370 
371  # in addition, verify the number of arguments w/o defaults
372  nargcount = f.__code__.co_argcount
373  fdefaults = f.__defaults__
374  ndefaults = fdefaults and len(fdefaults) or 0
375  if not nargcount - ndefaults <= nArgs <= nargcount:
376  raise TypeError(
377  "%s.%s requires exactly %d arguments" % (klass, meth, nArgs)
378  )
379 
380  # for using this Configurable as a (Gaudi) sequence
381  self.__children = []
382  self.__tools = {}
383 
384  # know who we are
385  if name == Configurable.DefaultName:
386  if hasattr(self.__class__, "DefaultedName"):
387  self._name = self.__class__.DefaultedName
388  else:
389  self._name = self.getType()
390  else:
391  self._name = name
392 
393  # set to True when collecting defaults, False otherwise
394  self._inSetDefaults = False
395 
396  # for later, in case __init__ itself is overridden
397  self._initok = True
398 
399  # for debugging purposes (temporary)
400  self._setupok = False
401 
402  # used to prevent spurious deprecation warnings when unpickling
403  self._unpickling = False
404 

Member Function Documentation

◆ __bool__()

def GaudiKernel.Configurable.Configurable.__bool__ (   self)

Definition at line 552 of file Configurable.py.

552  def __bool__(self):
553  return True
554 

◆ __deepcopy__()

def GaudiKernel.Configurable.Configurable.__deepcopy__ (   self,
  memo 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableService, GaudiKernel.Configurable.ConfigurableAlgorithm, and GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 446 of file Configurable.py.

446  def __deepcopy__(self, memo):
447  newconf = object.__new__(self.__class__)
448  self.__class__.__init__(newconf, self.getName())
449 
450  for proxy in self._properties.values():
451  try:
452  proxy.__set__(newconf, proxy.__get__(self))
453  except AttributeError:
454  pass # means property was not set for self
455 
456  for c in self.__children:
457  newconf += c # processes proper copy semantics
458 
459  return newconf
460 

◆ __delattr__()

def GaudiKernel.Configurable.Configurable.__delattr__ (   self,
  attr 
)

Definition at line 527 of file Configurable.py.

527  def __delattr__(self, attr):
528  # remove as property, otherwise try as child
529  try:
530  # remove history etc., then reset to default (in case set before)
531  prop = self._properties[attr]
532  prop.__delete__(self)
533  prop.__set__(self, prop.default)
534  return # reaches here? was property: done now
535  except KeyError:
536  pass
537  # otherwise, remove the private tool
538  if attr in self.__tools:
539  del self.__tools[attr]
540 
541  # otherwise, remove child, if one is so named
542  for c in self.__children:
543  if c.getName() == attr:
544  self.__children.remove(c)
545 
546  # potentially, there are left over caches (certain user derived classes)
547  try:
548  del self.__dict__[attr]
549  except (AttributeError, KeyError):
550  pass
551 

◆ __getattr__()

def GaudiKernel.Configurable.Configurable.__getattr__ (   self,
  attr 
)

Definition at line 497 of file Configurable.py.

497  def __getattr__(self, attr): # until ToolProperties exist ...
498  if attr in self.__tools:
499  return self.__tools[attr]
500 
501  if attr in self._properties:
502  if isinstance(self._properties[attr].__get__(self), DataHandle):
503  return self._properties[attr].__get__(self)
504 
505  for c in self.__children:
506  if c.getName() == attr:
507  return c
508 
509  raise AttributeError(
510  "'%s' object has no attribute '%s'" % (self.__class__, attr)
511  )
512 

◆ __getnewargs__()

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 419 of file Configurable.py.

419  def __getnewargs__(self):
420  return (self._name,)
421 

◆ __getstate__()

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 406 of file Configurable.py.

406  def __getstate__(self):
407  dict = {}
408  for name, proxy in self._properties.items():
409  try:
410  dict[name] = proxy.__get__(self)
411  except AttributeError:
412  pass
413 
414  dict["_Configurable__children"] = self.__children
415  dict["_Configurable__tools"] = self.__tools
416  dict["_name"] = self._name
417  return dict
418 

◆ __iadd__()

def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 462 of file Configurable.py.

462  def __iadd__(self, configs, descr=None):
463  if not isinstance(configs, (list, tuple)):
464  configs = (configs,)
465 
466  joname = self.getJobOptName()
467 
468  for cfg in configs:
469  # prevent type mismatches
470  if not isinstance(cfg, Configurable):
471  raise TypeError("'%s' is not a Configurable" % str(cfg))
472 
473  cc = self.copyChildAndSetParent(cfg, joname)
474 
475  # filters dupes; usually "ok" (backdoor should catch them)
476  ccjo = cc.getJobOptName()
477  for c in self.__children:
478  if c.getJobOptName() == ccjo:
479  log.error(
480  "attempt to add a duplicate ... dupe ignored%s",
481  error_explanation,
482  )
483  break
484  else:
485  self.__children.append(cc)
486 
487  try:
488  if descr: # support for tool properties
489  descr.__set__(self, cc)
490  else:
491  setattr(self, cc.getName(), cc)
492  except AttributeError:
493  pass # to allow free addition of tools/subalgorithms
494 
495  return self
496 

◆ __iter__()

def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 442 of file Configurable.py.

442  def __iter__(self):
443  return iter(self.__children)
444 

◆ __len__()

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 439 of file Configurable.py.

439  def __len__(self):
440  return len(self.__children)
441 

◆ __new__()

def GaudiKernel.Configurable.Configurable.__new__ (   cls,
args,
**  kwargs 
)
To Gaudi, any object with the same type/name is the same object. Hence,
this is mimicked in the configuration: instantiating a new Configurable
of a type with the same name will return the same instance.

Definition at line 185 of file Configurable.py.

185  def __new__(cls, *args, **kwargs):
186  """To Gaudi, any object with the same type/name is the same object. Hence,
187  this is mimicked in the configuration: instantiating a new Configurable
188  of a type with the same name will return the same instance."""
189 
190  global log
191  func_code = cls.__init__.__code__
192  func_defaults = cls.__init__.__defaults__
193  # try to get the name of the Configurable (having a name is compulsory)
194  if "name" in kwargs:
195  # simple keyword (by far the easiest)
196  name = kwargs["name"]
197  elif "name" in func_code.co_varnames:
198  # either positional in args, or default
199  index = list(func_code.co_varnames).index("name")
200  try:
201  # var names index is offset by one as __init__ is to be called with self
202  name = args[index - 1]
203  except IndexError:
204  # retrieve default value, then
205  name = func_defaults[index - (len(args) + 1)]
206  else:
207  # positional index is assumed (will work most of the time)
208  try:
209  name = args[1] # '0' is for self
210  except (IndexError, TypeError):
211  raise TypeError(
212  'no "name" argument while instantiating "%s"' % cls.__name__
213  )
214 
215  argname = name
216  if name == Configurable.DefaultName:
217  if hasattr(cls, "DefaultedName"):
218  name = cls.DefaultedName
219  else:
220  name = cls.getType()
221  elif not name or not isinstance(name, str):
222  # unnamed, highly specialized user code, etc. ... unacceptable
223  raise TypeError(
224  "could not retrieve name from %s.__init__ arguments" % cls.__name__
225  )
226 
227  # Handle the case of global tools to prepend ToolSvc in the name.
228  # This is needed for compatibility with old JobOptions files being read
229  if issubclass(cls, ConfigurableAlgTool) and "." not in name:
230  name = "ToolSvc." + name
231 
232  # close backdoor access to otherwise private subalgs/tools
233  # PM if 0 <= name.find( '.' ):
234  # PM # temp protection for old style types
235  # PM from OldStyleConfig import GenericConfigurable
236  # PM if not issubclass( cls, GenericConfigurable ): # except raised for new types only
237  # PM raise NameError( '"%s": backdoor access to private configurables not allowed' % name )
238 
239  # ordinary recycle case
240  if name in cls.configurables:
241  conf = cls.configurables[name]
242  if name != argname: # special case: user derived <-> real ... make same
243  cls.configurables[conf.getType()] = conf
244  # ---PM: Initialize additional properties
245  for n, v in kwargs.items():
246  if n != "name": # it should not be confused with a normal property
247  setattr(conf, n, v)
248  if (
249  not cls._configurationLocked
250  and "_enabled" not in kwargs
251  and isinstance(conf, ConfigurableUser)
252  ):
253  # Ensure that the ConfigurableUser gets enabled if nothing is
254  # specified in the constructor.
255  setattr(conf, "_enabled", True)
256  return conf
257 
258  # a couple of special cases (note that these cases don't mix)
259  spos = name.find("/")
260  ti_name = None
261  if spos < 0:
262  ti_name = "%s/%s" % (name, name)
263  if ti_name in cls.configurables:
264  # support for old-style name as type/name lookup where name==type
265  return cls.configurables[ti_name]
266 
267  i_name = None
268  if spos > 0:
269  i_name = name[:spos]
270  if i_name == name[spos + 1 :] and i_name in cls.configurables:
271  # this is the opposite of the above special case
272  return cls.configurables[i_name]
273 
274  # the following is purely for debugging support and should realistically bomb
275  conf = (
276  cls.allConfigurables.get(name, None)
277  or (spos < 0 and cls.allConfigurables.get(ti_name, None))
278  or (
279  spos > 0
280  and i_name == name[spos + 1 :]
281  and cls.allConfigurables.get(i_name, None)
282  )
283  )
284  if conf: # wrong type used?
285  if conf.__class__ is ConfigurableGeneric:
286  # If the instance found is ConfigurableGeneric then
287  # we create a new one with the proper type and fill with
288  # the contents of the generic one
289  newconf = object.__new__(cls)
290  cls.__init__(newconf, *args, **kwargs)
291  # initialize with the properties of generic configurable
292  # (we map the names of the properties to lowercase versions because
293  # old options are not case sensitive)
294  names = {}
295  for n in newconf.__slots__:
296  names[n.lower()] = n
297  for n in conf._properties:
298  if names[n.lower()] != n:
299  log.warning(
300  "Option '%s' was used for %s, but the correct spelling is '%s'"
301  % (n, name, names[n.lower()])
302  )
303  setattr(newconf, names[n.lower()], getattr(conf, n))
304  for n, v in kwargs.items():
305  setattr(newconf, n, v)
306  cls.configurables[name] = newconf
307  cls.allConfigurables[name] = newconf
308  return newconf
309  else:
310  # will be an actual error in the future (now only report as such)
311  log.error(
312  'attempt to redefine type of "%s" (was: %s, new: %s)%s',
313  name,
314  conf.__class__.__name__,
315  cls.__name__,
316  error_explanation,
317  )
318  # in the future:
319  # return None # will bomb on use (or go unharmed on non-use)
320  # for now, allow use through allConfigurables lookup
321  # ---PM: Initialize additional properties
322  for n, v in kwargs.items():
323  setattr(conf, n, v)
324  return conf
325 
326  # still here: create a new instance and initialize it
327  conf = object.__new__(cls)
328  cls.__init__(conf, *args, **kwargs)
329 
330  # update normal, per-class cache
331  cls.configurables[name] = conf
332 
333  for base in cls.__bases__:
334  if base.__name__ == "ConfigurableService":
335  cls.configurableServices[name] = conf
336 
337  # update generics super-cache, if needed
338  cls.allConfigurables[name] = conf
339  # -->PM#if hasattr( cls, 'getType' ) and name.find('/') < 0:
340  # -->PM# cls.allConfigurables[ cls.getType() + '/' + name ] = conf
341 
342  return conf
343 

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 968 of file Configurable.py.

968  def __repr__(self):
969  return "{0}({1!r})".format(self.__class__.__name__, self.name())
970 

◆ __setattr__()

def GaudiKernel.Configurable.Configurable.__setattr__ (   self,
  name,
  value 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 513 of file Configurable.py.

513  def __setattr__(self, name, value):
514  if self._configurationLocked:
515  raise RuntimeError(
516  "%s: Configuration cannot be modified after the ApplicationMgr has been started."
517  % self.name()
518  )
519  try:
520  super(Configurable, self).__setattr__(name, value)
521  except AttributeError:
522  raise AttributeError(
523  "Configurable '%s' does not have property '%s'."
524  % (self.__class__.__name__, name)
525  )
526 

◆ __setstate__()

def GaudiKernel.Configurable.Configurable.__setstate__ (   self,
  dict 
)

Definition at line 422 of file Configurable.py.

422  def __setstate__(self, dict):
423  self._initok = True
424  from contextlib import contextmanager
425 
426  @contextmanager
427  def unpickling():
428  try:
429  self._unpickling = True
430  yield
431  finally:
432  self._unpickling = False
433 
434  with unpickling():
435  for n, v in dict.items():
436  setattr(self, n, v)
437 

◆ __setupDefaults()

def GaudiKernel.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 943 of file Configurable.py.

943  def __setupDefaults(self):
944  # set handle defaults flags to inform __setattr__ that it is being
945  # called during setDefaults of the concrete Configurable
946  self._inSetDefaults = True
947  self.setDefaults(self)
948  self._inSetDefaults = False
949 

◆ __setupDlls()

def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 930 of file Configurable.py.

930  def __setupDlls(self):
931  dlls = self.getDlls()
932  if not dlls:
933  dlls = []
934  elif isinstance(dlls, types.StringType):
935  dlls = [dlls]
936 
937  from __main__ import theApp
938 
939  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
940  if dlls:
941  theApp.Dlls += dlls
942 

◆ __setupServices()

def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 912 of file Configurable.py.

912  def __setupServices(self):
913  # svcs = self.getServices()
914  # if not svcs:
915  svcs = []
916  # elif type(svcs) == types.StringType:
917  # svcs = [ svcs ]
918 
919  import __main__
920 
921  for svc in svcs:
922  handle = __main__.Service(svc) # noqa: F841 (used in eval below)
923  # services should be configurables as well, but aren't for now
924  # handle.setup()
925 
926  # allow Configurable to make some changes
927  if hasattr(self, "configure" + svc):
928  eval("self.configure" + svc + "( handle )")
929 

◆ __str__()

def GaudiKernel.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 971 of file Configurable.py.

971  def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
972  global log # to print some info depending on output level
973 
974  def _sorted_repr_set(value):
975  """Helper to print sorted set representation"""
976  return "{" + repr(sorted(value))[1:-1] + "}" if value else "set()"
977 
978  indentStr = indent * Configurable.indentUnit
979  # print header
980  title = self.getPrintTitle()
981  # print line to easily see start-of-configurable
982  if indent > 0:
983  headerIndent = (indent - 1) * Configurable.indentUnit + headerLastIndentUnit
984  else:
985  headerIndent = ""
986  rep = Configurable._printHeader(headerIndent, title)
987  rep += os.linesep
988  # print own properties
989  props = self.getProperties()
990  defs = self.getDefaultProperties()
991  if not props:
992  rep += indentStr + "|-<no properties>" + os.linesep
993  else:
994  # get property name with
995  nameWidth = 0
996  for p in props.keys():
997  nameWidth = max(nameWidth, len(p))
998  for p, v in props.items():
999  # start with indent and property name
1000  prefix = indentStr + "|-%-*s" % (nameWidth, p)
1001  # add memory address for debugging (not for defaults)
1002  if log.isEnabledFor(logging.DEBUG):
1003  if v != Configurable.propertyNoValue:
1004  address = " @%11s" % hex(id(v))
1005  else:
1006  address = 13 * " "
1007  prefix += address
1008  # add value and default
1009  default = defs.get(p)
1010  if v == Configurable.propertyNoValue:
1011  # show default value as value, and no extra 'default'
1012  strVal = repr(default)
1013  strDef = None
1014  else:
1015  # convert configurable to handle
1016  if hasattr(v, "getGaudiHandle"):
1017  vv = v.getGaudiHandle()
1018  else:
1019  vv = v
1020  if isinstance(vv, (GaudiHandle, GaudiHandleArray, DataHandle)):
1021  strVal = repr(vv)
1022  # the default may not be a GaudiHandle (?)
1023  if hasattr(default, "toStringProperty"):
1024  strDef = repr(default.toStringProperty())
1025  else:
1026  strDef = repr(default)
1027  if strDef == repr(vv.toStringProperty()):
1028  strDef = None
1029  elif isinstance(vv, set):
1030  strVal = _sorted_repr_set(vv)
1031  strDef = _sorted_repr_set(default)
1032  else:
1033  strVal = repr(vv)
1034  strDef = repr(default)
1035  # add the value
1036  line = prefix + " = " + strVal
1037  # add default if present
1038  if strDef is not None:
1039  # put default on new line if too big
1040  if len(line) + len(strDef) > Configurable.printHeaderWidth:
1041  line += (
1042  os.linesep
1043  + indentStr
1044  + "| "
1045  + (len(prefix) - len(indentStr) - 3) * " "
1046  )
1047  line += " (default: %s)" % (strDef,)
1048  # add the line to the total string
1049  rep += line + os.linesep
1050  # print out full private configurables
1051  # if isinstance(v,Configurable) and not v.isPublic():
1052 
1057 
1058  # print configurables + their properties, or loop over sequence
1059  # for cfg in self.__children:
1060  for cfg in self.getAllChildren():
1061  rep += cfg.__str__(indent + 1, "|=") + os.linesep
1062 
1063  # print line to easily see end-of-configurable. Note: No linesep!
1064  rep += Configurable._printFooter(indentStr, title)
1065  return rep
1066 

◆ _isInSetDefaults()

def GaudiKernel.Configurable.Configurable._isInSetDefaults (   self)
private

Definition at line 909 of file Configurable.py.

909  def _isInSetDefaults(self):
910  return self._inSetDefaults
911 

◆ _printFooter()

def GaudiKernel.Configurable.Configurable._printFooter (   indentStr,
  title 
)
staticprivate

Definition at line 960 of file Configurable.py.

960  def _printFooter(indentStr, title):
961  preLen = Configurable.printHeaderPre
962  postLen = (
963  Configurable.printHeaderWidth - preLen - 12 - len(title)
964  ) # - len(indentStr)
965  postLen = max(preLen, postLen)
966  return indentStr + "\\%s (End of %s) %s" % (preLen * "-", title, postLen * "-")
967 

◆ _printHeader()

def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 951 of file Configurable.py.

951  def _printHeader(indentStr, title):
952  preLen = Configurable.printHeaderPre
953  postLen = (
954  Configurable.printHeaderWidth - preLen - 3 - len(title)
955  ) # - len(indentStr)
956  postLen = max(preLen, postLen)
957  return indentStr + "/%s %s %s" % (preLen * "*", title, postLen * "*")
958 

◆ addTool()

def GaudiKernel.Configurable.Configurable.addTool (   self,
  tool,
  name = None 
)

Definition at line 886 of file Configurable.py.

886  def addTool(self, tool, name=None):
887  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
888  if name is None:
889  name = tool.__name__
890  priv_tool = tool(self.getName() + "." + name)
891  elif isinstance(tool, ConfigurableAlgTool):
892  if name is None:
893  name = tool.splitName()[1]
894  priv_tool = tool.clone(self.getName() + "." + name)
895  else:
896  if isclass(tool):
897  classname = tool.__name__
898  else:
899  classname = type(tool).__name__
900  raise TypeError(
901  "addTool requires AlgTool configurable. Got %s type" % classname
902  )
903  self.__tools[name] = priv_tool
904  if name in self.__slots__:
905  # this is to avoid that the property hides the tool
906  setattr(self, name, self.__tools[name])
907  return self.__tools[name]
908 

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 603 of file Configurable.py.

603  def children(self):
604  log.error("children() is deprecated, use getChildren() instead for consistency")
605  log.error(
606  "getChildren() returns a copy; to add a child, use 'parent += child'%s",
607  error_explanation,
608  )
609  return self.__children # by ref, for compatibility
610 

◆ clone()

def GaudiKernel.Configurable.Configurable.clone (   self,
  name = None,
**  kwargs 
)

Definition at line 839 of file Configurable.py.

839  def clone(self, name=None, **kwargs):
840  if not name:
841  if hasattr(self, "DefaultedName"):
842  name = self.DefaultedName
843  else:
844  name = self.getType()
845 
846  newconf = Configurable.__new__(self.__class__, name)
847  self.__class__.__init__(newconf, name)
848 
849  for proxy in self._properties.values():
850  try:
851  value = proxy.__get__(self)
852  if isinstance(value, (str, list, dict, tuple, set)):
853  # clone the values of the properties for basic types
854  value = type(value)(value)
855  proxy.__set__(newconf, value)
856  except AttributeError:
857  pass
858 
859  for c in self.__children:
860  newconf += c # processes proper copy semantics
861 
862  for n, t in self.__tools.items():
863  newconf.addTool(t, n)
864 
865  for name, value in kwargs.items():
866  setattr(newconf, name, value)
867 
868  return newconf
869 

◆ copyChild()

def GaudiKernel.Configurable.Configurable.copyChild (   self,
  child 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 565 of file Configurable.py.

565  def copyChild(self, child):
566  return copy.deepcopy(child)
567 

◆ copyChildAndSetParent()

def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 577 of file Configurable.py.

577  def copyChildAndSetParent(self, cfg, parent):
578  cc = self.copyChild(cfg)
579 
580  if hasattr(cc, "setParent") and parent:
581  try:
582  cc.setParent(parent)
583  except RuntimeError as e:
584  # temporary backdoor resolution for compatibility
585  log.error(str(e) + "%s", error_explanation)
586  ccbd = cc.configurables[cc.getJobOptName()]
587 
588  # merge properties, new over pre-existing
589  for proxy in self._properties.values():
590  if cc in proxy.history:
591  proxy.__set__(ccbd, proxy.__get__(cc))
592 
593  # consolidate
594  cc = ccbd
595  return cc
596 

◆ getAllChildren()

def GaudiKernel.Configurable.Configurable.getAllChildren (   self)
Get all (private) configurable children, both explicit ones (added with +=)
and the ones in the private GaudiHandle properties

Definition at line 611 of file Configurable.py.

611  def getAllChildren(self):
612  """Get all (private) configurable children, both explicit ones (added with +=)
613  and the ones in the private GaudiHandle properties"""
614  childs = []
615  # add private configurable properties (also inside handles)
616  for proxy in self._properties.values():
617  try:
618  c = proxy.__get__(self)
619  except AttributeError:
620  pass
621  else:
622  if isinstance(c, Configurable) and not c.isPublic():
623  childs.append(c)
624  elif isinstance(c, GaudiHandle):
625  try:
626  conf = c.configurable
627  except AttributeError:
628  pass
629  else:
630  if not conf.isPublic():
631  childs.append(conf)
632  elif isinstance(c, GaudiHandleArray):
633  # only setup private arrays
634  if not c.isPublic():
635  for ci in c:
636  if isinstance(ci, Configurable):
637  childs.append(ci)
638  else:
639  try:
640  conf = ci.configurable
641  except AttributeError:
642  pass
643  else:
644  childs.append(conf)
645 
646  # add explicit children
647  childs += self.__children
648  return childs
649 

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 597 of file Configurable.py.

597  def getChildren(self):
598  return self.__children[:] # read only
599 

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 741 of file Configurable.py.

741  def getDefaultProperties(cls):
742  # user provided defaults
743  c = _DefaultPropertiesCollectorHelper()
744  cls.setDefaults(c)
745 
746  # defaults from C++
747  for k, v in cls._properties.items():
748  if k not in c.__dict__ and hasattr(v, "default"):
749  c.__dict__[k] = v.default
750 
751  return c.__dict__
752 

◆ getDefaultProperty()

def GaudiKernel.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 754 of file Configurable.py.

754  def getDefaultProperty(cls, name):
755  # user provided defaults
756  c = _DefaultPropertiesCollectorHelper()
757  cls.setDefaults(c)
758 
759  if name in c.__dict__:
760  return c.__dict__[name]
761 
762  # defaults from C++
763  try:
764  v = cls._properties[name]
765  if hasattr(v, "default"):
766  return v.default
767  except KeyError:
768  pass
769 
770  return None
771 

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 824 of file Configurable.py.

824  def getFullJobOptName(self):
825  return "%s/%s" % (self.getType(), self.getJobOptName() or self.getName())
826 

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 821 of file Configurable.py.

821  def getFullName(self):
822  return str(self.getType() + "/" + self.getName())
823 

◆ getJobOptName()

def GaudiKernel.Configurable.Configurable.getJobOptName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAuditor, GaudiKernel.Configurable.ConfigurableAlgTool, GaudiKernel.Configurable.ConfigurableAlgorithm, and GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 807 of file Configurable.py.

807  def getJobOptName(self): # full hierachical name
808  return self.getName()
809 

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 801 of file Configurable.py.

801  def getName(self):
802  return self._name
803 

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 571 of file Configurable.py.

571  def getParent(self):
572  return ""
573 

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 827 of file Configurable.py.

827  def getPrintTitle(self):
828  return self.getGaudiType() + " " + self.getTitleName()
829 

◆ getProp()

def GaudiKernel.Configurable.Configurable.getProp (   self,
  name 
)
Returns the value of the given property.

Definition at line 772 of file Configurable.py.

772  def getProp(self, name):
773  """Returns the value of the given property."""
774  if hasattr(self, name):
775  return getattr(self, name)
776  else:
777  return self.getDefaultProperties()[name]
778 

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 690 of file Configurable.py.

690  def getProperties(self):
691  props = {}
692  for name, proxy in self._properties.items():
693  try:
694  props[name] = proxy.__get__(self)
695  except AttributeError:
696  props[name] = Configurable.propertyNoValue
697 
698  return props
699 

◆ getPropertiesWithDescription()

def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 700 of file Configurable.py.

700  def getPropertiesWithDescription(self):
701  """Get all properties with their description string as { name : (value, desc) }."""
702  props = {}
703  for name, proxy in self._properties.items():
704  try:
705  props[name] = (proxy.__get__(self), proxy.__doc__)
706  except AttributeError:
707  props[name] = (Configurable.propertyNoValue, proxy.__doc__)
708  return props
709 

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 650 of file Configurable.py.

650  def getSequence(self):
651  elems = []
652  for c in self.__children:
653  elems.append(c.getFullName())
654  return elems
655 

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 830 of file Configurable.py.

830  def getTitleName(self):
831  if log.isEnabledFor(logging.DEBUG):
832  return self.getFullJobOptName()
833  else:
834  return self.getFullName()
835 

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 600 of file Configurable.py.

600  def getTools(self):
601  return self.__tools.values() # read only
602 

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 798 of file Configurable.py.

798  def getType(cls):
799  return cls.__name__
800 

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 710 of file Configurable.py.

710  def getValuedProperties(self):
711  props = {}
712  for name, proxy in self._properties.items():
713  if self.isPropertySet(name):
714  value = proxy.__get__(self)
715  if hasattr(value, "getFullName"):
716  value = value.getFullName()
717  elif isinstance(value, (list, set, tuple)):
718  new_value = []
719  for i in value:
720  if hasattr(i, "getFullName"):
721  new_value.append(i.getFullName())
722  else:
723  new_value.append(i)
724  value = type(value)(new_value)
725  elif isinstance(value, dict):
726  new_value = {}
727  for i in value:
728  if hasattr(value[i], "getFullName"):
729  new_value[i] = value[i].getFullName()
730  else:
731  new_value[i] = value[i]
732  value = new_value
733  props[name] = value
734 
735  return props
736 

◆ hasParent()

def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 574 of file Configurable.py.

574  def hasParent(self, parent):
575  return False
576 

◆ isApplicable()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableUser.

Definition at line 1067 of file Configurable.py.

1067  def isApplicable(self):
1068  """
1069  Return True is the instance can be "applied".
1070  Always False for plain Configurable instances
1071  (i.e. not ConfigurableUser).
1072  """
1073  return False
1074 
1075 
1076 # classes for generic Gaudi component ===========
1077 
1078 

◆ isPropertySet()

def GaudiKernel.Configurable.Configurable.isPropertySet (   self,
  name 
)
Tell if the property 'name' has been set or not.

Because of a problem with list and dictionary properties, in those cases
if the value is equal to the default, the property is considered as not
set.

Definition at line 783 of file Configurable.py.

783  def isPropertySet(self, name):
784  """Tell if the property 'name' has been set or not.
785 
786  Because of a problem with list and dictionary properties, in those cases
787  if the value is equal to the default, the property is considered as not
788  set.
789  """
790  if not hasattr(self, name):
791  return False
792  default = self.getDefaultProperty(name)
793  if isinstance(default, (list, dict, set, DataHandle, GaudiHandleArray)):
794  value = getattr(self, name)
795  return value != default
796  return True
797 

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 810 of file Configurable.py.

810  def isPublic(self):
811  return True
812 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 814 of file Configurable.py.

814  def jobOptName(self):
815  log.error(
816  "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
817  error_explanation,
818  )
819  return self.getJobOptName() # compatibility
820 

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 804 of file Configurable.py.

804  def name(self):
805  return self.getName()
806 

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 737 of file Configurable.py.

737  def properties(self):
738  return self.getProperties() # compatibility
739 

◆ remove()

def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 555 of file Configurable.py.

555  def remove(self, items):
556  if not isinstance(items, (list, tuple)):
557  items = [items]
558 
559  self.__children = [e for e in self.__children if e not in items]
560 

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 561 of file Configurable.py.

561  def removeAll(self):
562  self.remove(self.__children)
563 

◆ setDefaults()

def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 836 of file Configurable.py.

836  def setDefaults(cls, handle):
837  pass
838 

◆ setParent()

def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 568 of file Configurable.py.

568  def setParent(self, parentName):
569  pass
570 

◆ setProp()

def GaudiKernel.Configurable.Configurable.setProp (   self,
  name,
  value 
)
Set the value of a given property

Definition at line 779 of file Configurable.py.

779  def setProp(self, name, value):
780  """Set the value of a given property"""
781  return setattr(self, name, value)
782 

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 656 of file Configurable.py.

656  def setup(self):
657  # make sure base class init has been called
658  if not hasattr(self, "_initok") or not self._initok:
659  # could check more, but this is the only explanation
660  raise TypeError(
661  "Configurable.__init__ not called in %s override"
662  % self.__class__.__name__
663  )
664 
665  # log.debug("calling setup() on " + self.getFullJobOptName())
666 
667  # setup self: this collects all values on the python side
668  self.__setupServices()
669  self.__setupDlls()
670  self.__setupDefaults()
671 
672  # setup children
673  for c in self.getAllChildren():
674  c.setup()
675 
676  # now get handle to work with for moving properties into the catalogue
677  handle = self.getHandle()
678  if not handle:
679  log.debug("no handle for %s: not transporting properties", self._name)
680  return # allowed, done early
681 
682  # pass final set of properties on to handle on the C++ side or JobOptSvc
683  for name in self._properties.keys():
684  if hasattr(self, name): # means property has python-side value/default
685  setattr(handle, name, getattr(self, name))
686 
687  # for debugging purposes
688  self._setupok = True
689 

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 870 of file Configurable.py.

870  def splitName(self):
871  fullname = self.getName()
872  dot = fullname.find(".")
873  if dot != -1:
874  parentname = fullname[:dot]
875  longname = fullname[dot + 1 :]
876  else:
877  parentname = ""
878  longname = fullname
879  dot = longname.find(".")
880  if dot != -1:
881  name = longname[:dot]
882  else:
883  name = longname
884  return parentname, name, longname
885 

Member Data Documentation

◆ __children

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 381 of file Configurable.py.

◆ __slots__

GaudiKernel.Configurable.Configurable.__slots__
staticprivate

Definition at line 169 of file Configurable.py.

◆ __tools

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 382 of file Configurable.py.

◆ _configurationLocked

GaudiKernel.Configurable.Configurable._configurationLocked
staticprivate

Definition at line 183 of file Configurable.py.

◆ _initok

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 397 of file Configurable.py.

◆ _inSetDefaults

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 394 of file Configurable.py.

◆ _name

GaudiKernel.Configurable.Configurable._name
private

Definition at line 387 of file Configurable.py.

◆ _setupok

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 400 of file Configurable.py.

◆ _unpickling

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 403 of file Configurable.py.

◆ allConfigurables

GaudiKernel.Configurable.Configurable.allConfigurables
static

Definition at line 179 of file Configurable.py.

◆ configurableServices

GaudiKernel.Configurable.Configurable.configurableServices
static

Definition at line 180 of file Configurable.py.

◆ indentUnit

GaudiKernel.Configurable.Configurable.indentUnit
static

Definition at line 165 of file Configurable.py.

◆ printHeaderPre

GaudiKernel.Configurable.Configurable.printHeaderPre
static

Definition at line 167 of file Configurable.py.

◆ printHeaderWidth

GaudiKernel.Configurable.Configurable.printHeaderWidth
static

Definition at line 166 of file Configurable.py.

◆ propertyNoValue

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 164 of file Configurable.py.


The documentation for this class was generated from the following file:
MSG::hex
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:277
GaudiPartProp.decorators.__getattr__
__getattr__
decorate the attribute access for Gaudi.ParticleProperty
Definition: decorators.py:186
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
GaudiPartProp.decorators.__repr__
__repr__
decorate the vector of properties
Definition: decorators.py:173
GaudiPartProp.tests.id
id
Definition: tests.py:111
bug_34121.tool
tool
Definition: bug_34121.py:18
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:99
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:68
GaudiPartProp.decorators.__len__
__len__
Definition: decorators.py:177
GaudiPython.Pythonizations.__iter__
__iter__
Definition: Pythonizations.py:143
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
StringKeyEx.keys
keys
Definition: StringKeyEx.py:64
GaudiPartProp.decorators.__str__
__str__
decorate the printout for Gaudi::ParticleProperty
Definition: decorators.py:176
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39