The Gaudi Framework  v36r1 (3e2fb5a8)
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)
 
- 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
 
- Static Public Attributes inherited from GaudiKernel.ConfigurableMeta.ConfigurableMeta
def newclass = type.__new__(self, name, bases, dct)
 
 configurables
 
dictionary properties = {}
 
 slots = dct.get('__slots__')
 
list props = [x for x in slots if x[0] != '_']
 
 propDict = dct.get('_propertyDocDct')
 
 docString = propDict and propDict.get(prop)
 
 default = slots[prop]
 
 proxy
 
 bprops = base._properties.copy()
 
 properties = bprops
 

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 118 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 298 of file Configurable.py.

298  def __init__(self, name=DefaultName):
299  # check class readiness, all required overloads should be there now
300  klass = self.__class__
301 
302  # this is an abstract class
303  if klass == Configurable:
304  raise TypeError(
305  "%s is an ABC and can not be instantiated" % str(Configurable))
306 
307  # the following methods require overloading
308  # NOT YET meths = { 'getServices' : 1, # retrieve list of services to configure
309  meths = {
310  'getDlls': 1, # provide list of Dlls to load
311  'getGaudiType': 1, # return string describing component class
312  'getHandle': 1
313  } # provide access to C++ side component instance
314  # 'getType' : 1 } # return the type of the actual C++ component
315 
316  for meth, nArgs in meths.items():
317  try:
318  f = six.get_unbound_function(getattr(klass, meth))
319  except AttributeError:
320  raise NotImplementedError(
321  "%s is missing in class %s" % (meth, str(klass)))
322 
323  # in addition, verify the number of arguments w/o defaults
324  nargcount = six.get_function_code(f).co_argcount
325  fdefaults = six.get_function_defaults(f)
326  ndefaults = fdefaults and len(fdefaults) or 0
327  if not nargcount - ndefaults <= nArgs <= nargcount:
328  raise TypeError("%s.%s requires exactly %d arguments" %
329  (klass, meth, nArgs))
330 
331  # for using this Configurable as a (Gaudi) sequence
332  self.__children = []
333  self.__tools = {}
334 
335  # know who we are
336  if name == Configurable.DefaultName:
337  if hasattr(self.__class__, 'DefaultedName'):
338  self._name = self.__class__.DefaultedName
339  else:
340  self._name = self.getType()
341  else:
342  self._name = name
343 
344  # set to True when collecting defaults, False otherwise
345  self._inSetDefaults = False
346 
347  # for later, in case __init__ itself is overridden
348  self._initok = True
349 
350  # for debugging purposes (temporary)
351  self._setupok = False
352 
353  # used to prevent spurious deprecation warnings when unpickling
354  self._unpickling = False
355 

Member Function Documentation

◆ __bool__()

def GaudiKernel.Configurable.Configurable.__bool__ (   self)

Definition at line 499 of file Configurable.py.

499  def __bool__(self):
500  return True
501 

◆ __deepcopy__()

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

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

Definition at line 397 of file Configurable.py.

397  def __deepcopy__(self, memo):
398  newconf = object.__new__(self.__class__)
399  self.__class__.__init__(newconf, self.getName())
400 
401  for proxy in self._properties.values():
402  try:
403  proxy.__set__(newconf, proxy.__get__(self))
404  except AttributeError:
405  pass # means property was not set for self
406 
407  for c in self.__children:
408  newconf += c # processes proper copy semantics
409 
410  return newconf
411 

◆ __delattr__()

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

Definition at line 474 of file Configurable.py.

474  def __delattr__(self, attr):
475  # remove as property, otherwise try as child
476  try:
477  # remove history etc., then reset to default (in case set before)
478  prop = self._properties[attr]
479  prop.__delete__(self)
480  prop.__set__(self, prop.default)
481  return # reaches here? was property: done now
482  except KeyError:
483  pass
484  # otherwise, remove the private tool
485  if attr in self.__tools:
486  del self.__tools[attr]
487 
488  # otherwise, remove child, if one is so named
489  for c in self.__children:
490  if c.getName() == attr:
491  self.__children.remove(c)
492 
493  # potentially, there are left over caches (certain user derived classes)
494  try:
495  del self.__dict__[attr]
496  except (AttributeError, KeyError):
497  pass
498 

◆ __getattr__()

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

Definition at line 446 of file Configurable.py.

