| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# PropertyProxy::GaudiHandlePropertyProxyBase Class Reference

Inheritance diagram for PropertyProxy::GaudiHandlePropertyProxyBase:

[legend]
Collaboration diagram for PropertyProxy::GaudiHandlePropertyProxyBase:

[legend]

List of all members.

## Detailed Description

    A class with some utilities for GaudiHandles and GaudiHandleArrays

Definition at line 151 of file PropertyProxy.py.

## Public Member Functions
def | __init__
def | __get__
def | __set__
def | isHandle
def | isConfig
def | getDefaultConfigurable
def | convertDefaultToBeSet
def | convertValueToBeSet
## Private Attributes
| _handleType
| _confTypeName

## Member Function Documentation

def PropertyProxy::GaudiHandlePropertyProxyBase::__init__ | ( |  | self,
|  |  | descr,
|  |  | docString,
|  |  | default,
|  |  | handleType,
|  |  | allowedType |
| ) |  |  |

    <descr>: the real property in the object instance (from __slots__)
    <docString>: the documentation string of this property
    <default>: default value from C++ (via python generated by genconf)
    <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
    <allowedType>: allowed instance type for default

Definition at line 154 of file PropertyProxy.py.

    00154                                                                            :
    00155         """<descr>: the real property in the object instance (from __slots__)
    00156         <docString>: the documentation string of this property
    00157         <default>: default value from C++ (via python generated by genconf)
    00158         <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
    00159         <allowedType>: allowed instance type for default
    00160         """
    00161         # check that default is of allowed type for this proxy
    00162         if not isinstance(default,allowedType):
    00163             raise TypeError( "%s: %s default: %r is not a %s" % \
    00164                              ( descr.__name__, self.__class__.__name__, default, allowedType.__name__ ) )
    00165         PropertyProxy.__init__( self, descr, docString, default )
    00166         self._handleType = handleType
    00167         self._confTypeName = 'Configurable' + handleType.componentType
    00168 #      print "%s: %r (%s)" % (self.__class__.__name__,self._handleType,self._confTypeName)
    00169
    00170
        def __get__( self, obj, type = None ):

def PropertyProxy::GaudiHandlePropertyProxyBase::__get__ | ( |  | self,
|  |  | obj,
|  |  | type = `None` |
| ) |  |  |

Reimplemented from PropertyProxy::PropertyProxy.

Definition at line 171 of file PropertyProxy.py.

    00171                                          :
    00172         try:
    00173             return self.descr.__get__( obj, type )
    00174         except AttributeError:
    00175             # Get default
    00176             try:
    00177                 default = obj.__class__.getDefaultProperty( self.descr.__name__ )
    00178                 default = self.convertDefaultToBeSet( obj, default )
    00179                 self.__set__( obj, default )
    00180             except AttributeError,e:
    00181                 # change type of exception to avoid false error message
    00182                 raise RuntimeError(*e.args)
    00183
    00184         return self.descr.__get__( obj, type )
    00185
    00186
        def __set__( self, obj, value ):

def PropertyProxy::GaudiHandlePropertyProxyBase::__set__ | ( |  | self,
|  |  | obj,
|  |  | value |
| ) |  |  |

Reimplemented from PropertyProxy::PropertyProxy.

Definition at line 187 of file PropertyProxy.py.

    00187                                    :
    00188      # allow a property to be set if we're in non-default mode, or if it
    00189      # simply hasn't been set before
    00190         if not obj._isInSetDefaults() or not obj in self.history:
    00191             value = self.convertValueToBeSet( obj, value )
    00192             # assign the value
    00193             self.descr.__set__( obj, value )
    00194             log.debug( "Setting %s = %r", self.fullPropertyName( obj ), value )
    00195             self.history.setdefault( obj, [] ).append( value )
    00196
    00197
    00198
        def isHandle(self,value):

def PropertyProxy::GaudiHandlePropertyProxyBase::isHandle | ( |  | self,
|  |  | value |
| ) |  |  |

    Check if <value> is a handle of the correct type

Definition at line 199 of file PropertyProxy.py.

    00199                             :
    00200         """Check if <value> is a handle of the correct type"""
    00201         return isinstance(value,self._handleType)
    00202
    00203
        def isConfig(self,value):

def PropertyProxy::GaudiHandlePropertyProxyBase::isConfig | ( |  | self,
|  |  | value |
| ) |  |  |

    Check if <value> is a configurable of the correct type

Definition at line 204 of file PropertyProxy.py.

    00204                             :
    00205         """Check if <value> is a configurable of the correct type"""
    00206         return derives_from(value,self._confTypeName)
    00207
    00208
        def getDefaultConfigurable(self,typeAndName,requester):

def PropertyProxy::GaudiHandlePropertyProxyBase::getDefaultConfigurable | ( |  | self,
|  |  | typeAndName,
|  |  | requester |
| ) |  |  |

    Return the configurable instance corresponding to the toolhandle if possible.
    Otherwise return None

