| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Attributes | List of all members
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase Class Reference
Inheritance diagram for GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase:
[legend]
Collaboration diagram for GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase:
[legend]

## Public Member Functions
def | __init__ (self, descr, docString, default, handleType, allowedType)
def | __get__ (self, obj, type=None)
def | __set__ (self, obj, value)
def | isHandle (self, value)
def | isConfig (self, value)
def | getDefaultConfigurable (self, typeAndName, requester)
def | convertDefaultToBeSet (self, obj, default)
def | convertValueToBeSet (self, obj, value)
Public Member Functions inherited from GaudiKernel.PropertyProxy.PropertyProxy
def | __init__ (self, descr, docString=None, default=None)
def | setDefault (self, value)
def | getDefault (self)
def | fullPropertyName (self, obj)
def | __get__ (self, obj, type=None)
def | __set__ (self, obj, value)
def | __delete__ (self, obj)

## Private Attributes
| _handleType
| _confTypeName

## Additional Inherited Members
Public Attributes inherited from GaudiKernel.PropertyProxy.PropertyProxy
| history
| descr
Properties inherited from GaudiKernel.PropertyProxy.PropertyProxy
| default = property( getDefault, setDefault )

## Detailed Description

    A class with some utilities for GaudiHandles and GaudiHandleArrays

Definition at line 152 of file PropertyProxy.py.

## Constructor & Destructor Documentation

def GaudiKernel.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 155 of file PropertyProxy.py.

155 def __init__(self, descr, docString, default, handleType, allowedType ):
156 """<descr>: the real property in the object instance (from __slots__)
157 <docString>: the documentation string of this property
158 <default>: default value from C++ (via python generated by genconf)
159 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
160 <allowedType>: allowed instance type for default
161 """
162 # check that default is of allowed type for this proxy
163 if not isinstance(default,allowedType):
164 raise TypeError( "%s: %s default: %r is not a %s" % \
165 ( descr.__name__, self.__class__.__name__, default, allowedType.__name__ ) )
166 PropertyProxy.__init__( self, descr, docString, default )
167 self._handleType = handleType
168 self._confTypeName = 'Configurable' + handleType.componentType
169 # print "%s: %r (%s)" % (self.__class__.__name__,self._handleType,self._confTypeName)
170
171
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:168
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
_handleType
Definition: PropertyProxy.py:167
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.__init__
def __init__(self, descr, docString, default, handleType, allowedType)
Definition: PropertyProxy.py:155

## Member Function Documentation

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

Definition at line 172 of file PropertyProxy.py.

172 def __get__( self, obj, type = None ):
173 try:
174 return self.descr.__get__( obj, type )
175 except AttributeError:
176 # Get default
177 try:
178 default = obj.__class__.getDefaultProperty( self.descr.__name__ )
179 default = self.convertDefaultToBeSet( obj, default )
180 if default:
181 self.__set__( obj, default )
182 except AttributeError,e:
183 # change type of exception to avoid false error message
184 raise RuntimeError(*e.args)
185
186 return self.descr.__get__( obj, type )
187
188
GaudiKernel.PropertyProxy.PropertyProxy.__set__
def __set__(self, obj, value)
Definition: PropertyProxy.py:97
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.__get__
def __get__(self, obj, type=None)
Definition: PropertyProxy.py:172
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertDefaultToBeSet
def convertDefaultToBeSet(self, obj, default)
Definition: PropertyProxy.py:232

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.__set__ | ( |  | self,
|  |  | obj,
|  |  | value
| ) |  |

Definition at line 189 of file PropertyProxy.py.

189 def __set__( self, obj, value ):
190 # allow a property to be set if we're in non-default mode, or if it
191 # simply hasn't been set before
192 if not obj._isInSetDefaults() or not obj in self.history:
193 value = self.convertValueToBeSet( obj, value )
194 # assign the value
195 self.descr.__set__( obj, value )
196 log.debug( "Setting %s = %r", self.fullPropertyName( obj ), value )
197 self.history.setdefault( obj, [] ).append( value )
198
199
200
GaudiKernel.PropertyProxy.PropertyProxy.history
history
Definition: PropertyProxy.py:64
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertValueToBeSet
def convertValueToBeSet(self, obj, value)
Definition: PropertyProxy.py:265
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.__set__
def __set__(self, obj, value)
Definition: PropertyProxy.py:189
GaudiKernel.PropertyProxy.PropertyProxy.fullPropertyName
def fullPropertyName(self, obj)
Definition: PropertyProxy.py:80

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertDefaultToBeSet | ( |  | self,
|  |  | obj,
|  |  | default
| ) |  |

Definition at line 232 of file PropertyProxy.py.

