| The Gaudi Framework v29r0 (ff2e7097)

- 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 157 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 160 of file PropertyProxy.py.

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

## Member Function Documentation

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

Definition at line 176 of file PropertyProxy.py.

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

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

Definition at line 192 of file PropertyProxy.py.

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

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

Definition at line 230 of file PropertyProxy.py.

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

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

Definition at line 264 of file PropertyProxy.py.

264 def convertValueToBeSet(self, obj, value):
265 if value is None:
266 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__,
286 value.getName())
287 raise RuntimeError(self.fullPropertyName(obj) +
288 ': Public tool %s is not yet in ToolSvc. %s' %
289 (value.getJobOptName(), suggestion))
290 # make it read-only
291 return self._handleType(value.toStringProperty())
292 elif value.hasParent(obj.getJobOptName()):
293 # is already a child, keep as-is
294 return value
295 else:
296 # make a copy of the configurable
297 value = obj.copyChildAndSetParent(value, obj.getJobOptName())
298 # ensure that the new object is in allConfigurables
299 obj.allConfigurables[value.name()] = value
300 return value
301 else:
302 raise TypeError("Property %s value %r is not a %s nor a %s nor a string" %
303 (self.fullPropertyName(obj), value, self._confTypeName, self._handleType.__name__))
304
305 return value
306
307
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig
def isConfig(self, value)
Definition: PropertyProxy.py:206
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle
def isHandle(self, value)
Definition: PropertyProxy.py:202
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:173
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.convertValueToBeSet
def convertValueToBeSet(self, obj, value)
Definition: PropertyProxy.py:264
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
_handleType
Definition: PropertyProxy.py:172
gaudirun.type
type
Definition: gaudirun.py:133
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:22
GaudiKernel.PropertyProxy.PropertyProxy.fullPropertyName
def fullPropertyName(self, obj)
Definition: PropertyProxy.py:85

def GaudiKernel.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.

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

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
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig
def isConfig(self, value)
Definition: PropertyProxy.py:206
GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
_confTypeName
Definition: PropertyProxy.py:173
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:22

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

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

Definition at line 202 of file PropertyProxy.py.

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

## Member Data Documentation

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
| private

Definition at line 173 of file PropertyProxy.py.

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
| private

Definition at line 172 of file PropertyProxy.py.

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

- GaudiKernel/python/GaudiKernel/PropertyProxy.py