The Gaudi Framework  v31r0 (aeb156f0)
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 106 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 285 of file Configurable.py.

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

Member Function Documentation

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

Definition at line 383 of file Configurable.py.

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

Definition at line 461 of file Configurable.py.

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

Definition at line 432 of file Configurable.py.

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

Definition at line 356 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 343 of file Configurable.py.

343  def __getstate__(self):
344  dict = {}
345  for name, proxy in self._properties.items():
346  try:
347  dict[name] = proxy.__get__(self)
348  except AttributeError:
349  pass
350 
351  dict['_Configurable__children'] = self.__children
352  dict['_Configurable__tools'] = self.__tools
353  dict['_name'] = self._name
354  return dict
355 
def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 399 of file Configurable.py.

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

Definition at line 379 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__len__ (   self)

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

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

Definition at line 486 of file Configurable.py.

486  def __nonzero__(self):
487  return True
488 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 906 of file Configurable.py.

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

Definition at line 449 of file Configurable.py.

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

Definition at line 359 of file Configurable.py.

359  def __setstate__(self, dict):
360  self._initok = True
361  from contextlib import contextmanager
362 
363  @contextmanager
364  def unpickling():
365  try:
366  self._unpickling = True
367  yield
368  finally:
369  self._unpickling = False
370 
371  with unpickling():
372  for n, v in dict.items():
373  setattr(self, n, v)
374 
def GaudiKernel.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 882 of file Configurable.py.

882  def __setupDefaults(self):
883  # set handle defaults flags to inform __setattr__ that it is being
884  # called during setDefaults of the concrete Configurable
885  self._inSetDefaults = True
886  self.setDefaults(self)
887  self._inSetDefaults = False
888 
def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 870 of file Configurable.py.

870  def __setupDlls(self):
871  dlls = self.getDlls()
872  if not dlls:
873  dlls = []
874  elif type(dlls) == types.StringType:
875  dlls = [dlls]
876 
877  from __main__ import theApp
878  dlls = filter(lambda d: d not in theApp.Dlls, dlls)
879  if dlls:
880  theApp.Dlls += dlls
881 
def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 853 of file Configurable.py.

853  def __setupServices(self):
854  #svcs = self.getServices()
855  # if not svcs:
856  svcs = []
857  # elif type(svcs) == types.StringType:
858  # svcs = [ svcs ]
859 
860  import __main__
861  for svc in svcs:
862  handle = __main__.Service(svc)
863  # services should be configurables as well, but aren't for now
864  # handle.setup()
865 
866  # allow Configurable to make some changes
867  if hasattr(self, 'configure' + svc):
868  eval('self.configure' + svc + '( handle )')
869 
def GaudiKernel.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 909 of file Configurable.py.

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

Definition at line 850 of file Configurable.py.

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

Definition at line 898 of file Configurable.py.

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

Definition at line 890 of file Configurable.py.