232 def convertDefaultToBeSet( self, obj, default ):
233 # turn string into handle
234 isString = type(default) == str
235 if not isString and self.isConfig(default):
236 # print self.fullPropertyName(obj) + ": Setting default configurable: %r" % default
237 return default
238 elif isString or self.isHandle(default):
239 if isString:
240 # convert string into handle
241 typeAndName = default
242 default = self._handleType( typeAndName )
243 else:
244 typeAndName = default.typeAndName
245 if not self._handleType.isPublic:
246 if not typeAndName:
247 return None
248 # Find corresponding default configurable of private handles
249 try:
250 conf = self.getDefaultConfigurable(typeAndName, self.fullPropertyName(obj))
251 # print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
252 except AttributeError,e:
253 # change type of exception to avoid false error message
254 raise RuntimeError(*e.args)
255 if conf is None:
256 raise RuntimeError( "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" % \
257 (self.fullPropertyName(obj),default.getType() ) )
258 return conf
259 else: # not a config, not a handle, not a string
260 raise TypeError( "%s: default value %r is not of type %s or %s" % \
261 (self.fullPropertyName(obj),default,self._confTypeName,self._handleType.__name__) )
262
263 return default
264
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.getDefaultConfigurable
def getDefaultConfigurable(self, typeAndName, requester)
Definition: PropertyProxy.py:211
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig
def isConfig(self, value)
Definition: PropertyProxy.py:206
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle
def isHandle(self, value)
Definition: PropertyProxy.py:201
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:168
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
_handleType
Definition: PropertyProxy.py:167
gaudirun.type
type
Definition: gaudirun.py:125
GaudiKernel.PropertyProxy.PropertyProxy.fullPropertyName
def fullPropertyName(self, obj)
Definition: PropertyProxy.py:80
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertDefaultToBeSet
def convertDefaultToBeSet(self, obj, default)
Definition: PropertyProxy.py:232

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertValueToBeSet | ( |  | self,
|  |  | obj,
|  |  | value
| ) |  |

Definition at line 265 of file PropertyProxy.py.

265 def convertValueToBeSet( self, obj, value ):
266 if value is None: value = ''
267 isString = type(value) == str
268 if isString:
269 # create an new handle
270 return self._handleType(value)
271 elif self.isHandle(value):
272 # make a copy of the handle
273 return self._handleType(value.toStringProperty())
274 elif self.isConfig(value):
275 if self._handleType.isPublic:
276 # A public tool must be registered to ToolSvc before assigning it
277 if derives_from(value,'ConfigurableAlgTool'):
278 if not value.isInToolSvc():
279 suggestion = 'You may need to add jobOptions lines something like:' + os.linesep + \
280 'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
281 'ToolSvc += '
282 if value.getName() == value.getType(): # using default name
283 suggestion += '%s()' % value.__class__.__name__
284 else: # using user-defined name
285 suggestion += '%s(%r)' % (value.__class__.__name__,value.getName())
286 raise RuntimeError( self.fullPropertyName(obj) +
287 ': Public tool %s is not yet in ToolSvc. %s' %
288 (value.getJobOptName(),suggestion) )
289 # make it read-only
290 return self._handleType(value.toStringProperty())
291 elif value.hasParent( obj.getJobOptName() ):
292 # is already a child, keep as-is
293 return value
294 else:
295 # make a copy of the configurable
296 value = obj.copyChildAndSetParent( value, obj.getJobOptName() )
297 # ensure that the new object is in allConfigurables
298 obj.allConfigurables[value.name()] = value
299 return value
300 else:
301 raise TypeError( "Property %s value %r is not a %s nor a %s nor a string" % \
302 (self.fullPropertyName(obj),value,self._confTypeName,self._handleType.__name__) )
303
304 return value
305
306
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig
def isConfig(self, value)
Definition: PropertyProxy.py:206
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle
def isHandle(self, value)
Definition: PropertyProxy.py:201
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:168
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertValueToBeSet
def convertValueToBeSet(self, obj, value)
Definition: PropertyProxy.py:265
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
_handleType
Definition: PropertyProxy.py:167
gaudirun.type
type
Definition: gaudirun.py:125
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:20
GaudiKernel.PropertyProxy.PropertyProxy.fullPropertyName
def fullPropertyName(self, obj)
Definition: PropertyProxy.py:80

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.getDefaultConfigurable | ( |  | self,
|  |  | typeAndName,
|  |  | requester
| ) |  |

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

Definition at line 211 of file PropertyProxy.py.

211 def getDefaultConfigurable(self,typeAndName,requester):
212 """Return the configurable instance corresponding to the toolhandle if possible.
213 Otherwise return None"""
214 global log
215 # find the module
216 typeAndNameTuple = typeAndName.split('/')
217 confType = typeAndNameTuple[0]
218 confClass=ConfigurableDb.getConfigurable(confType)
219 # check the type of the configurable
220 if not derives_from(confClass,self._confTypeName):
221 log.error( "%s: Configurable %s is not a %s",
222 requester, confType, self._confTypeName )
223 return None
224 try:
225 confName = typeAndNameTuple[1]
226 except IndexError:
227 return confClass() # use default name
228 else:
229 return confClass(confName)
230
231
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.getDefaultConfigurable
def getDefaultConfigurable(self, typeAndName, requester)
Definition: PropertyProxy.py:211
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:168
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:20

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig | ( |  | self,
|  |  | value
| ) |  |

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

Definition at line 206 of file PropertyProxy.py.

206 def isConfig(self,value):
207 """Check if <value> is a configurable of the correct type"""
208 return derives_from(value,self._confTypeName)
209
210
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig
def isConfig(self, value)
Definition: PropertyProxy.py:206
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:168
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:20

def GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle | ( |  | self,
|  |  | value
| ) |  |

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

Definition at line 201 of file PropertyProxy.py.

201 def isHandle(self,value):
202 """Check if <value> is a handle of the correct type"""
203 return isinstance(value,self._handleType)
204
205
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle
def isHandle(self, value)
Definition: PropertyProxy.py:201
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
_handleType
Definition: PropertyProxy.py:167

## Member Data Documentation

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
| private

Definition at line 168 of file PropertyProxy.py.

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
| private

Definition at line 167 of file PropertyProxy.py.

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

- GaudiKernel/python/GaudiKernel/PropertyProxy.py