The Gaudi Framework  v33r2 (a6f0ec87)
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 258 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 261 of file Bindings.py.

261  def __init__(self, name, ip=None):
262  if ip:
263  self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
264  else:
265  self.__dict__['_ip'] = None
266  self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
267  optsvc = Helper.service(self._svcloc, 'JobOptionsSvc')
268  if optsvc:
269  self.__dict__['_optsvc'] = InterfaceCast(
270  gbl.IJobOptionsSvc)(optsvc)
271  else:
272  self.__dict__['_optsvc'] = None
273  self.__dict__['_name'] = name
274 

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 283 of file Bindings.py.

283  def __call_interface_method__(self, ifname, method, *args):
284  if not getattr(self, ifname):
285  self.retrieveInterface()
286  return getattr(getattr(self, ifname), method)(*args)
287 

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

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

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

288  def __setattr__(self, name, value):
289  """
290  The method which is used for setting the property from the given value.
291  - In the case of the valid instance it sets the property through IProperty interface
292  - In the case of placeholder the property is added to JobOptionsCatalogue
293  """
294  if hasattr(value, 'toStringProperty'):
295  # user defined behaviour
296  value = '%s' % value.toStringProperty()
297  ip = self.getInterface()
298  if ip:
299  if not gbl.Gaudi.Utils.hasProperty(ip, name):
300  raise AttributeError('property %s does not exist' % name)
301  prop = ip.getProperty(name)
302 
303  if ROOT6WorkAroundEnabled('ROOT-7201'):
304  canSetValue = (hasattr(prop, 'value')
305  and 'const&[' not in prop.value.func_doc
306  and type(value) == type(prop.value()))
307  else:
308  canSetValue = (hasattr(prop, 'value')
309  and type(value) == type(prop.value()))
310 
311  if canSetValue:
312  if not prop.setValue(value):
313  raise AttributeError(
314  'property %s could not be set from %s' % (name, value))
315  else:
316  if tuple == type(value):
317  value = str(value)
318  elif hasattr(value, 'toString'):
319  value = value.toString()
320  elif not long == type(value):
321  value = '%s' % value
322  else:
323  value = '%d' % value
324  if ROOT6WorkAroundEnabled('ROOT-6028'):
325  sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
326  prop, value)
327  else:
328  sc = prop.fromString(value)
329  if sc.isFailure():
330  raise AttributeError(
331  'property %s could not be set from %s' % (name, value))
332  else:
333  if type(value) == str:
334  value = '"%s"' % value # need double quotes
335  elif type(value) == tuple:
336  value = str(value)
337  elif hasattr(value, 'toString'):
338  value = value.toString()
339  elif type(value) == long:
340  value = '%d' % value # prevent pending 'L'
341  sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
342  self._optsvc.addPropertyToCatalogue(self._name, sp).ignore()
343 
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 275 of file Bindings.py.

275  def getInterface(self):
276  if not self._ip:
277  self.retrieveInterface()
278  return self._ip
279 

◆ name()

def GaudiPython.Bindings.iProperty.name (   self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 395 of file Bindings.py.

395  def name(self):
396  return self._name
397 
398 
399 # ----iService class-----------------------------------------------------------
400 
401 

◆ properties()

def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 375 of file Bindings.py.

375  def properties(self):
376  dct = {}
377  props = None
378  ip = self.getInterface()
379  if ip:
380  props = ip.getProperties()
381  propsFrom = self._name # "interface"
382  else:
383  props = self._optsvc.getProperties(self._name)
384  propsFrom = "jobOptionsSvc"
385  if props:
386  for p in props:
387  try:
388  dct[p.name()] = PropertyEntry(p)
389  except (ValueError, TypeError) as e:
390  raise ValueError("gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
391  (e.__class__.__name__, e.args,
392  propsFrom, p.name(), p.value()))
393  return dct
394 

◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

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

Definition at line 280 of file Bindings.py.

280  def retrieveInterface(self):
281  pass
282 

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