The Gaudi Framework  v33r0 (d5ea422b)
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 248 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 251 of file Bindings.py.

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

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 273 of file Bindings.py.

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

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

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

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

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

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

◆ name()

def GaudiPython.Bindings.iProperty.name (   self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 385 of file Bindings.py.

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

◆ properties()

def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 365 of file Bindings.py.

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

◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

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

Definition at line 270 of file Bindings.py.

270  def retrieveInterface(self):
271  pass
272 

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