The Gaudi Framework  master (3415b466)
Loading...
Searching...
No Matches
GaudiConfig2._configurables.Configurable Class Reference
Inheritance diagram for GaudiConfig2._configurables.Configurable:
Collaboration diagram for GaudiConfig2._configurables.Configurable:

Public Member Functions

 __init__ (self, name=None, **kwargs)
 
 getInstance (cls, name)
 
 name (self)
 
 name (self, value)
 
 name (self)
 
 __repr__ (self)
 
 __getstate__ (self)
 
 __setstate__ (self, state)
 
 __opt_value__ (self)
 
 __opt_properties__ (self, explicit_defaults=False)
 
 is_property_set (self, propname)
 
 getGaudiType (cls)
 
 getType (cls)
 
 getName (self)
 
 getFullJobOptName (self)
 
 toStringProperty (self)
 
 getDefaultProperties (cls)
 
 getDefaultProperty (cls, name)
 
 clone (self, newname=None)
 
 merge (self, other)
 
- Public Member Functions inherited from GaudiConfig2._configurables.ConfigurableMeta
 __new__ (cls, name, bases, namespace, **kwds)
 

Public Attributes

 name = name
 

Static Public Attributes

dict instances = {}
 

Protected Attributes

 _name = None
 
dict _properties = {}
 

Private Attributes

 __cpp_type__ = self.name:
 

Detailed Description

Base class for all configurable instances.

Definition at line 130 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

GaudiConfig2._configurables.Configurable.__init__ ( self,
name = None,
** kwargs )

Definition at line 137 of file _configurables.py.

137 def __init__(self, name=None, **kwargs):
138 self._name = None
139 self._properties = {}
140 if "parent" in kwargs:
141 parent = kwargs.pop("parent")
142 if isinstance(parent, str):
143 parent = self.instances[parent]
144 if not name:
145 raise TypeError("name is needed when a parent is specified")
146 name = f"{parent.name}.{name}"
147 if name:
148 self.name = name
149 elif not _GLOBAL_INSTANCES:
150 self.name = self.__cpp_type__
151 for key, value in kwargs.items():
152 setattr(self, key, value)
153

Member Function Documentation

◆ __getstate__()

GaudiConfig2._configurables.Configurable.__getstate__ ( self)

Definition at line 200 of file _configurables.py.

200 def __getstate__(self):
201 state = {"properties": self._properties}
202 try:
203 state["name"] = self.name
204 except AttributeError:
205 pass # no name
206 return state
207

◆ __opt_properties__()

GaudiConfig2._configurables.Configurable.__opt_properties__ ( self,
explicit_defaults = False )

Definition at line 218 of file _configurables.py.

218 def __opt_properties__(self, explicit_defaults=False):
219 name = self.name
220 out = {}
221 for p in self._descriptors.values():
222 if explicit_defaults or p.__is_set__(self, type(self)):
223 out[".".join([name, p.name])] = opt_repr(
224 p.__opt_value__(self, type(self))
225 )
226 return out
227

◆ __opt_value__()

GaudiConfig2._configurables.Configurable.__opt_value__ ( self)

Definition at line 213 of file _configurables.py.

213 def __opt_value__(self):
214 if self.__cpp_type__ == self.name:
215 return self.__cpp_type__
216 return f"{self.__cpp_type__}/{self.name}"
217

◆ __repr__()

GaudiConfig2._configurables.Configurable.__repr__ ( self)

Definition at line 191 of file _configurables.py.

191 def __repr__(self):
192 args = []
193 try:
194 args.append(repr(self.name))
195 except AttributeError:
196 pass # no name
197 args.extend(f"{k}={repr(v)}" for k, v in self._properties.items())
198 return "{}({})".format(type(self).__name__, ", ".join(args))
199
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

◆ __setstate__()

GaudiConfig2._configurables.Configurable.__setstate__ ( self,
state )

Definition at line 208 of file _configurables.py.

208 def __setstate__(self, state):
209 self._name = None
210 self.name = state.get("name")
211 self._properties = state["properties"]
212

◆ clone()

GaudiConfig2._configurables.Configurable.clone ( self,
newname = None )
Clone instance with all its properties.

Definition at line 256 of file _configurables.py.

256 def clone(self, newname=None):
257 """Clone instance with all its properties."""
258 return self.__class__(newname, **self._properties)
259

◆ getDefaultProperties()

GaudiConfig2._configurables.Configurable.getDefaultProperties ( cls)

Definition at line 249 of file _configurables.py.

249 def getDefaultProperties(cls):
250 return {k: v.default for k, v in cls._descriptors.items()}
251

◆ getDefaultProperty()

GaudiConfig2._configurables.Configurable.getDefaultProperty ( cls,
name )

Definition at line 253 of file _configurables.py.