446  def __getattr__(self, attr): # until ToolProperties exist ...
447 
448  if attr in self.__tools:
449  return self.__tools[attr]
450 
451  if attr in self._properties:
452  if isinstance(self._properties[attr].__get__(self), DataHandle):
453  return self._properties[attr].__get__(self)
454 
455  for c in self.__children:
456  if c.getName() == attr:
457  return c
458 
459  raise AttributeError(
460  "'%s' object has no attribute '%s'" % (self.__class__, attr))
461 

◆ __getnewargs__()

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 370 of file Configurable.py.

370  def __getnewargs__(self):
371  return (self._name, )
372 

◆ __getstate__()

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 357 of file Configurable.py.

357  def __getstate__(self):
358  dict = {}
359  for name, proxy in self._properties.items():
360  try:
361  dict[name] = proxy.__get__(self)
362  except AttributeError:
363  pass
364 
365  dict['_Configurable__children'] = self.__children
366  dict['_Configurable__tools'] = self.__tools
367  dict['_name'] = self._name
368  return dict
369 

◆ __iadd__()

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

Definition at line 413 of file Configurable.py.

413  def __iadd__(self, configs, descr=None):
414  if not type(configs) in (list, tuple):
415  configs = (configs, )
416 
417  joname = self.getJobOptName()
418 
419  for cfg in configs:
420  # prevent type mismatches
421  if not isinstance(cfg, Configurable):
422  raise TypeError("'%s' is not a Configurable" % str(cfg))
423 
424  cc = self.copyChildAndSetParent(cfg, joname)
425 
426  # filters dupes; usually "ok" (backdoor should catch them)
427  ccjo = cc.getJobOptName()
428  for c in self.__children:
429  if c.getJobOptName() == ccjo:
430  log.error('attempt to add a duplicate ... dupe ignored%s',
431  error_explanation)
432  break
433  else:
434  self.__children.append(cc)
435 
436  try:
437  if descr: # support for tool properties
438  descr.__set__(self, cc)
439  else:
440  setattr(self, cc.getName(), cc)
441  except AttributeError:
442  pass # to allow free addition of tools/subalgorithms
443 
444  return self
445 

◆ __iter__()

def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 393 of file Configurable.py.

393  def __iter__(self):
394  return iter(self.__children)
395 

◆ __len__()

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 390 of file Configurable.py.

390  def __len__(self):
391  return len(self.__children)
392 

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

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

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 924 of file Configurable.py.

924  def __repr__(self):
925  return '{0}({1!r})'.format(self.__class__.__name__, self.name())
926 

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 462 of file Configurable.py.

462  def __setattr__(self, name, value):
463  if self._configurationLocked:
464  raise RuntimeError(
465  "%s: Configuration cannot be modified after the ApplicationMgr has been started."
466  % self.name())
467  try:
468  super(Configurable, self).__setattr__(name, value)
469  except AttributeError:
470  raise AttributeError(
471  "Configurable '%s' does not have property '%s'." %
472  (self.__class__.__name__, name))
473 

◆ __setstate__()

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

Definition at line 373 of file Configurable.py.

373  def __setstate__(self, dict):
374  self._initok = True
375  from contextlib import contextmanager
376 
377  @contextmanager
378  def unpickling():
379  try:
380  self._unpickling = True
381  yield
382  finally:
383  self._unpickling = False
384 
385  with unpickling():
386  for n, v in dict.items():
387  setattr(self, n, v)
388 

◆ __setupDefaults()

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

Definition at line 900 of file Configurable.py.

900  def __setupDefaults(self):
901  # set handle defaults flags to inform __setattr__ that it is being
902  # called during setDefaults of the concrete Configurable
903  self._inSetDefaults = True
904  self.setDefaults(self)
905  self._inSetDefaults = False
906 

◆ __setupDlls()

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

Definition at line 888 of file Configurable.py.

888  def __setupDlls(self):
889  dlls = self.getDlls()
890  if not dlls:
891  dlls = []
892  elif type(dlls) == types.StringType:
893  dlls = [dlls]
894 
895  from __main__ import theApp
896  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
897  if dlls:
898  theApp.Dlls += dlls
899 

◆ __setupServices()

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

Definition at line 871 of file Configurable.py.

