The Gaudi Framework  v36r13 (995e4364)
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
 
 __nonzero__
 

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

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

Member Function Documentation

◆ __bool__()

def GaudiKernel.Configurable.Configurable.__bool__ (   self)

Definition at line 549 of file Configurable.py.

549  def __bool__(self):
550  return True
551 

◆ __deepcopy__()

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

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

Definition at line 442 of file Configurable.py.

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

◆ __delattr__()

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

Definition at line 524 of file Configurable.py.

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

◆ __getattr__()

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

Definition at line 493 of file Configurable.py.

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

◆ __getnewargs__()

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 415 of file Configurable.py.

415  def __getnewargs__(self):
416  return (self._name,)
417 

◆ __getstate__()

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 402 of file Configurable.py.

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

◆ __iadd__()

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

Definition at line 458 of file Configurable.py.

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

◆ __iter__()

def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 438 of file Configurable.py.

438  def __iter__(self):
439  return iter(self.__children)
440 

◆ __len__()

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 435 of file Configurable.py.

435  def __len__(self):
436  return len(self.__children)
437 

◆ __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 181 of file Configurable.py.

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

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 974 of file Configurable.py.

974  def __repr__(self):
975  return "{0}({1!r})".format(self.__class__.__name__, self.name())
976 

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 510 of file Configurable.py.

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

◆ __setstate__()

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

Definition at line 418 of file Configurable.py.

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

◆ __setupDefaults()

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

Definition at line 949 of file Configurable.py.

949  def __setupDefaults(self):
950  # set handle defaults flags to inform __setattr__ that it is being
951  # called during setDefaults of the concrete Configurable
952  self._inSetDefaults = True
953  self.setDefaults(self)
954  self._inSetDefaults = False
955 

◆ __setupDlls()

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

Definition at line 936 of file Configurable.py.

936  def __setupDlls(self):
937  dlls = self.getDlls()
938  if not dlls:
939  dlls = []
940  elif isinstance(dlls, types.StringType):
941  dlls = [dlls]
942 
943  from __main__ import theApp
944 
945  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
946  if dlls:
947  theApp.Dlls += dlls
948 

◆ __setupServices()

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

Definition at line 918 of file Configurable.py.

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

◆ __str__()

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

Definition at line 977 of file Configurable.py.

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

◆ _isInSetDefaults()

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

Definition at line 915 of file Configurable.py.

915  def _isInSetDefaults(self):
916  return self._inSetDefaults
917 

◆ _printFooter()

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

Definition at line 966 of file Configurable.py.

966  def _printFooter(indentStr, title):
967  preLen = Configurable.printHeaderPre
968  postLen = (
969  Configurable.printHeaderWidth - preLen - 12 - len(title)
970  ) # - len(indentStr)
971  postLen = max(preLen, postLen)
972  return indentStr + "\\%s (End of %s) %s" % (preLen * "-", title, postLen * "-")
973 

◆ _printHeader()

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

Definition at line 957 of file Configurable.py.

957  def _printHeader(indentStr, title):
958  preLen = Configurable.printHeaderPre
959  postLen = (
960  Configurable.printHeaderWidth - preLen - 3 - len(title)
961  ) # - len(indentStr)
962  postLen = max(preLen, postLen)
963  return indentStr + "/%s %s %s" % (preLen * "*", title, postLen * "*")
964 

◆ addTool()

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

Definition at line 892 of file Configurable.py.

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

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

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

◆ 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  class collector:
743  pass
744 
745  # user provided defaults
746  c = collector()
747  cls.setDefaults(c)
748 
749  # defaults from C++
750  for k, v in cls._properties.items():
751  if k not in c.__dict__ and hasattr(v, "default"):
752  c.__dict__[k] = v.default
753 
754  return c.__dict__
755 

◆ getDefaultProperty()

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

Definition at line 757 of file Configurable.py.

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

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 830 of file Configurable.py.

830  def getFullJobOptName(self):
831  return "%s/%s" % (self.getType(), self.getJobOptName() or self.getName())
832 

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 827 of file Configurable.py.

827  def getFullName(self):
828  return str(self.getType() + "/" + self.getName())
829 

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

813  def getJobOptName(self): # full hierachical name
814  return self.getName()
815 

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 807 of file Configurable.py.

807  def getName(self):
808  return self._name
809 

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

833  def getPrintTitle(self):
834  return self.getGaudiType() + " " + self.getTitleName()
835 

◆ getProp()

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

Definition at line 778 of file Configurable.py.

778  def getProp(self, name):
779  """Returns the value of the given property."""
780  if hasattr(self, name):
781  return getattr(self, name)
782  else:
783  return self.getDefaultProperties()[name]
784 

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

836  def getTitleName(self):
837  if log.isEnabledFor(logging.DEBUG):
838  return self.getFullJobOptName()
839  else:
840  return self.getFullName()
841 

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

804  def getType(cls):
805  return cls.__name__
806 

◆ 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 type(value) in [list, 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 type(value) is 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 1065 of file Configurable.py.

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

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

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

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 816 of file Configurable.py.

816  def isPublic(self):
817  return True
818 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 820 of file Configurable.py.

820  def jobOptName(self):
821  log.error(
822  "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
823  error_explanation,
824  )
825  return self.getJobOptName() # compatibility
826 

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 810 of file Configurable.py.

810  def name(self):
811  return self.getName()
812 

◆ 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 type(items) != list and type(items) != 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 842 of file Configurable.py.

842  def setDefaults(cls, handle):
843  pass
844 

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

785  def setProp(self, name, value):
786  """Set the value of a given property"""
787  return setattr(self, name, value)
788 

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

876  def splitName(self):
877  fullname = self.getName()
878  dot = fullname.find(".")
879  if dot != -1:
880  parentname = fullname[:dot]
881  longname = fullname[dot + 1 :]
882  else:
883  parentname = ""
884  longname = fullname
885  dot = longname.find(".")
886  if dot != -1:
887  name = longname[:dot]
888  else:
889  name = longname
890  return parentname, name, longname
891 

Member Data Documentation

◆ __children

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 377 of file Configurable.py.

◆ __nonzero__

GaudiKernel.Configurable.Configurable.__nonzero__
staticprivate

Definition at line 553 of file Configurable.py.

◆ __slots__

GaudiKernel.Configurable.Configurable.__slots__
staticprivate

Definition at line 165 of file Configurable.py.

◆ __tools

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 378 of file Configurable.py.

◆ _configurationLocked

GaudiKernel.Configurable.Configurable._configurationLocked
staticprivate

Definition at line 179 of file Configurable.py.

◆ _initok

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 393 of file Configurable.py.

◆ _inSetDefaults

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 390 of file Configurable.py.

◆ _name

GaudiKernel.Configurable.Configurable._name
private

Definition at line 383 of file Configurable.py.

◆ _setupok

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 396 of file Configurable.py.

◆ _unpickling

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 399 of file Configurable.py.

◆ allConfigurables

GaudiKernel.Configurable.Configurable.allConfigurables
static

Definition at line 175 of file Configurable.py.

◆ configurableServices

GaudiKernel.Configurable.Configurable.configurableServices
static

Definition at line 176 of file Configurable.py.

◆ indentUnit

GaudiKernel.Configurable.Configurable.indentUnit
static

Definition at line 161 of file Configurable.py.

◆ printHeaderPre

GaudiKernel.Configurable.Configurable.printHeaderPre
static

Definition at line 163 of file Configurable.py.

◆ printHeaderWidth

GaudiKernel.Configurable.Configurable.printHeaderWidth
static

Definition at line 162 of file Configurable.py.

◆ propertyNoValue

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 160 of file Configurable.py.


The documentation for this class was generated from the following file:
MSG::hex
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:282
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
GaudiPython.HistoUtils.__str__
__str__
Definition: HistoUtils.py:539
bug_34121.tool
tool
Definition: bug_34121.py:17
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:444
TimingHistograms.name
name
Definition: TimingHistograms.py:25
GaudiPython.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:536
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:69
GaudiPython.Pythonizations.__iter__
__iter__
Definition: Pythonizations.py:146
gaudirun.type
type
Definition: gaudirun.py:162
StringKeyEx.keys
keys
Definition: StringKeyEx.py:64
GaudiPython.Pythonizations.__len__
__len__
Definition: Pythonizations.py:145
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546