All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
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 88 of file Configurable.py.

Constructor & Destructor Documentation

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

Definition at line 255 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

Member Function Documentation

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

Definition at line 335 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
def GaudiKernel.Configurable.Configurable.__delattr__ (   self,
  attr 
)

Definition at line 402 of file Configurable.py.

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

Definition at line 383 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  for c in self.__children:
389  if c.getName() == attr:
390  return c
391 
392  raise AttributeError( "'%s' object has no attribute '%s'" % (self.__class__,attr) )
def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 318 of file Configurable.py.

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

Definition at line 305 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
def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 351 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
string type
Definition: gaudirun.py:126
def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 331 of file Configurable.py.

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

Definition at line 328 of file Configurable.py.

329  def __len__( self ):
330  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 120 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
string type
Definition: gaudirun.py:126
def GaudiKernel.Configurable.Configurable.__nonzero__ (   self)

Definition at line 427 of file Configurable.py.

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

Definition at line 828 of file Configurable.py.

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

Definition at line 393 of file Configurable.py.

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

Definition at line 321 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
def GaudiKernel.Configurable.Configurable.__setupDefaults (   self)
private

Definition at line 807 of file Configurable.py.

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

Definition at line 796 of file Configurable.py.

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

Definition at line 779 of file Configurable.py.

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

Definition at line 831 of file Configurable.py.

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

Definition at line 776 of file Configurable.py.

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

Definition at line 822 of file Configurable.py.

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

Definition at line 815 of file Configurable.py.

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

Definition at line 756 of file Configurable.py.

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

Definition at line 479 of file Configurable.py.

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

Definition at line 711 of file Configurable.py.

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

Definition at line 441 of file Configurable.py.

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

Definition at line 453 of file Configurable.py.

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

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

Definition at line 473 of file Configurable.py.

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

Definition at line 603 of file Configurable.py.

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

Definition at line 619 of file Configurable.py.

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

Definition at line 696 of file Configurable.py.

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

Definition at line 693 of file Configurable.py.

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

Definition at line 681 of file Configurable.py.

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

Definition at line 675 of file Configurable.py.

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

Definition at line 447 of file Configurable.py.

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

Definition at line 699 of file Configurable.py.

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

Definition at line 640 of file Configurable.py.

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

Definition at line 562 of file Configurable.py.

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

Definition at line 524 of file Configurable.py.

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

Definition at line 702 of file Configurable.py.

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

Definition at line 476 of file Configurable.py.

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

Definition at line 672 of file Configurable.py.

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

Definition at line 572 of file Configurable.py.

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

Definition at line 450 of file Configurable.py.

451  def hasParent( self, parent ):
452  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 653 of file Configurable.py.

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

Definition at line 684 of file Configurable.py.

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

Definition at line 688 of file Configurable.py.

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

Definition at line 678 of file Configurable.py.

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

Definition at line 599 of file Configurable.py.

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

Definition at line 431 of file Configurable.py.

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

Definition at line 437 of file Configurable.py.

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

Definition at line 708 of file Configurable.py.

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

Definition at line 444 of file Configurable.py.

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

Definition at line 648 of file Configurable.py.

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

Definition at line 530 of file Configurable.py.

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

Definition at line 740 of file Configurable.py.

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

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 283 of file Configurable.py.

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

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

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 284 of file Configurable.py.

GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 118 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 299 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 296 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 289 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 302 of file Configurable.py.

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

Definition at line 114 of file Configurable.py.

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

Definition at line 115 of file Configurable.py.

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

Definition at line 99 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 101 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 100 of file Configurable.py.


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