| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | List of all members
GaudiPython.Bindings.iProperty Class Reference
Inheritance diagram for GaudiPython.Bindings.iProperty:
[legend]
Collaboration diagram for GaudiPython.Bindings.iProperty:
[legend]

## Public Member Functions
def | __init__ (self, name, ip=None)
def | getInterface (self)
def | retrieveInterface (self)
def | __call_interface_method__ (self, ifname, method, *args)
def | __setattr__ (self, name, value)
def | __getattr__ (self, name)
def | properties (self)
def | name (self)

## Detailed Description

    Python equivalent to the C++ Property interface

Definition at line 230 of file Bindings.py.

## Constructor & Destructor Documentation

## ◆ __init__()

def GaudiPython.Bindings.iProperty.__init__ | ( |  | self,
|  |  | name,
|  |  | ip = `None`
| ) |  |

Reimplemented in GaudiPython.Bindings.iJobOptSvc, GaudiPython.Bindings.iToolSvc, GaudiPython.Bindings.iNTupleSvc, GaudiPython.Bindings.iHistogramSvc, GaudiPython.Bindings.iDataSvc, GaudiPython.Bindings.iAlgTool, GaudiPython.Bindings.iAlgorithm, and GaudiPython.Bindings.iService.

Definition at line 233 of file Bindings.py.

233 def __init__(self, name, ip=None):
234 if ip:
235 self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
236 else:
237 self.__dict__['_ip'] = None
238 self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
239 optsvc = Helper.service(self._svcloc, 'JobOptionsSvc')
240 if optsvc:
241 self.__dict__['_optsvc'] = InterfaceCast(
242 gbl.IJobOptionsSvc)(optsvc)
243 else:
244 self.__dict__['_optsvc'] = None
245 self.__dict__['_name'] = name
246

## Member Function Documentation

## ◆ __call_interface_method__()

def GaudiPython.Bindings.iProperty.__call_interface_method__ | ( |  | self,
|  |  | ifname,
|  |  | method,
|  | * | args
| ) |  |

Definition at line 255 of file Bindings.py.

255 def __call_interface_method__(self, ifname, method, *args):
256 if not getattr(self, ifname):
257 self.retrieveInterface()
258 return getattr(getattr(self, ifname), method)(*args)
259

## ◆ __getattr__()

def GaudiPython.Bindings.iProperty.__getattr__ | ( |  | self,
|  |  | name
| ) |  |

    The method which returns the value for the given property
    - In the case of the valid instance it returns the valid property value through IProperty interface
    - In the case of placeholder the property value is retrieved from JobOptionsCatalogue

Definition at line 316 of file Bindings.py.

316 def __getattr__(self, name):
317 """
318 The method which returns the value for the given property
319 - In the case of the valid instance it returns the valid property value through IProperty interface
320 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
321 """
322 ip = self.getInterface()
323 if ip:
324 if not gbl.Gaudi.Utils.hasProperty(ip, name):
325 raise AttributeError('property %s does not exist' % name)
326 prop = ip.getProperty(name)
327 if StringProperty == type(prop):
328 return prop.value()
329 elif StringPropertyRef == type(prop):
330 return prop.value()
331 try:
332 return eval(prop.toString(), {}, {})
333 except:
334 return prop.value()
335 else:
336 props = self._optsvc.getProperties(self._name)
337 for p in props:
338 if not p.name() == name:
339 continue
340 # from JobOptionsSvc we always have only strings
341 try:
342 return eval(p.value(), {}, {})
343 except:
344 return p.value()
345 raise AttributeError('property %s does not exist' % name)
346
gaudirun.type
type
Definition: gaudirun.py:142

## ◆ __setattr__()

def GaudiPython.Bindings.iProperty.__setattr__ | ( |  | self,
|  |  | name,
|  |  | value
| ) |  |

    The method which is used for setting the property from the given value.
    - In the case of the valid instance it sets the property through IProperty interface
    - In the case of placeholder the property is added to JobOptionsCatalogue

Definition at line 260 of file Bindings.py.

