GaudiKernel.Configurable.Configurable Class Reference
Inheritance diagram for GaudiKernel.Configurable.Configurable:
Collaboration diagram for GaudiKernel.Configurable.Configurable:

Classes

class  DefaultName
 for detecting the default name More...
 

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
 

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

Constructor & Destructor Documentation

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

Definition at line 256 of file Configurable.py.

256  def __init__( self, name = DefaultName ):
257  # check class readiness, all required overloads should be there now
258  klass = self.__class__
259 
260  # this is an abstract class
261  if klass == Configurable:
262  raise TypeError, "%s is an ABC and can not be instantiated" % str(Configurable)
263 
264  # the following methods require overloading
265  #NOT YET meths = { 'getServices' : 1, # retrieve list of services to configure
266  meths = { 'getDlls' : 1, # provide list of Dlls to load
267  'getGaudiType' : 1, # return string describing component class
268  'getHandle' : 1 } # provide access to C++ side component instance
269 # 'getType' : 1 } # return the type of the actual C++ component
270 
271  for meth, nArgs in meths.items():
272  try:
273  f = getattr( klass, meth ).im_func
274  except AttributeError:
275  raise NotImplementedError, "%s is missing in class %s" % (meth,str(klass))
276 
277  # in addition, verify the number of arguments w/o defaults
278  nargcount = f.func_code.co_argcount
279  ndefaults = f.func_defaults and len(f.func_defaults) or 0
280  if not nargcount - ndefaults <= nArgs <= nargcount:
281  raise TypeError, "%s.%s requires exactly %d arguments" % (klass,meth,nArgs)
282 
283  # for using this Configurable as a (Gaudi) sequence
284  self.__children = []
285  self.__tools = {}
286 
287  # know who we are
288  if name == Configurable.DefaultName :
289  if hasattr(self.__class__, 'DefaultedName' ) :
290  self._name = self.__class__.DefaultedName
291  else :
292  self._name = self.getType()
293  else :
294  self._name = name
295 
296  # set to True when collecting defaults, False otherwise
297  self._inSetDefaults = False
298 
299  # for later, in case __init__ itself is overridden
300  self._initok = True
301 
302  # for debugging purposes (temporary)
303  self._setupok = False
304 
def __init__(self, name=DefaultName)

Member Function Documentation

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

Definition at line 336 of file Configurable.py.

336  def __deepcopy__( self, memo ):
337  newconf = object.__new__( self.__class__ )
338  self.__class__.__init__( newconf, self.getName() )
339 
340  for proxy in self._properties.values():
341  try:
342  proxy.__set__( newconf, proxy.__get__( self ) )
343  except AttributeError:
344  pass # means property was not set for self
345 
346  for c in self.__children:
347  newconf += c # processes proper copy semantics
348 
349  return newconf
350 
def GaudiKernel.Configurable.Configurable.__delattr__ (   self,
  attr 
)

Definition at line 407 of file Configurable.py.

407  def __delattr__( self, attr ):
408  # remove as property, otherwise try as child
409  try:
410  # remove history etc., then reset to default (in case set before)
411  prop = self._properties[ attr ]
412  prop.__delete__( self )
413  prop.__set__( self, prop.default )
414  return # reaches here? was property: done now
415  except KeyError:
416  pass
417  # otherwise, remove the private tool
418  if attr in self.__tools :
419  del self.__tools[attr]
420 
421  # otherwise, remove child, if one is so named
422  for c in self.__children:
423  if c.getName() == attr:
424  self.__children.remove( c )
425 
426  # potentially, there are left over caches (certain user derived classes)
427  try:
428  del self.__dict__[ attr ]
429  except (AttributeError,KeyError):
430  pass
431 
def GaudiKernel.Configurable.Configurable.__getattr__ (   self,
  attr 
)

Definition at line 384 of file Configurable.py.

