The Gaudi Framework  v33r0 (d5ea422b)
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 119 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 500 of file Configurable.py.

500  def __bool__(self):
501  return True
502 

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

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

◆ __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),
453  DataObjectHandleBase):
454  return self._properties[attr].__get__(self)
455 
456  for c in self.__children:
457  if c.getName() == attr:
458  return c
459 
460  raise AttributeError(
461  "'%s' object has no attribute '%s'" % (self.__class__, attr))
462 

◆ __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 
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 925 of file Configurable.py.

925  def __repr__(self):
926  return '{0}({1!r})'.format(self.__class__.__name__, self.name())
927 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 463 of file Configurable.py.

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

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

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

◆ __setupDlls()

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

Definition at line 889 of file Configurable.py.

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

◆ __setupServices()

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

Definition at line 872 of file Configurable.py.

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

◆ __str__()

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

Definition at line 928 of file Configurable.py.

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

◆ _isInSetDefaults()

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

Definition at line 869 of file Configurable.py.

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

◆ _printFooter()

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

Definition at line 917 of file Configurable.py.

917  def _printFooter(indentStr, title):
918  preLen = Configurable.printHeaderPre
919  postLen = Configurable.printHeaderWidth - \
920  preLen - 12 - len(title) # - len(indentStr)
921  postLen = max(preLen, postLen)
922  return indentStr + '\\%s (End of %s) %s' % (preLen * '-', title,
923  postLen * '-')
924 
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225

◆ _printHeader()

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

Definition at line 909 of file Configurable.py.

909  def _printHeader(indentStr, title):
910  preLen = Configurable.printHeaderPre
911  postLen = Configurable.printHeaderWidth - \
912  preLen - 3 - len(title) # - len(indentStr)
913  postLen = max(preLen, postLen)
914  return indentStr + '/%s %s %s' % (preLen * '*', title, postLen * '*')
915 
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:225

◆ addTool()

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

Definition at line 846 of file Configurable.py.

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

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 554 of file Configurable.py.

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

◆ clone()

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

Definition at line 799 of file Configurable.py.

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

◆ copyChild()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 516 of file Configurable.py.

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

◆ copyChildAndSetParent()

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

Definition at line 528 of file Configurable.py.

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

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

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

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 548 of file Configurable.py.

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

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 693 of file Configurable.py.

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

◆ getDefaultProperty()

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

Definition at line 709 of file Configurable.py.

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

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 783 of file Configurable.py.

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

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 780 of file Configurable.py.

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

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

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

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 761 of file Configurable.py.

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

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 522 of file Configurable.py.

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

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 787 of file Configurable.py.

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

◆ getProp()

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

Definition at line 730 of file Configurable.py.

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

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 642 of file Configurable.py.

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

◆ getPropertiesWithDescription()

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

Definition at line 652 of file Configurable.py.

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

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 602 of file Configurable.py.

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

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 790 of file Configurable.py.

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

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 551 of file Configurable.py.

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

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 758 of file Configurable.py.

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

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 662 of file Configurable.py.

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

◆ hasParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 525 of file Configurable.py.

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

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

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

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 770 of file Configurable.py.

770  def isPublic(self):
771  return True
772 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 774 of file Configurable.py.

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

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 764 of file Configurable.py.

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

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 689 of file Configurable.py.

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

◆ remove()

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

Definition at line 506 of file Configurable.py.

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

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 512 of file Configurable.py.

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

◆ setDefaults()

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

Definition at line 796 of file Configurable.py.

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

◆ setParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 519 of file Configurable.py.

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

◆ setProp()

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

Definition at line 738 of file Configurable.py.

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

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 608 of file Configurable.py.

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

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 830 of file Configurable.py.

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

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 504 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: