The Gaudi Framework  v37r1 (a7f61348)
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 548 of file Configurable.py.

548  def __bool__(self):
549  return True
550 

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

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

◆ __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  if attr in self.__tools:
495  return self.__tools[attr]
496 
497  if attr in self._properties:
498  if isinstance(self._properties[attr].__get__(self), DataHandle):
499  return self._properties[attr].__get__(self)
500 
501  for c in self.__children:
502  if c.getName() == attr:
503  return c
504 
505  raise AttributeError(
506  "'%s' object has no attribute '%s'" % (self.__class__, attr)
507  )
508 

◆ __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 not isinstance(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 973 of file Configurable.py.

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

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 509 of file Configurable.py.

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

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

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

◆ __setupDlls()

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

Definition at line 935 of file Configurable.py.

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

◆ __setupServices()

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

Definition at line 917 of file Configurable.py.

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

◆ __str__()

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

Definition at line 976 of file Configurable.py.

976  def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
977  global log # to print some info depending on output level
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  else:
1030  strVal = repr(vv)
1031  strDef = repr(default)
1032  # add the value
1033  line = prefix + " = " + strVal
1034  # add default if present
1035  if strDef is not None:
1036  # put default on new line if too big
1037  if len(line) + len(strDef) > Configurable.printHeaderWidth:
1038  line += (
1039  os.linesep
1040  + indentStr
1041  + "| "
1042  + (len(prefix) - len(indentStr) - 3) * " "
1043  )
1044  line += " (default: %s)" % (strDef,)
1045  # add the line to the total string
1046  rep += line + os.linesep
1047  # print out full private configurables
1048  # if isinstance(v,Configurable) and not v.isPublic():
1049 
1054 
1055  # print configurables + their properties, or loop over sequence
1056  # for cfg in self.__children:
1057  for cfg in self.getAllChildren():
1058  rep += cfg.__str__(indent + 1, "|=") + os.linesep
1059 
1060  # print line to easily see end-of-configurable. Note: No linesep!
1061  rep += Configurable._printFooter(indentStr, title)
1062  return rep
1063 

◆ _isInSetDefaults()

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

Definition at line 914 of file Configurable.py.

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

◆ _printFooter()

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

Definition at line 965 of file Configurable.py.

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

◆ _printHeader()

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

Definition at line 956 of file Configurable.py.

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

◆ addTool()

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

Definition at line 891 of file Configurable.py.

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

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 602 of file Configurable.py.

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

◆ clone()

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

Definition at line 844 of file Configurable.py.

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

◆ copyChild()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 564 of file Configurable.py.

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

◆ copyChildAndSetParent()

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

Definition at line 576 of file Configurable.py.

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

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

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

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 596 of file Configurable.py.

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

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 740 of file Configurable.py.

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

◆ getDefaultProperty()

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

Definition at line 756 of file Configurable.py.

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

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 829 of file Configurable.py.

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

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 826 of file Configurable.py.

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

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

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

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 806 of file Configurable.py.

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

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 570 of file Configurable.py.

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

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 832 of file Configurable.py.

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

◆ getProp()

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

Definition at line 777 of file Configurable.py.

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

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 689 of file Configurable.py.

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

◆ getPropertiesWithDescription()

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

Definition at line 699 of file Configurable.py.

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

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 649 of file Configurable.py.

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

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 835 of file Configurable.py.

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

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 599 of file Configurable.py.

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

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 803 of file Configurable.py.

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

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 709 of file Configurable.py.

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

◆ hasParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 573 of file Configurable.py.

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

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

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

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

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

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 815 of file Configurable.py.

815  def isPublic(self):
816  return True
817 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 819 of file Configurable.py.

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

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 809 of file Configurable.py.

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

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 736 of file Configurable.py.

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

◆ remove()

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

Definition at line 554 of file Configurable.py.

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

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 560 of file Configurable.py.

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

◆ setDefaults()

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

Definition at line 841 of file Configurable.py.

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

◆ setParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 567 of file Configurable.py.

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

◆ setProp()

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

Definition at line 784 of file Configurable.py.

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

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 655 of file Configurable.py.

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

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 875 of file Configurable.py.

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

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 552 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
bug_34121.name
name
Definition: bug_34121.py:20
GaudiAlg.HistoUtils.__str__
__str__
Definition: HistoUtils.py:539
max
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225
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: details.h:440
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:63
GaudiPython.Pythonizations.__len__
__len__
Definition: Pythonizations.py:145
GaudiAlg.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:536
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546