Gaudi Framework, version v23r10

Home   Generated: Mon Sep 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GaudiKernel.Configurable.Configurable Class Reference
Inheritance diagram for GaudiKernel.Configurable.Configurable:
Inheritance graph
[legend]
Collaboration diagram for GaudiKernel.Configurable.Configurable:
Collaboration graph
[legend]

Classes

class  DefaultName
 for detecting the default name More...
 

Public Member Functions

def __new__
 
def __init__
 
def __getstate__
 
def __getnewargs__
 
def __setstate__
 
def __len__
 
def __iter__
 
def __deepcopy__
 
def __iadd__
 
def __getattr__
 
def __setattr__
 
def __delattr__
 
def __nonzero__
 
def remove
 
def removeAll
 
def copyChild
 
def setParent
 
def getParent
 
def hasParent
 
def copyChildAndSetParent
 
def getChildren
 
def getTools
 
def children
 
def getAllChildren
 
def getSequence
 
def setup
 
def getProperties
 
def getValuedProperties
 
def properties
 
def getDefaultProperties
 
def getDefaultProperty
 
def getProp
 
def setProp
 
def isPropertySet
 
def getType
 
def getName
 
def name
 
def getJobOptName
 
def isPublic
 
def jobOptName
 
def getFullName
 
def getFullJobOptName
 
def getPrintTitle
 
def getTitleName
 
def setDefaults
 
def clone
 
def splitName
 
def addTool
 
def __repr__
 
def __str__
 

Static Public Attributes

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

Private Member Functions

def _isInSetDefaults
 
def __setupServices
 
def __setupDlls
 
def __setupDefaults
 

Static Private Member Functions

def _printHeader
 
def _printFooter
 

Private Attributes

 __children
 
 __tools
 
 _name
 
 _inSetDefaults
 
 _initok
 
 _setupok
 

Static Private Attributes

 __metaclass__ ConfigurableMeta.ConfigurableMeta
 
tuple __slots__
 
 _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 87 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 254 of file Configurable.py.

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

Member Function Documentation

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

Definition at line 334 of file Configurable.py.

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

Definition at line 401 of file Configurable.py.

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

Definition at line 382 of file Configurable.py.

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

Definition at line 317 of file Configurable.py.

318  def __getnewargs__(self) :
319  return (self._name,)
def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 304 of file Configurable.py.

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

Definition at line 350 of file Configurable.py.

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

Definition at line 330 of file Configurable.py.

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

Definition at line 327 of file Configurable.py.

328  def __len__( self ):
329  return len( self.__children )
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 119 of file Configurable.py.

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

Definition at line 426 of file Configurable.py.

427  def __nonzero__(self):
428  return True
429 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 827 of file Configurable.py.

828  def __repr__( self ):
829  return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
def GaudiKernel.Configurable.Configurable.__setattr__ (   self,
  name,
  value 
)

Definition at line 392 of file Configurable.py.

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

Definition at line 320 of file Configurable.py.

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

Definition at line 806 of file Configurable.py.

807  def __setupDefaults( self ):
808  # set handle defaults flags to inform __setattr__ that it is being
809  # called during setDefaults of the concrete Configurable
810  self._inSetDefaults = True
811  self.setDefaults( self )
812  self._inSetDefaults = False
def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 795 of file Configurable.py.

796  def __setupDlls( self ):
797  dlls = self.getDlls()
798  if not dlls:
799  dlls = []
800  elif type(dlls) == types.StringType:
801  dlls = [ dlls ]
802 
803  from __main__ import theApp
804  dlls = filter( lambda d: d not in theApp.Dlls, dlls )
805  if dlls: theApp.Dlls += dlls
def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 778 of file Configurable.py.

779  def __setupServices( self ):
780  #svcs = self.getServices()
781  #if not svcs:
782  svcs = []
783  #elif type(svcs) == types.StringType:
784  # svcs = [ svcs ]
785 
786  import __main__
787  for svc in svcs:
788  handle = __main__.Service( svc )
789  # services should be configurables as well, but aren't for now
790  # handle.setup()
791 
792  # allow Configurable to make some changes
793  if hasattr( self, 'configure' + svc ):
794  eval( 'self.configure' + svc + '( handle )' )
def GaudiKernel.Configurable.Configurable.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = indentUnit 
)

Definition at line 830 of file Configurable.py.

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

Definition at line 775 of file Configurable.py.

776  def _isInSetDefaults( self ):
777  return self._inSetDefaults
def GaudiKernel.Configurable.Configurable._printFooter (   indentStr,
  title 
)
staticprivate

Definition at line 821 of file Configurable.py.

