The Gaudi Framework  v30r3 (a5ef0a68)
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 __nonzero__ (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)
 

Static Public Attributes

 propertyNoValue
 
string indentUnit = '| '
 
int printHeaderWidth = 100
 
int printHeaderPre = 5
 
dictionary allConfigurables = {}
 
dictionary configurableServices = {}
 

Private Member Functions

def _isInSetDefaults (self)
 
def __setupServices (self)
 
def __setupDlls (self)
 
def __setupDefaults (self)
 

Static Private Member Functions

def _printHeader (indentStr, title)
 
def _printFooter (indentStr, title)
 

Private Attributes

 __children
 
 __tools
 
 _name
 
 _inSetDefaults
 
 _initok
 
 _setupok
 
 _unpickling
 

Static Private Attributes

 __metaclass__ = ConfigurableMeta.ConfigurableMeta
 
tuple __slots__
 
bool _configurationLocked = False
 

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

Constructor & Destructor Documentation

def GaudiKernel.Configurable.Configurable.__init__ (   self,
  name = DefaultName 
)

Definition at line 279 of file Configurable.py.

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

Member Function Documentation

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

Definition at line 374 of file Configurable.py.

374  def __deepcopy__(self, memo):
375  newconf = object.__new__(self.__class__)
376  self.__class__.__init__(newconf, self.getName())
377 
378  for proxy in self._properties.values():
379  try:
380  proxy.__set__(newconf, proxy.__get__(self))
381  except AttributeError:
382  pass # means property was not set for self
383 
384  for c in self.__children:
385  newconf += c # processes proper copy semantics
386 
387  return newconf
388 
def GaudiKernel.Configurable.Configurable.__delattr__ (   self,
  attr 
)

Definition at line 449 of file Configurable.py.

449  def __delattr__(self, attr):
450  # remove as property, otherwise try as child
451  try:
452  # remove history etc., then reset to default (in case set before)
453  prop = self._properties[attr]
454  prop.__delete__(self)
455  prop.__set__(self, prop.default)
456  return # reaches here? was property: done now
457  except KeyError:
458  pass
459  # otherwise, remove the private tool
460  if attr in self.__tools:
461  del self.__tools[attr]
462 
463  # otherwise, remove child, if one is so named
464  for c in self.__children:
465  if c.getName() == attr:
466  self.__children.remove(c)
467 
468  # potentially, there are left over caches (certain user derived classes)
469  try:
470  del self.__dict__[attr]
471  except (AttributeError, KeyError):
472  pass
473 
def GaudiKernel.Configurable.Configurable.__getattr__ (   self,
  attr 
)

Definition at line 423 of file Configurable.py.

423  def __getattr__(self, attr): # until ToolProperties exist ...
424 
425  if attr in self.__tools:
426  return self.__tools[attr]
427 
428  if attr in self._properties:
429  if isinstance(self._properties[attr].__get__(self), DataObjectHandleBase):
430  return self._properties[attr].__get__(self)
431 
432  for c in self.__children:
433  if c.getName() == attr:
434  return c
435 
436  raise AttributeError(
437  "'%s' object has no attribute '%s'" % (self.__class__, attr))
438 
def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 348 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 335 of file Configurable.py.

335  def __getstate__(self):
336  dict = {}
337  for name, proxy in self._properties.items():
338  try:
339  dict[name] = proxy.__get__(self)
340  except AttributeError:
341  pass
342 
343  dict['_Configurable__children'] = self.__children
344  dict['_Configurable__tools'] = self.__tools
345  dict['_name'] = self._name
346  return dict
347 
def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 390 of file Configurable.py.

