The Gaudi Framework  v29r0 (ff2e7097)
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 219 of file Bindings.py.

Constructor & Destructor Documentation

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

Definition at line 222 of file Bindings.py.

222  def __init__(self, name, ip=None):
223  if ip:
224  self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
225  else:
226  self.__dict__['_ip'] = None
227  self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
228  optsvc = Helper.service(self._svcloc, 'JobOptionsSvc')
229  if optsvc:
230  self.__dict__['_optsvc'] = InterfaceCast(
231  gbl.IJobOptionsSvc)(optsvc)
232  else:
233  self.__dict__['_optsvc'] = None
234  self.__dict__['_name'] = name
235 
def __init__(self, name, ip=None)
Definition: Bindings.py:222

Member Function Documentation

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

Definition at line 244 of file Bindings.py.

244  def __call_interface_method__(self, ifname, method, *args):
245  if not getattr(self, ifname):
246  self.retrieveInterface()
247  return getattr(getattr(self, ifname), method)(*args)
248 
def __call_interface_method__(self, ifname, method, args)
Definition: Bindings.py:244
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 305 of file Bindings.py.

305  def __getattr__(self, name):
306  """
307  The method which returns the value for the given property
308  - In the case of the valid instance it returns the valid property value through IProperty interface
309  - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
310  """
311  ip = self.getInterface()
312  if ip:
313  if not gbl.Gaudi.Utils.hasProperty(ip, name):
314  raise AttributeError, 'property %s does not exist' % name
315  prop = ip.getProperty(name)
316  if StringProperty == type(prop):
317  return prop.value()
318  elif StringPropertyRef == type(prop):
319  return prop.value()
320  try:
321  return eval(prop.toString(), {}, {})
322  except:
323  return prop.value()
324  else:
325  props = self._optsvc.getProperties(self._name)
326  for p in props:
327  if not p.name() == name:
328  continue
329  # from JobOptionsSvc we always have only strings
330  try:
331  return eval(p.value(), {}, {})
332  except:
333  return p.value()
334  raise AttributeError, 'property %s does not exist' % name
335 
def __getattr__(self, name)
Definition: Bindings.py:305
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 249 of file Bindings.py.

249  def __setattr__(self, name, value):
250  """
251  The method which is used for setting the property from the given value.
252  - In the case of the valid instance it sets the property through IProperty interface
253  - In the case of placeholder the property is added to JobOptionsCatalogue
254  """
255  if hasattr(value, 'toStringProperty'):
256  # user defined behaviour
257  value = '%s' % value.toStringProperty()
258  ip = self.getInterface()
259  if ip:
260  if not gbl.Gaudi.Utils.hasProperty(ip, name):
261  raise AttributeError, 'property %s does not exist' % name
262  prop = ip.getProperty(name)
263 
264  if ROOT6WorkAroundEnabled('ROOT-7201'):
265  canSetValue = (hasattr(prop, 'value') and
266  'const&[' not in prop.value.func_doc and
267  type(value) == type(prop.value()))
268  else:
269  canSetValue = (hasattr(prop, 'value') and
270  type(value) == type(prop.value()))
271 
272  if canSetValue:
273  if not prop.setValue(value):
274  raise AttributeError, 'property %s could not be set from %s' % (
275  name, value)
276  else:
277  if tuple == type(value):
278  value = str(value)
279  elif hasattr(value, 'toString'):
280  value = value.toString()
281  elif not long == type(value):
282  value = '%s' % value
283  else:
284  value = '%d' % value
285  if ROOT6WorkAroundEnabled('ROOT-6028'):
286  sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
287  prop, value)
288  else:
289  sc = prop.fromString(value)
290  if sc.isFailure():
291  raise AttributeError, 'property %s could not be set from %s' % (
292  name, value)
293  else:
294  if type(value) == str:
295  value = '"%s"' % value # need double quotes
296  elif type(value) == tuple:
297  value = str(value)
298  elif hasattr(value, 'toString'):
299  value = value.toString()
300  elif type(value) == long:
301  value = '%d' % value # prevent pending 'L'
302  sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
303  self._optsvc.addPropertyToCatalogue(self._name, sp).ignore()
304 
def ROOT6WorkAroundEnabled(id=None)
Definition: __init__.py:4
def __setattr__(self, name, value)
Definition: Bindings.py:249
def GaudiPython.Bindings.iProperty.getInterface (   self)

Definition at line 236 of file Bindings.py.

236  def getInterface(self):
237  if not self._ip:
238  self.retrieveInterface()
239  return self._ip
240 
def GaudiPython.Bindings.iProperty.name (   self)

Definition at line 356 of file Bindings.py.

356  def name(self):
357  return self._name
358 
359 # ----iService class-----------------------------------------------------------
360 
361 
def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 336 of file Bindings.py.

336  def properties(self):
337  dct = {}
338  props = None
339  ip = self.getInterface()
340  if ip:
341  props = ip.getProperties()
342  propsFrom = self._name # "interface"
343  else:
344  props = self._optsvc.getProperties(self._name)
345  propsFrom = "jobOptionsSvc"
346  if props:
347  for p in props:
348  try:
349  dct[p.name()] = PropertyEntry(p)
350  except (ValueError, TypeError), e:
351  raise ValueError, "gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
352  (e.__class__.__name__, e.args,
353  propsFrom, p.name(), p.value())
354  return dct
355 
Definition: Bindings.py:173
def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

Definition at line 241 of file Bindings.py.

241  def retrieveInterface(self):
242  pass
243 

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