871  def __setupServices(self):
872  #svcs = self.getServices()
873  # if not svcs:
874  svcs = []
875  # elif type(svcs) == types.StringType:
876  # svcs = [ svcs ]
877 
878  import __main__
879  for svc in svcs:
880  handle = __main__.Service(svc)
881  # services should be configurables as well, but aren't for now
882  # handle.setup()
883 
884  # allow Configurable to make some changes
885  if hasattr(self, 'configure' + svc):
886  eval('self.configure' + svc + '( handle )')
887 

◆ __str__()

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

Definition at line 927 of file Configurable.py.

927  def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
928  global log # to print some info depending on output level
929  indentStr = indent * Configurable.indentUnit
930  # print header
931  title = self.getPrintTitle()
932  # print line to easily see start-of-configurable
933  if indent > 0:
934  headerIndent = (indent - 1) * \
935  Configurable.indentUnit + headerLastIndentUnit
936  else:
937  headerIndent = ''
938  rep = Configurable._printHeader(headerIndent, title)
939  rep += os.linesep
940  # print own properties
941  props = self.getProperties()
942  defs = self.getDefaultProperties()
943  if not props:
944  rep += indentStr + '|-<no properties>' + os.linesep
945  else:
946  # get property name with
947  nameWidth = 0
948  for p in props.keys():
949  nameWidth = max(nameWidth, len(p))
950  for p, v in props.items():
951  # start with indent and property name
952  prefix = indentStr + '|-%-*s' % (nameWidth, p)
953  # add memory address for debugging (not for defaults)
954  if log.isEnabledFor(logging.DEBUG):
955  if v != Configurable.propertyNoValue:
956  address = ' @%11s' % hex(id(v))
957  else:
958  address = 13 * ' '
959  prefix += address
960  # add value and default
961  default = defs.get(p)
962  if v == Configurable.propertyNoValue:
963  # show default value as value, and no extra 'default'
964  strVal = repr(default)
965  strDef = None
966  else:
967  # convert configurable to handle
968  if hasattr(v, "getGaudiHandle"):
969  vv = v.getGaudiHandle()
970  else:
971  vv = v
972  if isinstance(vv,
973  (GaudiHandle, GaudiHandleArray, DataHandle)):
974  strVal = repr(vv)
975  # the default may not be a GaudiHandle (?)
976  if hasattr(default, "toStringProperty"):
977  strDef = repr(default.toStringProperty())
978  else:
979  strDef = repr(default)
980  if strDef == repr(vv.toStringProperty()):
981  strDef = None
982  else:
983  strVal = repr(vv)
984  strDef = repr(default)
985  # add the value
986  line = prefix + ' = ' + strVal
987  # add default if present
988  if strDef is not None:
989  # put default on new line if too big
990  if len(line) + len(strDef) > Configurable.printHeaderWidth:
991  line += os.linesep + indentStr + '| ' + \
992  (len(prefix) - len(indentStr) - 3) * ' '
993  line += ' (default: %s)' % (strDef, )
994  # add the line to the total string
995  rep += line + os.linesep
996  # print out full private configurables
997 # if isinstance(v,Configurable) and not v.isPublic():

◆ _isInSetDefaults()

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

Definition at line 868 of file Configurable.py.

868  def _isInSetDefaults(self):
869  return self._inSetDefaults
870 

◆ _printFooter()

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

Definition at line 916 of file Configurable.py.

916  def _printFooter(indentStr, title):
917  preLen = Configurable.printHeaderPre
918  postLen = Configurable.printHeaderWidth - \
919  preLen - 12 - len(title) # - len(indentStr)
920  postLen = max(preLen, postLen)
921  return indentStr + '\\%s (End of %s) %s' % (preLen * '-', title,
922  postLen * '-')
923 

◆ _printHeader()

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

Definition at line 908 of file Configurable.py.

908  def _printHeader(indentStr, title):
909  preLen = Configurable.printHeaderPre
910  postLen = Configurable.printHeaderWidth - \
911  preLen - 3 - len(title) # - len(indentStr)
912  postLen = max(preLen, postLen)
913  return indentStr + '/%s %s %s' % (preLen * '*', title, postLen * '*')
914 

◆ addTool()

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

Definition at line 845 of file Configurable.py.