390  def __iadd__(self, configs, descr=None):
391  if not type(configs) in (list, tuple):
392  configs = (configs, )
393 
394  joname = self.getJobOptName()
395 
396  for cfg in configs:
397  # prevent type mismatches
398  if not isinstance(cfg, Configurable):
399  raise TypeError("'%s' is not a Configurable" % str(cfg))
400 
401  cc = self.copyChildAndSetParent(cfg, joname)
402 
403  # filters dupes; usually "ok" (backdoor should catch them)
404  ccjo = cc.getJobOptName()
405  for c in self.__children:
406  if c.getJobOptName() == ccjo:
407  log.error(
408  'attempt to add a duplicate ... dupe ignored%s', error_explanation)
409  break
410  else:
411  self.__children.append(cc)
412 
413  try:
414  if descr: # support for tool properties
415  descr.__set__(self, cc)
416  else:
417  setattr(self, cc.getName(), cc)
418  except AttributeError:
419  pass # to allow free addition of tools/subalgorithms
420 
421  return self
422 
def copyChildAndSetParent(self, cfg, parent)
def __iadd__(self, configs, descr=None)
def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 370 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 367 of file Configurable.py.

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

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

Definition at line 474 of file Configurable.py.

474  def __nonzero__(self):
475  return True
476 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 887 of file Configurable.py.

887  def __repr__(self):
888  return '{0}({1!r})'.format(self.__class__.__name__, self.name())
889 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
def GaudiKernel.Configurable.Configurable.__setattr__ (   self,
  name,
  value 
)

Definition at line 439 of file Configurable.py.

439  def __setattr__(self, name, value):
440  if self._configurationLocked:
441  raise RuntimeError(
442  "%s: Configuration cannot be modified after the ApplicationMgr has been started." % self.name())
443  try:
444  super(Configurable, self).__setattr__(name, value)
445  except AttributeError:
446  raise AttributeError("Configurable '%s' does not have property '%s'."
447  % (self.__class__.__name__, name))
448 
def __setattr__(self, name, value)
def GaudiKernel.Configurable.Configurable.__setstate__ (   self,
  dict 
)

Definition at line 351 of file Configurable.py.

351  def __setstate__(self, dict):
352  self._initok = True
353  from contextlib import contextmanager
354 
355  @contextmanager
356  def unpickling():
357  try:
358  self._unpickling = True
359  yield
360  finally:
361  self._unpickling = False
362  with unpickling():
363  for n, v in dict.items():
364  setattr(self, n, v)
365 
def GaudiKernel.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 864 of file Configurable.py.

864  def __setupDefaults(self):
865  # set handle defaults flags to inform __setattr__ that it is being
866  # called during setDefaults of the concrete Configurable
867  self._inSetDefaults = True
868  self.setDefaults(self)
869  self._inSetDefaults = False
870 
def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 852 of file Configurable.py.

852  def __setupDlls(self):
853  dlls = self.getDlls()
854  if not dlls:
855  dlls = []
856  elif type(dlls) == types.StringType:
857  dlls = [dlls]
858 
859  from __main__ import theApp
860  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
861  if dlls:
862  theApp.Dlls += dlls
863 
def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 835 of file Configurable.py.

835  def __setupServices(self):
836  #svcs = self.getServices()
837  # if not svcs:
838  svcs = []
839  # elif type(svcs) == types.StringType:
840  # svcs = [ svcs ]
841 
842  import __main__
843  for svc in svcs:
844  handle = __main__.Service(svc)
845  # services should be configurables as well, but aren't for now
846  # handle.setup()
847 
848  # allow Configurable to make some changes
849  if hasattr(self, 'configure' + svc):
850  eval('self.configure' + svc + '( handle )')
851 
def GaudiKernel.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 890 of file Configurable.py.

