The Gaudi Framework  master (905e8f18)
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 131 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 138 of file _configurables.py.

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

Member Function Documentation

◆ __getstate__()

GaudiConfig2._configurables.Configurable.__getstate__ ( self)

Definition at line 201 of file _configurables.py.

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

◆ __opt_properties__()

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

Definition at line 219 of file _configurables.py.

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

◆ __opt_value__()

GaudiConfig2._configurables.Configurable.__opt_value__ ( self)

Definition at line 214 of file _configurables.py.

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

◆ __repr__()

GaudiConfig2._configurables.Configurable.__repr__ ( self)

Definition at line 192 of file _configurables.py.

192 def __repr__(self):
193 args = []
194 try:
195 args.append(repr(self.name))
196 except AttributeError:
197 pass # no name
198 args.extend(f"{k}={repr(v)}" for k, v in self._properties.items())
199 return "{}({})".format(type(self).__name__, ", ".join(args))
200
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 209 of file _configurables.py.

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

◆ clone()

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

Definition at line 257 of file _configurables.py.

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

◆ getDefaultProperties()

GaudiConfig2._configurables.Configurable.getDefaultProperties ( cls)

Definition at line 250 of file _configurables.py.

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

◆ getDefaultProperty()

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

Definition at line 254 of file _configurables.py.

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

◆ getFullJobOptName()

GaudiConfig2._configurables.Configurable.getFullJobOptName ( self)

Definition at line 243 of file _configurables.py.

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

◆ getGaudiType()

GaudiConfig2._configurables.Configurable.getGaudiType ( cls)

Definition at line 233 of file _configurables.py.

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

◆ getInstance()

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

Definition at line 156 of file _configurables.py.

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

◆ getName()

GaudiConfig2._configurables.Configurable.getName ( self)

Definition at line 240 of file _configurables.py.

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

◆ getType()

GaudiConfig2._configurables.Configurable.getType ( cls)

Definition at line 237 of file _configurables.py.

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

◆ is_property_set()

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

Definition at line 229 of file _configurables.py.

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

◆ 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 261 of file _configurables.py.

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

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

◆ name() [2/3]

GaudiConfig2._configurables.Configurable.name ( self)

Definition at line 184 of file _configurables.py.

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

◆ name() [3/3]

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

Definition at line 168 of file _configurables.py.

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

◆ toStringProperty()

GaudiConfig2._configurables.Configurable.toStringProperty ( self)

Definition at line 246 of file _configurables.py.

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

Member Data Documentation

◆ __cpp_type__

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

Definition at line 215 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name = None
protected

Definition at line 139 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties = {}
protected

Definition at line 140 of file _configurables.py.

◆ instances

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

Definition at line 136 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name = name

Definition at line 149 of file _configurables.py.


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