The Gaudi Framework  v32r2 (46d42edc)
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 109 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 288 of file Configurable.py.

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

Member Function Documentation

◆ __bool__()

def GaudiKernel.Configurable.Configurable.__bool__ (   self)

Definition at line 490 of file Configurable.py.

490  def __bool__(self):
491  return True
492 

◆ __deepcopy__()

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

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

Definition at line 387 of file Configurable.py.

387  def __deepcopy__(self, memo):
388  newconf = object.__new__(self.__class__)
389  self.__class__.__init__(newconf, self.getName())
390 
391  for proxy in self._properties.values():
392  try:
393  proxy.__set__(newconf, proxy.__get__(self))
394  except AttributeError:
395  pass # means property was not set for self
396 
397  for c in self.__children:
398  newconf += c # processes proper copy semantics
399 
400  return newconf
401 

◆ __delattr__()

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

Definition at line 465 of file Configurable.py.

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

◆ __getattr__()

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

Definition at line 436 of file Configurable.py.

436  def __getattr__(self, attr): # until ToolProperties exist ...
437 
438  if attr in self.__tools:
439  return self.__tools[attr]
440 
441  if attr in self._properties:
442  if isinstance(self._properties[attr].__get__(self),
443  DataObjectHandleBase):
444  return self._properties[attr].__get__(self)
445 
446  for c in self.__children:
447  if c.getName() == attr:
448  return c
449 
450  raise AttributeError(
451  "'%s' object has no attribute '%s'" % (self.__class__, attr))
452 

◆ __getnewargs__()

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 360 of file Configurable.py.

360  def __getnewargs__(self):
361  return (self._name, )
362 

◆ __getstate__()

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 347 of file Configurable.py.

347  def __getstate__(self):
348  dict = {}
349  for name, proxy in self._properties.items():
350  try:
351  dict[name] = proxy.__get__(self)
352  except AttributeError:
353  pass
354 
355  dict['_Configurable__children'] = self.__children
356  dict['_Configurable__tools'] = self.__tools
357  dict['_name'] = self._name
358  return dict
359 

◆ __iadd__()

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

Definition at line 403 of file Configurable.py.

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

◆ __iter__()

def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 383 of file Configurable.py.

383  def __iter__(self):
384  return iter(self.__children)
385 

◆ __len__()

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 380 of file Configurable.py.

380  def __len__(self):
381  return len(self.__children)
382 

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

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

◆ __repr__()

def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 915 of file Configurable.py.

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

◆ __setattr__()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableGeneric.

Definition at line 453 of file Configurable.py.

453  def __setattr__(self, name, value):
454  if self._configurationLocked:
455  raise RuntimeError(
456  "%s: Configuration cannot be modified after the ApplicationMgr has been started."
457  % self.name())
458  try:
459  super(Configurable, self).__setattr__(name, value)
460  except AttributeError:
461  raise AttributeError(
462  "Configurable '%s' does not have property '%s'." %
463  (self.__class__.__name__, name))
464 

◆ __setstate__()

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

Definition at line 363 of file Configurable.py.

363  def __setstate__(self, dict):
364  self._initok = True
365  from contextlib import contextmanager
366 
367  @contextmanager
368  def unpickling():
369  try:
370  self._unpickling = True
371  yield
372  finally:
373  self._unpickling = False
374 
375  with unpickling():
376  for n, v in dict.items():
377  setattr(self, n, v)
378 

◆ __setupDefaults()

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

Definition at line 891 of file Configurable.py.

891  def __setupDefaults(self):
892  # set handle defaults flags to inform __setattr__ that it is being
893  # called during setDefaults of the concrete Configurable
894  self._inSetDefaults = True
895  self.setDefaults(self)
896  self._inSetDefaults = False
897 

◆ __setupDlls()

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

Definition at line 879 of file Configurable.py.

879  def __setupDlls(self):
880  dlls = self.getDlls()
881  if not dlls:
882  dlls = []
883  elif type(dlls) == types.StringType:
884  dlls = [dlls]
885 
886  from __main__ import theApp
887  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
888  if dlls:
889  theApp.Dlls += dlls
890 