890  def __str__(self, indent=0, headerLastIndentUnit=indentUnit):
891  global log # to print some info depending on output level
892  indentStr = indent * Configurable.indentUnit
893  # print header
894  title = self.getPrintTitle()
895  # print line to easily see start-of-configurable
896  if indent > 0:
897  headerIndent = (indent - 1) * \
898  Configurable.indentUnit + headerLastIndentUnit
899  else:
900  headerIndent = ''
901  rep = Configurable._printHeader(headerIndent, title)
902  rep += os.linesep
903  # print own properties
904  props = self.getProperties()
905  defs = self.getDefaultProperties()
906  if not props:
907  rep += indentStr + '|-<no properties>' + os.linesep
908  else:
909  # get property name with
910  nameWidth = 0
911  for p in props.keys():
912  nameWidth = max(nameWidth, len(p))
913  for p, v in props.items():
914  # start with indent and property name
915  prefix = indentStr + '|-%-*s' % (nameWidth, p)
916  # add memory address for debugging (not for defaults)
917  if log.isEnabledFor(logging.DEBUG):
918  if v != Configurable.propertyNoValue:
919  address = ' @%11s' % hex(id(v))
920  else:
921  address = 13 * ' '
922  prefix += address
923  # add value and default
924  default = defs.get(p)
925  if v == Configurable.propertyNoValue:
926  # show default value as value, and no extra 'default'
927  strVal = repr(default)
928  strDef = None
929  else:
930  # convert configurable to handle
931  if hasattr(v, "getGaudiHandle"):
932  vv = v.getGaudiHandle()
933  else:
934  vv = v
935  if isinstance(vv, GaudiHandle) or isinstance(vv, GaudiHandleArray):
936  strVal = repr(vv)
937  # the default may not be a GaudiHandle (?)
938  if hasattr(default, "toStringProperty"):
939  strDef = repr(default.toStringProperty())
940  else:
941  strDef = repr(default)
942  if strDef == repr(vv.toStringProperty()):
943  strDef = None
944  else:
945  strVal = repr(vv)
946  strDef = repr(default)
947  # add the value
948  line = prefix + ' = ' + strVal
949  # add default if present
950  if strDef is not None:
951  # put default on new line if too big
952  if len(line) + len(strDef) > Configurable.printHeaderWidth:
953  line += os.linesep + indentStr + '| ' + \
954  (len(prefix) - len(indentStr) - 3) * ' '
955  line += ' (default: %s)' % (strDef,)
956  # add the line to the total string
957  rep += line + os.linesep
958  # print out full private configurables
959 # if isinstance(v,Configurable) and not v.isPublic():
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:304
def __str__(self, indent=0, headerLastIndentUnit=indentUnit)
def GaudiKernel.Configurable.Configurable._isInSetDefaults (   self)
private

Definition at line 832 of file Configurable.py.

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

Definition at line 880 of file Configurable.py.

880  def _printFooter(indentStr, title):
881  preLen = Configurable.printHeaderPre
882  postLen = Configurable.printHeaderWidth - \
883  preLen - 12 - len(title) # - len(indentStr)
884  postLen = max(preLen, postLen)
885  return indentStr + '\\%s (End of %s) %s' % (preLen * '-', title, postLen * '-')
886 
def _printFooter(indentStr, title)
def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 872 of file Configurable.py.

872  def _printHeader(indentStr, title):
873  preLen = Configurable.printHeaderPre
874  postLen = Configurable.printHeaderWidth - \
875  preLen - 3 - len(title) # - len(indentStr)
876  postLen = max(preLen, postLen)
877  return indentStr + '/%s %s %s' % (preLen * '*', title, postLen * '*')
878 
def _printHeader(indentStr, title)
def GaudiKernel.Configurable.Configurable.addTool (   self,
  tool,
  name = None 
)

Definition at line 811 of file Configurable.py.

811  def addTool(self, tool, name=None):
812  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
813  if name is None:
814  name = tool.__name__
815  priv_tool = tool(self.getName() + '.' + name)
816  elif isinstance(tool, ConfigurableAlgTool):
817  if name is None:
818  name = tool.splitName()[1]
819  priv_tool = tool.clone(self.getName() + '.' + name)
820  else:
821  if isclass(tool):
822  classname = tool.__name__
823  else:
824  classname = type(tool).__name__
825  raise TypeError, "addTool requires AlgTool configurable. Got %s type" % classname
826  self.__tools[name] = priv_tool
827  if name in self.__slots__:
828  # this is to avoid that the property hides the tool
829  setattr(self, name, self.__tools[name])
830  return self.__tools[name]
831 
def addTool(self, tool, name=None)
def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 525 of file Configurable.py.