384  def __getattr__( self, attr ): # until ToolProperties exist ...
385 
386  if attr in self.__tools : return self.__tools[attr]
387 
388  if attr in self._properties:
389  if isinstance(self._properties[attr].__get__( self ), DataObjectHandleBase):
390  return self._properties[attr].__get__( self )
391 
392  for c in self.__children:
393  if c.getName() == attr:
394  return c
395 
396  raise AttributeError( "'%s' object has no attribute '%s'" % (self.__class__,attr) )
397 
def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 319 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 306 of file Configurable.py.

306  def __getstate__ (self):
307  dict = {}
308  for name, proxy in self._properties.items():
309  try:
310  dict[ name ] = proxy.__get__( self )
311  except AttributeError:
312  pass
313 
314  dict[ '_Configurable__children' ] = self.__children
315  dict[ '_Configurable__tools' ] = self.__tools
316  dict[ '_name' ] = self._name
317  return dict
318 
def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 352 of file Configurable.py.

352  def __iadd__( self, configs, descr = None ):
353  if not type(configs) in (list,tuple):
354  configs = ( configs, )
355 
356  joname = self.getJobOptName()
357 
358  for cfg in configs:
359  # prevent type mismatches
360  if not isinstance( cfg, Configurable ):
361  raise TypeError( "'%s' is not a Configurable" % str(cfg) )
362 
363  cc = self.copyChildAndSetParent( cfg, joname )
364 
365  # filters dupes; usually "ok" (backdoor should catch them)
366  ccjo = cc.getJobOptName()
367  for c in self.__children:
368  if c.getJobOptName() == ccjo:
369  log.error( 'attempt to add a duplicate ... dupe ignored%s', error_explanation )
370  break
371  else:
372  self.__children.append( cc )
373 
374  try:
375  if descr: # support for tool properties
376  descr.__set__( self, cc )
377  else:
378  setattr( self, cc.getName(), cc )
379  except AttributeError:
380  pass # to allow free addition of tools/subalgorithms
381 
382  return self
383 
def copyChildAndSetParent(self, cfg, parent)
def __iadd__(self, configs, descr=None)
def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 332 of file Configurable.py.

332  def __iter__( self ):
333  return iter( self.__children )
334 
def GaudiKernel.Configurable.Configurable.__len__ (   self)

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

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

Definition at line 432 of file Configurable.py.

432  def __nonzero__(self):
433  return True
434 
435 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 841 of file Configurable.py.

841  def __repr__( self ):
842  return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
843 
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:339
def GaudiKernel.Configurable.Configurable.__setattr__ (   self,
  name,
  value 
)

Definition at line 398 of file Configurable.py.

398  def __setattr__( self, name, value ) :
399  if self._configurationLocked:
400  raise RuntimeError("%s: Configuration cannot be modified after the ApplicationMgr has been started."%self.name())
401  try :
402  super( Configurable, self ).__setattr__( name, value )
403  except AttributeError:
404  raise AttributeError( "Configurable '%s' does not have property '%s'."
405  % ( self.__class__.__name__, name) )
406 
def __setattr__(self, name, value)
def GaudiKernel.Configurable.Configurable.__setstate__ (   self,
  dict 
)

Definition at line 322 of file Configurable.py.

322  def __setstate__ ( self, dict ):
323  self._initok = True
324  for n, v in dict.items():
325  setattr (self, n, v)
326  return
327 
def GaudiKernel.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 820 of file Configurable.py.

820  def __setupDefaults( self ):
821  # set handle defaults flags to inform __setattr__ that it is being
822  # called during setDefaults of the concrete Configurable
823  self._inSetDefaults = True
824  self.setDefaults( self )
825  self._inSetDefaults = False
826 
def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 809 of file Configurable.py.

809  def __setupDlls( self ):
810  dlls = self.getDlls()
811  if not dlls:
812  dlls = []
813  elif type(dlls) == types.StringType:
814  dlls = [ dlls ]
815 
816  from __main__ import theApp
817  dlls = filter( lambda d: d not in theApp.Dlls, dlls )
818  if dlls: theApp.Dlls += dlls
819 
def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 792 of file Configurable.py.

792  def __setupServices( self ):
793  #svcs = self.getServices()
794  #if not svcs:
795  svcs = []
796  #elif type(svcs) == types.StringType:
797  # svcs = [ svcs ]
798 
799  import __main__
800  for svc in svcs:
801  handle = __main__.Service( svc )
802  # services should be configurables as well, but aren't for now
803  # handle.setup()
804 
805  # allow Configurable to make some changes
806  if hasattr( self, 'configure' + svc ):
807  eval( 'self.configure' + svc + '( handle )' )
808 
def GaudiKernel.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 844 of file Configurable.py.

844  def __str__( self, indent = 0, headerLastIndentUnit=indentUnit ):
845  global log # to print some info depending on output level
846  indentStr = indent*Configurable.indentUnit
847  # print header
848  title = self.getPrintTitle()
849  # print line to easily see start-of-configurable
850  if indent > 0:
851  headerIndent = (indent-1)*Configurable.indentUnit + headerLastIndentUnit
852  else:
853  headerIndent = ''
854  rep = Configurable._printHeader( headerIndent, title )
855  rep += os.linesep
856  # print own properties
857  props = self.getProperties()
858  defs = self.getDefaultProperties()
859  if not props:
860  rep += indentStr + '|-<no properties>' + os.linesep
861  else:
862  # get property name with
863  nameWidth = 0
864  for p in props.keys():
865  nameWidth=max(nameWidth,len(p))
866  for p, v in props.items():
867  # start with indent and property name
868  prefix = indentStr + '|-%-*s' % (nameWidth,p)
869  # add memory address for debugging (not for defaults)
870  if log.isEnabledFor( logging.DEBUG ):
871  if v != Configurable.propertyNoValue:
872  address = ' @%11s' % hex(id(v))
873  else:
874  address = 13*' '
875  prefix += address
876  # add value and default
877  default = defs.get(p)
878  if v == Configurable.propertyNoValue:
879  # show default value as value, and no extra 'default'
880  strVal = repr(default)
881  strDef = None
882  else:
883  # convert configurable to handle
884  if hasattr(v,"getGaudiHandle"):
885  vv = v.getGaudiHandle()
886  else:
887  vv = v
888  if isinstance(vv,GaudiHandle) or isinstance(vv,GaudiHandleArray):
889  strVal = repr(vv)
890  if hasattr(default,"toStringProperty"): # the default may not be a GaudiHandle (?)
891  strDef = repr(default.toStringProperty())
892  else:
893  strDef = repr(default)
894  if strDef == repr(vv.toStringProperty()):
895  strDef = None
896  else:
897  strVal = repr(vv)
898  strDef = repr(default)
899  # add the value
900  line = prefix + ' = ' + strVal
901  # add default if present
902  if strDef is not None:
903  # put default on new line if too big
904  if len(line) + len(strDef) > Configurable.printHeaderWidth:
905  line += os.linesep + indentStr + '| ' + (len(prefix)-len(indentStr)-3)*' '
906  line += ' (default: %s)' % (strDef,)
907  # add the line to the total string
908  rep += line + os.linesep
909  # print out full private configurables
MsgStream & hex(MsgStream &log)
Definition: MsgStream.h:339
def __str__(self, indent=0, headerLastIndentUnit=indentUnit)
def GaudiKernel.Configurable.Configurable._isInSetDefaults (   self)
private

Definition at line 789 of file Configurable.py.

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

Definition at line 835 of file Configurable.py.

835  def _printFooter( indentStr, title ):
836  preLen = Configurable.printHeaderPre
837  postLen = Configurable.printHeaderWidth - preLen - 12 - len(title)# - len(indentStr)
838  postLen = max(preLen,postLen)
839  return indentStr + '\\%s (End of %s) %s' % (preLen*'-',title,postLen*'-')
840 
def _printFooter(indentStr, title)
def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 828 of file Configurable.py.

828  def _printHeader( indentStr, title ):
829  preLen = Configurable.printHeaderPre
830  postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
831  postLen = max(preLen,postLen)
832  return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
833 
def _printHeader(indentStr, title)
def GaudiKernel.Configurable.Configurable.addTool (   self,
  tool,
  name = None 
)