◆ __setupServices()

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

Definition at line 862 of file Configurable.py.

862  def __setupServices(self):
863  #svcs = self.getServices()
864  # if not svcs:
865  svcs = []
866  # elif type(svcs) == types.StringType:
867  # svcs = [ svcs ]
868 
869  import __main__
870  for svc in svcs:
871  handle = __main__.Service(svc)
872  # services should be configurables as well, but aren't for now
873  # handle.setup()
874 
875  # allow Configurable to make some changes
876  if hasattr(self, 'configure' + svc):
877  eval('self.configure' + svc + '( handle )')
878 

◆ __str__()

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

Definition at line 918 of file Configurable.py.

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

◆ _isInSetDefaults()

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

Definition at line 859 of file Configurable.py.

859  def _isInSetDefaults(self):
860  return self._inSetDefaults
861 

◆ _printFooter()

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

Definition at line 907 of file Configurable.py.

907  def _printFooter(indentStr, title):
908  preLen = Configurable.printHeaderPre
909  postLen = Configurable.printHeaderWidth - \
910  preLen - 12 - len(title) # - len(indentStr)
911  postLen = max(preLen, postLen)
912  return indentStr + '\\%s (End of %s) %s' % (preLen * '-', title,
913  postLen * '-')
914 
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215

◆ _printHeader()

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

Definition at line 899 of file Configurable.py.

899  def _printHeader(indentStr, title):
900  preLen = Configurable.printHeaderPre
901  postLen = Configurable.printHeaderWidth - \
902  preLen - 3 - len(title) # - len(indentStr)
903  postLen = max(preLen, postLen)
904  return indentStr + '/%s %s %s' % (preLen * '*', title, postLen * '*')
905 
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215

◆ addTool()

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

Definition at line 836 of file Configurable.py.

836  def addTool(self, tool, name=None):
837  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
838  if name is None:
839  name = tool.__name__
840  priv_tool = tool(self.getName() + '.' + name)
841  elif isinstance(tool, ConfigurableAlgTool):
842  if name is None:
843  name = tool.splitName()[1]
844  priv_tool = tool.clone(self.getName() + '.' + name)
845  else:
846  if isclass(tool):
847  classname = tool.__name__
848  else:
849  classname = type(tool).__name__
850  raise TypeError(
851  "addTool requires AlgTool configurable. Got %s type" %
852  classname)
853  self.__tools[name] = priv_tool
854  if name in self.__slots__:
855  # this is to avoid that the property hides the tool
856  setattr(self, name, self.__tools[name])
857  return self.__tools[name]
858 

◆ children()

def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 544 of file Configurable.py.

544  def children(self):
545  log.error(
546  "children() is deprecated, use getChildren() instead for consistency"
547  )
548  log.error(
549  "getChildren() returns a copy; to add a child, use 'parent += child'%s",
550  error_explanation)
551  return self.__children # by ref, for compatibility
552 

◆ clone()

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

Definition at line 789 of file Configurable.py.

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

◆ copyChild()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableService.

Definition at line 506 of file Configurable.py.

506  def copyChild(self, child):
507  return copy.deepcopy(child)
508 

◆ copyChildAndSetParent()

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

Definition at line 518 of file Configurable.py.

518  def copyChildAndSetParent(self, cfg, parent):
519  cc = self.copyChild(cfg)
520 
521  if hasattr(cc, 'setParent') and parent:
522  try:
523  cc.setParent(parent)
524  except RuntimeError as e:
525  # temporary backdoor resolution for compatibility
526  log.error(str(e) + '%s', error_explanation)
527  ccbd = cc.configurables[cc.getJobOptName()]
528 
529  # merge properties, new over pre-existing
530  for proxy in self._properties.values():
531  if cc in proxy.history:
532  proxy.__set__(ccbd, proxy.__get__(cc))
533 
534  # consolidate
535  cc = ccbd
536  return cc
537 

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

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

◆ getChildren()

def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 538 of file Configurable.py.

538  def getChildren(self):
539  return self.__children[:] # read only
540 

