The Gaudi Framework  master (594c33fa)
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=cppyy.nullptr)
 
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 282 of file Bindings.py.

Constructor & Destructor Documentation

◆ __init__()

def GaudiPython.Bindings.iProperty.__init__ (   self,
  name,
  ip = cppyy.nullptr 
)

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

Definition at line 285 of file Bindings.py.

285  def __init__(self, name, ip=cppyy.nullptr):
286  self.__dict__["_ip"] = InterfaceCast(gbl.IProperty)(ip)
287  self.__dict__["_svcloc"] = gbl.Gaudi.svcLocator()
288  self.__dict__["_name"] = name
289 

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 298 of file Bindings.py.

298  def __call_interface_method__(self, ifname, method, *args):
299  if not getattr(self, ifname):
300  self.retrieveInterface()
301  return getattr(getattr(self, ifname), method)(*args)
302 

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

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

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

303  def __setattr__(self, name, value):
304  """
305  The method which is used for setting the property from the given value.
306  - In the case of the valid instance it sets the property through IProperty interface
307  - In the case of placeholder the property is added to JobOptionsCatalogue
308  """
309  if hasattr(value, "toStringProperty"):
310  # user defined behaviour
311  value = str(value.toStringProperty())
312  elif hasattr(value, "toString"):
313  value = str(value.toString())
314  elif isinstance(value, set) and value:
315  # We want a reproducible (sorted) representation in the catalogue
316  value = "{" + repr(sorted(value))[1:-1] + "}"
317  else:
318  value = str(value)
319 
320  ip = self.getInterface()
321  if ip:
322  if not gbl.Gaudi.Utils.hasProperty(ip, name):
323  raise AttributeError("property %s does not exist" % name)
324  ip.setPropertyRepr(name, value)
325  else:
326  gbl.GaudiPython.Helpers.setProperty(
327  self._svcloc, ".".join([self._name, name]), value
328  )
329 

◆ getInterface()

def GaudiPython.Bindings.iProperty.getInterface (   self)

Definition at line 290 of file Bindings.py.

290  def getInterface(self):
291  if not self._ip:
292  self.retrieveInterface()
293  return self._ip
294 

◆ name()

def GaudiPython.Bindings.iProperty.name (   self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 378 of file Bindings.py.

378  def name(self):
379  return self._name
380 
381 
382 # ----iService class-----------------------------------------------------------
383 
384 

◆ properties()

def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 356 of file Bindings.py.

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

◆ retrieveInterface()

def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

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

Definition at line 295 of file Bindings.py.

295  def retrieveInterface(self):
296  pass
297 

The documentation for this class was generated from the following file:
GaudiPartProp.decorators.__getattr__
__getattr__
decorate the attribute access for Gaudi.ParticleProperty
Definition: decorators.py:186
GaudiPartProp.Service.InterfaceCast
InterfaceCast
Definition: Service.py:40
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:68
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77