All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiPython.Bindings.iProperty Class Reference
Inheritance diagram for GaudiPython.Bindings.iProperty:
Collaboration diagram for GaudiPython.Bindings.iProperty:

Public Member Functions

def __init__
 
def getInterface
 
def retrieveInterface
 
def __call_interface_method__
 
def __setattr__
 
def __getattr__
 
def properties
 
def name
 

Detailed Description

Python equivalent to the C++ Property interface 

Definition at line 178 of file Bindings.py.

Constructor & Destructor Documentation

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

Definition at line 180 of file Bindings.py.

181  def __init__(self, name, ip = None) :
182  if ip : self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
183  else : self.__dict__['_ip'] = None
184  self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
185  optsvc = Helper.service(self._svcloc,'JobOptionsSvc')
186  if optsvc : self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(optsvc)
187  else : self.__dict__['_optsvc'] = None
self.__dict__['_name'] = name

Member Function Documentation

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

Definition at line 193 of file Bindings.py.

194  def __call_interface_method__(self,ifname,method,*args):
195  if not getattr(self,ifname) : self.retrieveInterface()
return getattr(getattr(self,ifname),method)(*args)
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 240 of file Bindings.py.

241  def __getattr__(self, name ):
242  """
243  The method which returns the value for the given property
244  - In the case of the valid instance it returns the valid property value through IProperty interface
245  - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
246  """
247  ip = self.getInterface()
248  if ip :
249  if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
250  raise AttributeError, 'property %s does not exist' % name
251  prop = ip.getProperty(name)
252  if StringProperty == type( prop ) : return prop.value()
253  elif StringPropertyRef == type( prop ) : return prop.value()
254  try: return eval( prop.toString(), {}, {} )
255  except : return prop.value()
256  else :
257  props = self._optsvc.getProperties(self._name)
258  for p in props :
259  if not p.name() == name : continue
260  # from JobOptionsSvc we always have only strings
261  try: return eval( p.value(), {}, {} )
262  except: return p.value()
raise AttributeError, 'property %s does not exist' % name
string type
Definition: gaudirun.py:126
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 196 of file Bindings.py.

197  def __setattr__(self, name, value):
198  """
199  The method which is used for setting the property from the given value.
200  - In the case of the valid instance it sets the property through IProperty interface
201  - In the case of placeholder the property is added to JobOptionsCatalogue
202  """
203  if hasattr( value, 'toStringProperty' ):
204  # user defined behaviour
205  value = '%s' % value.toStringProperty()
206  ip = self.getInterface()
207  if ip :
208  if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
209  raise AttributeError, 'property %s does not exist' % name
210  prop = ip.getProperty(name)
211 
212  if ROOT6WorkAroundEnabled('ROOT-6032'):
213  canSetValue = (hasattr(prop, 'value') and
214  'const(&)[' not in prop.value.func_doc and
215  type(value) == type(prop.value()))
216  else:
217  canSetValue = (hasattr(prop, 'value') and
218  type(value) == type(prop.value()))
219 
220  if canSetValue:
221  if not prop.setValue(value) :
222  raise AttributeError, 'property %s could not be set from %s' % (name, value)
223  else:
224  if tuple == type( value ) : value = str(value)
225  elif hasattr ( value , 'toString' ) : value = value.toString()
226  elif not long == type( value ) : value = '%s' % value
227  else : value = '%d' % value
228  if ROOT6WorkAroundEnabled('ROOT-6028'):
229  sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(prop, value)
230  else:
231  sc = prop.fromString(value)
232  if sc.isFailure() :
233  raise AttributeError, 'property %s could not be set from %s' % (name,value)
234  else :
235  if type(value) == str : value = '"%s"' % value # need double quotes
236  elif type(value) == tuple : value = str(value)
237  elif hasattr( value , 'toString' ) : value = value.toString()
238  elif type(value) == long: value = '%d' % value # prevent pending 'L'
239  sp = StringProperty( name , str(value))
self._optsvc.addPropertyToCatalogue( self._name , sp )
string type
Definition: gaudirun.py:126
def ROOT6WorkAroundEnabled
Definition: __init__.py:3
def GaudiPython.Bindings.iProperty.getInterface (   self)

Definition at line 188 of file Bindings.py.

189  def getInterface(self) :
190  if not self._ip : self.retrieveInterface()
return self._ip
def GaudiPython.Bindings.iProperty.name (   self)

Definition at line 281 of file Bindings.py.

282  def name(self) :
283  return self._name
284 
#----iService class---------------------------------------------------------------------
def GaudiPython.Bindings.iProperty.properties (   self)

Definition at line 263 of file Bindings.py.

264  def properties(self):
265  dct = {}
266  props = None
267  ip = self.getInterface()
268  if ip :
269  props = ip.getProperties()
270  propsFrom = self._name # "interface"
271  else:
272  props = self._optsvc.getProperties( self._name )
273  propsFrom = "jobOptionsSvc"
274  if props:
275  for p in props :
276  try:
277  dct[p.name()] = PropertyEntry(p)
278  except (ValueError,TypeError),e:
279  raise ValueError, "gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
280  (e.__class__.__name__, e.args, propsFrom, p.name(), p.value())
return dct
Definition: Bindings.py:143
def GaudiPython.Bindings.iProperty.retrieveInterface (   self)

Definition at line 191 of file Bindings.py.

192  def retrieveInterface(self) :
pass

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