845  def addTool(self, tool, name=None):
846  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
847  if name is None:
848  name = tool.__name__
849  priv_tool = tool(self.getName() + '.' + name)
850  elif isinstance(tool, ConfigurableAlgTool):
851  if name is None:
852  name = tool.splitName()[1]
853  priv_tool = tool.clone(self.getName() + '.' + name)
854  else:
855  if isclass(tool):
856  classname = tool.__name__
857  else:
858  classname = type(tool).__name__
859  raise TypeError(
860  "addTool requires AlgTool configurable. Got %s type" %
861  classname)
862  self.__tools[name] = priv_tool
863  if name in self.__slots__:
864  # this is to avoid that the property hides the tool
865  setattr(self, name, self.__tools[name])
866  return self.__tools[name]
867 

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 553 of file Configurable.py.

553  def children(self):
554  log.error(
555  "children() is deprecated, use getChildren() instead for consistency"
556  )
557  log.error(
558  "getChildren() returns a copy; to add a child, use 'parent += child'%s",
559  error_explanation)
560  return self.__children # by ref, for compatibility
561 

◆ clone()

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

Definition at line 798 of file Configurable.py.

798  def clone(self, name=None, **kwargs):
799  if not name:
800  if hasattr(self, 'DefaultedName'):
801  name = self.DefaultedName
802  else:
803  name = self.getType()
804 
805  newconf = Configurable.__new__(self.__class__, name)
806  self.__class__.__init__(newconf, name)
807 
808  for proxy in self._properties.values():
809  try:
810  value = proxy.__get__(self)
811  if type(value) in [str, list, dict, tuple]:
812  # clone the values of the properties for basic types
813  value = type(value)(value)
814  proxy.__set__(newconf, value)
815  except AttributeError:
816  pass
817 
818  for c in self.__children:
819  newconf += c # processes proper copy semantics
820 
821  for n, t in self.__tools.items():
822  newconf.addTool(t, n)
823 
824  for name, value in kwargs.items():
825  setattr(newconf, name, value)
826 
827  return newconf
828 

◆ copyChild()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 515 of file Configurable.py.

515  def copyChild(self, child):
516  return copy.deepcopy(child)
517 

◆ copyChildAndSetParent()

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

Definition at line 527 of file Configurable.py.

527  def copyChildAndSetParent(self, cfg, parent):
528  cc = self.copyChild(cfg)
529 
530  if hasattr(cc, 'setParent') and parent:
531  try:
532  cc.setParent(parent)
533  except RuntimeError as e:
534  # temporary backdoor resolution for compatibility
535  log.error(str(e) + '%s', error_explanation)
536  ccbd = cc.configurables[cc.getJobOptName()]
537 
538  # merge properties, new over pre-existing
539  for proxy in self._properties.values():
540  if cc in proxy.history:
541  proxy.__set__(ccbd, proxy.__get__(cc))
542 
543  # consolidate
544  cc = ccbd
545  return cc
546 

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

562  def getAllChildren(self):
563  """Get all (private) configurable children, both explicit ones (added with +=)
564  and the ones in the private GaudiHandle properties"""
565  childs = []
566  # add private configurable properties (also inside handles)
567  for proxy in self._properties.values():
568  try:
569  c = proxy.__get__(self)
570  except AttributeError:
571  pass
572  else:
573  if isinstance(c, Configurable) and not c.isPublic():
574  childs.append(c)
575  elif isinstance(c, GaudiHandle):
576  try:
577  conf = c.configurable
578  except AttributeError:
579  pass
580  else:
581  if not conf.isPublic():
582  childs.append(conf)
583  elif isinstance(c, GaudiHandleArray):
584  # only setup private arrays
585  if not c.isPublic():
586  for ci in c:
587  if isinstance(ci, Configurable):
588  childs.append(ci)
589  else:
590  try:
591  conf = ci.configurable
592  except AttributeError:
593  pass
594  else:
595  childs.append(conf)
596 
597  # add explicit children
598  childs += self.__children
599  return childs
600 

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 547 of file Configurable.py.

547  def getChildren(self):
548  return self.__children[:] # read only
549 

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 692 of file Configurable.py.

692  def getDefaultProperties(cls):
693  class collector:
694  pass
695 
696  # user provided defaults
697  c = collector()
698  cls.setDefaults(c)
699 
700  # defaults from C++
701  for k, v in cls._properties.items():
702  if not k in c.__dict__ and hasattr(v, 'default'):
703  c.__dict__[k] = v.default
704 
705  return c.__dict__
706 

◆ getDefaultProperty()

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