Definition at line 209 of file PropertyProxy.py.

    00209                                                           :
    00210         """Return the configurable instance corresponding to the toolhandle if possible.
    00211         Otherwise return None"""
    00212         global log
    00213         # find the module
    00214         typeAndNameTuple = typeAndName.split('/')
    00215         confType = typeAndNameTuple[0]
    00216         confClass=ConfigurableDb.getConfigurable(confType)
    00217         # check the type of the configurable
    00218         if not derives_from(confClass,self._confTypeName):
    00219             log.error( "%s: Configurable %s is not a %s",
    00220                        requester, confType, self._confTypeName )
    00221             return None
    00222         try:
    00223             confName = typeAndNameTuple[1]
    00224         except IndexError:
    00225             return confClass() # use default name
    00226         else:
    00227             return confClass(confName)
    00228
    00229
        def convertDefaultToBeSet( self, obj, default ):

def PropertyProxy::GaudiHandlePropertyProxyBase::convertDefaultToBeSet | ( |  | self,
|  |  | obj,
|  |  | default |
| ) |  |  |

Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.

Definition at line 230 of file PropertyProxy.py.

    00230                                                    :
    00231         # turn string into handle
    00232         isString = type(default) == str
    00233         if not isString and self.isConfig(default):
    00234 #         print self.fullPropertyName(obj) + ": Setting default configurable: %r" % default
    00235             return default
    00236         elif isString or self.isHandle(default):
    00237             if isString:
    00238                 # convert string into handle
    00239                 typeAndName = default
    00240                 default = self._handleType( typeAndName )
    00241             else:
    00242                 typeAndName = default.typeAndName
    00243             if not self._handleType.isPublic:
    00244                 # Find corresponding default configurable of private handles
    00245                 try:
    00246                     conf = self.getDefaultConfigurable(typeAndName, self.fullPropertyName(obj))
    00247 #               print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
    00248                 except AttributeError,e:
    00249                     # change type of exception to avoid false error message
    00250                     raise RuntimeError(*e.args)
    00251                 if conf is None:
    00252                     raise RuntimeError( "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" % \
    00253                                         (self.fullPropertyName(obj),default.getType() ) )
    00254                 return conf
    00255         else: # not a config, not a handle, not a string
    00256             raise TypeError( "%s: default value %r is not of type %s or %s" % \
    00257                              (self.fullPropertyName(obj),default,self._confTypeName,self._handleType.__name__) )
    00258
    00259         return default
    00260
        def convertValueToBeSet( self, obj, value ):

def PropertyProxy::GaudiHandlePropertyProxyBase::convertValueToBeSet | ( |  | self,
|  |  | obj,
|  |  | value |
| ) |  |  |

Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.

Definition at line 261 of file PropertyProxy.py.

    00261                                                :
    00262         if value is None: value = ''
    00263         isString = type(value) == str
    00264         if isString:
    00265         # create an new handle
    00266             return self._handleType(value)
    00267         elif self.isHandle(value):
    00268         # make a copy of the handle
    00269             return self._handleType(value.toStringProperty())
    00270         elif self.isConfig(value):
    00271             if self._handleType.isPublic:
    00272              # A public tool must be registered to ToolSvc before assigning it
    00273                 if derives_from(value,'ConfigurableAlgTool'):
    00274                     if not value.isInToolSvc():
    00275                         suggestion = 'You may need to add jobOptions lines something like:' + os.linesep + \
    00276                                      'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
    00277                                      'ToolSvc += '
    00278                         if value.getName() == value.getType(): # using default name
    00279                             suggestion += '%s()' % value.__class__.__name__
    00280                         else: # using user-defined name
    00281                             suggestion += '%s(%r)' % (value.__class__.__name__,value.getName())
    00282                         raise RuntimeError( self.fullPropertyName(obj) +
    00283                                             ': Public tool %s is not yet in ToolSvc. %s' %
    00284                                             (value.getJobOptName(),suggestion) )
    00285              # make it read-only
    00286                 return self._handleType(value.toStringProperty())
    00287             elif value.hasParent( obj.getJobOptName() ):
    00288              # is already a child, keep as-is
    00289                 return value
    00290             else:
    00291              # make a copy of the configurable
    00292                 value = obj.copyChildAndSetParent( value, obj.getJobOptName() )
    00293                 # ensure that the new object is in allConfigurables
    00294                 obj.allConfigurables[value.name()] = value
    00295                 return value
    00296         else:
    00297             raise TypeError( "Property %s value %r is not a %s nor a %s nor a string" % \
    00298                              (self.fullPropertyName(obj),value,self._confTypeName,self._handleType.__name__) )
    00299
    00300         return value
    00301
    00302
    class GaudiHandlePropertyProxy(GaudiHandlePropertyProxyBase):

## Member Data Documentation

PropertyProxy::GaudiHandlePropertyProxyBase::_handleType`[private]`

Definition at line 166 of file PropertyProxy.py.

PropertyProxy::GaudiHandlePropertyProxyBase::_confTypeName`[private]`

Definition at line 167 of file PropertyProxy.py.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r6/GaudiKernel/python/GaudiKernel/PropertyProxy.py