| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# Configurable::Configurable Class Reference

Inheritance diagram for Configurable::Configurable:

[legend]
Collaboration diagram for Configurable::Configurable:

[legend]

List of all members.

## Public Member Functions
def | __new__
def | __init__
def | __getstate__
def | __getnewargs__
def | __setstate__
def | __len__
def | __iter__
def | __deepcopy__
def | __iadd__
def | __getattr__
def | __setattr__
def | __delattr__
def | __nonzero__
def | remove
def | removeAll
def | copyChild
def | setParent
def | getParent
def | hasParent
def | copyChildAndSetParent
def | getChildren
def | getTools
def | children
def | getAllChildren
def | getSequence
def | setup
def | getProperties
def | getValuedProperties
def | properties
def | getDefaultProperties
def | getDefaultProperty
def | getProp
def | setProp
def | isPropertySet
def | getType
def | getName
def | name
def | getJobOptName
def | isPublic
def | jobOptName
def | getFullName
def | getFullJobOptName
def | getPrintTitle
def | getTitleName
def | setDefaults
def | clone
def | splitName
def | addTool
def | __repr__
def | __str__
## Static Public Attributes
string | propertyNoValue = '<no value>'
string | indentUnit = '| '
int | printHeaderWidth = 100
int | printHeaderPre = 5
dictionary | allConfigurables = {}
dictionary | configurableServices = {}
## Private Member Functions
def | _isInSetDefaults
def | __setupServices
def | __setupDlls
def | __setupDefaults
def | _printHeader
def | _printFooter
## Private Attributes
| __children
| __tools
| _name
| _inSetDefaults
| _initok
| _setupok
## Static Private Attributes
| __metaclass__ = ConfigurableMeta.ConfigurableMeta
tuple | __slots__
| _configurationLocked = False
## Classes
class | DefaultName
| for detecting the default name More...

## Detailed Description

    Base class for Gaudi components that implement the IProperty interface.
       Provides most of the boilerplate code, but the actual useful classes
       are its derived ConfigurableAlgorithm, ConfigurableService, and
       ConfigurableAlgTool.

Definition at line 87 of file Configurable.py.

## Member Function Documentation

def Configurable::Configurable::__new__ | ( |  | cls,
|  |  | args,
|  |  | kwargs |
| ) |  |  |

    To Gaudi, any object with the same type/name is the same object. Hence,
       this is mimicked in the configuration: instantiating a new Configurable
       of a type with the same name will return the same instance.

