The Gaudi Framework  v36r7 (7f57a304)
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
 
string indentUnit = "| "
 
int printHeaderWidth = 100
 
int printHeaderPre = 5
 
dictionary allConfigurables = {}
 
dictionary 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

tuple __slots__
 
bool _configurationLocked = False
 
def __nonzero__ = __bool__
 

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 145 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 335 of file Configurable.py.

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

Member Function Documentation

◆ __bool__()

def GaudiKernel.Configurable.Configurable.__bool__ (   self)

Definition at line 544 of file Configurable.py.

544  def __bool__(self):
545  return True
546 

◆ __deepcopy__()

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

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

Definition at line 437 of file Configurable.py.

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

◆ __delattr__()

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

Definition at line 519 of file Configurable.py.

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

◆ __getattr__()

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

Definition at line 488 of file Configurable.py.

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

◆ __getnewargs__()

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 410 of file Configurable.py.

410  def __getnewargs__(self):
411  return (self._name,)
412 

◆ __getstate__()

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 397 of file Configurable.py.

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

◆ __iadd__()

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

Definition at line 453 of file Configurable.py.

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

◆ __iter__()

def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 433 of file Configurable.py.

433  def __iter__(self):
434  return iter(self.__children)
435 

◆ __len__()

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 430 of file Configurable.py.

430  def __len__(self):
431  return len(self.__children)
432 

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

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

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 969 of file Configurable.py.

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

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 505 of file Configurable.py.

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

◆ __setstate__()

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

Definition at line 413 of file Configurable.py.

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

◆ __setupDefaults()

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

Definition at line 944 of file Configurable.py.

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

◆ __setupDlls()

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

Definition at line 931 of file Configurable.py.

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

◆ __setupServices()

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

Definition at line 913 of file Configurable.py.

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

◆ __str__()

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

Definition at line 972 of file Configurable.py.

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

◆ _isInSetDefaults()

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

Definition at line 910 of file Configurable.py.

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

◆ _printFooter()

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

Definition at line 961 of file Configurable.py.

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

◆ _printHeader()

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

Definition at line 952 of file Configurable.py.

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

◆ addTool()

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

Definition at line 887 of file Configurable.py.

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

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 598 of file Configurable.py.

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

◆ clone()

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

Definition at line 840 of file Configurable.py.

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

◆ copyChild()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 560 of file Configurable.py.

560  def copyChild(self, child):
561  return copy.deepcopy(child)
562 

◆ copyChildAndSetParent()

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

Definition at line 572 of file Configurable.py.

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

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

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

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 592 of file Configurable.py.

592  def getChildren(self):
593  return self.__children[:] # read only
594 

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 736 of file Configurable.py.

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

◆ getDefaultProperty()

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

Definition at line 752 of file Configurable.py.

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

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 825 of file Configurable.py.

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

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 822 of file Configurable.py.

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

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

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

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 802 of file Configurable.py.

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

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 566 of file Configurable.py.

566  def getParent(self):
567  return ""
568 

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 828 of file Configurable.py.

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

◆ getProp()

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

Definition at line 773 of file Configurable.py.

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

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 685 of file Configurable.py.

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

◆ getPropertiesWithDescription()

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

Definition at line 695 of file Configurable.py.

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

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 645 of file Configurable.py.

645  def getSequence(self):
646  elems = []
647  for c in self.__children:
648  elems.append(c.getFullName())
649  return elems
650 

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 831 of file Configurable.py.

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

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 595 of file Configurable.py.

595  def getTools(self):
596  return self.__tools.values() # read only
597 

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 799 of file Configurable.py.

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

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 705 of file Configurable.py.

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

◆ hasParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 569 of file Configurable.py.

569  def hasParent(self, parent):
570  return False
571 

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

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

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

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

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 811 of file Configurable.py.

811  def isPublic(self):
812  return True
813 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 815 of file Configurable.py.

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

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 805 of file Configurable.py.

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

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 732 of file Configurable.py.

732  def properties(self):
733  return self.getProperties() # compatibility
734 

◆ remove()

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

Definition at line 550 of file Configurable.py.

550  def remove(self, items):
551  if type(items) != list and type(items) != tuple:
552  items = [items]
553 
554  self.__children = [e for e in self.__children if not e in items]
555 

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 556 of file Configurable.py.

556  def removeAll(self):
557  self.remove(self.__children)
558 

◆ setDefaults()

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

Definition at line 837 of file Configurable.py.

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

◆ setParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 563 of file Configurable.py.

563  def setParent(self, parentName):
564  pass
565 

◆ setProp()

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

Definition at line 780 of file Configurable.py.

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

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 651 of file Configurable.py.

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

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 871 of file Configurable.py.

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

Member Data Documentation

◆ __children

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 372 of file Configurable.py.

◆ __nonzero__

def GaudiKernel.Configurable.Configurable.__nonzero__ = __bool__
staticprivate

Definition at line 548 of file Configurable.py.

◆ __slots__

tuple GaudiKernel.Configurable.Configurable.__slots__
staticprivate
Initial value:
= (
"__children", # controlled components, e.g. private AlgTools
"__tools", # private AlgTools (#PM-->)
"_name", # the (unqualified) component name
"_inSetDefaults", # currently setting default values
"_initok", # used to enforce base class init
"_setupok", # for debugging purposes (temporary)
"_unpickling", # flag for actions done during unpickling
)

Definition at line 160 of file Configurable.py.

◆ __tools

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 373 of file Configurable.py.

◆ _configurationLocked

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 174 of file Configurable.py.

◆ _initok

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 388 of file Configurable.py.

◆ _inSetDefaults

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 385 of file Configurable.py.

◆ _name

GaudiKernel.Configurable.Configurable._name
private

Definition at line 378 of file Configurable.py.

◆ _setupok

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 391 of file Configurable.py.

◆ _unpickling

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 394 of file Configurable.py.

◆ allConfigurables

dictionary GaudiKernel.Configurable.Configurable.allConfigurables = {}
static

Definition at line 170 of file Configurable.py.

◆ configurableServices

dictionary GaudiKernel.Configurable.Configurable.configurableServices = {}
static

Definition at line 171 of file Configurable.py.

◆ indentUnit

string GaudiKernel.Configurable.Configurable.indentUnit = "| "
static

Definition at line 156 of file Configurable.py.

◆ printHeaderPre

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 158 of file Configurable.py.

◆ printHeaderWidth

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 157 of file Configurable.py.

◆ propertyNoValue

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 155 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:160
GaudiPython.Pythonizations.__len__
__len__
Definition: Pythonizations.py:145
StringKeyEx.keys
list keys
Definition: StringKeyEx.py:67
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546