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

Constructor & Destructor Documentation

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

Definition at line 256 of file Configurable.py.

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

Definition at line 256 of file Configurable.py.

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

Member Function Documentation

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

Definition at line 336 of file Configurable.py.

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

Definition at line 336 of file Configurable.py.

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

Definition at line 409 of file Configurable.py.

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

Definition at line 409 of file Configurable.py.

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

Definition at line 384 of file Configurable.py.

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

Definition at line 384 of file Configurable.py.

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

Definition at line 319 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getnewargs__ (   self)

Definition at line 319 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.__getstate__ (   self)

Definition at line 306 of file Configurable.py.

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

Definition at line 306 of file Configurable.py.

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

Definition at line 352 of file Configurable.py.

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

Definition at line 352 of file Configurable.py.

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

Definition at line 332 of file Configurable.py.

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

Definition at line 332 of file Configurable.py.

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

Definition at line 329 of file Configurable.py.

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

Definition at line 329 of file Configurable.py.

329  def __len__( self ):
330  return len( self.__children )
331 
def GaudiKernel.Configurable.Configurable.__new__ (   cls,
  args,
  kwargs 
)
To Gaudi, any object with the same type/name is the same object. Hence,
   this is mimicked in the configuration: instantiating a new Configurable
   of a type with the same name will return the same instance.

Definition at line 121 of file Configurable.py.

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

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

Definition at line 434 of file Configurable.py.

434  def __nonzero__(self):
435  return True
436 
437 
def GaudiKernel.Configurable.Configurable.__nonzero__ (   self)

Definition at line 434 of file Configurable.py.

434  def __nonzero__(self):
435  return True
436 
437 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 843 of file Configurable.py.

843  def __repr__( self ):
844  return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
845 
def GaudiKernel.Configurable.Configurable.__repr__ (   self)

Definition at line 843 of file Configurable.py.

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

Definition at line 400 of file Configurable.py.

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

Definition at line 400 of file Configurable.py.

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

Definition at line 322 of file Configurable.py.

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

Definition at line 322 of file Configurable.py.

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

Definition at line 822 of file Configurable.py.

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

Definition at line 822 of file Configurable.py.

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

Definition at line 811 of file Configurable.py.

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

Definition at line 811 of file Configurable.py.

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

Definition at line 794 of file Configurable.py.

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

Definition at line 794 of file Configurable.py.

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

Definition at line 846 of file Configurable.py.

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

Definition at line 846 of file Configurable.py.

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

Definition at line 791 of file Configurable.py.

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

Definition at line 791 of file Configurable.py.

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

Definition at line 837 of file Configurable.py.

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

Definition at line 837 of file Configurable.py.

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

Definition at line 830 of file Configurable.py.

830  def _printHeader( indentStr, title ):
831  preLen = Configurable.printHeaderPre
832  postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
833  postLen = max(preLen,postLen)
834  return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
835 
def _printHeader(indentStr, title)
def GaudiKernel.Configurable.Configurable._printHeader (   indentStr,
  title 
)
staticprivate

Definition at line 830 of file Configurable.py.

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

Definition at line 770 of file Configurable.py.

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

Definition at line 770 of file Configurable.py.

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

Definition at line 486 of file Configurable.py.

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

Definition at line 486 of file Configurable.py.

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

Definition at line 725 of file Configurable.py.

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

Definition at line 725 of file Configurable.py.

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

Definition at line 448 of file Configurable.py.

448  def copyChild( self, child ):
449  return copy.deepcopy( child )
450 
def GaudiKernel.Configurable.Configurable.copyChild (   self,
  child 
)

Definition at line 448 of file Configurable.py.

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

Definition at line 460 of file Configurable.py.

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

Definition at line 460 of file Configurable.py.

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

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

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

Definition at line 480 of file Configurable.py.

480  def getChildren( self ):
481  return self.__children[:] # read only
482 
def GaudiKernel.Configurable.Configurable.getChildren (   self)

Definition at line 480 of file Configurable.py.

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

Definition at line 620 of file Configurable.py.

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

Definition at line 620 of file Configurable.py.

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

Definition at line 636 of file Configurable.py.

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

Definition at line 636 of file Configurable.py.

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

Definition at line 710 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullJobOptName (   self)

Definition at line 710 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 707 of file Configurable.py.

707  def getFullName( self ) :
708  return str( self.getType() + '/' + self.getName() )
709 
def GaudiKernel.Configurable.Configurable.getFullName (   self)

Definition at line 707 of file Configurable.py.

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

Definition at line 695 of file Configurable.py.

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

Definition at line 695 of file Configurable.py.

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

Definition at line 689 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getName (   self)

Definition at line 689 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 454 of file Configurable.py.

454  def getParent( self ):
455  return ""
456 
def GaudiKernel.Configurable.Configurable.getParent (   self)

Definition at line 454 of file Configurable.py.

454  def getParent( self ):
455  return ""
456 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 713 of file Configurable.py.

713  def getPrintTitle(self):
714  return self.getGaudiType() + ' ' + self.getTitleName()
715 
def GaudiKernel.Configurable.Configurable.getPrintTitle (   self)

Definition at line 713 of file Configurable.py.

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

Definition at line 657 of file Configurable.py.

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

Definition at line 657 of file Configurable.py.

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

Definition at line 569 of file Configurable.py.