260 def __setattr__(self, name, value):
261 """
262 The method which is used for setting the property from the given value.
263 - In the case of the valid instance it sets the property through IProperty interface
264 - In the case of placeholder the property is added to JobOptionsCatalogue
265 """
266 if hasattr(value, 'toStringProperty'):
267 # user defined behaviour
268 value = '%s' % value.toStringProperty()
269 ip = self.getInterface()
270 if ip:
271 if not gbl.Gaudi.Utils.hasProperty(ip, name):
272 raise AttributeError('property %s does not exist' % name)
273 prop = ip.getProperty(name)
274
275 if ROOT6WorkAroundEnabled('ROOT-7201'):
276 canSetValue = (hasattr(prop, 'value')
277 and 'const&[' not in prop.value.func_doc
278 and type(value) == type(prop.value()))
279 else:
280 canSetValue = (hasattr(prop, 'value')
281 and type(value) == type(prop.value()))
282
283 if canSetValue:
284 if not prop.setValue(value):
285 raise AttributeError(
286 'property %s could not be set from %s' % (name, value))
287 else:
288 if tuple == type(value):
289 value = str(value)
290 elif hasattr(value, 'toString'):
291 value = value.toString()
292 elif not long == type(value):
293 value = '%s' % value
294 else:
295 value = '%d' % value
296 if ROOT6WorkAroundEnabled('ROOT-6028'):
297 sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
298 prop, value)
299 else:
300 sc = prop.fromString(value)
301 if sc.isFailure():
302 raise AttributeError(
303 'property %s could not be set from %s' % (name, value))
304 else:
305 if type(value) == str:
306 value = '"%s"' % value # need double quotes
307 elif type(value) == tuple:
308 value = str(value)
309 elif hasattr(value, 'toString'):
310 value = value.toString()
311 elif type(value) == long:
312 value = '%d' % value # prevent pending 'L'
313 sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
314 self._optsvc.addPropertyToCatalogue(self._name, sp).ignore()
315
addPropertyToCatalogue
bool PyHelper() addPropertyToCatalogue(IInterface *p, char *comp, char *name, char *value)
Definition: Bootstrap.cpp:245
GaudiKernel.ROOT6WorkAroundEnabled
def ROOT6WorkAroundEnabled(id=None)
Definition: __init__.py:4
gaudirun.type
type
Definition: gaudirun.py:142

## ◆ getInterface()

def GaudiPython.Bindings.iProperty.getInterface | ( |  | self | ) |

Definition at line 247 of file Bindings.py.

247 def getInterface(self):
248 if not self._ip:
249 self.retrieveInterface()
250 return self._ip
251

## ◆ name()

def GaudiPython.Bindings.iProperty.name | ( |  | self | ) |

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 367 of file Bindings.py.

367 def name(self):
368 return self._name
369
370
371 # ----iService class-----------------------------------------------------------
372
373
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41

## ◆ properties()

def GaudiPython.Bindings.iProperty.properties | ( |  | self | ) |

Definition at line 347 of file Bindings.py.

347 def properties(self):
348 dct = {}
349 props = None
350 ip = self.getInterface()
351 if ip:
352 props = ip.getProperties()
353 propsFrom = self._name # "interface"
354 else:
355 props = self._optsvc.getProperties(self._name)
356 propsFrom = "jobOptionsSvc"
357 if props:
358 for p in props:
359 try:
360 dct[p.name()] = PropertyEntry(p)
361 except (ValueError, TypeError) as e:
362 raise ValueError("gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
363 (e.__class__.__name__, e.args,
364 propsFrom, p.name(), p.value()))
365 return dct
366
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:51

## ◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface | ( |  | self | ) |

Reimplemented in GaudiPython.Bindings.iAlgTool, GaudiPython.Bindings.iAlgorithm, and GaudiPython.Bindings.iService.

Definition at line 252 of file Bindings.py.

252 def retrieveInterface(self):
253 pass
254

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

- GaudiPython/python/GaudiPython/Bindings.py