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__
 
def __getstate__ (self)
 
def __getnewargs__ (self)
 
def __setstate__ (self, dict)
 
def __len__ (self)
 
def __iter__ (self)
 
def __deepcopy__ (self, memo)
 
def __iadd__
 
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
 
def __repr__ (self)
 
def __str__
 
def __new__ (cls, args, kwargs)
 
def __init__
 
def __getstate__ (self)
 
def __getnewargs__ (self)
 
def __setstate__ (self, dict)
 
def __len__ (self)
 
def __iter__ (self)
 
def __deepcopy__ (self, memo)
 
def __iadd__
 
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
 
def __repr__ (self)
 
def __str__
 

Static Public Attributes

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)
 
def _isInSetDefaults (self)
 
def __setupServices (self)
 
def __setupDlls (self)
 
def __setupDefaults (self)
 

Static Private Member Functions

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

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.

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
303 
def GaudiKernel.Configurable.Configurable.__init__ (   self,
  name = DefaultName 
)

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

Member Function Documentation

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

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

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

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

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

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

Definition at line 383 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) )
392 
def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 318 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 318 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 305 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
317 
def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

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

Definition at line 351 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
382 
def copyChildAndSetParent(self, cfg, parent)
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.__iadd__ (   self,
  configs,
  descr = None 
)

Definition at line 351 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
382 
def copyChildAndSetParent(self, cfg, parent)
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.__iter__ (   self)

Definition at line 331 of file Configurable.py.

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

Definition at line 331 of file Configurable.py.

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

Definition at line 328 of file Configurable.py.

328  def __len__( self ):
329  return len( self.__children )
330 
def GaudiKernel.Configurable.Configurable.__len__ (   self)

Definition at line 328 of file Configurable.py.

328  def __len__( self ):
329  return len( self.__children )
330 
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.

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
254 
string type
Definition: gaudirun.py:151
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.

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
254 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.__nonzero__ (   self)

Definition at line 427 of file Configurable.py.

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

Definition at line 427 of file Configurable.py.

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

Definition at line 838 of file Configurable.py.

838  def __repr__( self ):
839  return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
840 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 838 of file Configurable.py.

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

Definition at line 393 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) )
401 
def __setattr__(self, name, value)
def GaudiKernel.Configurable.Configurable.__setattr__ (   self,
  name,
  value 
)

Definition at line 393 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) )
401 
def __setattr__(self, name, value)
def GaudiKernel.Configurable.Configurable.__setstate__ (   self,
  dict 
)

Definition at line 321 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
326 
def GaudiKernel.Configurable.Configurable.__setstate__ (   self,
  dict 
)

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

Definition at line 817 of file Configurable.py.

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

Definition at line 817 of file Configurable.py.

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

Definition at line 806 of file Configurable.py.

806  def __setupDlls( self ):
807  dlls = self.getDlls()
808  if not dlls:
809  dlls = []
810  elif type(dlls) == types.StringType:
811  dlls = [ dlls ]
812 
813  from __main__ import theApp
814  dlls = filter( lambda d: d not in theApp.Dlls, dlls )
815  if dlls: theApp.Dlls += dlls
816 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.__setupDlls (   self)
private

Definition at line 806 of file Configurable.py.

806  def __setupDlls( self ):
807  dlls = self.getDlls()
808  if not dlls:
809  dlls = []
810  elif type(dlls) == types.StringType:
811  dlls = [ dlls ]
812 
813  from __main__ import theApp
814  dlls = filter( lambda d: d not in theApp.Dlls, dlls )
815  if dlls: theApp.Dlls += dlls
816 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.__setupServices (   self)
private

Definition at line 789 of file Configurable.py.

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

Definition at line 789 of file Configurable.py.

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

Definition at line 841 of file Configurable.py.

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

Definition at line 841 of file Configurable.py.

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

Definition at line 786 of file Configurable.py.

def GaudiKernel.Configurable.Configurable._isInSetDefaults (   self)
private

Definition at line 786 of file Configurable.py.

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

Definition at line 832 of file Configurable.py.

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

