The Gaudi Framework  master (ff829712)
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 132 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 139 of file _configurables.py.

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

Member Function Documentation

◆ __getstate__()

GaudiConfig2._configurables.Configurable.__getstate__ ( self)

Definition at line 202 of file _configurables.py.

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

◆ __opt_properties__()

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

Definition at line 220 of file _configurables.py.

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

◆ __opt_value__()

GaudiConfig2._configurables.Configurable.__opt_value__ ( self)

Definition at line 215 of file _configurables.py.

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

◆ __repr__()

GaudiConfig2._configurables.Configurable.__repr__ ( self)

Definition at line 193 of file _configurables.py.

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

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

◆ clone()

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

Definition at line 258 of file _configurables.py.

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

◆ getDefaultProperties()

GaudiConfig2._configurables.Configurable.getDefaultProperties ( cls)

Definition at line 251 of file _configurables.py.

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

◆ getDefaultProperty()

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

Definition at line 255 of file _configurables.py.

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

◆ getFullJobOptName()

GaudiConfig2._configurables.Configurable.getFullJobOptName ( self)

Definition at line 244 of file _configurables.py.

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

◆ getGaudiType()

GaudiConfig2._configurables.Configurable.getGaudiType ( cls)

Definition at line 234 of file _configurables.py.

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

◆ getInstance()

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

Definition at line 157 of file _configurables.py.

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

◆ getName()

GaudiConfig2._configurables.Configurable.getName ( self)

Definition at line 241 of file _configurables.py.

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

◆ getType()

GaudiConfig2._configurables.Configurable.getType ( cls)

Definition at line 238 of file _configurables.py.

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

◆ is_property_set()

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

Definition at line 230 of file _configurables.py.

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

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

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

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

◆ name() [2/3]

GaudiConfig2._configurables.Configurable.name ( self)

Definition at line 185 of file _configurables.py.

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

◆ name() [3/3]

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

Definition at line 169 of file _configurables.py.

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

◆ toStringProperty()

GaudiConfig2._configurables.Configurable.toStringProperty ( self)

Definition at line 247 of file _configurables.py.

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

Member Data Documentation

◆ __cpp_type__

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

Definition at line 216 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name = None
protected

Definition at line 140 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties = {}
protected

Definition at line 141 of file _configurables.py.

◆ instances

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

Definition at line 137 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name = name

Definition at line 150 of file _configurables.py.


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