Definition at line 119 of file Configurable.py.

    00119                                         :
    00120         """To Gaudi, any object with the same type/name is the same object. Hence,
    00121            this is mimicked in the configuration: instantiating a new Configurable
    00122            of a type with the same name will return the same instance."""
    00123
    00124         global log
    00125         # try to get the name of the Configurable (having a name is compulsory)
    00126         if 'name' in kwargs:
    00127         # simple keyword (by far the easiest)
    00128             name = kwargs[ 'name' ]
    00129         elif 'name' in cls.__init__.func_code.co_varnames:
    00130         # either positional in args, or default
    00131             index =  list(cls.__init__.func_code.co_varnames).index( 'name' )
    00132             try:
    00133              # var names index is offset by one as __init__ is to be called with self
    00134                 name = args[ index - 1 ]
    00135             except IndexError:
    00136              # retrieve default value, then
    00137                 name = cls.__init__.func_defaults[ index - (len(args)+1) ]
    00138         else:
    00139         # positional index is assumed (will work most of the time)
    00140             try:
    00141                 name = args[1]    # '0' is for self
    00142             except (IndexError,TypeError):
    00143                 raise TypeError( 'no "name" argument while instantiating "%s"' % cls.__name__ )
    00144
    00145         argname = name
    00146         if name == Configurable.DefaultName :
    00147             if hasattr(cls, 'DefaultedName' ) :
    00148                 name = cls.DefaultedName
    00149             else :
    00150                 name = cls.getType()
    00151         elif not name or type(name) != str:
    00152         # unnamed, highly specialized user code, etc. ... unacceptable
    00153             raise TypeError( 'could not retrieve name from %s.__init__ arguments' % cls.__name__ )
    00154
    00155         # Handle the case of global tools to prepend ToolSvc in the name.
    00156         # This is needed for compatibility with old JobOptions files being read
    00157         if issubclass( cls, ConfigurableAlgTool) and '.' not in name :
    00158             name = 'ToolSvc.' + name
    00159
    00160         # close backdoor access to otherwise private subalgs/tools
    00161         #PM if 0 <= name.find( '.' ):
    00162         #PM # temp protection for old style types
    00163         #PM   from OldStyleConfig import GenericConfigurable
    00164         #PM   if not issubclass( cls, GenericConfigurable ): # except raised for new types only
    00165         #PM      raise NameError( '"%s": backdoor access to private configurables not allowed' % name )
    00166
    00167         # ordinary recycle case
    00168         if name in cls.configurables:
    00169             conf = cls.configurables[ name ]
    00170             if name != argname:      # special case: user derived <-> real ... make same
    00171                 cls.configurables[ conf.getType() ] = conf
    00172             #---PM: Initialize additional properties
    00173             for n,v in kwargs.items():
    00174                 setattr(conf, n, v)
    00175             if not cls._configurationLocked and not "_enabled" in kwargs and isinstance(conf, ConfigurableUser):
    00176                 # Ensure that the ConfigurableUser gets enabled if nothing is
    00177                 # specified in the constructor.
    00178                 setattr(conf, "_enabled", True)
    00179             return conf
    00180
    00181         # a couple of special cases (note that these cases don't mix)
    00182         spos = name.find( '/' )
    00183         ti_name = None
    00184         if spos < 0:
    00185             ti_name = "%s/%s" % (name,name)
    00186             if ti_name in cls.configurables:
    00187                 # support for old-style name as type/name lookup where name==type
    00188                 return cls.configurables[ ti_name ]
    00189
    00190         i_name = None
    00191         if spos > 0:
    00192             i_name = name[:spos]
    00193             if i_name == name[spos+1:] and i_name in cls.configurables:
    00194             # this is the opposite of the above special case
    00195                 return cls.configurables[ i_name ]
    00196
    00197         # the following is purely for debugging support and should realistically bomb
    00198         conf = cls.allConfigurables.get( name, None ) or\
    00199                  (spos < 0 and cls.allConfigurables.get( ti_name, None )) or\
    00200                  (spos > 0 and i_name == name[spos+1:] and cls.allConfigurables.get( i_name, None ))
    00201         if conf:                    # wrong type used?
    00202             if conf.__class__ is ConfigurableGeneric :
    00203                 #  If the instance found is ConfigurableGeneric then
    00204                 #  we create a new one with the proper type and fill with
    00205                 #  the contents of the generic one
    00206                 newconf = object.__new__( cls, *args, **kwargs )
    00207                 cls.__init__( newconf, *args )
    00208                 #  initialize with the properties of generic configurable
    00209                 #  (we map the names of the properties to lowercase versions because
    00210                 #  old options are not case sensitive)
    00211                 names = {}
    00212                 for n in newconf.__slots__:
    00213                     names[n.lower()] = n
    00214                 for n in conf._properties:
    00215                     if names[n.lower()] != n:
    00216                         log.warning( "Option '%s' was used for %s, but the correct spelling is '%s'"%(n,name,names[n.lower()]) )
    00217                     setattr(newconf, names[n.lower()], getattr( conf, n ) )
    00218                 for n,v in kwargs.items():
    00219                     setattr(newconf, n, v)
    00220                 cls.configurables[ name ] = newconf
    00221                 cls.allConfigurables[ name ] = newconf
    00222                 return newconf
    00223             else :
    00224                 #  will be an actual error in the future (now only report as such)
    00225                 log.error( 'attempt to redefine type of "%s" (was: %s, new: %s)%s',
    00226                 name, conf.__class__.__name__, cls.__name__, error_explanation )
    00227                 #  in the future:
    00228                 #  return None             # will bomb on use (or go unharmed on non-use)
    00229                 #  for now, allow use through allConfigurables lookup
    00230                 #---PM: Initialize additional properties
    00231                 for n,v in kwargs.items():
    00232                     setattr(conf, n, v)
    00233                 return conf
    00234
    00235         # still here: create a new instance and initialize it
    00236         conf = object.__new__( cls, *args, **kwargs )
    00237         cls.__init__( conf, *args, **kwargs )
    00238
    00239         # update normal, per-class cache
    00240         cls.configurables[ name ] = conf
    00241
    00242         for base in cls.__bases__:
    00243             if base.__name__ == 'ConfigurableService':
    00244                 cls.configurableServices[ name ] = conf
    00245
    00246         # update generics super-cache, if needed
    00247         cls.allConfigurables[ name ] = conf
    00248         #-->PM#if hasattr( cls, 'getType' ) and name.find('/') < 0:
    00249         #-->PM#   cls.allConfigurables[ cls.getType() + '/' + name ] = conf
    00250
    00251         return conf
    00252
        def __init__( self, name = DefaultName ):

def Configurable::Configurable::__init__ | ( |  | self,
|  |  | name = `DefaultName` |
| ) |  |  |

Reimplemented in Configurable::ConfigurableGeneric, Configurable::ConfigurableAlgorithm, Configurable::ConfigurableAlgTool, and Configurable::ConfigurableAuditor.

Definition at line 253 of file Configurable.py.

    00253                                             :
    00254         # check class readiness, all required overloads should be there now
    00255         klass = self.__class__
    00256
    00257         # this is an abstract class
    00258         if klass == Configurable:
    00259             raise TypeError, "%s is an ABC and can not be instantiated" % str(Configurable)
    00260
    00261         # the following methods require overloading
    00262         #NOT YET  meths = { 'getServices'   : 1,    # retrieve list of services to configure
    00263         meths = { 'getDlls'       : 1,    # provide list of Dlls to load
    00264                   'getGaudiType'  : 1,    # return string describing component class
    00265                   'getHandle'     : 1 }   # provide access to C++ side component instance
    00266 #                'getType'       : 1 }   # return the type of the actual C++ component
    00267
    00268         for meth, nArgs in meths.items():
    00269             try:
    00270                 f = getattr( klass, meth ).im_func
    00271             except AttributeError:
    00272                 raise NotImplementedError, "%s is missing in class %s" % (meth,str(klass))
    00273
    00274             # in addition, verify the number of arguments w/o defaults
    00275             nargcount = f.func_code.co_argcount
    00276             ndefaults = f.func_defaults and len(f.func_defaults) or 0
    00277             if not nargcount - ndefaults <= nArgs <= nargcount:
    00278                 raise TypeError, "%s.%s requires exactly %d arguments" % (klass,meth,nArgs)
    00279
    00280         # for using this Configurable as a (Gaudi) sequence
    00281         self.__children = []
    00282         self.__tools = {}
    00283
    00284         # know who we are
    00285         if name == Configurable.DefaultName :
    00286             if hasattr(self.__class__, 'DefaultedName' ) :
    00287                 self._name = self.__class__.DefaultedName
    00288             else :
    00289                 self._name = self.getType()
    00290         else :
    00291             self._name = name
    00292
    00293         # set to True when collecting defaults, False otherwise
    00294         self._inSetDefaults = False
    00295
    00296         # for later, in case __init__ itself is overridden
    00297         self._initok = True
    00298
    00299         # for debugging purposes (temporary)
    00300         self._setupok = False
    00301
    00302     # pickle support
        def __getstate__ (self):

def Configurable::Configurable::__getstate__ | ( |  | self | ) |

Definition at line 303 of file Configurable.py.

    00303                            :
    00304         dict = {}
    00305         for name, proxy in self._properties.items():
    00306             try:
    00307                 dict[ name ] = proxy.__get__( self )
    00308             except AttributeError:
    00309                 pass
    00310
    00311         dict[ '_Configurable__children' ] = self.__children
    00312         dict[ '_Configurable__tools' ] = self.__tools
    00313         dict[ '_name' ] = self._name
    00314         return dict
    00315
        def __getnewargs__(self) :

def Configurable::Configurable::__getnewargs__ | ( |  | self | ) |

Definition at line 316 of file Configurable.py.

    00316                              :
    00317         return (self._name,)
    00318
        def __setstate__ ( self, dict ):

def Configurable::Configurable::__setstate__ | ( |  | self,
|  |  | dict |
| ) |  |  |

Definition at line 319 of file Configurable.py.

    00319                                    :
    00320         self._initok = True
    00321         for n, v in dict.items():
    00322             setattr (self, n, v)
    00323         return
    00324
    00325     # to allow a few basic sanity checks, as well as nice syntax
        def __len__( self ):

def Configurable::Configurable::__len__ | ( |  | self | ) |

Definition at line 326 of file Configurable.py.

    00326                        :
    00327         return len( self.__children )
    00328
        def __iter__( self ):

def Configurable::Configurable::__iter__ | ( |  | self | ) |

Definition at line 329 of file Configurable.py.

    00329                         :
    00330         return iter( self.__children )
    00331
    00332     # ownership rules of self through copying
        def __deepcopy__( self, memo ):

def Configurable::Configurable::__deepcopy__ | ( |  | self,
|  |  | memo |
| ) |  |  |

Reimplemented in Configurable::ConfigurableGeneric, Configurable::ConfigurableAlgorithm, and Configurable::ConfigurableService.

Definition at line 333 of file Configurable.py.

    00333                                   :
    00334         newconf = object.__new__( self.__class__, self.getName() )
    00335         self.__class__.__init__( newconf, self.getName() )
    00336
    00337         for proxy in self._properties.values():
    00338             try:
    00339                 proxy.__set__( newconf, proxy.__get__( self ) )
    00340             except AttributeError:
    00341                 pass                   # means property was not set for self
    00342
    00343         for c in self.__children:
    00344             newconf += c              # processes proper copy semantics
    00345
    00346         return newconf
    00347
    00348     # hierarchy building, and ownership rules of children
        def __iadd__( self, configs, descr = None ):

def Configurable::Configurable::__iadd__ | ( |  | self,
|  |  | configs,
|  |  | descr = `None` |
| ) |  |  |

Definition at line 349 of file Configurable.py.

    00349                                                :
    00350         if not type(configs) in (list,tuple):
    00351             configs = ( configs, )
    00352
    00353         joname = self.getJobOptName()
    00354
    00355         for cfg in configs:
    00356             # prevent type mismatches
    00357             if not isinstance( cfg, Configurable ):
    00358                 raise TypeError( "'%s' is not a Configurable" % str(cfg) )
    00359
    00360             cc = self.copyChildAndSetParent( cfg, joname )
    00361
    00362             # filters dupes; usually "ok" (backdoor should catch them)
    00363             ccjo = cc.getJobOptName()
    00364             for c in self.__children:
    00365                 if c.getJobOptName() == ccjo:
    00366                     log.error( 'attempt to add a duplicate ... dupe ignored%s', error_explanation )
    00367                     break
    00368             else:
    00369                 self.__children.append( cc )
    00370
    00371             try:
    00372                 if descr:         # support for tool properties
    00373                     descr.__set__( self, cc )
    00374                 else:
    00375                     setattr( self, cc.getName(), cc )
    00376             except AttributeError:
    00377                 pass              # to allow free addition of tools/subalgorithms
    00378
    00379         return self
    00380
        def __getattr__( self, attr ):  # until ToolProperties exist ...

def Configurable::Configurable::__getattr__ | ( |  | self,
|  |  | attr |
| ) |  |  |

Definition at line 381 of file Configurable.py.

    00381                                  :  # until ToolProperties exist ...
    00382
    00383         if attr in self.__tools : return self.__tools[attr]
    00384
    00385         for c in self.__children:
    00386             if c.getName() == attr:
    00387                 return c
    00388
    00389         raise AttributeError( "'%s' object has no attribute '%s'" % (self.__class__,attr) )
    00390

def Configurable::Configurable::__setattr__ | ( |  | self,
|  |  | name,
|  |  | value |
| ) |  |  |

Reimplemented in Configurable::ConfigurableGeneric.

Definition at line 391 of file Configurable.py.

    00391                                          :
    00392         if self._configurationLocked:
    00393             raise RuntimeError("%s: Configuration cannot be modified after the ApplicationMgr has been started."%self.name())
    00394         try :
    00395             super( Configurable, self ).__setattr__( name, value )
    00396         except AttributeError:
    00397             raise AttributeError( "Configurable '%s' does not have property '%s'."
    00398                                   % ( self.__class__.__name__, name) )
    00399
        def __delattr__( self, attr ):

def Configurable::Configurable::__delattr__ | ( |  | self,
|  |  | attr |
| ) |  |  |

Definition at line 400 of file Configurable.py.

    00400                                  :
    00401         # remove as property, otherwise try as child
    00402         try:
    00403             # remove history etc., then reset to default (in case set before)
    00404             prop = self._properties[ attr ]
    00405             prop.__delete__( self )
    00406             prop.__set__( self, prop.default )
    00407             return               # reaches here? was property: done now
    00408         except KeyError:
    00409             pass
    00410         # otherwise, remove the private tool
    00411         if attr in self.__tools :
    00412             del self.__tools[attr]
    00413
    00414         # otherwise, remove child, if one is so named
    00415         for c in self.__children:
    00416             if c.getName() == attr:
    00417                 self.__children.remove( c )
    00418
    00419         # potentially, there are left over caches (certain user derived classes)
    00420         try:
    00421             del self.__dict__[ attr ]
    00422         except (AttributeError,KeyError):
    00423             pass
    00424
        def __nonzero__(self):

def Configurable::Configurable::__nonzero__ | ( |  | self | ) |

Definition at line 425 of file Configurable.py.

    00425                          :
    00426         return True
    00427
    00428
        def remove( self, items ):

def Configurable::Configurable::remove | ( |  | self,
|  |  | items |
| ) |  |  |

Definition at line 429 of file Configurable.py.

    00429                              :
    00430         if type(items) != list and type(items) != tuple:
    00431             items = [ items ]
    00432
    00433         self.__children = [ e for e in self.__children if not e in items ]
    00434
        def removeAll( self ):

def Configurable::Configurable::removeAll | ( |  | self | ) |

Definition at line 435 of file Configurable.py.

    00435                          :
    00436         self.remove( self.__children )
    00437
    00438     # called by __iadd__; determines child copy semantics
        def copyChild( self, child ):

def Configurable::Configurable::copyChild | ( |  | self,
|  |  | child |
| ) |  |  |

Reimplemented in Configurable::ConfigurableService.

Definition at line 439 of file Configurable.py.

    00439                                 :
    00440         return copy.deepcopy( child )
    00441
        def setParent( self, parentName ):

def Configurable::Configurable::setParent | ( |  | self,
|  |  | parentName |
| ) |  |  |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 442 of file Configurable.py.

    00442                                      :
    00443         pass
    00444
        def getParent( self ):

def Configurable::Configurable::getParent | ( |  | self | ) |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 445 of file Configurable.py.

    00445                          :
    00446         return ""
    00447
        def hasParent( self, parent ):

def Configurable::Configurable::hasParent | ( |  | self,
|  |  | parent |
| ) |  |  |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 448 of file Configurable.py.

    00448                                  :
    00449         return False
    00450
        def copyChildAndSetParent(self,cfg,parent):

def Configurable::Configurable::copyChildAndSetParent | ( |  | self,
|  |  | cfg,
|  |  | parent |
| ) |  |  |

Definition at line 451 of file Configurable.py.

    00451                                               :
    00452         cc = self.copyChild( cfg )
    00453
    00454         if hasattr( cc, 'setParent' ) and parent:
    00455             try:
    00456                 cc.setParent( parent )
    00457             except RuntimeError, e:
    00458                 # temporary backdoor resolution for compatibility
    00459                 log.error( str(e) + '%s', error_explanation )
    00460                 ccbd = cc.configurables[ cc.getJobOptName() ]
    00461
    00462                 # merge properties, new over pre-existing
    00463                 for proxy in self._properties.values():
    00464                     if proxy.history.has_key( cc ):
    00465                         proxy.__set__( ccbd, proxy.__get__( cc ) )
    00466
    00467                 # consolidate
    00468                 cc = ccbd
    00469         return cc
    00470
        def getChildren( self ):

def Configurable::Configurable::getChildren | ( |  | self | ) |

Definition at line 471 of file Configurable.py.

    00471                            :
    00472         return self.__children[:]    # read only
    00473
        def getTools( self ):

def Configurable::Configurable::getTools | ( |  | self | ) |

Definition at line 474 of file Configurable.py.

    00474                         :
    00475         return self.__tools.values()    # read only
    00476
        def children( self ):

def Configurable::Configurable::children | ( |  | self | ) |

Definition at line 477 of file Configurable.py.

    00477                         :
    00478         log.error( "children() is deprecated, use getChildren() instead for consistency" )
    00479         log.error( "getChildren() returns a copy; to add a child, use 'parent += child'%s",
    00480                    error_explanation )
    00481         return self.__children       # by ref, for compatibility
    00482
        def getAllChildren( self ):

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

    00483                               :
    00484         """Get all (private) configurable children, both explicit ones (added with +=)
    00485         and the ones in the private GaudiHandle properties"""
    00486         childs = []
    00487         # add private configurable properties (also inside handles)
    00488         for proxy in self._properties.values():
    00489             try:
    00490                 c = proxy.__get__( self )
    00491             except AttributeError:
    00492                 pass
    00493             else:
    00494                 if isinstance(c,Configurable) and not c.isPublic():
    00495                     childs.append(c)
    00496                 elif isinstance(c,GaudiHandle):
    00497                     try:
    00498                         conf = c.configurable
    00499                     except AttributeError:
    00500                         pass
    00501                     else:
    00502                         if not conf.isPublic():
    00503                             childs.append(conf)
    00504                 elif isinstance(c,GaudiHandleArray):
    00505                     # only setup private arrays
    00506                     if not c.isPublic():
    00507                         for ci in c:
    00508                             if isinstance(ci,Configurable):
    00509                                 childs.append(ci)
    00510                             else:
    00511                                 try:
    00512                                     conf = ci.configurable
    00513                                 except AttributeError:
    00514                                     pass
    00515                                 else:
    00516                                     childs.append(conf)
    00517
    00518         # add explicit children
    00519         childs += self.__children
    00520         return childs
    00521
        def getSequence( self ):

def Configurable::Configurable::getSequence | ( |  | self | ) |

Definition at line 522 of file Configurable.py.

    00522                            :
    00523         elems = []
    00524         for c in self.__children:
    00525             elems.append( c.getFullName() )
    00526         return elems
    00527
        def setup( self ):

def Configurable::Configurable::setup | ( |  | self | ) |

Definition at line 528 of file Configurable.py.

    00528                      :
    00529         # make sure base class init has been called
    00530         if not hasattr(self,'_initok') or not self._initok:
    00531         # could check more, but this is the only explanation
    00532             raise TypeError, \
    00533                "Configurable.__init__ not called in %s override" % self.__class__.__name__
    00534
    00535 #      log.debug("calling setup() on " + self.getFullJobOptName())
    00536
    00537         # setup self: this collects all values on the python side
    00538         self.__setupServices()
    00539         self.__setupDlls()
    00540         self.__setupDefaults()
    00541
    00542         # setup children
    00543         for c in self.getAllChildren():
    00544             c.setup()
    00545
    00546         # now get handle to work with for moving properties into the catalogue
    00547         handle = self.getHandle()
    00548         if not handle:
    00549             log.debug( 'no handle for %s: not transporting properties', self._name )
    00550             return                    # allowed, done early
    00551
    00552         # pass final set of properties on to handle on the C++ side or JobOptSvc
    00553         for name in self._properties.keys():
    00554             if hasattr( self, name ): # means property has python-side value/default
    00555                 setattr( handle, name, getattr(self,name) )
    00556
    00557         # for debugging purposes
    00558         self._setupok = True
    00559
        def getProperties( self ):

def Configurable::Configurable::getProperties | ( |  | self | ) |

Definition at line 560 of file Configurable.py.

    00560                              :
    00561         props = {}
    00562         for name, proxy in self._properties.items():
    00563             try:
    00564                 props[ name ] = proxy.__get__( self )
    00565             except AttributeError:
    00566                 props[ name ] = Configurable.propertyNoValue
    00567
    00568         return props
    00569
        def getValuedProperties( self ):

def Configurable::Configurable::getValuedProperties | ( |  | self | ) |

Definition at line 570 of file Configurable.py.

    00570                                    :
    00571         props = {}
    00572         for name, proxy in self._properties.items():
    00573             if self.isPropertySet(name):
    00574                 value = proxy.__get__( self )
    00575                 if hasattr(value, 'getFullName') :
    00576                     value = value.getFullName()
    00577                 elif type(value) in [list, tuple]:
    00578                     new_value = []
    00579                     for i in value:
    00580                         if hasattr(i, 'getFullName'):
    00581                             new_value.append(i.getFullName())
    00582                         else:
    00583                             new_value.append(i)
    00584                     value = type(value)(new_value)
    00585                 elif type(value) is dict:
    00586                     new_value = {}
    00587                     for i in value:
    00588                         if hasattr(value[i], 'getFullName'):
    00589                             new_value[i] = value[i].getFullName()
    00590                         else:
    00591                             new_value[i] = value[i]
    00592                     value = new_value
    00593                 props[ name ] = value
    00594
    00595         return props
    00596
        def properties( self ):

def Configurable::Configurable::properties | ( |  | self | ) |

Definition at line 597 of file Configurable.py.

    00597                           :
    00598         return self.getProperties()           # compatibility
    00599
    00600     @classmethod
        def getDefaultProperties( cls ):

def Configurable::Configurable::getDefaultProperties | ( |  | cls | ) |

Definition at line 601 of file Configurable.py.

    00601                                    :
    00602         class collector:
    00603             pass
    00604
    00605         # user provided defaults
    00606         c = collector()
    00607         cls.setDefaults( c )
    00608
    00609         # defaults from C++
    00610         for k,v in cls._properties.items():
    00611             if not k in c.__dict__ and hasattr( v, 'default' ):
    00612                 c.__dict__[ k ] = v.default
    00613
    00614         return c.__dict__
    00615
    00616     @classmethod
        def getDefaultProperty( cls, name ):

def Configurable::Configurable::getDefaultProperty | ( |  | cls,
|  |  | name |
| ) |  |  |

Definition at line 617 of file Configurable.py.

    00617                                        :
    00618         class collector:
    00619             pass
    00620
    00621         # user provided defaults
    00622         c = collector()
    00623         cls.setDefaults( c )
    00624
    00625         if name in c.__dict__:
    00626             return c.__dict__[ name ]
    00627
    00628         # defaults from C++
    00629         try:
    00630             v = cls._properties[name]
    00631             if hasattr( v, 'default' ):
    00632                 return v.default
    00633         except KeyError:
    00634             pass
    00635
    00636         return None
    00637
        def getProp(self, name):

def Configurable::Configurable::getProp | ( |  | self,
|  |  | name |
| ) |  |  |

    Returns the value of the given property.

Definition at line 638 of file Configurable.py.

    00638                            :
    00639         """Returns the value of the given property.
    00640         """
    00641         if hasattr(self, name):
    00642             return getattr(self, name)
    00643         else:
    00644             return self.getDefaultProperties()[name]
    00645
        def setProp(self, name, value):

def Configurable::Configurable::setProp | ( |  | self,
|  |  | name,
|  |  | value |
| ) |  |  |

    Set the value of a given property

Definition at line 646 of file Configurable.py.

    00646                                   :
    00647         """Set the value of a given property
    00648         """
    00649         return setattr(self, name, value)
    00650
        def isPropertySet(self, name):

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

    00651                                  :
    00652         """Tell if the property 'name' has been set or not.
    00653
    00654         Because of a problem with list and dictionary properties, in those cases
    00655         if the value is equal to the default, the property is considered as not
    00656         set.
    00657         """
    00658         if not hasattr(self, name):
    00659             return False
    00660         else:
    00661             try:
    00662                 default = self.getDefaultProperties()[name]
    00663                 if isinstance(default, (list, dict)):
    00664                     value = getattr(self, name)
    00665                     return value != default
    00666             except KeyError:
    00667                 pass # no default found
    00668             return True
    00669
        def getType( cls ):

def Configurable::Configurable::getType | ( |  | cls | ) |

Definition at line 670 of file Configurable.py.

    00670                       :
    00671         return cls.__name__
    00672
        def getName( self ):

def Configurable::Configurable::getName | ( |  | self | ) |

Definition at line 673 of file Configurable.py.

    00673                        :
    00674         return self._name
    00675
        def name( self ):

def Configurable::Configurable::name | ( |  | self | ) |

Definition at line 676 of file Configurable.py.

    00676                     :
    00677         return self.getName()
    00678
        def getJobOptName( self ):               # full hierachical name

def Configurable::Configurable::getJobOptName | ( |  | self | ) |

Reimplemented in Configurable::ConfigurableGeneric, Configurable::ConfigurableAlgorithm, Configurable::ConfigurableAlgTool, and Configurable::ConfigurableAuditor.

Definition at line 679 of file Configurable.py.

    00679                              :               # full hierachical name
    00680         return self.getName()
    00681

def Configurable::Configurable::isPublic | ( |  | self | ) |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 682 of file Configurable.py.

    00682                         :
    00683         return True
    00684
    00685     # for a couple of existing uses out there
        def jobOptName( self ):

def Configurable::Configurable::jobOptName | ( |  | self | ) |

Definition at line 686 of file Configurable.py.

    00686                           :
    00687         log.error( "jobOptName() is deprecated, use getJobOptName() instead for consistency%s",
    00688                    error_explanation )
    00689         return self.getJobOptName()           # compatibility
    00690
        def getFullName( self ) :

def Configurable::Configurable::getFullName | ( |  | self | ) |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 691 of file Configurable.py.

    00691                             :
    00692         return str( self.getType() + '/' + self.getName() )
    00693
        def getFullJobOptName( self ):

def Configurable::Configurable::getFullJobOptName | ( |  | self | ) |

Definition at line 694 of file Configurable.py.

    00694                                  :
    00695         return "%s/%s" % (self.getType(),self.getJobOptName() or self.getName())
    00696
        def getPrintTitle(self):

def Configurable::Configurable::getPrintTitle | ( |  | self | ) |

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 697 of file Configurable.py.

    00697                            :
    00698         return self.getGaudiType() + ' ' + self.getTitleName()
    00699
        def getTitleName( self ):

def Configurable::Configurable::getTitleName | ( |  | self | ) |

Definition at line 700 of file Configurable.py.

    00700                             :
    00701         if log.isEnabledFor( logging.DEBUG ):
    00702             return self.getFullJobOptName()
    00703         else:
    00704             return self.getFullName()
    00705
        def setDefaults( cls, handle ):

def Configurable::Configurable::setDefaults | ( |  | cls,
|  |  | handle |
| ) |  |  |

Definition at line 706 of file Configurable.py.

    00706                                   :
    00707         pass
    00708
        def clone( self, name = None, **kwargs  ) :

def Configurable::Configurable::clone | ( |  | self,
|  |  | name = `None`,
|  |  | kwargs |
| ) |  |  |

Definition at line 709 of file Configurable.py.

    00709                                               :
    00710         if not name :
    00711             if hasattr(self, 'DefaultedName' ) : name = self.DefaultedName
    00712             else                               : name = self.getType()
    00713
    00714         newconf = Configurable.__new__( self.__class__, name )
    00715         self.__class__.__init__( newconf, name )
    00716
    00717         for proxy in self._properties.values():
    00718             try :
    00719                 value = proxy.__get__( self )
    00720                 if type(value) in [ str, list, dict, tuple ]:
    00721                     # clone the values of the properties for basic types
    00722                     value = type(value)(value)
    00723                 proxy.__set__( newconf, value )
    00724             except AttributeError:
    00725                 pass
    00726
    00727         for c in self.__children:
    00728             newconf += c              # processes proper copy semantics
    00729
    00730         for n , t in self.__tools.items():
    00731             newconf.addTool(t, n)
    00732
    00733         for name, value in kwargs.items():
    00734             setattr(newconf, name, value)
    00735
    00736         return newconf
    00737
        def splitName( self ) :

def Configurable::Configurable::splitName | ( |  | self | ) |

Definition at line 738 of file Configurable.py.

    00738                           :
    00739         fullname = self.getName()
    00740         dot = fullname.find('.')
    00741         if dot != -1 :
    00742             parentname = fullname[:dot]
    00743             longname = fullname[dot+1:]
    00744         else :
    00745             parentname = ''
    00746             longname = fullname
    00747         dot = longname.find('.')
    00748         if dot != -1 :
    00749             name = longname[:dot]
    00750         else :
    00751             name = longname
    00752         return parentname, name, longname
    00753
        def addTool( self, tool, name = None ) :

def Configurable::Configurable::addTool | ( |  | self,
|  |  | tool,
|  |  | name = `None` |
| ) |  |  |

Definition at line 754 of file Configurable.py.

    00754                                            :
    00755         if isclass(tool) and issubclass(tool, ConfigurableAlgTool):
    00756             if name is None:
    00757                 name = tool.__name__
    00758             priv_tool = tool( self.getName()+ '.' + name )
    00759         elif isinstance(tool, ConfigurableAlgTool):
    00760             if name is None:
    00761                 name = tool.splitName()[1]
    00762             priv_tool = tool.clone( self.getName()+ '.' + name )
    00763         else:
    00764             if isclass(tool):
    00765                 classname = tool.__name__
    00766             else:
    00767                 classname = type(tool).__name__
    00768             raise TypeError, "addTool requires AlgTool configurable. Got %s type" % classname
    00769         self.__tools[name] =  priv_tool
    00770         if name in self.__slots__:
    00771             # this is to avoid that the property hides the tool
    00772             setattr(self,name,self.__tools[name])
    00773
        def _isInSetDefaults( self ):

def Configurable::Configurable::_isInSetDefaults | ( |  | self | ) | `[private]`

Definition at line 774 of file Configurable.py.

    00774                                 :
    00775         return self._inSetDefaults
    00776
        def __setupServices( self ):

def Configurable::Configurable::__setupServices | ( |  | self | ) | `[private]`

Definition at line 777 of file Configurable.py.

    00777                                :
    00778         #svcs = self.getServices()
    00779         #if not svcs:
    00780         svcs = []
    00781         #elif type(svcs) == types.StringType:
    00782         #   svcs = [ svcs ]
    00783
    00784         import __main__
    00785         for svc in svcs:
    00786             handle = __main__.Service( svc )
    00787             # services should be configurables as well, but aren't for now
    00788             # handle.setup()
    00789
    00790             # allow Configurable to make some changes
    00791             if hasattr( self, 'configure' + svc ):
    00792                 eval( 'self.configure' + svc + '( handle )' )
    00793
        def __setupDlls( self ):

def Configurable::Configurable::__setupDlls | ( |  | self | ) | `[private]`

Definition at line 794 of file Configurable.py.

    00794                            :
    00795         dlls = self.getDlls()
    00796         if not dlls:
    00797             dlls = []
    00798         elif type(dlls) == types.StringType:
    00799             dlls = [ dlls ]
    00800
    00801         from __main__ import theApp
    00802         dlls = filter( lambda d: d not in theApp.Dlls, dlls )
    00803         if dlls: theApp.Dlls += dlls
    00804
        def __setupDefaults( self ):

def Configurable::Configurable::__setupDefaults | ( |  | self | ) | `[private]`

Definition at line 805 of file Configurable.py.

    00805                                :
    00806         # set handle defaults flags to inform __setattr__ that it is being
    00807         # called during setDefaults of the concrete Configurable
    00808         self._inSetDefaults = True
    00809         self.setDefaults( self )
    00810         self._inSetDefaults = False
    00811
    00812     @staticmethod
        def _printHeader( indentStr, title ):

def Configurable::Configurable::_printHeader | ( |  | indentStr,
|  |  | title |
| ) |  |  | `[private]`

Definition at line 813 of file Configurable.py.

    00813                                         :
    00814         preLen  = Configurable.printHeaderPre
    00815         postLen = Configurable.printHeaderWidth - preLen - 3 - len(title)# - len(indentStr)
    00816         postLen = max(preLen,postLen)
    00817         return indentStr + '/%s %s %s' % (preLen*'*',title,postLen*'*')
    00818
    00819     @staticmethod
        def _printFooter( indentStr, title ):

def Configurable::Configurable::_printFooter | ( |  | indentStr,
|  |  | title |
| ) |  |  | `[private]`

Definition at line 820 of file Configurable.py.

    00820                                         :
    00821         preLen  = Configurable.printHeaderPre
    00822         postLen = Configurable.printHeaderWidth - preLen - 12 - len(title)# - len(indentStr)
    00823         postLen = max(preLen,postLen)
    00824         return indentStr + '\\%s (End of %s) %s' % (preLen*'-',title,postLen*'-')
    00825
        def __repr__( self ):

def Configurable::Configurable::__repr__ | ( |  | self | ) |

Definition at line 826 of file Configurable.py.

    00826                         :
    00827         return '<%s at %s>' % (self.getFullJobOptName(),hex(id(self)))
    00828
        def __str__( self, indent = 0, headerLastIndentUnit=indentUnit ):

def Configurable::Configurable::__str__ | ( |  | self,
|  |  | indent = `0`,
|  |  | headerLastIndentUnit = `indentUnit` |
| ) |  |  |