Definition at line 832 of file Configurable.py.

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

Definition at line 825 of file Configurable.py.

825  def _printHeader( indentStr, title ):
826  preLen = Configurable.printHeaderPre
827  postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
828  postLen = max(preLen,postLen)
829  return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
830 
def _printHeader(indentStr, title)
def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 825 of file Configurable.py.

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

Definition at line 766 of file Configurable.py.

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

Definition at line 766 of file Configurable.py.

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

Definition at line 479 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
484 
def GaudiKernel.Configurable.Configurable.children (   self)

Definition at line 479 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
484 
def GaudiKernel.Configurable.Configurable.clone (   self,
  name = None,
  kwargs 
)

Definition at line 721 of file Configurable.py.

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

Definition at line 721 of file Configurable.py.

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

Definition at line 441 of file Configurable.py.

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

Definition at line 441 of file Configurable.py.

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

Definition at line 453 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
472 
def copyChildAndSetParent(self, cfg, parent)
def GaudiKernel.Configurable.Configurable.copyChildAndSetParent (   self,
  cfg,
  parent 
)

Definition at line 453 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
472 
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 485 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
523 
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.

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
523 
def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 473 of file Configurable.py.

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

Definition at line 473 of file Configurable.py.

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

Definition at line 613 of file Configurable.py.

614  class collector:
615  pass
616 
617  # user provided defaults
618  c = collector()
619  cls.setDefaults( c )
620 
621  # defaults from C++
622  for k,v in cls._properties.items():
623  if not k in c.__dict__ and hasattr( v, 'default' ):
624  c.__dict__[ k ] = v.default
625 
626  return c.__dict__
627 
def GaudiKernel.Configurable.Configurable.getDefaultProperties (   cls)

Definition at line 613 of file Configurable.py.

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

Definition at line 629 of file Configurable.py.

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

Definition at line 629 of file Configurable.py.

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

Definition at line 706 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 706 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 703 of file Configurable.py.

703  def getFullName( self ) :
704  return str( self.getType() + '/' + self.getName() )
705 
def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 703 of file Configurable.py.

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

Definition at line 691 of file Configurable.py.

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

Definition at line 691 of file Configurable.py.

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

Definition at line 685 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 685 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 447 of file Configurable.py.

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

Definition at line 447 of file Configurable.py.

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

Definition at line 709 of file Configurable.py.

709  def getPrintTitle(self):
710  return self.getGaudiType() + ' ' + self.getTitleName()
711 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 709 of file Configurable.py.

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

Definition at line 650 of file Configurable.py.

650  def getProp(self, name):
651  """Returns the value of the given property.
652  """
653  if hasattr(self, name):
654  return getattr(self, name)
655  else:
656  return self.getDefaultProperties()[name]
657 
def GaudiKernel.Configurable.Configurable.getProp (   self,
  name 
)
Returns the value of the given property.

Definition at line 650 of file Configurable.py.

650  def getProp(self, name):
651  """Returns the value of the given property.
652  """
653  if hasattr(self, name):
654  return getattr(self, name)
655  else:
656  return self.getDefaultProperties()[name]
657 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 562 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
571 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 562 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
571 
def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 572 of file Configurable.py.

573  """Get all properties with their description string as { name : (value, desc) }."""
574  props = {}
575  for name, proxy in self._properties.items():
576  try:
577  props[ name ] = ( proxy.__get__( self ), proxy.__doc__)
578  except AttributeError:
579  props[ name ] = ( Configurable.propertyNoValue, proxy.__doc__)
580  return props
581 
def GaudiKernel.Configurable.Configurable.getPropertiesWithDescription (   self)
Get all properties with their description string as { name : (value, desc) }.

Definition at line 572 of file Configurable.py.

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

Definition at line 524 of file Configurable.py.

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

Definition at line 524 of file Configurable.py.

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

Definition at line 712 of file Configurable.py.

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

Definition at line 712 of file Configurable.py.

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

Definition at line 476 of file Configurable.py.

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

Definition at line 476 of file Configurable.py.

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