822  def _printFooter( indentStr, title ):
823  preLen = Configurable.printHeaderPre
824  postLen = Configurable.printHeaderWidth - preLen - 12 - len(title)# - len(indentStr)
825  postLen = max(preLen,postLen)
826  return indentStr + '\\%s (End of %s) %s' % (preLen*'-',title,postLen*'-')
def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 814 of file Configurable.py.

815  def _printHeader( indentStr, title ):
816  preLen = Configurable.printHeaderPre
817  postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
818  postLen = max(preLen,postLen)
819  return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
def GaudiKernel.Configurable.Configurable.addTool (   self,
  tool,
  name = None 
)

Definition at line 755 of file Configurable.py.

756  def addTool( self, tool, name = None ) :
757  if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
758  if name is None:
759  name = tool.__name__
760  priv_tool = tool( self.getName()+ '.' + name )
761  elif isinstance(tool, ConfigurableAlgTool):
762  if name is None:
763  name = tool.splitName()[1]
764  priv_tool = tool.clone( self.getName()+ '.' + name )
765  else:
766  if isclass(tool):
767  classname = tool.__name__
768  else:
769  classname = type(tool).__name__
770  raise TypeError, "addTool requires AlgTool configurable. Got %s type" % classname
771  self.__tools[name] = priv_tool
772  if name in self.__slots__:
773  # this is to avoid that the property hides the tool
774  setattr(self,name,self.__tools[name])
def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 478 of file Configurable.py.

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

Definition at line 710 of file Configurable.py.

711  def clone( self, name = None, **kwargs ) :
712  if not name :
713  if hasattr(self, 'DefaultedName' ) : name = self.DefaultedName
714  else : name = self.getType()
715 
716  newconf = Configurable.__new__( self.__class__, name )
717  self.__class__.__init__( newconf, name )
718 
719  for proxy in self._properties.values():
720  try :
721  value = proxy.__get__( self )
722  if type(value) in [ str, list, dict, tuple ]:
723  # clone the values of the properties for basic types
724  value = type(value)(value)
725  proxy.__set__( newconf, value )
726  except AttributeError:
727  pass
728 
729  for c in self.__children:
730  newconf += c # processes proper copy semantics
731 
732  for n , t in self.__tools.items():
733  newconf.addTool(t, n)
734 
735  for name, value in kwargs.items():
736  setattr(newconf, name, value)
737 
738  return newconf
def GaudiKernel.Configurable.Configurable.copyChild (   self,
  child 
)

Definition at line 440 of file Configurable.py.

441  def copyChild( self, child ):
442  return copy.deepcopy( child )
def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 452 of file Configurable.py.

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

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

Definition at line 472 of file Configurable.py.

473  def getChildren( self ):
474  return self.__children[:] # read only
def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 602 of file Configurable.py.

603  def getDefaultProperties( cls ):
604  class collector:
605  pass
606 
607  # user provided defaults
608  c = collector()
609  cls.setDefaults( c )
610 
611  # defaults from C++
612  for k,v in cls._properties.items():
613  if not k in c.__dict__ and hasattr( v, 'default' ):
614  c.__dict__[ k ] = v.default
615 
616  return c.__dict__
def GaudiKernel.Configurable.Configurable.getDefaultProperty (   cls,
  name 
)

Definition at line 618 of file Configurable.py.

619  def getDefaultProperty( cls, name ):
620  class collector:
621  pass
622 
623  # user provided defaults
624  c = collector()
625  cls.setDefaults( c )
626 
627  if name in c.__dict__:
628  return c.__dict__[ name ]
629 
630  # defaults from C++
631  try:
632  v = cls._properties[name]
633  if hasattr( v, 'default' ):
634  return v.default
635  except KeyError:
636  pass
637 
638  return None
def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 695 of file Configurable.py.

696  def getFullJobOptName( self ):
697  return "%s/%s" % (self.getType(),self.getJobOptName() or self.getName())
def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 692 of file Configurable.py.

693  def getFullName( self ) :
694  return str( self.getType() + '/' + self.getName() )
def GaudiKernel.Configurable.Configurable.getJobOptName (   self)

Definition at line 680 of file Configurable.py.

681  def getJobOptName( self ): # full hierachical name
682  return self.getName()
def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 674 of file Configurable.py.

675  def getName( self ):
676  return self._name
def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 446 of file Configurable.py.

447  def getParent( self ):
448  return ""
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 698 of file Configurable.py.

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

Definition at line 639 of file Configurable.py.

640  def getProp(self, name):
641  """Returns the value of the given property.
642  """
643  if hasattr(self, name):
644  return getattr(self, name)
645  else:
646  return self.getDefaultProperties()[name]
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 561 of file Configurable.py.