Definition at line 768 of file Configurable.py.

768  def addTool( self, tool, name = None ) :
769  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
770  if name is None:
771  name = tool.__name__
772  priv_tool = tool( self.getName()+ '.' + name )
773  elif isinstance(tool, ConfigurableAlgTool):
774  if name is None:
775  name = tool.splitName()[1]
776  priv_tool = tool.clone( self.getName()+ '.' + name )
777  else:
778  if isclass(tool):
779  classname = tool.__name__
780  else:
781  classname = type(tool).__name__
782  raise TypeError, "addTool requires AlgTool configurable. Got %s type" % classname
783  self.__tools[name] = priv_tool
784  if name in self.__slots__:
785  # this is to avoid that the property hides the tool
786  setattr(self,name,self.__tools[name])
787  return self.__tools[name]
788 
def addTool(self, tool, name=None)
def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 484 of file Configurable.py.

484  def children( self ):
485  log.error( "children() is deprecated, use getChildren() instead for consistency" )
486  log.error( "getChildren() returns a copy; to add a child, use 'parent += child'%s",
487  error_explanation )
488  return self.__children # by ref, for compatibility
489 
def GaudiKernel.Configurable.Configurable.clone (   self,
  name = None,
  kwargs 
)

Definition at line 723 of file Configurable.py.

723  def clone( self, name = None, **kwargs ) :
724  if not name :
725  if hasattr(self, 'DefaultedName' ) : name = self.DefaultedName
726  else : name = self.getType()
727 
728  newconf = Configurable.__new__( self.__class__, name )
729  self.__class__.__init__( newconf, name )
730 
731  for proxy in self._properties.values():
732  try :
733  value = proxy.__get__( self )
734  if type(value) in [ str, list, dict, tuple ]:
735  # clone the values of the properties for basic types
736  value = type(value)(value)
737  proxy.__set__( newconf, value )
738  except AttributeError:
739  pass
740 
741  for c in self.__children:
742  newconf += c # processes proper copy semantics
743 
744  for n , t in self.__tools.items():
745  newconf.addTool(t, n)
746 
747  for name, value in kwargs.items():
748  setattr(newconf, name, value)
749 
750  return newconf
751 
def clone(self, name=None, kwargs)
def GaudiKernel.Configurable.Configurable.copyChild (   self,
  child 
)

Definition at line 446 of file Configurable.py.

446  def copyChild( self, child ):
447  return copy.deepcopy( child )
448 
def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 458 of file Configurable.py.

458  def copyChildAndSetParent(self,cfg,parent):
459  cc = self.copyChild( cfg )
460 
461  if hasattr( cc, 'setParent' ) and parent:
462  try:
463  cc.setParent( parent )
464  except RuntimeError, e:
465  # temporary backdoor resolution for compatibility
466  log.error( str(e) + '%s', error_explanation )
467  ccbd = cc.configurables[ cc.getJobOptName() ]
468 
469  # merge properties, new over pre-existing
470  for proxy in self._properties.values():
471  if proxy.history.has_key( cc ):
472  proxy.__set__( ccbd, proxy.__get__( cc ) )
473 
474  # consolidate
475  cc = ccbd
476  return cc
477 
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 490 of file Configurable.py.

490  def getAllChildren( self ):
491  """Get all (private) configurable children, both explicit ones (added with +=)
492  and the ones in the private GaudiHandle properties"""
493  childs = []
494  # add private configurable properties (also inside handles)
495  for proxy in self._properties.values():
496  try:
497  c = proxy.__get__( self )
498  except AttributeError:
499  pass
500  else:
501  if isinstance(c,Configurable) and not c.isPublic():
502  childs.append(c)
503  elif isinstance(c,GaudiHandle):
504  try:
505  conf = c.configurable
506  except AttributeError:
507  pass
508  else:
509  if not conf.isPublic():
510  childs.append(conf)
511  elif isinstance(c,GaudiHandleArray):
512  # only setup private arrays
513  if not c.isPublic():
514  for ci in c:
515  if isinstance(ci,Configurable):
516  childs.append(ci)
517  else:
518  try:
519  conf = ci.configurable
520  except AttributeError:
521  pass
522  else:
523  childs.append(conf)
524 
525  # add explicit children
526  childs += self.__children
527  return childs
528 
def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 478 of file Configurable.py.

478  def getChildren( self ):
479  return self.__children[:] # read only
480 
def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 618 of file Configurable.py.

619  class collector:
620  pass
621 
622  # user provided defaults
623  c = collector()
624  cls.setDefaults( c )
625 
626  # defaults from C++
627  for k,v in cls._properties.items():
628  if not k in c.__dict__ and hasattr( v, 'default' ):
629  c.__dict__[ k ] = v.default
630 
631  return c.__dict__
632 
def GaudiKernel.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 634 of file Configurable.py.

634  def getDefaultProperty( cls, name ):
635  class collector:
636  pass
637 
638  # user provided defaults
639  c = collector()
640  cls.setDefaults( c )
641 
642  if name in c.__dict__:
643  return c.__dict__[ name ]
644 
645  # defaults from C++
646  try:
647  v = cls._properties[name]
648  if hasattr( v, 'default' ):
649  return v.default
650  except KeyError:
651  pass
652 
653  return None
654 
def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 708 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 705 of file Configurable.py.

705  def getFullName( self ) :
706  return str( self.getType() + '/' + self.getName() )
707 
def GaudiKernel.Configurable.Configurable.getJobOptName (   self)

Definition at line 693 of file Configurable.py.

693  def getJobOptName( self ): # full hierachical name
694  return self.getName()
695 
def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 687 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 452 of file Configurable.py.

452  def getParent( self ):
453  return ""
454 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 711 of file Configurable.py.

711  def getPrintTitle(self):
712  return self.getGaudiType() + ' ' + self.getTitleName()
713 
def GaudiKernel.Configurable.Configurable.getProp (   self,
  name 
)
Returns the value of the given property.

Definition at line 655 of file Configurable.py.

655  def getProp(self, name):
656  """Returns the value of the given property.
657  """
658  if hasattr(self, name):
659  return getattr(self, name)
660  else:
661  return self.getDefaultProperties()[name]
662 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 567 of file Configurable.py.

567  def getProperties( self ):
568  props = {}
569  for name, proxy in self._properties.items():
570  try:
571  props[ name ] = proxy.__get__( self )
572  except AttributeError:
573  props[ name ] = Configurable.propertyNoValue
574 
575  return props
576 
def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 577 of file Configurable.py.

578  """Get all properties with their description string as { name : (value, desc) }."""
579  props = {}
580  for name, proxy in self._properties.items():
581  try:
582  props[ name ] = ( proxy.__get__( self ), proxy.__doc__)
583  except AttributeError:
584  props[ name ] = ( Configurable.propertyNoValue, proxy.__doc__)
585  return props
586 
def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 529 of file Configurable.py.

529  def getSequence( self ):
530  elems = []
531  for c in self.__children:
532  elems.append( c.getFullName() )
533  return elems
534 
def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 714 of file Configurable.py.

714  def getTitleName( self ):
715  if log.isEnabledFor( logging.DEBUG ):
716  return self.getFullJobOptName()
717  else:
718  return self.getFullName()
719 
def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 481 of file Configurable.py.

481  def getTools( self ):
482  return self.__tools.values() # read only
483 
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 684 of file Configurable.py.

684  def getType( cls ):
685  return cls.__name__
686 
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 587 of file Configurable.py.

587  def getValuedProperties( self ):
588  props = {}
589  for name, proxy in self._properties.items():
590  if self.isPropertySet(name):
591  value = proxy.__get__( self )
592  if hasattr(value, 'getFullName') :
593  value = value.getFullName()
594  elif type(value) in [list, tuple]:
595  new_value = []
596  for i in value:
597  if hasattr(i, 'getFullName'):
598  new_value.append(i.getFullName())
599  else:
600  new_value.append(i)
601  value = type(value)(new_value)
602  elif type(value) is dict:
603  new_value = {}
604  for i in value:
605  if hasattr(value[i], 'getFullName'):
606  new_value[i] = value[i].getFullName()
607  else:
608  new_value[i] = value[i]
609  value = new_value
610  props[ name ] = value
611 
612  return props
613 
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 455 of file Configurable.py.

455  def hasParent( self, parent ):
456  return False
457 
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 668 of file Configurable.py.

668  def isPropertySet(self, name):
669  """Tell if the property 'name' has been set or not.
670 
671  Because of a problem with list and dictionary properties, in those cases
672  if the value is equal to the default, the property is considered as not
673  set.
674  """
675  if not hasattr(self, name):
676  return False
677  else:
678  default = self.getDefaultProperty(name)
679  if isinstance(default, (list, dict)):
680  value = getattr(self, name)
681  return value != default
682  return True
683 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 696 of file Configurable.py.

696  def isPublic( self ):
697  return True
698 
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 700 of file Configurable.py.

700  def jobOptName( self ):
701  log.error( "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
702  error_explanation )
703  return self.getJobOptName() # compatibility
704 
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 690 of file Configurable.py.

690  def name( self ):
691  return self.getName()
692 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 614 of file Configurable.py.

614  def properties( self ):
615  return self.getProperties() # compatibility
616 
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 436 of file Configurable.py.

436  def remove( self, items ):
437  if type(items) != list and type(items) != tuple:
438  items = [ items ]
439 
440  self.__children = [ e for e in self.__children if not e in items ]
441 
def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 442 of file Configurable.py.

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

Definition at line 720 of file Configurable.py.

720  def setDefaults( cls, handle ):
721  pass
722 
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 449 of file Configurable.py.

449  def setParent( self, parentName ):
450  pass
451 
def GaudiKernel.Configurable.Configurable.setProp (   self,
  name,
  value 
)
Set the value of a given property

Definition at line 663 of file Configurable.py.

663  def setProp(self, name, value):
664  """Set the value of a given property
665  """
666  return setattr(self, name, value)
667 
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 535 of file Configurable.py.

535  def setup( self ):
536  # make sure base class init has been called
537  if not hasattr(self,'_initok') or not self._initok:
538  # could check more, but this is the only explanation
539  raise TypeError, \
540  "Configurable.__init__ not called in %s override" % self.__class__.__name__
541 
542 # log.debug("calling setup() on " + self.getFullJobOptName())
543 
544  # setup self: this collects all values on the python side
545  self.__setupServices()
546  self.__setupDlls()
547  self.__setupDefaults()
548 
549  # setup children
550  for c in self.getAllChildren():
551  c.setup()
552 
553  # now get handle to work with for moving properties into the catalogue
554  handle = self.getHandle()
555  if not handle:
556  log.debug( 'no handle for %s: not transporting properties', self._name )
557  return # allowed, done early
558 
559  # pass final set of properties on to handle on the C++ side or JobOptSvc
560  for name in self._properties.keys():
561  if hasattr( self, name ): # means property has python-side value/default
562  setattr( handle, name, getattr(self,name) )
563 
564  # for debugging purposes
565  self._setupok = True
566 
def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 752 of file Configurable.py.

752  def splitName( self ) :
753  fullname = self.getName()
754  dot = fullname.find('.')
755  if dot != -1 :
756  parentname = fullname[:dot]
757  longname = fullname[dot+1:]
758  else :
759  parentname = ''
760  longname = fullname
761  dot = longname.find('.')
762  if dot != -1 :
763  name = longname[:dot]
764  else :
765  name = longname
766  return parentname, name, longname
767 

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 284 of file Configurable.py.

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

Definition at line 104 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  )

Definition at line 106 of file Configurable.py.

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 285 of file Configurable.py.

bool GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 119 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 300 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 297 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 290 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 303 of file Configurable.py.

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

Definition at line 115 of file Configurable.py.

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

Definition at line 116 of file Configurable.py.

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

Definition at line 100 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 102 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 101 of file Configurable.py.

GaudiKernel.Configurable.Configurable.propertyNoValue
static

Definition at line 99 of file Configurable.py.


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