◆ getDefaultProperties()

def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 683 of file Configurable.py.

683  def getDefaultProperties(cls):
684  class collector:
685  pass
686 
687  # user provided defaults
688  c = collector()
689  cls.setDefaults(c)
690 
691  # defaults from C++
692  for k, v in cls._properties.items():
693  if not k in c.__dict__ and hasattr(v, 'default'):
694  c.__dict__[k] = v.default
695 
696  return c.__dict__
697 

◆ getDefaultProperty()

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

Definition at line 699 of file Configurable.py.

699  def getDefaultProperty(cls, name):
700  class collector:
701  pass
702 
703  # user provided defaults
704  c = collector()
705  cls.setDefaults(c)
706 
707  if name in c.__dict__:
708  return c.__dict__[name]
709 
710  # defaults from C++
711  try:
712  v = cls._properties[name]
713  if hasattr(v, 'default'):
714  return v.default
715  except KeyError:
716  pass
717 
718  return None
719 

◆ getFullJobOptName()

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 773 of file Configurable.py.

773  def getFullJobOptName(self):
774  return "%s/%s" % (self.getType(), self.getJobOptName()
775  or self.getName())
776 

◆ getFullName()

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 770 of file Configurable.py.

770  def getFullName(self):
771  return str(self.getType() + '/' + self.getName())
772 

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

757  def getJobOptName(self): # full hierachical name
758  return self.getName()
759 

◆ getName()

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 751 of file Configurable.py.

751  def getName(self):
752  return self._name
753 

◆ getParent()