Definition at line 708 of file Configurable.py.

708  def getDefaultProperty(cls, name):
709  class collector:
710  pass
711 
712  # user provided defaults
713  c = collector()
714  cls.setDefaults(c)
715 
716  if name in c.__dict__:
717  return c.__dict__[name]
718 
719  # defaults from C++
720  try:
721  v = cls._properties[name]
722  if hasattr(v, 'default'):
723  return v.default
724  except KeyError:
725  pass
726 
727  return None
728 

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 782 of file Configurable.py.

782  def getFullJobOptName(self):
783  return "%s/%s" % (self.getType(), self.getJobOptName()
784  or self.getName())
785 

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 779 of file Configurable.py.

779  def getFullName(self):
780  return str(self.getType() + '/' + self.getName())
781 

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

766  def getJobOptName(self): # full hierachical name
767  return self.getName()
768 

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 760 of file Configurable.py.

760  def getName(self):
761  return self._name
762 

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 521 of file Configurable.py.

521  def getParent(self):
522  return ""
523 

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 786 of file Configurable.py.

786  def getPrintTitle(self):
787  return self.getGaudiType() + ' ' + self.getTitleName()
788 

◆ getProp()

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

Definition at line 729 of file Configurable.py.

729  def getProp(self, name):
730  """Returns the value of the given property.
731  """
732  if hasattr(self, name):
733  return getattr(self, name)
734  else:
735  return self.getDefaultProperties()[name]
736 

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 641 of file Configurable.py.

641  def getProperties(self):
642  props = {}
643  for name, proxy in self._properties.items():
644  try:
645  props[name] = proxy.__get__(self)
646  except AttributeError:
647  props[name] = Configurable.propertyNoValue
648 
649  return props
650 

◆ getPropertiesWithDescription()

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

Definition at line 651 of file Configurable.py.

651  def getPropertiesWithDescription(self):
652  """Get all properties with their description string as { name : (value, desc) }."""
653  props = {}
654  for name, proxy in self._properties.items():
655  try:
656  props[name] = (proxy.__get__(self), proxy.__doc__)
657  except AttributeError:
658  props[name] = (Configurable.propertyNoValue, proxy.__doc__)
659  return props
660 

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 601 of file Configurable.py.

601  def getSequence(self):
602  elems = []
603  for c in self.__children:
604  elems.append(c.getFullName())
605  return elems
606 

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 789 of file Configurable.py.

789  def getTitleName(self):
790  if log.isEnabledFor(logging.DEBUG):
791  return self.getFullJobOptName()
792  else:
793  return self.getFullName()
794 

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 550 of file Configurable.py.

550  def getTools(self):
551  return self.__tools.values() # read only
552 

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 757 of file Configurable.py.

757  def getType(cls):
758  return cls.__name__
759 

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 661 of file Configurable.py.

661  def getValuedProperties(self):
662  props = {}
663  for name, proxy in self._properties.items():
664  if self.isPropertySet(name):
665  value = proxy.__get__(self)
666  if hasattr(value, 'getFullName'):
667  value = value.getFullName()
668  elif type(value) in [list, tuple]:
669  new_value = []
670  for i in value:
671  if hasattr(i, 'getFullName'):
672  new_value.append(i.getFullName())
673  else:
674  new_value.append(i)
675  value = type(value)(new_value)
676  elif type(value) is dict:
677  new_value = {}
678  for i in value:
679  if hasattr(value[i], 'getFullName'):
680  new_value[i] = value[i].getFullName()
681  else:
682  new_value[i] = value[i]
683  value = new_value
684  props[name] = value
685 
686  return props
687 

◆ hasParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 524 of file Configurable.py.

524  def hasParent(self, parent):
525  return False
526 

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

742  def isPropertySet(self, name):
743  """Tell if the property 'name' has been set or not.
744 
745  Because of a problem with list and dictionary properties, in those cases
746  if the value is equal to the default, the property is considered as not
747  set.
748  """
749  if not hasattr(self, name):
750  return False
751  default = self.getDefaultProperty(name)
752  if isinstance(default, (list, dict, DataHandle)):
753  value = getattr(self, name)
754  return value != default
755  return True
756 

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 769 of file Configurable.py.

769  def isPublic(self):
770  return True
771 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 773 of file Configurable.py.

