The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
GaudiPython.Bindings.iProperty Class Reference
Inheritance diagram for GaudiPython.Bindings.iProperty:
Collaboration diagram for GaudiPython.Bindings.iProperty:

Public Member Functions

 __init__ (self, name, ip=cppyy.nullptr)
 
 getInterface (self)
 
 retrieveInterface (self)
 
 __call_interface_method__ (self, ifname, method, *args)
 
 __setattr__ (self, name, value)
 
 __getattr__ (self, name)
 
 properties (self)
 
 name (self)
 

Protected Attributes

 _ip
 
 _svcloc
 
 _name
 

Detailed Description

Python equivalent to the C++ Property interface

Definition at line 282 of file Bindings.py.

Constructor & Destructor Documentation

◆ __init__()

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

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__()

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__()

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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

◆ __setattr__()

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()

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()

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()

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()

GaudiPython.Bindings.iProperty.retrieveInterface ( self)

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

Definition at line 295 of file Bindings.py.

295 def retrieveInterface(self):
296 pass
297

Member Data Documentation

◆ _ip

GaudiPython.Bindings.iProperty._ip
protected

Definition at line 291 of file Bindings.py.

◆ _name

GaudiPython.Bindings.iProperty._name
protected

Definition at line 327 of file Bindings.py.

◆ _svcloc

GaudiPython.Bindings.iProperty._svcloc
protected

Definition at line 327 of file Bindings.py.


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