890  def _printHeader(indentStr, title):
891  preLen = Configurable.printHeaderPre
892  postLen = Configurable.printHeaderWidth - \
893  preLen - 3 - len(title) # - len(indentStr)
894  postLen = max(preLen, postLen)
895  return indentStr + '/%s %s %s' % (preLen * '*', title, postLen * '*')
896 
def _printHeader(indentStr, title)
EventIDBase max(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:215
def GaudiKernel.Configurable.Configurable.addTool (   self,
  tool,
  name = None 
)

Definition at line 829 of file Configurable.py.

829  def addTool(self, tool, name=None):
830  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
831  if name is None:
832  name = tool.__name__
833  priv_tool = tool(self.getName() + '.' + name)
834  elif isinstance(tool, ConfigurableAlgTool):
835  if name is None:
836  name = tool.splitName()[1]
837  priv_tool = tool.clone(self.getName() + '.' + name)
838  else:
839  if isclass(tool):
840  classname = tool.__name__
841  else:
842  classname = type(tool).__name__
843  raise TypeError, "addTool requires AlgTool configurable. Got %s type" % classname
844  self.__tools[name] = priv_tool
845  if name in self.__slots__:
846  # this is to avoid that the property hides the tool
847  setattr(self, name, self.__tools[name])
848  return self.__tools[name]
849 
def addTool(self, tool, name=None)
def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 537 of file Configurable.py.

537  def children(self):
538  log.error(
539  "children() is deprecated, use getChildren() instead for consistency"
540  )
541  log.error(
542  "getChildren() returns a copy; to add a child, use 'parent += child'%s",
543  error_explanation)
544  return self.__children # by ref, for compatibility
545 
def GaudiKernel.Configurable.Configurable.clone (   self,
  name = None,
  kwargs 
)

Definition at line 782 of file Configurable.py.

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

Definition at line 499 of file Configurable.py.

499  def copyChild(self, child):
500  return copy.deepcopy(child)
501 
def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 511 of file Configurable.py.

511  def copyChildAndSetParent(self, cfg, parent):
512  cc = self.copyChild(cfg)
513 
514  if hasattr(cc, 'setParent') and parent:
515  try:
516  cc.setParent(parent)
517  except RuntimeError, e:
518  # temporary backdoor resolution for compatibility
519  log.error(str(e) + '%s', error_explanation)
520  ccbd = cc.configurables[cc.getJobOptName()]
521 
522  # merge properties, new over pre-existing
523  for proxy in self._properties.values():
524  if proxy.history.has_key(cc):
525  proxy.__set__(ccbd, proxy.__get__(cc))
526 
527  # consolidate
528  cc = ccbd
529  return cc
530 
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 546 of file Configurable.py.

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

Definition at line 531 of file Configurable.py.

531  def getChildren(self):
532  return self.__children[:] # read only
533 
def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 676 of file Configurable.py.

677  class collector:
678  pass
679 
680  # user provided defaults
681  c = collector()
682  cls.setDefaults(c)
683 
684  # defaults from C++
685  for k, v in cls._properties.items():
686  if not k in c.__dict__ and hasattr(v, 'default'):
687  c.__dict__[k] = v.default
688 
689  return c.__dict__
690 
def GaudiKernel.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 692 of file Configurable.py.

692  def getDefaultProperty(cls, name):
693  class collector:
694  pass
695 
696  # user provided defaults
697  c = collector()
698  cls.setDefaults(c)
699 
700  if name in c.__dict__:
701  return c.__dict__[name]
702 
703  # defaults from C++
704  try:
705  v = cls._properties[name]
706  if hasattr(v, 'default'):
707  return v.default
708  except KeyError:
709  pass
710 
711  return None
712 
def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 766 of file Configurable.py.

766  def getFullJobOptName(self):
767  return "%s/%s" % (self.getType(), self.getJobOptName()
768  or self.getName())
769 
def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 763 of file Configurable.py.

763  def getFullName(self):
764  return str(self.getType() + '/' + self.getName())
765 
def GaudiKernel.Configurable.Configurable.getJobOptName (   self)

Definition at line 750 of file Configurable.py.

750  def getJobOptName(self): # full hierachical name
751  return self.getName()
752 
def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 744 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 505 of file Configurable.py.

505  def getParent(self):
506  return ""
507 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 770 of file Configurable.py.

770  def getPrintTitle(self):
771  return self.getGaudiType() + ' ' + self.getTitleName()
772 
def GaudiKernel.Configurable.Configurable.getProp (   self,
  name 
)
Returns the value of the given property.

Definition at line 713 of file Configurable.py.

713  def getProp(self, name):
714  """Returns the value of the given property.
715  """
716  if hasattr(self, name):
717  return getattr(self, name)
718  else:
719  return self.getDefaultProperties()[name]
720 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 625 of file Configurable.py.

625  def getProperties(self):
626  props = {}
627  for name, proxy in self._properties.items():
628  try:
629  props[name] = proxy.__get__(self)
630  except AttributeError:
631  props[name] = Configurable.propertyNoValue
632 
633  return props
634 
def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 635 of file Configurable.py.

636  """Get all properties with their description string as { name : (value, desc) }."""
637  props = {}
638  for name, proxy in self._properties.items():
639  try:
640  props[name] = (proxy.__get__(self), proxy.__doc__)
641  except AttributeError:
642  props[name] = (Configurable.propertyNoValue, proxy.__doc__)
643  return props
644 
def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 585 of file Configurable.py.

585  def getSequence(self):
586  elems = []
587  for c in self.__children:
588  elems.append(c.getFullName())
589  return elems
590 
def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 773 of file Configurable.py.

773  def getTitleName(self):
774  if log.isEnabledFor(logging.DEBUG):
775  return self.getFullJobOptName()
776  else:
777  return self.getFullName()
778 
def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 534 of file Configurable.py.

534  def getTools(self):
535  return self.__tools.values() # read only
536 
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 741 of file Configurable.py.

741  def getType(cls):
742  return cls.__name__
743 
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 645 of file Configurable.py.

646  props = {}
647  for name, proxy in self._properties.items():
648  if self.isPropertySet(name):
649  value = proxy.__get__(self)
650  if hasattr(value, 'getFullName'):
651  value = value.getFullName()
652  elif type(value) in [list, tuple]:
653  new_value = []
654  for i in value:
655  if hasattr(i, 'getFullName'):
656  new_value.append(i.getFullName())
657  else:
658  new_value.append(i)
659  value = type(value)(new_value)
660  elif type(value) is dict:
661  new_value = {}
662  for i in value:
663  if hasattr(value[i], 'getFullName'):
664  new_value[i] = value[i].getFullName()
665  else:
666  new_value[i] = value[i]
667  value = new_value
668  props[name] = value
669 
670  return props
671 
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 508 of file Configurable.py.

508  def hasParent(self, parent):
509  return False
510 
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 726 of file Configurable.py.

726  def isPropertySet(self, name):
727  """Tell if the property 'name' has been set or not.
728 
729  Because of a problem with list and dictionary properties, in those cases
730  if the value is equal to the default, the property is considered as not
731  set.
732  """
733  if not hasattr(self, name):
734  return False
735  default = self.getDefaultProperty(name)
736  if isinstance(default, (list, dict, DataObjectHandleBase)):
737  value = getattr(self, name)
738  return value != default
739  return True
740 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 753 of file Configurable.py.

753  def isPublic(self):
754  return True
755 
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 757 of file Configurable.py.

757  def jobOptName(self):
758  log.error(
759  "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
760  error_explanation)
761  return self.getJobOptName() # compatibility
762 
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 747 of file Configurable.py.

747  def name(self):
748  return self.getName()
749 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 672 of file Configurable.py.

672  def properties(self):
673  return self.getProperties() # compatibility
674 
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 489 of file Configurable.py.

489  def remove(self, items):
490  if type(items) != list and type(items) != tuple:
491  items = [items]
492 
493  self.__children = [e for e in self.__children if not e in items]
494 
def GaudiKernel.Configurable.Configurable.removeAll (   self)
def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 779 of file Configurable.py.

779  def setDefaults(cls, handle):
780  pass
781 
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 502 of file Configurable.py.

502  def setParent(self, parentName):
503  pass
504 
def GaudiKernel.Configurable.Configurable.setProp (   self,
  name,
  value 
)
Set the value of a given property

Definition at line 721 of file Configurable.py.

721  def setProp(self, name, value):
722  """Set the value of a given property
723  """
724  return setattr(self, name, value)
725 
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 591 of file Configurable.py.

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

Definition at line 813 of file Configurable.py.

813  def splitName(self):
814  fullname = self.getName()
815  dot = fullname.find('.')
816  if dot != -1:
817  parentname = fullname[:dot]
818  longname = fullname[dot + 1:]
819  else:
820  parentname = ''
821  longname = fullname
822  dot = longname.find('.')
823  if dot != -1:
824  name = longname[:dot]
825  else:
826  name = longname
827  return parentname, name, longname
828 

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 318 of file Configurable.py.

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

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

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 319 of file Configurable.py.

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 139 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 334 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 331 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 324 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 337 of file Configurable.py.

GaudiKernel.Configurable.Configurable._unpickling
private

Definition at line 340 of file Configurable.py.

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

Definition at line 133 of file Configurable.py.

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

Definition at line 135 of file Configurable.py.

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

Definition at line 117 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 119 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 118 of file Configurable.py.

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 116 of file Configurable.py.


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