| The Gaudi Framework v32r1 (f65d50dc)

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 | __delete__ (self, obj)

## Private Attributes
| _handleType
| _confTypeName

## Additional Inherited Members
Public Attributes inherited from GaudiKernel.PropertyProxy.PropertyProxy
| history
| descr
| deprecated
Static Public Attributes inherited from GaudiKernel.PropertyProxy.PropertyProxy
| proptype = type(self.default)
| allowcompat = True
bool | allowcompat = True
| value = _isCompatible(proptype, value)
def | oldvec = self.descr.__get__(obj, type)
| tpo = type(oldvec[0])
Properties inherited from GaudiKernel.PropertyProxy.PropertyProxy
| default = property(getDefault, setDefault)

## Detailed Description

    A class with some utilities for GaudiHandles and GaudiHandleArrays

Definition at line 172 of file PropertyProxy.py.

## Constructor & Destructor Documentation

## ◆ __init__()

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

175 def __init__(self, descr, docString, default, handleType, allowedType):
176 """<descr>: the real property in the object instance (from __slots__)
177 <docString>: the documentation string of this property
178 <default>: default value from C++ (via python generated by genconf)
179 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
180 <allowedType>: allowed instance type for default
181 """
182 # check that default is of allowed type for this proxy
183 if not isinstance(default, allowedType):
184 raise TypeError("%s: %s default: %r is not a %s" %
185 (descr.__name__, self.__class__.__name__, default,
186 allowedType.__name__))
187 PropertyProxy.__init__(self, descr, docString, default)
188 self._handleType = handleType
189 self._confTypeName = 'Configurable' + handleType.componentType
190 # print "%s: %r (%s)" % (self.__class__.__name__,self._handleType,self._confTypeName)
191

## Member Function Documentation

## ◆ __get__()

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

Reimplemented from GaudiKernel.PropertyProxy.PropertyProxy.

Definition at line 192 of file PropertyProxy.py.

192 def __get__(self, obj, type=None):
193 try:
194 return self.descr.__get__(obj, type)
195 except AttributeError:
196 # Get default
197 try:
198 default = obj.__class__.getDefaultProperty(self.descr.__name__)
199 default = self.convertDefaultToBeSet(obj, default)
200 if default:
201 self.__set__(obj, default)
202 except AttributeError as e:
203 # change type of exception to avoid false error message
204 raise RuntimeError(*e.args)
205
206 return self.descr.__get__(obj, type)
207

## ◆ __set__()

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

Reimplemented from GaudiKernel.PropertyProxy.PropertyProxy.

Definition at line 208 of file PropertyProxy.py.

208 def __set__(self, obj, value):
209 # allow a property to be set if we're in non-default mode, or if it
210 # simply hasn't been set before
211 if not obj._isInSetDefaults() or not obj in self.history:
212 value = self.convertValueToBeSet(obj, value)
213 # assign the value
214 self.descr.__set__(obj, value)
215 log.debug("Setting %s = %r", self.fullPropertyName(obj), value)
216 self.history.setdefault(obj, []).append(value)
217

## ◆ convertDefaultToBeSet()

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

Reimplemented in GaudiKernel.PropertyProxy.GaudiHandleArrayPropertyProxy.

Definition at line 246 of file PropertyProxy.py.

246 def convertDefaultToBeSet(self, obj, default):
247 # turn string into handle
248 isString = type(default) == str
249 if not isString and self.isConfig(default):
250 # print self.fullPropertyName(obj) + ": Setting default configurable: %r" % default
251 return default
252 elif isString or self.isHandle(default):
253 if isString:
254 # convert string into handle
255 typeAndName = default
256 default = self._handleType(typeAndName)
257 else:
258 typeAndName = default.typeAndName
259 if not self._handleType.isPublic:
260 if not typeAndName:
261 return None
262 # Find corresponding default configurable of private handles
263 try:
264 conf = self.getDefaultConfigurable(
265 typeAndName, self.fullPropertyName(obj))
266
267
268 # print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
269 except AttributeError as e:
270 # change type of exception to avoid false error message
271 raise RuntimeError(*e.args)
272 if conf is None:
273 raise RuntimeError(
274 "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb"
275 % (self.fullPropertyName(obj), default.getType()))
276 return conf
277 else: # not a config, not a handle, not a string
278 raise TypeError("%s: default value %r is not of type %s or %s" %
279 (self.fullPropertyName(obj), default,
280 self._confTypeName, self._handleType.__name__))
281
282 return default
283
gaudirun.type
type
Definition: gaudirun.py:142