525  def children(self):
526  log.error(
527  "children() is deprecated, use getChildren() instead for consistency")
528  log.error("getChildren() returns a copy; to add a child, use 'parent += child'%s",
529  error_explanation)
530  return self.__children # by ref, for compatibility
531 
def GaudiKernel.Configurable.Configurable.clone (   self,
  name = None,
  kwargs 
)

Definition at line 764 of file Configurable.py.

764  def clone(self, name=None, **kwargs):
765  if not name:
766  if hasattr(self, 'DefaultedName'):
767  name = self.DefaultedName
768  else:
769  name = self.getType()
770 
771  newconf = Configurable.__new__(self.__class__, name)
772  self.__class__.__init__(newconf, name)
773 
774  for proxy in self._properties.values():
775  try:
776  value = proxy.__get__(self)
777  if type(value) in [str, list, dict, tuple]:
778  # clone the values of the properties for basic types
779  value = type(value)(value)
780  proxy.__set__(newconf, value)
781  except AttributeError:
782  pass
783 
784  for c in self.__children:
785  newconf += c # processes proper copy semantics
786 
787  for n, t in self.__tools.items():
788  newconf.addTool(t, n)
789 
790  for name, value in kwargs.items():
791  setattr(newconf, name, value)
792 
793  return newconf
794 
def clone(self, name=None, kwargs)
def GaudiKernel.Configurable.Configurable.copyChild (   self,
  child 
)

Definition at line 487 of file Configurable.py.

487  def copyChild(self, child):
488  return copy.deepcopy(child)
489 
def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 499 of file Configurable.py.

499  def copyChildAndSetParent(self, cfg, parent):
500  cc = self.copyChild(cfg)
501 
502  if hasattr(cc, 'setParent') and parent:
503  try:
504  cc.setParent(parent)
505  except RuntimeError, e:
506  # temporary backdoor resolution for compatibility
507  log.error(str(e) + '%s', error_explanation)
508  ccbd = cc.configurables[cc.getJobOptName()]
509 
510  # merge properties, new over pre-existing
511  for proxy in self._properties.values():
512  if proxy.history.has_key(cc):
513  proxy.__set__(ccbd, proxy.__get__(cc))
514 
515  # consolidate
516  cc = ccbd
517  return cc
518 
def copyChildAndSetParent(self, cfg, parent)
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 532 of file Configurable.py.

532  def getAllChildren(self):
533  """Get all (private) configurable children, both explicit ones (added with +=)
534  and the ones in the private GaudiHandle properties"""
535  childs = []
536  # add private configurable properties (also inside handles)
537  for proxy in self._properties.values():
538  try:
539  c = proxy.__get__(self)
540  except AttributeError:
541  pass
542  else:
543  if isinstance(c, Configurable) and not c.isPublic():
544  childs.append(c)
545  elif isinstance(c, GaudiHandle):
546  try:
547  conf = c.configurable
548  except AttributeError:
549  pass
550  else:
551  if not conf.isPublic():
552  childs.append(conf)
553  elif isinstance(c, GaudiHandleArray):
554  # only setup private arrays
555  if not c.isPublic():
556  for ci in c:
557  if isinstance(ci, Configurable):
558  childs.append(ci)
559  else:
560  try:
561  conf = ci.configurable
562  except AttributeError:
563  pass
564  else:
565  childs.append(conf)
566 
567  # add explicit children
568  childs += self.__children
569  return childs
570 
def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 519 of file Configurable.py.