def GaudiKernel.Configurable.Configurable.getParent (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 512 of file Configurable.py.

512  def getParent(self):
513  return ""
514 

◆ getPrintTitle()

def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 777 of file Configurable.py.

777  def getPrintTitle(self):
778  return self.getGaudiType() + ' ' + self.getTitleName()
779 

◆ getProp()

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

Definition at line 720 of file Configurable.py.

720  def getProp(self, name):
721  """Returns the value of the given property.
722  """
723  if hasattr(self, name):
724  return getattr(self, name)
725  else:
726  return self.getDefaultProperties()[name]
727 

◆ getProperties()

def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 632 of file Configurable.py.

632  def getProperties(self):
633  props = {}
634  for name, proxy in self._properties.items():
635  try:
636  props[name] = proxy.__get__(self)
637  except AttributeError:
638  props[name] = Configurable.propertyNoValue
639 
640  return props
641 

◆ getPropertiesWithDescription()

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

Definition at line 642 of file Configurable.py.

642  def getPropertiesWithDescription(self):
643  """Get all properties with their description string as { name : (value, desc) }."""
644  props = {}
645  for name, proxy in self._properties.items():
646  try:
647  props[name] = (proxy.__get__(self), proxy.__doc__)
648  except AttributeError:
649  props[name] = (Configurable.propertyNoValue, proxy.__doc__)
650  return props
651 

◆ getSequence()

def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 592 of file Configurable.py.

592  def getSequence(self):
593  elems = []
594  for c in self.__children:
595  elems.append(c.getFullName())
596  return elems
597 

◆ getTitleName()

def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 780 of file Configurable.py.

780  def getTitleName(self):
781  if log.isEnabledFor(logging.DEBUG):
782  return self.getFullJobOptName()
783  else:
784  return self.getFullName()
785 

◆ getTools()

def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 541 of file Configurable.py.

541  def getTools(self):
542  return self.__tools.values() # read only
543 

◆ getType()

def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 748 of file Configurable.py.

748  def getType(cls):
749  return cls.__name__
750 

◆ getValuedProperties()

def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 652 of file Configurable.py.

652  def getValuedProperties(self):
653  props = {}
654  for name, proxy in self._properties.items():
655  if self.isPropertySet(name):
656  value = proxy.__get__(self)
657  if hasattr(value, 'getFullName'):
658  value = value.getFullName()
659  elif type(value) in [list, tuple]:
660  new_value = []
661  for i in value:
662  if hasattr(i, 'getFullName'):
663  new_value.append(i.getFullName())
664  else:
665  new_value.append(i)
666  value = type(value)(new_value)
667  elif type(value) is dict:
668  new_value = {}
669  for i in value:
670  if hasattr(value[i], 'getFullName'):
671  new_value[i] = value[i].getFullName()
672  else:
673  new_value[i] = value[i]
674  value = new_value
675  props[name] = value
676 
677  return props
678 

◆ hasParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 515 of file Configurable.py.

515  def hasParent(self, parent):
516  return False
517 

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

733  def isPropertySet(self, name):
734  """Tell if the property 'name' has been set or not.
735 
736  Because of a problem with list and dictionary properties, in those cases
737  if the value is equal to the default, the property is considered as not
738  set.
739  """
740  if not hasattr(self, name):
741  return False
742  default = self.getDefaultProperty(name)
743  if isinstance(default, (list, dict, DataObjectHandleBase)):
744  value = getattr(self, name)
745  return value != default
746  return True
747 

◆ isPublic()

def GaudiKernel.Configurable.Configurable.isPublic (   self)

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 760 of file Configurable.py.

760  def isPublic(self):
761  return True
762 

◆ jobOptName()

def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 764 of file Configurable.py.

764  def jobOptName(self):
765  log.error(
766  "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
767  error_explanation)
768  return self.getJobOptName() # compatibility
769 

◆ name()

def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 754 of file Configurable.py.

754  def name(self):
755  return self.getName()
756 

◆ properties()

def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 679 of file Configurable.py.

679  def properties(self):
680  return self.getProperties() # compatibility
681 

◆ remove()

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

Definition at line 496 of file Configurable.py.

496  def remove(self, items):
497  if type(items) != list and type(items) != tuple:
498  items = [items]
499 
500  self.__children = [e for e in self.__children if not e in items]
501 

◆ removeAll()

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 502 of file Configurable.py.

502  def removeAll(self):
503  self.remove(self.__children)
504 

◆ setDefaults()

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

Definition at line 786 of file Configurable.py.

786  def setDefaults(cls, handle):
787  pass
788 

◆ setParent()

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

Reimplemented in GaudiKernel.Configurable.ConfigurableAlgTool.

Definition at line 509 of file Configurable.py.

509  def setParent(self, parentName):
510  pass
511 

◆ setProp()

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

Definition at line 728 of file Configurable.py.

728  def setProp(self, name, value):
729  """Set the value of a given property
730  """
731  return setattr(self, name, value)
732 

◆ setup()

def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 598 of file Configurable.py.

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

◆ splitName()

def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 820 of file Configurable.py.

820  def splitName(self):
821  fullname = self.getName()
822  dot = fullname.find('.')
823  if dot != -1:
824  parentname = fullname[:dot]
825  longname = fullname[dot + 1:]
826  else:
827  parentname = ''
828  longname = fullname
829  dot = longname.find('.')
830  if dot != -1:
831  name = longname[:dot]
832  else:
833  name = longname
834  return parentname, name, longname
835 

Member Data Documentation

◆ __children

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 322 of file Configurable.py.

◆ __nonzero__

def GaudiKernel.Configurable.Configurable.__nonzero__ = __bool__
staticprivate

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

◆ __tools

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 323 of file Configurable.py.

◆ _configurationLocked

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 140 of file Configurable.py.

◆ _initok

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 338 of file Configurable.py.

◆ _inSetDefaults

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 335 of file Configurable.py.

◆ _name

GaudiKernel.Configurable.Configurable._name
private

Definition at line 328 of file Configurable.py.

◆ _setupok

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 341 of file Configurable.py.

◆ _unpickling

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 344 of file Configurable.py.

◆ allConfigurables

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

Definition at line 134 of file Configurable.py.

◆ configurableServices

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

Definition at line 136 of file Configurable.py.

◆ indentUnit

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

Definition at line 120 of file Configurable.py.

◆ printHeaderPre

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 122 of file Configurable.py.

◆ printHeaderWidth

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 121 of file Configurable.py.

◆ propertyNoValue

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 119 of file Configurable.py.


The documentation for this class was generated from the following file: