The Gaudi Framework  master (9f3f8895)
Loading...
Searching...
No Matches
GaudiPython.Bindings.iProperty Class Reference
Inheritance 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 281 of file Bindings.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 284 of file Bindings.py.

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

Member Function Documentation

◆ __call_interface_method__()

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

Definition at line 297 of file Bindings.py.

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

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

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

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

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

◆ getInterface()

GaudiPython.Bindings.iProperty.getInterface ( self)

Definition at line 289 of file Bindings.py.

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

◆ name()

GaudiPython.Bindings.iProperty.name ( self)

Reimplemented in GaudiPython.Bindings.iAlgTool.

Definition at line 376 of file Bindings.py.

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

◆ properties()

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 raise NotImplementedError("rely on IJobOptionsSvc")
364 props = self._optsvc.getProperties(self._name)
365 propsFrom = "jobOptionsSvc"
366 if props:
367 for p in props:
368 try:
369 dct[p.name()] = PropertyEntry(p)
370 except (ValueError, TypeError) as e:
371 raise ValueError(
372 f"gaudimodule.iProperty.properties(): {e.__class__.__name__}{e.args} processing property {propsFrom}.{p.name()} = {p.value()}"
373 )
374 return dct
375

◆ retrieveInterface()

GaudiPython.Bindings.iProperty.retrieveInterface ( self)

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

Definition at line 294 of file Bindings.py.

294 def retrieveInterface(self):
295 pass
296

Member Data Documentation

◆ _ip

GaudiPython.Bindings.iProperty._ip
protected

Definition at line 290 of file Bindings.py.

◆ _name

GaudiPython.Bindings.iProperty._name
protected

Definition at line 326 of file Bindings.py.

◆ _svcloc

GaudiPython.Bindings.iProperty._svcloc
protected

Definition at line 326 of file Bindings.py.


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