The Gaudi Framework  v33r1 (b1225454)
GaudiPython.Bindings.iProperty Class Reference
Inheritance diagram for GaudiPython.Bindings.iProperty:
Collaboration diagram for GaudiPython.Bindings.iProperty:

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 249 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 252 of file Bindings.py.

252  def __init__(self, name, ip=None):
253  if ip:
254  self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
255  else:
256  self.__dict__['_ip'] = None
257  self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
258  optsvc = Helper.service(self._svcloc, 'JobOptionsSvc')
259  if optsvc:
260  self.__dict__['_optsvc'] = InterfaceCast(
261  gbl.IJobOptionsSvc)(optsvc)
262  else:
263  self.__dict__['_optsvc'] = None
264  self.__dict__['_name'] = name
265 

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 274 of file Bindings.py.

274  def __call_interface_method__(self, ifname, method, *args):
275  if not getattr(self, ifname):
276  self.retrieveInterface()
277  return getattr(getattr(self, ifname), method)(*args)
278 

◆ __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 335 of file Bindings.py.

335  def __getattr__(self, name):
336  """
337  The method which returns the value for the given property
338  - In the case of the valid instance it returns the valid property value through IProperty interface
339  - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
340  """
341  ip = self.getInterface()
342  if ip:
343  if not gbl.Gaudi.Utils.hasProperty(ip, name):
344  raise AttributeError('property %s does not exist' % name)
345  prop = ip.getProperty(name)
346  if StringProperty == type(prop):
347  return prop.value()
348  elif StringPropertyRef == type(prop):
349  return prop.value()
350  try:
351  return eval(prop.toString(), {}, {})
352  except:
353  return prop.value()
354  else:
355  props = self._optsvc.getProperties(self._name)
356  for p in props:
357  if not p.name() == name:
358  continue
359  # from JobOptionsSvc we always have only strings
360  try:
361  return eval(p.value(), {}, {})
362  except:
363  return p.value()
364  raise AttributeError('property %s does not exist' % name)
365 

◆ __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 279 of file Bindings.py.

279  def __setattr__(self, name, value):
280  """
281  The method which is used for setting the property from the given value.
282  - In the case of the valid instance it sets the property through IProperty interface
283  - In the case of placeholder the property is added to JobOptionsCatalogue
284  """
285  if hasattr(value, 'toStringProperty'):
286  # user defined behaviour
287  value = '%s' % value.toStringProperty()
288  ip = self.getInterface()
289  if ip:
290  if not gbl.Gaudi.Utils.hasProperty(ip, name):
291  raise AttributeError('property %s does not exist' % name)
292  prop = ip.getProperty(name)
293 
294  if ROOT6WorkAroundEnabled('ROOT-7201'):
295  canSetValue = (hasattr(prop, 'value')
296  and 'const&[' not in prop.value.func_doc
297  and type(value) == type(prop.value()))
298  else:
299  canSetValue = (hasattr(prop, 'value')
300  and type(value) == type(prop.value()))
301 
302  if canSetValue:
303  if not prop.setValue(value):
304  raise AttributeError(
305  'property %s could not be set from %s' % (name, value))
306  else:
307  if tuple == type(value):
308  value = str(value)
309  elif hasattr(value, 'toString'):
310  value = value.toString()
311  elif not long == type(value):
312  value = '%s' % value
313  else:
314  value = '%d' % value
315  if ROOT6WorkAroundEnabled('ROOT-6028'):
316  sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
317  prop, value)
318  else:
319  sc = prop.fromString(value)
320  if sc.isFailure():
321  raise AttributeError(
322  'property %s could not be set from %s' % (name, value))
323  else:
324  if type(value) == str:
325  value = '"%s"' % value # need double quotes
326  elif type(value) == tuple:
327  value = str(value)
328  elif hasattr(value, 'toString'):
329  value = value.toString()
330  elif type(value) == long:
331  value = '%d' % value # prevent pending 'L'
332  sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
333  self._optsvc.addPropertyToCatalogue(self._name, sp).ignore()
334 
bool PyHelper() addPropertyToCatalogue(IInterface *p, char *comp, char *name, char *value)
Definition: Bootstrap.cpp:255
def ROOT6WorkAroundEnabled(id=None)
Definition: __init__.py:14

◆ getInterface()

def GaudiPython.Bindings.iProperty.getInterface (   self)

Definition at line 266 of file Bindings.py.

266  def getInterface(self):
267  if not self._ip:
268  self.retrieveInterface()
269  return self._ip
270 

◆ name()

def GaudiPython.Bindings.iProperty.name (   self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 386 of file Bindings.py.

386  def name(self):
387  return self._name
388 
389 
390 # ----iService class-----------------------------------------------------------
391 
392 

◆ properties()

def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 366 of file Bindings.py.

366  def properties(self):
367  dct = {}
368  props = None
369  ip = self.getInterface()
370  if ip:
371  props = ip.getProperties()
372  propsFrom = self._name # "interface"
373  else:
374  props = self._optsvc.getProperties(self._name)
375  propsFrom = "jobOptionsSvc"
376  if props:
377  for p in props:
378  try:
379  dct[p.name()] = PropertyEntry(p)
380  except (ValueError, TypeError) as e:
381  raise ValueError("gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
382  (e.__class__.__name__, e.args,
383  propsFrom, p.name(), p.value()))
384  return dct
385 

◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

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

Definition at line 271 of file Bindings.py.

271  def retrieveInterface(self):
272  pass
273 

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