|
Gaudi Framework, version v22r4 |
| Home | Generated: Fri Sep 2 2011 |


Public Member Functions | |
| def | __init__ |
| def | __get__ |
| def | __set__ |
| def | isHandle |
| def | isConfig |
| def | getDefaultConfigurable |
| def | convertDefaultToBeSet |
| def | convertValueToBeSet |
Private Attributes | |
| _handleType | |
| _confTypeName | |
A class with some utilities for GaudiHandles and GaudiHandleArrays
Definition at line 151 of file PropertyProxy.py.
| 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.
00155 : 00156 """<descr>: the real property in the object instance (from __slots__) 00157 <docString>: the documentation string of this property 00158 <default>: default value from C++ (via python generated by genconf) 00159 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...) 00160 <allowedType>: allowed instance type for default 00161 """ 00162 # check that default is of allowed type for this proxy 00163 if not isinstance(default,allowedType): 00164 raise TypeError( "%s: %s default: %r is not a %s" % \ 00165 ( descr.__name__, self.__class__.__name__, default, allowedType.__name__ ) ) 00166 PropertyProxy.__init__( self, descr, docString, default ) 00167 self._handleType = handleType 00168 self._confTypeName = 'Configurable' + handleType.componentType 00169 # print "%s: %r (%s)" % (self.__class__.__name__,self._handleType,self._confTypeName) 00170
| def PropertyProxy::GaudiHandlePropertyProxyBase::__get__ | ( | self, | |
| obj, | |||
type = None |
|||
| ) |
Reimplemented from PropertyProxy::PropertyProxy.
Definition at line 171 of file PropertyProxy.py.
00172 : 00173 try: 00174 return self.descr.__get__( obj, type ) 00175 except AttributeError: 00176 # Get default 00177 try: 00178 default = obj.__class__.getDefaultProperty( self.descr.__name__ ) 00179 default = self.convertDefaultToBeSet( obj, default ) 00180 if default: 00181 self.__set__( obj, default ) 00182 except AttributeError,e: 00183 # change type of exception to avoid false error message 00184 raise RuntimeError(*e.args) 00185 00186 return self.descr.__get__( obj, type ) 00187
| def PropertyProxy::GaudiHandlePropertyProxyBase::__set__ | ( | self, | |
| obj, | |||
| value | |||
| ) |
Reimplemented from PropertyProxy::PropertyProxy.
Definition at line 188 of file PropertyProxy.py.
00189 : 00190 # allow a property to be set if we're in non-default mode, or if it 00191 # simply hasn't been set before 00192 if not obj._isInSetDefaults() or not obj in self.history: 00193 value = self.convertValueToBeSet( obj, value ) 00194 # assign the value 00195 self.descr.__set__( obj, value ) 00196 log.debug( "Setting %s = %r", self.fullPropertyName( obj ), value ) 00197 self.history.setdefault( obj, [] ).append( value ) 00198 00199
| def PropertyProxy::GaudiHandlePropertyProxyBase::convertDefaultToBeSet | ( | self, | |
| obj, | |||
| default | |||
| ) |
Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.
Definition at line 231 of file PropertyProxy.py.
00232 : 00233 # turn string into handle 00234 isString = type(default) == str 00235 if not isString and self.isConfig(default): 00236 # print self.fullPropertyName(obj) + ": Setting default configurable: %r" % default 00237 return default 00238 elif isString or self.isHandle(default): 00239 if isString: 00240 # convert string into handle 00241 typeAndName = default 00242 default = self._handleType( typeAndName ) 00243 else: 00244 typeAndName = default.typeAndName 00245 if not self._handleType.isPublic: 00246 if not typeAndName: 00247 return None 00248 # Find corresponding default configurable of private handles 00249 try: 00250 conf = self.getDefaultConfigurable(typeAndName, self.fullPropertyName(obj)) 00251 # print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf 00252 except AttributeError,e: 00253 # change type of exception to avoid false error message 00254 raise RuntimeError(*e.args) 00255 if conf is None: 00256 raise RuntimeError( "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" % \ 00257 (self.fullPropertyName(obj),default.getType() ) ) 00258 return conf 00259 else: # not a config, not a handle, not a string 00260 raise TypeError( "%s: default value %r is not of type %s or %s" % \ 00261 (self.fullPropertyName(obj),default,self._confTypeName,self._handleType.__name__) ) 00262 00263 return default
| def PropertyProxy::GaudiHandlePropertyProxyBase::convertValueToBeSet | ( | self, | |
| obj, | |||
| value | |||
| ) |
Reimplemented in PropertyProxy::GaudiHandleArrayPropertyProxy.
Definition at line 264 of file PropertyProxy.py.
00265 : 00266 if value is None: value = '' 00267 isString = type(value) == str 00268 if isString: 00269 # create an new handle 00270 return self._handleType(value) 00271 elif self.isHandle(value): 00272 # make a copy of the handle 00273 return self._handleType(value.toStringProperty()) 00274 elif self.isConfig(value): 00275 if self._handleType.isPublic: 00276 # A public tool must be registered to ToolSvc before assigning it 00277 if derives_from(value,'ConfigurableAlgTool'): 00278 if not value.isInToolSvc(): 00279 suggestion = 'You may need to add jobOptions lines something like:' + os.linesep + \ 00280 'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \ 00281 'ToolSvc += ' 00282 if value.getName() == value.getType(): # using default name 00283 suggestion += '%s()' % value.__class__.__name__ 00284 else: # using user-defined name 00285 suggestion += '%s(%r)' % (value.__class__.__name__,value.getName()) 00286 raise RuntimeError( self.fullPropertyName(obj) + 00287 ': Public tool %s is not yet in ToolSvc. %s' % 00288 (value.getJobOptName(),suggestion) ) 00289 # make it read-only 00290 return self._handleType(value.toStringProperty()) 00291 elif value.hasParent( obj.getJobOptName() ): 00292 # is already a child, keep as-is 00293 return value 00294 else: 00295 # make a copy of the configurable 00296 value = obj.copyChildAndSetParent( value, obj.getJobOptName() ) 00297 # ensure that the new object is in allConfigurables 00298 obj.allConfigurables[value.name()] = value 00299 return value 00300 else: 00301 raise TypeError( "Property %s value %r is not a %s nor a %s nor a string" % \ 00302 (self.fullPropertyName(obj),value,self._confTypeName,self._handleType.__name__) ) 00303 00304 return value 00305
| 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.
00211 : 00212 """Return the configurable instance corresponding to the toolhandle if possible. 00213 Otherwise return None""" 00214 global log 00215 # find the module 00216 typeAndNameTuple = typeAndName.split('/') 00217 confType = typeAndNameTuple[0] 00218 confClass=ConfigurableDb.getConfigurable(confType) 00219 # check the type of the configurable 00220 if not derives_from(confClass,self._confTypeName): 00221 log.error( "%s: Configurable %s is not a %s", 00222 requester, confType, self._confTypeName ) 00223 return None 00224 try: 00225 confName = typeAndNameTuple[1] 00226 except IndexError: 00227 return confClass() # use default name 00228 else: 00229 return confClass(confName) 00230
| def PropertyProxy::GaudiHandlePropertyProxyBase::isConfig | ( | self, | |
| value | |||
| ) |
Check if <value> is a configurable of the correct type
Definition at line 205 of file PropertyProxy.py.
| def PropertyProxy::GaudiHandlePropertyProxyBase::isHandle | ( | self, | |
| value | |||
| ) |
Check if <value> is a handle of the correct type
Definition at line 200 of file PropertyProxy.py.
Definition at line 159 of file PropertyProxy.py.
Definition at line 159 of file PropertyProxy.py.