773  def jobOptName(self):
774  log.error(
775  "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
776  error_explanation)
777  return self.getJobOptName() # compatibility
778 

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 763 of file Configurable.py.

763  def name(self):
764  return self.getName()
765 

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 688 of file Configurable.py.

688  def properties(self):
689  return self.getProperties() # compatibility
690 

◆ remove()

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

Definition at line 505 of file Configurable.py.

505  def remove(self, items):
506  if type(items) != list and type(items) != tuple:
507  items = [items]
508 
509  self.__children = [e for e in self.__children if not e in items]
510 

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 511 of file Configurable.py.

511  def removeAll(self):
512  self.remove(self.__children)
513 

◆ setDefaults()

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

Definition at line 795 of file Configurable.py.

795  def setDefaults(cls, handle):
796  pass
797 

◆ setParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 518 of file Configurable.py.

518  def setParent(self, parentName):
519  pass
520 

◆ setProp()

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

Definition at line 737 of file Configurable.py.

737  def setProp(self, name, value):
738  """Set the value of a given property
739  """
740  return setattr(self, name, value)
741 

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 607 of file Configurable.py.

607  def setup(self):
608  # make sure base class init has been called
609  if not hasattr(self, '_initok') or not self._initok:
610  # could check more, but this is the only explanation
611  raise TypeError("Configurable.__init__ not called in %s override" %
612  self.__class__.__name__)
613 
614 # log.debug("calling setup() on " + self.getFullJobOptName())
615 
616 # setup self: this collects all values on the python side
617  self.__setupServices()
618  self.__setupDlls()
619  self.__setupDefaults()
620 
621  # setup children
622  for c in self.getAllChildren():
623  c.setup()
624 
625  # now get handle to work with for moving properties into the catalogue
626  handle = self.getHandle()
627  if not handle:
628  log.debug('no handle for %s: not transporting properties',
629  self._name)
630  return # allowed, done early
631 
632  # pass final set of properties on to handle on the C++ side or JobOptSvc
633  for name in self._properties.keys():
634  if hasattr(self,
635  name): # means property has python-side value/default
636  setattr(handle, name, getattr(self, name))
637 
638  # for debugging purposes
639  self._setupok = True
640 

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 829 of file Configurable.py.

829  def splitName(self):
830  fullname = self.getName()
831  dot = fullname.find('.')
832  if dot != -1:
833  parentname = fullname[:dot]
834  longname = fullname[dot + 1:]
835  else:
836  parentname = ''
837  longname = fullname
838  dot = longname.find('.')
839  if dot != -1:
840  name = longname[:dot]
841  else:
842  name = longname
843  return parentname, name, longname
844 

Member Data Documentation

◆ __children

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 332 of file Configurable.py.

◆ __nonzero__

def GaudiKernel.Configurable.Configurable.__nonzero__ = __bool__
staticprivate

Definition at line 503 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 134 of file Configurable.py.

◆ __tools

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 333 of file Configurable.py.

◆ _configurationLocked

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 150 of file Configurable.py.

◆ _initok

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 348 of file Configurable.py.

◆ _inSetDefaults

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 345 of file Configurable.py.

◆ _name

GaudiKernel.Configurable.Configurable._name
private

Definition at line 338 of file Configurable.py.

◆ _setupok

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 351 of file Configurable.py.

◆ _unpickling

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 354 of file Configurable.py.

◆ allConfigurables

dictionary GaudiKernel.Configurable.Configurable.allConfigurables
static
Initial value:
= {
}

Definition at line 144 of file Configurable.py.

◆ configurableServices

dictionary GaudiKernel.Configurable.Configurable.configurableServices
static
Initial value:
= {
}

Definition at line 146 of file Configurable.py.

◆ indentUnit

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

Definition at line 130 of file Configurable.py.

◆ printHeaderPre

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 132 of file Configurable.py.

◆ printHeaderWidth

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 131 of file Configurable.py.

◆ propertyNoValue

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 129 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:521
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:391
TimingHistograms.name
name
Definition: TimingHistograms.py:23
GaudiPython.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:519
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:62
GaudiPython.Pythonizations.__iter__
__iter__
Definition: Pythonizations.py:129
gaudirun.type
type
Definition: gaudirun.py:154
GaudiPython.Pythonizations.__len__
__len__
Definition: Pythonizations.py:128
StringKeyEx.keys
list keys
Definition: StringKeyEx.py:67
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:526