Gaudi Framework, version v21r10p1

Home   Generated: 29 Jul 2010

PropertyProxy::GaudiHandlePropertyProxyBase Class Reference

Inheritance diagram for PropertyProxy::GaudiHandlePropertyProxyBase:

Inheritance graph
[legend]
Collaboration diagram for PropertyProxy::GaudiHandlePropertyProxyBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __get__
def __set__
def isHandle
def isConfig
def getDefaultConfigurable
def convertDefaultToBeSet
def convertValueToBeSet

Private Attributes

 _handleType
 _confTypeName


Detailed Description

A class with some utilities for GaudiHandles and GaudiHandleArrays

Definition at line 151 of file PropertyProxy.py.


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                 if default:
00180                     self.__set__( obj, default )
00181             except AttributeError,e:
00182                 # change type of exception to avoid false error message
00183                 raise RuntimeError(*e.args)
00184 
00185         return self.descr.__get__( obj, type )
00186 
00187 
    def __set__( self, obj, value ):

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

Reimplemented from PropertyProxy::PropertyProxy.

Definition at line 188 of file PropertyProxy.py.

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

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

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

Definition at line 200 of file PropertyProxy.py.

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

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

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

Definition at line 205 of file PropertyProxy.py.

00205                             :
00206         """Check if <value> is a configurable of the correct type"""
00207         return derives_from(value,self._confTypeName)
00208 
00209 
    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 210 of file PropertyProxy.py.

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

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

Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.

Definition at line 231 of file PropertyProxy.py.

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

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

Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.

Definition at line 264 of file PropertyProxy.py.

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


Member Data Documentation

Definition at line 166 of file PropertyProxy.py.

Definition at line 167 of file PropertyProxy.py.


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

Generated at Thu Jul 29 10:20:06 2010 for Gaudi Framework, version v21r10p1 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004