253 def getDefaultProperty(cls, name):
254 return cls._descriptors[name].default
255

◆ getFullJobOptName()

GaudiConfig2._configurables.Configurable.getFullJobOptName ( self)

Definition at line 242 of file _configurables.py.

242 def getFullJobOptName(self):
243 return f"{self.__cpp_type__}/{self.name}"
244

◆ getGaudiType()

GaudiConfig2._configurables.Configurable.getGaudiType ( cls)

Definition at line 232 of file _configurables.py.

232 def getGaudiType(cls):
233 return cls.__component_type__
234

◆ getInstance()

GaudiConfig2._configurables.Configurable.getInstance ( cls,
name )

Definition at line 155 of file _configurables.py.

155 def getInstance(cls, name):
156 return cls.instances.get(name) or cls(name)
157

◆ getName()

GaudiConfig2._configurables.Configurable.getName ( self)

Definition at line 239 of file _configurables.py.

239 def getName(self):
240 return self.name
241

◆ getType()

GaudiConfig2._configurables.Configurable.getType ( cls)

Definition at line 236 of file _configurables.py.

236 def getType(cls):
237 return cls.__cpp_type__
238

◆ is_property_set()

GaudiConfig2._configurables.Configurable.is_property_set ( self,
propname )

Definition at line 228 of file _configurables.py.

228 def is_property_set(self, propname):
229 return self._descriptors[propname].__is_set__(self, type(self))
230

◆ merge()

GaudiConfig2._configurables.Configurable.merge ( self,
other )
Merge the properties of the other instance into the current one.

The two instances have to be of the same type, have the same name
(or both unnamed) and the settings must be mergable (according to
their semantics).

Definition at line 260 of file _configurables.py.

260 def merge(self, other):
261 """
262 Merge the properties of the other instance into the current one.
263
264 The two instances have to be of the same type, have the same name
265 (or both unnamed) and the settings must be mergable (according to
266 their semantics).
267 """
268 if self is other:
269 return self
270 if type(self) is not type(other):
271 raise TypeError(
272 f"cannot merge instance of {type(other).__name__} into an instance of { type(self).__name__}"
273 )
274 if hasattr(self, "name") != hasattr(other, "name"):
275 raise ValueError("cannot merge a named configurable with an unnamed one")
276 if hasattr(self, "name") and (self.name != other.name):
277 raise ValueError(
278 f"cannot merge configurables with different names ({self.name} and {other.name})"
279 )
280
281 for name in other._properties:
282 if (
283 name in self._properties
284 and self._properties[name] == other._properties[name]
285 ):
286 continue
287 try:
288 self._properties[name] = self._descriptors[name].__merge__(
289 self, type(self), getattr(other, name)
290 )
291 except ValueError as err:
292 raise ValueError(
293 "conflicting settings for property {} of {}: {}".format(
294 name,
295 self.name if hasattr(self, "name") else type(self).__name__,
296 str(err),
297 )
298 )
299
300 return self
301
302
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
Definition merge.C:417

◆ name() [1/3]

GaudiConfig2._configurables.Configurable.name ( self)

Definition at line 159 of file _configurables.py.

159 def name(self):
160 if not self._name:
161 raise AttributeError(
162 f"{repr(type(self).__name__)} instance was not named yet"
163 )
164 return self._name
165

◆ name() [2/3]

GaudiConfig2._configurables.Configurable.name ( self)

Definition at line 183 of file _configurables.py.

183 def name(self):
184 if _GLOBAL_INSTANCES:
185 # check if it was set
186 del self.instances[self.name]
187 self._name = None
188 else:
189 raise TypeError("name attribute cannot be deleted")
190

◆ name() [3/3]

GaudiConfig2._configurables.Configurable.name ( self,
value )

Definition at line 167 of file _configurables.py.

167 def name(self, value):
168 if value == self._name:
169 return # it's already the name of the instance, nothing to do
170 if not isinstance(value, str) or not value:
171 raise TypeError(f"expected string, got {type(value).__name__} instead")
172 if _GLOBAL_INSTANCES:
173 if value in self.instances:
174 raise ValueError(f"name {repr(value)} already used")
175 if self._name in self.instances:
176 del self.instances[self._name]
177 self._name = value
178 self.instances[value] = self
179 else:
180 self._name = value
181

◆ toStringProperty()

GaudiConfig2._configurables.Configurable.toStringProperty ( self)

Definition at line 245 of file _configurables.py.

245 def toStringProperty(self):
246 return f"{self.__cpp_type__}/{self.name}"
247

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__ = self.name:
private

Definition at line 214 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name = None
protected

Definition at line 138 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties = {}
protected

Definition at line 139 of file _configurables.py.

◆ instances

dict GaudiConfig2._configurables.Configurable.instances = {}
static

Definition at line 135 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name = name

Definition at line 148 of file _configurables.py.


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