Definition at line 682 of file Configurable.py.

682  def getType( cls ):
683  return cls.__name__
684 
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 682 of file Configurable.py.

682  def getType( cls ):
683  return cls.__name__
684 
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 582 of file Configurable.py.

582  def getValuedProperties( self ):
583  props = {}
584  for name, proxy in self._properties.items():
585  if self.isPropertySet(name):
586  value = proxy.__get__( self )
587  if hasattr(value, 'getFullName') :
588  value = value.getFullName()
589  elif type(value) in [list, tuple]:
590  new_value = []
591  for i in value:
592  if hasattr(i, 'getFullName'):
593  new_value.append(i.getFullName())
594  else:
595  new_value.append(i)
596  value = type(value)(new_value)
597  elif type(value) is dict:
598  new_value = {}
599  for i in value:
600  if hasattr(value[i], 'getFullName'):
601  new_value[i] = value[i].getFullName()
602  else:
603  new_value[i] = value[i]
604  value = new_value
605  props[ name ] = value
606 
607  return props
608 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 582 of file Configurable.py.

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

Definition at line 450 of file Configurable.py.

450  def hasParent( self, parent ):
451  return False
452 
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 450 of file Configurable.py.

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

663  def isPropertySet(self, name):
664  """Tell if the property 'name' has been set or not.
665 
666  Because of a problem with list and dictionary properties, in those cases
667  if the value is equal to the default, the property is considered as not
668  set.
669  """
670  if not hasattr(self, name):
671  return False
672  else:
673  try:
674  default = self.getDefaultProperties()[name]
675  if isinstance(default, (list, dict)):
676  value = getattr(self, name)
677  return value != default
678  except KeyError:
679  pass # no default found
680  return True
681 
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 663 of file Configurable.py.

663  def isPropertySet(self, name):
664  """Tell if the property 'name' has been set or not.
665 
666  Because of a problem with list and dictionary properties, in those cases
667  if the value is equal to the default, the property is considered as not
668  set.
669  """
670  if not hasattr(self, name):
671  return False
672  else:
673  try:
674  default = self.getDefaultProperties()[name]
675  if isinstance(default, (list, dict)):
676  value = getattr(self, name)
677  return value != default
678  except KeyError:
679  pass # no default found
680  return True
681 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 694 of file Configurable.py.

694  def isPublic( self ):
695  return True
696 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 694 of file Configurable.py.

694  def isPublic( self ):
695  return True
696 
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 698 of file Configurable.py.

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

Definition at line 698 of file Configurable.py.

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

Definition at line 688 of file Configurable.py.

688  def name( self ):
689  return self.getName()
690 
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 688 of file Configurable.py.

688  def name( self ):
689  return self.getName()
690 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 609 of file Configurable.py.

609  def properties( self ):
610  return self.getProperties() # compatibility
611 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 609 of file Configurable.py.

609  def properties( self ):
610  return self.getProperties() # compatibility
611 
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 431 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 ]
436 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 431 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 ]
436 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 437 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 437 of file Configurable.py.

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

Definition at line 718 of file Configurable.py.

718  def setDefaults( cls, handle ):
719  pass
720 
def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 718 of file Configurable.py.

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

Definition at line 444 of file Configurable.py.

444  def setParent( self, parentName ):
445  pass
446 
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 444 of file Configurable.py.

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

Definition at line 658 of file Configurable.py.

658  def setProp(self, name, value):
659  """Set the value of a given property
660  """
661  return setattr(self, name, value)
662 
def GaudiKernel.Configurable.Configurable.setProp (   self,
  name,
  value 
)
Set the value of a given property

Definition at line 658 of file Configurable.py.

658  def setProp(self, name, value):
659  """Set the value of a given property
660  """
661  return setattr(self, name, value)
662 
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 530 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
561 
def GaudiKernel.Configurable.Configurable.setup (   self)

Definition at line 530 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
561 
def GaudiKernel.Configurable.Configurable.splitName (   self)

Definition at line 750 of file Configurable.py.

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

Definition at line 750 of file Configurable.py.

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

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: