| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# Configurable::Configurable Class Reference

Inheritance 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                 if n != "name": # it should not be confused with a normal property
    00175                     setattr(conf, n, v)
    00176             if not cls._configurationLocked and not "_enabled" in kwargs and isinstance(conf, ConfigurableUser):
    00177                 # Ensure that the ConfigurableUser gets enabled if nothing is
    00178                 # specified in the constructor.
    00179                 setattr(conf, "_enabled", True)
    00180             return conf
    00181
    00182         # a couple of special cases (note that these cases don't mix)
    00183         spos = name.find( '/' )
    00184         ti_name = None
    00185         if spos < 0:
    00186             ti_name = "%s/%s" % (name,name)
    00187             if ti_name in cls.configurables:
    00188                 # support for old-style name as type/name lookup where name==type
    00189                 return cls.configurables[ ti_name ]
    00190
    00191         i_name = None
    00192         if spos > 0:
    00193             i_name = name[:spos]
    00194             if i_name == name[spos+1:] and i_name in cls.configurables:
    00195             # this is the opposite of the above special case
    00196                 return cls.configurables[ i_name ]
    00197
    00198         # the following is purely for debugging support and should realistically bomb
    00199         conf = cls.allConfigurables.get( name, None ) or\
    00200                  (spos < 0 and cls.allConfigurables.get( ti_name, None )) or\
    00201                  (spos > 0 and i_name == name[spos+1:] and cls.allConfigurables.get( i_name, None ))
    00202         if conf:                    # wrong type used?
    00203             if conf.__class__ is ConfigurableGeneric :
    00204                 #  If the instance found is ConfigurableGeneric then
    00205                 #  we create a new one with the proper type and fill with
    00206                 #  the contents of the generic one
    00207                 newconf = object.__new__( cls )
    00208                 cls.__init__( newconf, *args, **kwargs )
    00209                 #  initialize with the properties of generic configurable
    00210                 #  (we map the names of the properties to lowercase versions because
    00211                 #  old options are not case sensitive)
    00212                 names = {}
    00213                 for n in newconf.__slots__:
    00214                     names[n.lower()] = n
    00215                 for n in conf._properties:
    00216                     if names[n.lower()] != n:
    00217                         log.warning( "Option '%s' was used for %s, but the correct spelling is '%s'"%(n,name,names[n.lower()]) )
    00218                     setattr(newconf, names[n.lower()], getattr( conf, n ) )
    00219                 for n,v in kwargs.items():
    00220                     setattr(newconf, n, v)
    00221                 cls.configurables[ name ] = newconf
    00222                 cls.allConfigurables[ name ] = newconf
    00223                 return newconf
    00224             else :
    00225                 #  will be an actual error in the future (now only report as such)
    00226                 log.error( 'attempt to redefine type of "%s" (was: %s, new: %s)%s',
    00227                 name, conf.__class__.__name__, cls.__name__, error_explanation )
    00228                 #  in the future:
    00229                 #  return None             # will bomb on use (or go unharmed on non-use)
    00230                 #  for now, allow use through allConfigurables lookup
    00231                 #---PM: Initialize additional properties
    00232                 for n,v in kwargs.items():
    00233                     setattr(conf, n, v)
    00234                 return conf
    00235
    00236         # still here: create a new instance and initialize it
    00237         conf = object.__new__(cls)
    00238         cls.__init__( conf, *args, **kwargs )
    00239
    00240         # update normal, per-class cache
    00241         cls.configurables[ name ] = conf
    00242
    00243         for base in cls.__bases__:
    00244             if base.__name__ == 'ConfigurableService':
    00245                 cls.configurableServices[ name ] = conf
    00246
    00247         # update generics super-cache, if needed
    00248         cls.allConfigurables[ name ] = conf
    00249         #-->PM#if hasattr( cls, 'getType' ) and name.find('/') < 0:
    00250         #-->PM#   cls.allConfigurables[ cls.getType() + '/' + name ] = conf
    00251
    00252         return conf
    00253
        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 254 of file Configurable.py.

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

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

Definition at line 304 of file Configurable.py.

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

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

Definition at line 317 of file Configurable.py.

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

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

Definition at line 320 of file Configurable.py.

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

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

Definition at line 327 of file Configurable.py.

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

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

Definition at line 330 of file Configurable.py.

    00330                         :
    00331         return iter( self.__children )
    00332
    00333     # 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 334 of file Configurable.py.

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

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

Definition at line 350 of file Configurable.py.

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

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

Definition at line 382 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableGeneric.

Definition at line 392 of file Configurable.py.

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

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

Definition at line 401 of file Configurable.py.

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

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

Definition at line 426 of file Configurable.py.

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

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

Definition at line 430 of file Configurable.py.

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

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

Definition at line 436 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableService.

Definition at line 440 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 443 of file Configurable.py.

    00443                                      :
    00444         pass
    00445
        def getParent( self ):

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 446 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 449 of file Configurable.py.

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

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

Definition at line 452 of file Configurable.py.

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

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

Definition at line 472 of file Configurable.py.

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

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

Definition at line 475 of file Configurable.py.

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

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

Definition at line 478 of file Configurable.py.

    00478                         :
    00479         log.error( "children() is deprecated, use getChildren() instead for consistency" )
    00480         log.error( "getChildren() returns a copy; to add a child, use 'parent += child'%s",
    00481                    error_explanation )
    00482         return self.__children       # by ref, for compatibility
    00483
        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 484 of file Configurable.py.

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

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

Definition at line 523 of file Configurable.py.

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

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

Definition at line 529 of file Configurable.py.

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

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

Definition at line 561 of file Configurable.py.

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

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

Definition at line 571 of file Configurable.py.

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

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

Definition at line 598 of file Configurable.py.

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

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

Definition at line 602 of file Configurable.py.

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

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

Definition at line 618 of file Configurable.py.

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

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

    Returns the value of the given property.

Definition at line 639 of file Configurable.py.

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

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

    Set the value of a given property

Definition at line 647 of file Configurable.py.

    00647                                   :
    00648         """Set the value of a given property
    00649         """
    00650         return setattr(self, name, value)
    00651
        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 652 of file Configurable.py.

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

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

Definition at line 671 of file Configurable.py.

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

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

Definition at line 674 of file Configurable.py.

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

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

Definition at line 677 of file Configurable.py.

    00677                     :
    00678         return self.getName()
    00679
        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 680 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 683 of file Configurable.py.

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

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

Definition at line 687 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 692 of file Configurable.py.

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

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

Definition at line 695 of file Configurable.py.

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

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

Reimplemented in Configurable::ConfigurableAlgTool.

Definition at line 698 of file Configurable.py.

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

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

Definition at line 701 of file Configurable.py.

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

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

Definition at line 707 of file Configurable.py.

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

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

Definition at line 710 of file Configurable.py.

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

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

Definition at line 739 of file Configurable.py.

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

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

Definition at line 755 of file Configurable.py.

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

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

Definition at line 775 of file Configurable.py.

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

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

Definition at line 778 of file Configurable.py.

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

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

Definition at line 795 of file Configurable.py.

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

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

Definition at line 806 of file Configurable.py.

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

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

Definition at line 814 of file Configurable.py.

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

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

Definition at line 821 of file Configurable.py.

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

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

Definition at line 827 of file Configurable.py.

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

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

Definition at line 830 of file Configurable.py.

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

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

Definition at line 283 of file Configurable.py.

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

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

Definition at line 288 of file Configurable.py.

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

Definition at line 295 of file Configurable.py.

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

Definition at line 298 of file Configurable.py.

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

Definition at line 301 of file Configurable.py.

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

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