## ◆ convertValueToBeSet()

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

Reimplemented in GaudiKernel.PropertyProxy.GaudiHandleArrayPropertyProxy.

Definition at line 284 of file PropertyProxy.py.

284 def convertValueToBeSet(self, obj, value):
285 if value is None:
286 value = ''
287 isString = type(value) == str
288 if isString:
289 # create an new handle
290 return self._handleType(value)
291 elif self.isHandle(value):
292 # make a copy of the handle
293 return self._handleType(value.toStringProperty())
294 elif self.isConfig(value):
295 if self._handleType.isPublic:
296 # A public tool must be registered to ToolSvc before assigning it
297 if derives_from(value, 'ConfigurableAlgTool'):
298 if not value.isInToolSvc():
299 suggestion = 'You may need to add jobOptions lines something like:' + os.linesep + \
300 'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
301 'ToolSvc += '
302 if value.getName() == value.getType(
303 ): # using default name
304 suggestion += '%s()' % value.__class__.__name__
305 else: # using user-defined name
306 suggestion += '%s(%r)' % (value.__class__.__name__,
307 value.getName())
308 raise RuntimeError(
309 self.fullPropertyName(obj) +
310 ': Public tool %s is not yet in ToolSvc. %s' %
311 (value.getJobOptName(), suggestion))
312 # make it read-only
313 return self._handleType(value.toStringProperty())
314 elif value.hasParent(obj.getJobOptName()):
315 # is already a child, keep as-is
316 return value
317 else:
318 # make a copy of the configurable
319 value = obj.copyChildAndSetParent(value, obj.getJobOptName())
320 # ensure that the new object is in allConfigurables
321 obj.allConfigurables[value.name()] = value
322 return value
323 else:
324 raise TypeError(
325 "Property %s value %r is not a %s nor a %s nor a string" %
326 (self.fullPropertyName(obj), value, self._confTypeName,
327 self._handleType.__name__))
328
329 return value
330
331
gaudirun.type
type
Definition: gaudirun.py:142
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:24

## ◆ getDefaultConfigurable()

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

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

Definition at line 226 of file PropertyProxy.py.

226 def getDefaultConfigurable(self, typeAndName, requester):
227 """Return the configurable instance corresponding to the toolhandle if possible.
228 Otherwise return None"""
229 global log
230 # find the module
231 typeAndNameTuple = typeAndName.split('/')
232 confType = typeAndNameTuple[0]
233 confClass = ConfigurableDb.getConfigurable(confType)
234 # check the type of the configurable
235 if not derives_from(confClass, self._confTypeName):
236 log.error("%s: Configurable %s is not a %s", requester, confType,
237 self._confTypeName)
238 return None
239 try:
240 confName = typeAndNameTuple[1]
241 except IndexError:
242 return confClass() # use default name
243 else:
244 return confClass(confName)
245
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:24

## ◆ isConfig()

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

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

Definition at line 222 of file PropertyProxy.py.

222 def isConfig(self, value):
223 """Check if <value> is a configurable of the correct type"""
224 return derives_from(value, self._confTypeName)
225
GaudiKernel.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:24

## ◆ isHandle()

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

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

Definition at line 218 of file PropertyProxy.py.

218 def isHandle(self, value):
219 """Check if <value> is a handle of the correct type"""
220 return isinstance(value, self._handleType)
221

## Member Data Documentation

## ◆ _confTypeName

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
| private

Definition at line 189 of file PropertyProxy.py.

## ◆ _handleType

GaudiKernel.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
| private

Definition at line 188 of file PropertyProxy.py.

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

- GaudiKernel/python/GaudiKernel/PropertyProxy.py