Definition at line 829 of file Configurable.py.

    00829                                                                     :
    00830         global log  # to print some info depending on output level
    00831         indentStr = indent*Configurable.indentUnit
    00832         # print header
    00833         title = self.getPrintTitle()
    00834         # print line to easily see start-of-configurable
    00835         if indent > 0:
    00836             headerIndent = (indent-1)*Configurable.indentUnit + headerLastIndentUnit
    00837         else:
    00838             headerIndent = ''
    00839         rep = Configurable._printHeader( headerIndent, title )
    00840         rep += os.linesep
    00841         # print own properties
    00842         props = self.getProperties()
    00843         defs = self.getDefaultProperties()
    00844         if not props:
    00845             rep += indentStr + '|-<no properties>' + os.linesep
    00846         else:
    00847             # get property name with
    00848             nameWidth = 0
    00849             for p in props.keys():
    00850                 nameWidth=max(nameWidth,len(p))
    00851             for p, v in props.items():
    00852                 # start with indent and property name
    00853                 prefix = indentStr + '|-%-*s' % (nameWidth,p)
    00854                 # add memory address for debugging (not for defaults)
    00855                 if log.isEnabledFor( logging.DEBUG ):
    00856                     if v != Configurable.propertyNoValue:
    00857                         address = ' @%11s' % hex(id(v))
    00858                     else:
    00859                         address = 13*' '
    00860                     prefix += address
    00861                 # add value and default
    00862                 default = defs.get(p)
    00863                 if v == Configurable.propertyNoValue:
    00864                     # show default value as value, and no extra 'default'
    00865                     strVal = repr(default)
    00866                     strDef = None
    00867                 else:
    00868                     # convert configurable to handle
    00869                     if hasattr(v,"getGaudiHandle"):
    00870                         vv = v.getGaudiHandle()
    00871                     else:
    00872                         vv = v
    00873                     if isinstance(vv,GaudiHandle) or isinstance(vv,GaudiHandleArray):
    00874                         strVal = repr(vv)
    00875                         if hasattr(default,"toStringProperty"): # the default may not be a GaudiHandle (?)
    00876                             strDef = repr(default.toStringProperty())
    00877                         else:
    00878                             strDef = repr(default)
    00879                         if strDef == repr(vv.toStringProperty()):
    00880                             strDef = None
    00881                     else:
    00882                         strVal = repr(vv)
    00883                         strDef = repr(default)
    00884                 # add the value
    00885                 line = prefix + ' = ' + strVal
    00886                 # add default if present
    00887                 if strDef is not None:
    00888                     # put default on new line if too big
    00889                     if len(line) + len(strDef) > Configurable.printHeaderWidth:
    00890                         line += os.linesep + indentStr + '| ' + (len(prefix)-len(indentStr)-3)*' '
    00891                     line += '  (default: %s)' % (strDef,)
    00892                 # add the line to the total string
    00893                 rep += line + os.linesep
    00894                 # print out full private configurables
    ##              if isinstance(v,Configurable) and not v.isPublic():

## Member Data Documentation

string Configurable::Configurable::propertyNoValue = '<no value>'`[static]`

Definition at line 97 of file Configurable.py.

string Configurable::Configurable::indentUnit = '| '`[static]`

Definition at line 98 of file Configurable.py.

int Configurable::Configurable::printHeaderWidth = 100`[static]`

Definition at line 99 of file Configurable.py.

int Configurable::Configurable::printHeaderPre = 5`[static]`

Definition at line 100 of file Configurable.py.

Configurable::Configurable::__metaclass__ = ConfigurableMeta.ConfigurableMeta`[static, private]`

Definition at line 102 of file Configurable.py.

tuple Configurable::Configurable::__slots__`[static, private]`

Initial value:

    (
           '__children',           # controlled components, e.g. private AlgTools
           '__tools',              # private AlgTools  (#PM-->)
           '_name',                # the (unqualified) component name
           '_inSetDefaults',       # currently setting default values
           '_initok',              # used to enforce base class init
           '_setupok'              # for debugging purposes (temporary)
        )

Reimplemented in Configurable::ConfigurableAlgorithm, Configurable::ConfigurableService, Configurable::ConfigurableAlgTool, Configurable::ConfigurableAuditor, and Configurable::ConfigurableUser.

Definition at line 104 of file Configurable.py.

dictionary Configurable::Configurable::allConfigurables = {}`[static]`

Definition at line 113 of file Configurable.py.

dictionary Configurable::Configurable::configurableServices = {}`[static]`

Definition at line 114 of file Configurable.py.

Configurable::Configurable::_configurationLocked = False`[static, private]`

Definition at line 117 of file Configurable.py.

Configurable::Configurable::__children`[private]`

Definition at line 281 of file Configurable.py.

Configurable::Configurable::__tools`[private]`

Definition at line 282 of file Configurable.py.

Configurable::Configurable::_name`[private]`

Reimplemented in Configurable::ConfigurableGeneric, and Configurable::ConfigurableAlgTool.

Definition at line 287 of file Configurable.py.

Configurable::Configurable::_inSetDefaults`[private]`

Definition at line 294 of file Configurable.py.

Configurable::Configurable::_initok`[private]`

Definition at line 297 of file Configurable.py.

Configurable::Configurable::_setupok`[private]`

Definition at line 300 of file Configurable.py.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r7p1/GaudiKernel/python/GaudiKernel/Configurable.py