The Gaudi Framework  v32r2 (46d42edc)
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 238 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 241 of file Bindings.py.

241  def __init__(self, name, ip=None):
242  if ip:
243  self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
244  else:
245  self.__dict__['_ip'] = None
246  self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
247  optsvc = Helper.service(self._svcloc, 'JobOptionsSvc')
248  if optsvc:
249  self.__dict__['_optsvc'] = InterfaceCast(
250  gbl.IJobOptionsSvc)(optsvc)
251  else:
252  self.__dict__['_optsvc'] = None
253  self.__dict__['_name'] = name
254 

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 263 of file Bindings.py.

263  def __call_interface_method__(self, ifname, method, *args):
264  if not getattr(self, ifname):
265  self.retrieveInterface()
266  return getattr(getattr(self, ifname), method)(*args)
267 

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

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

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

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

◆ getInterface()

def GaudiPython.Bindings.iProperty.getInterface (   self)

Definition at line 255 of file Bindings.py.

255  def getInterface(self):
256  if not self._ip:
257  self.retrieveInterface()
258  return self._ip
259 

◆ name()

def GaudiPython.Bindings.iProperty.name (   self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 375 of file Bindings.py.

375  def name(self):
376  return self._name
377 
378 
379 # ----iService class-----------------------------------------------------------
380 
381 

◆ properties()

def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 355 of file Bindings.py.

355  def properties(self):
356  dct = {}
357  props = None
358  ip = self.getInterface()
359  if ip:
360  props = ip.getProperties()
361  propsFrom = self._name # "interface"
362  else:
363  props = self._optsvc.getProperties(self._name)
364  propsFrom = "jobOptionsSvc"
365  if props:
366  for p in props:
367  try:
368  dct[p.name()] = PropertyEntry(p)
369  except (ValueError, TypeError) as e:
370  raise ValueError("gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
371  (e.__class__.__name__, e.args,
372  propsFrom, p.name(), p.value()))
373  return dct
374 

◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

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

Definition at line 260 of file Bindings.py.

260  def retrieveInterface(self):
261  pass
262 

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