The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
GaudiKernel.ConfigurableMeta.ConfigurableMeta Class Reference
Inheritance diagram for GaudiKernel.ConfigurableMeta.ConfigurableMeta:
Collaboration diagram for GaudiKernel.ConfigurableMeta.ConfigurableMeta:

Public Member Functions

 __new__ (self, name, bases, dct)
 __call__ (cls, *args, **kwargs)

Detailed Description

The setting of Gaudi component properties needs to be deferred and
history of who set what where needs to be collected. This is done
by using PropertyProxy descriptors rather than the default ones.

Definition at line 25 of file ConfigurableMeta.py.

Member Function Documentation

◆ __call__()

GaudiKernel.ConfigurableMeta.ConfigurableMeta.__call__ ( cls,
* args,
** kwargs )
To Gaudi, any object with the same type/name is the same object. Hence,
this is mimicked in the configuration: instantiating a new Configurable
of a type with the same name will return the same instance.

Definition at line 78 of file ConfigurableMeta.py.

78 def __call__(cls, *args, **kwargs):
79 """To Gaudi, any object with the same type/name is the same object. Hence,
80 this is mimicked in the configuration: instantiating a new Configurable
81 of a type with the same name will return the same instance."""
82
83 # Get the instance: `singleton' logic needs to be in __new__, not here,
84 # for compatibililty with pickling.)
85 cfg = cls.__new__(cls, *args, **kwargs)
86
87 # Initialize the object, if not done already.
88 if not hasattr(cfg, "_initok") or not cfg._initok:
89 cls.__init__(cfg, *args, **kwargs)
90
91 return cfg

◆ __new__()

GaudiKernel.ConfigurableMeta.ConfigurableMeta.__new__ ( self,
name,
bases,
dct )

Definition at line 30 of file ConfigurableMeta.py.

30 def __new__(self, name, bases, dct):
31 # enfore use of classmethod for getType() and setDefaults()
32 if "getType" in dct and not isinstance(dct["getType"], classmethod):
33 dct["getType"] = classmethod(dct["getType"])
34
35 if "setDefaults" in dct and not isinstance(dct["setDefaults"], classmethod):
36 dct["setDefaults"] = classmethod(dct["setDefaults"])
37
38 # collect what are properties (basically, any public name; C++ variables
39 # shouldn't start with an '_' because of portability constraints, hence
40 # it is safe to assume that any such vars are python private ones)
41 newclass = type.__new__(self, name, bases, dct)
42
43 # cache references of instances by name for duplicate removal
44 newclass.configurables = {}
45
46 # loop over slots, which are all assumed to be properties, create proxies, defaults
47 properties = {}
48 slots = dct.get("__slots__")
49 if slots:
50 props = [x for x in slots if x[0] != "_"]
51 propDict = dct.get("_propertyDocDct")
52 for prop in props:
53 docString = propDict and propDict.get(prop)
54 if isinstance(slots, dict):
55 default = slots[prop]
56 else:
57 default = None
58 proxy = PropertyProxy.PropertyProxyFactory(
59 getattr(newclass, prop), docString, default
60 )
61
62 properties[prop] = proxy
63 setattr(newclass, prop, proxy)
64
65 # complete set of properties includes those from base classes
66 for base in bases:
67 try:
68 bprops = base._properties.copy()
69 bprops.update(properties)
70 properties = bprops
71 except AttributeError:
72 pass
73
74 newclass._properties = properties
75
76 return newclass
77

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