569  def getProperties( self ):
570  props = {}
571  for name, proxy in self._properties.items():
572  try:
573  props[ name ] = proxy.__get__( self )
574  except AttributeError:
575  props[ name ] = Configurable.propertyNoValue
576 
577  return props
578 
def GaudiKernel.Configurable.Configurable.getProperties (   self)

Definition at line 569 of file Configurable.py.

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

Definition at line 579 of file Configurable.py.

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

Definition at line 579 of file Configurable.py.

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

Definition at line 531 of file Configurable.py.

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

Definition at line 531 of file Configurable.py.

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

Definition at line 716 of file Configurable.py.

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

Definition at line 716 of file Configurable.py.

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

Definition at line 483 of file Configurable.py.

483  def getTools( self ):
484  return self.__tools.values() # read only
485 
def GaudiKernel.Configurable.Configurable.getTools (   self)

Definition at line 483 of file Configurable.py.

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

Definition at line 686 of file Configurable.py.

686  def getType( cls ):
687  return cls.__name__
688 
def GaudiKernel.Configurable.Configurable.getType (   cls)

Definition at line 686 of file Configurable.py.

686  def getType( cls ):
687  return cls.__name__
688 
def GaudiKernel.Configurable.Configurable.getValuedProperties (   self)

Definition at line 589 of file Configurable.py.

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

Definition at line 589 of file Configurable.py.

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

Definition at line 457 of file Configurable.py.

457  def hasParent( self, parent ):
458  return False
459 
def GaudiKernel.Configurable.Configurable.hasParent (   self,
  parent 
)

Definition at line 457 of file Configurable.py.

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

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

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

Definition at line 698 of file Configurable.py.

698  def isPublic( self ):
699  return True
700 
def GaudiKernel.Configurable.Configurable.isPublic (   self)

Definition at line 698 of file Configurable.py.

698  def isPublic( self ):
699  return True
700 
def GaudiKernel.Configurable.Configurable.jobOptName (   self)

Definition at line 702 of file Configurable.py.

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

Definition at line 702 of file Configurable.py.

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

Definition at line 692 of file Configurable.py.

692  def name( self ):
693  return self.getName()
694 
def GaudiKernel.Configurable.Configurable.name (   self)

Definition at line 692 of file Configurable.py.

692  def name( self ):
693  return self.getName()
694 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 616 of file Configurable.py.

616  def properties( self ):
617  return self.getProperties() # compatibility
618 
def GaudiKernel.Configurable.Configurable.properties (   self)

Definition at line 616 of file Configurable.py.

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

Definition at line 438 of file Configurable.py.

438  def remove( self, items ):
439  if type(items) != list and type(items) != tuple:
440  items = [ items ]
441 
442  self.__children = [ e for e in self.__children if not e in items ]
443 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.remove (   self,
  items 
)

Definition at line 438 of file Configurable.py.

438  def remove( self, items ):
439  if type(items) != list and type(items) != tuple:
440  items = [ items ]
441 
442  self.__children = [ e for e in self.__children if not e in items ]
443 
string type
Definition: gaudirun.py:151
def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 444 of file Configurable.py.

def GaudiKernel.Configurable.Configurable.removeAll (   self)

Definition at line 444 of file Configurable.py.

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

Definition at line 722 of file Configurable.py.

722  def setDefaults( cls, handle ):
723  pass
724 
def GaudiKernel.Configurable.Configurable.setDefaults (   cls,
  handle 
)

Definition at line 722 of file Configurable.py.

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

Definition at line 451 of file Configurable.py.

451  def setParent( self, parentName ):
452  pass
453 
def GaudiKernel.Configurable.Configurable.setParent (   self,
  parentName 
)

Definition at line 451 of file Configurable.py.

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

Definition at line 665 of file Configurable.py.

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

Definition at line 665 of file Configurable.py.

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

Definition at line 537 of file Configurable.py.

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

Definition at line 537 of file Configurable.py.

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

Definition at line 754 of file Configurable.py.

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

Definition at line 754 of file Configurable.py.

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

Member Data Documentation

GaudiKernel.Configurable.Configurable.__children
private

Definition at line 284 of file Configurable.py.

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

Definition at line 104 of file Configurable.py.

tuple GaudiKernel.Configurable.Configurable.__slots__
staticprivate
Initial value:
1 = (
2  '__children', # controlled components, e.g. private AlgTools
3  '__tools', # private AlgTools (#PM-->)
4  '_name', # the (unqualified) component name
5  '_inSetDefaults', # currently setting default values
6  '_initok', # used to enforce base class init
7  '_setupok' # for debugging purposes (temporary)
8  )

Definition at line 106 of file Configurable.py.

GaudiKernel.Configurable.Configurable.__tools
private

Definition at line 285 of file Configurable.py.

GaudiKernel.Configurable.Configurable._configurationLocked = False
staticprivate

Definition at line 119 of file Configurable.py.

GaudiKernel.Configurable.Configurable._initok
private

Definition at line 300 of file Configurable.py.

GaudiKernel.Configurable.Configurable._inSetDefaults
private

Definition at line 297 of file Configurable.py.

GaudiKernel.Configurable.Configurable._name
private

Definition at line 290 of file Configurable.py.

GaudiKernel.Configurable.Configurable._setupok
private

Definition at line 303 of file Configurable.py.

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

Definition at line 115 of file Configurable.py.

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

Definition at line 116 of file Configurable.py.

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

Definition at line 100 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderPre = 5
static

Definition at line 102 of file Configurable.py.

int GaudiKernel.Configurable.Configurable.printHeaderWidth = 100
static

Definition at line 101 of file Configurable.py.


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