519  def getChildren(self):
520  return self.__children[:] # read only
521 
def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 660 of file Configurable.py.

661  class collector:
662  pass
663 
664  # user provided defaults
665  c = collector()
666  cls.setDefaults(c)
667 
668  # defaults from C++
669  for k, v in cls._properties.items():
670  if not k in c.__dict__ and hasattr(v, 'default'):
671  c.__dict__[k] = v.default
672 
673  return c.__dict__
674 
def GaudiKernel.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 676 of file Configurable.py.

676  def getDefaultProperty(cls, name):
677  class collector:
678  pass
679 
680  # user provided defaults
681  c = collector()
682  cls.setDefaults(c)
683 
684  if name in c.__dict__:
685  return c.__dict__[name]
686 
687  # defaults from C++
688  try:
689  v = cls._properties[name]
690  if hasattr(v, 'default'):
691  return v.default
692  except KeyError:
693  pass
694 
695  return None
696 
def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 749 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 746 of file Configurable.py.

746  def getFullName(self):
747  return str(self.getType() + '/' + self.getName())
748 
def GaudiKernel.Configurable.Configurable.getJobOptName (   self)

Definition at line 734 of file Configurable.py.

734  def getJobOptName(self): # full hierachical name
735  return self.getName()
736 
def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 728 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 493 of file Configurable.py.

493  def getParent(self):
494  return ""
495 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 752 of file Configurable.py.

752  def getPrintTitle(self):
753  return self.getGaudiType() + ' ' + self.getTitleName()
754 
def GaudiKernel.Configurable.Configurable.getProp (   self,
  name 
)
Returns the value of the given property.

Definition at line 697 of file Configurable.py.

697  def getProp(self, name):
698  """Returns the value of the given property.
699  """
700  if hasattr(self, name):
701  return getattr(self, name)
702  else:
703  return self.getDefaultProperties()[name]
704 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 609 of file Configurable.py.

609  def getProperties(self):
610  props = {}
611  for name, proxy in self._properties.items():
612  try:
613  props[name] = proxy.__get__(self)
614  except AttributeError:
615  props[name] = Configurable.propertyNoValue
616 
617  return props
618 
def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 619 of file Configurable.py.

620  """Get all properties with their description string as { name : (value, desc) }."""
621  props = {}
622  for name, proxy in self._properties.items():
623  try:
624  props[name] = (proxy.__get__(self), proxy.__doc__)
625  except AttributeError:
626  props[name] = (Configurable.propertyNoValue, proxy.__doc__)
627  return props
628 
def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 571 of file Configurable.py.

571  def getSequence(self):
572  elems = []
573  for c in self.__children:
574  elems.append(c.getFullName())
575  return elems
576 
def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 755 of file Configurable.py.

755  def getTitleName(self):
756  if log.isEnabledFor(logging.DEBUG):
757  return self.getFullJobOptName()
758  else:
759  return self.getFullName()
760 
def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 522 of file Configurable.py.

522  def getTools(self):
523  return self.__tools.values() # read only
524 
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 725 of file Configurable.py.

725  def getType(cls):
726  return cls.__name__
727 
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 629 of file Configurable.py.

630  props = {}
631  for name, proxy in self._properties.items():
632  if self.isPropertySet(name):
633  value = proxy.__get__(self)
634  if hasattr(value, 'getFullName'):
635  value = value.getFullName()
636  elif type(value) in [list, tuple]:
637  new_value = []
638  for i in value:
639  if hasattr(i, 'getFullName'):
640  new_value.append(i.getFullName())
641  else:
642  new_value.append(i)
643  value = type(value)(new_value)
644  elif type(value) is dict:
645  new_value = {}
646  for i in value:
647  if hasattr(value[i], 'getFullName'):
648  new_value[i] = value[i].getFullName()
649  else:
650  new_value[i] = value[i]
651  value = new_value
652  props[name] = value
653 
654  return props
655 
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 496 of file Configurable.py.

496  def hasParent(self, parent):
497  return False
498 
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 710 of file Configurable.py.

710  def isPropertySet(self, name):
711  """Tell if the property 'name' has been set or not.
712 
713  Because of a problem with list and dictionary properties, in those cases
714  if the value is equal to the default, the property is considered as not
715  set.
716  """
717  if not hasattr(self, name):
718  return False
719  default = self.getDefaultProperty(name)
720  if isinstance(default, (list, dict, DataObjectHandleBase)):
721  value = getattr(self, name)
722  return value != default
723  return True
724 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 737 of file Configurable.py.

737  def isPublic(self):
738  return True
739 
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 741 of file Configurable.py.

741  def jobOptName(self):
742  log.error("jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
743  error_explanation)
744  return self.getJobOptName() # compatibility
745 
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 731 of file Configurable.py.

731  def name(self):
732  return self.getName()
733 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 656 of file Configurable.py.

656  def properties(self):
657  return self.getProperties() # compatibility
658 
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 477 of file Configurable.py.

477  def remove(self, items):
478  if type(items) != list and type(items) != tuple:
479  items = [items]
480 
481  self.__children = [e for e in self.__children if not e in items]
482 
def GaudiKernel.Configurable.Configurable.removeAll (   self)
def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 761 of file Configurable.py.

761  def setDefaults(cls, handle):
762  pass
763 
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 490 of file Configurable.py.

490  def setParent(self, parentName):
491  pass
492 
def GaudiKernel.Configurable.Configurable.setProp (   self,
  name,
  value 
)
Set the value of a given property

Definition at line 705 of file Configurable.py.

705  def setProp(self, name, value):
706  """Set the value of a given property
707  """
708  return setattr(self, name, value)
709 
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 577 of file Configurable.py.

577  def setup(self):
578  # make sure base class init has been called
579  if not hasattr(self, '_initok') or not self._initok:
580  # could check more, but this is the only explanation
581  raise TypeError, \
582  "Configurable.__init__ not called in %s override" % self.__class__.__name__
583 
584 # log.debug("calling setup() on " + self.getFullJobOptName())
585 
586  # setup self: this collects all values on the python side
587  self.__setupServices()
588  self.__setupDlls()
589  self.__setupDefaults()
590 
591  # setup children
592  for c in self.getAllChildren():
593  c.setup()
594 
595  # now get handle to work with for moving properties into the catalogue
596  handle = self.getHandle()
597  if not handle:
598  log.debug('no handle for %s: not transporting properties', self._name)
599  return # allowed, done early
600 
601  # pass final set of properties on to handle on the C++ side or JobOptSvc
602  for name in self._properties.keys():
603  if hasattr(self, name): # means property has python-side value/default
604  setattr(handle, name, getattr(self, name))
605 
606  # for debugging purposes
607  self._setupok = True
608 
def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 795 of file Configurable.py.

795  def splitName(self):
796  fullname = self.getName()
797  dot = fullname.find('.')
798  if dot != -1:
799  parentname = fullname[:dot]
800  longname = fullname[dot + 1:]
801  else:
802  parentname = ''
803  longname = fullname
804  dot = longname.find('.')
805  if dot != -1:
806  name = longname[:dot]
807  else:
808  name = longname
809  return parentname, name, longname
810 

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 310 of file Configurable.py.

GaudiKernel.Configurable.Configurable.__metaclass__ = ConfigurableMeta.ConfigurableMeta
staticprivate

Definition at line 122 of file Configurable.py.

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

Definition at line 124 of file Configurable.py.

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 311 of file Configurable.py.

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 138 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 326 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 323 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 316 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 329 of file Configurable.py.

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 332 of file Configurable.py.

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

Definition at line 134 of file Configurable.py.

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

Definition at line 135 of file Configurable.py.

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

Definition at line 118 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 120 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 119 of file Configurable.py.

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 117 of file Configurable.py.


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