562  def getProperties( self ):
563  props = {}
564  for name, proxy in self._properties.items():
565  try:
566  props[ name ] = proxy.__get__( self )
567  except AttributeError:
568  props[ name ] = Configurable.propertyNoValue
569 
570  return props
def GaudiKernel.Configurable.Configurable.getSequence (   self)

Definition at line 523 of file Configurable.py.

524  def getSequence( self ):
525  elems = []
526  for c in self.__children:
527  elems.append( c.getFullName() )
528  return elems
def GaudiKernel.Configurable.Configurable.getTitleName (   self)

Definition at line 701 of file Configurable.py.

702  def getTitleName( self ):
703  if log.isEnabledFor( logging.DEBUG ):
704  return self.getFullJobOptName()
705  else:
706  return self.getFullName()
def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 475 of file Configurable.py.

476  def getTools( self ):
477  return self.__tools.values() # read only
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 671 of file Configurable.py.

672  def getType( cls ):
673  return cls.__name__
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 571 of file Configurable.py.

572  def getValuedProperties( self ):
573  props = {}
574  for name, proxy in self._properties.items():
575  if self.isPropertySet(name):
576  value = proxy.__get__( self )
577  if hasattr(value, 'getFullName') :
578  value = value.getFullName()
579  elif type(value) in [list, tuple]:
580  new_value = []
581  for i in value:
582  if hasattr(i, 'getFullName'):
583  new_value.append(i.getFullName())
584  else:
585  new_value.append(i)
586  value = type(value)(new_value)
587  elif type(value) is dict:
588  new_value = {}
589  for i in value:
590  if hasattr(value[i], 'getFullName'):
591  new_value[i] = value[i].getFullName()
592  else:
593  new_value[i] = value[i]
594  value = new_value
595  props[ name ] = value
596 
597  return props
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 449 of file Configurable.py.

450  def hasParent( self, parent ):
451  return False
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 652 of file Configurable.py.

653  def isPropertySet(self, name):
654  """Tell if the property 'name' has been set or not.
655 
656  Because of a problem with list and dictionary properties, in those cases
657  if the value is equal to the default, the property is considered as not
658  set.
659  """
660  if not hasattr(self, name):
661  return False
662  else:
663  try:
664  default = self.getDefaultProperties()[name]
665  if isinstance(default, (list, dict)):
666  value = getattr(self, name)
667  return value != default
668  except KeyError:
669  pass # no default found
670  return True
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 683 of file Configurable.py.

684  def isPublic( self ):
685  return True
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 687 of file Configurable.py.

688  def jobOptName( self ):
689  log.error( "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
690  error_explanation )
691  return self.getJobOptName() # compatibility
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 677 of file Configurable.py.

678  def name( self ):
679  return self.getName()
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 598 of file Configurable.py.

599  def properties( self ):
600  return self.getProperties() # compatibility
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 430 of file Configurable.py.

431  def remove( self, items ):
432  if type(items) != list and type(items) != tuple:
433  items = [ items ]
434 
435  self.__children = [ e for e in self.__children if not e in items ]
def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 436 of file Configurable.py.

437  def removeAll( self ):
438  self.remove( self.__children )
def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 707 of file Configurable.py.

708  def setDefaults( cls, handle ):
709  pass
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 443 of file Configurable.py.

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

Definition at line 647 of file Configurable.py.

648  def setProp(self, name, value):
649  """Set the value of a given property
650  """
651  return setattr(self, name, value)
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 529 of file Configurable.py.

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

Definition at line 739 of file Configurable.py.

740  def splitName( self ) :
741  fullname = self.getName()
742  dot = fullname.find('.')
743  if dot != -1 :
744  parentname = fullname[:dot]
745  longname = fullname[dot+1:]
746  else :
747  parentname = ''
748  longname = fullname
749  dot = longname.find('.')
750  if dot != -1 :
751  name = longname[:dot]
752  else :
753  name = longname
754  return parentname, name, longname

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 282 of file Configurable.py.

GaudiKernel.Configurable.Configurable.__metaclass__ ConfigurableMeta.ConfigurableMeta
staticprivate

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

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 283 of file Configurable.py.

GaudiKernel.Configurable.Configurable._configurationLocked False
staticprivate

Definition at line 117 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 298 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 295 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 288 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 301 of file Configurable.py.

dictionary GaudiKernel.Configurable.Configurable.allConfigurables {}
static

Definition at line 113 of file Configurable.py.

dictionary GaudiKernel.Configurable.Configurable.configurableServices {}
static

Definition at line 114 of file Configurable.py.

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

Definition at line 98 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre 5
static

Definition at line 100 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth 100
static

Definition at line 99 of file Configurable.py.


The documentation for this class was generated from the following file:
Generated at Mon Sep 30 2013 14:52:07 for Gaudi Framework, version v23r10 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004