The Gaudi Framework  master (594c33fa)
GaudiConfig2._configurables.Configurable Class Reference
Inheritance diagram for GaudiConfig2._configurables.Configurable:
Collaboration diagram for GaudiConfig2._configurables.Configurable:

Public Member Functions

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

Public Attributes

 name
 

Static Public Attributes

 instances
 

Private Attributes

 _name
 
 _properties
 
 __cpp_type__
 

Detailed Description

Base class for all configurable instances.

Definition at line 128 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 135 of file _configurables.py.

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

Member Function Documentation

◆ __getstate__()

def GaudiConfig2._configurables.Configurable.__getstate__ (   self)

Definition at line 198 of file _configurables.py.

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

◆ __opt_properties__()

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

Definition at line 216 of file _configurables.py.

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

◆ __opt_value__()

def GaudiConfig2._configurables.Configurable.__opt_value__ (   self)

Definition at line 211 of file _configurables.py.

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

◆ __repr__()

def GaudiConfig2._configurables.Configurable.__repr__ (   self)

Definition at line 189 of file _configurables.py.

189  def __repr__(self):
190  args = []
191  try:
192  args.append(repr(self.name))
193  except AttributeError:
194  pass # no name
195  args.extend(f"{k}={repr(v)}" for k, v in self._properties.items())
196  return "{}({})".format(type(self).__name__, ", ".join(args))
197 

◆ __setstate__()

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

Definition at line 206 of file _configurables.py.

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

◆ clone()

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

Definition at line 254 of file _configurables.py.

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

◆ getDefaultProperties()

def GaudiConfig2._configurables.Configurable.getDefaultProperties (   cls)

Definition at line 247 of file _configurables.py.

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

◆ getDefaultProperty()

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

Definition at line 251 of file _configurables.py.

251  def getDefaultProperty(cls, name):
252  return cls._descriptors[name].default
253 

◆ getFullJobOptName()

def GaudiConfig2._configurables.Configurable.getFullJobOptName (   self)

Definition at line 240 of file _configurables.py.

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

◆ getGaudiType()

def GaudiConfig2._configurables.Configurable.getGaudiType (   cls)

Definition at line 230 of file _configurables.py.

230  def getGaudiType(cls):
231  return cls.__component_type__
232 

◆ getInstance()

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

Definition at line 153 of file _configurables.py.

153  def getInstance(cls, name):
154  return cls.instances.get(name) or cls(name)
155 

◆ getName()

def GaudiConfig2._configurables.Configurable.getName (   self)

Definition at line 237 of file _configurables.py.

237  def getName(self):
238  return self.name
239 

◆ getType()

def GaudiConfig2._configurables.Configurable.getType (   cls)

Definition at line 234 of file _configurables.py.

234  def getType(cls):
235  return cls.__cpp_type__
236 

◆ is_property_set()

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

Definition at line 226 of file _configurables.py.

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

◆ merge()

def 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 258 of file _configurables.py.

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

◆ name() [1/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 157 of file _configurables.py.

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

◆ name() [2/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 181 of file _configurables.py.

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

◆ name() [3/3]

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

Definition at line 165 of file _configurables.py.

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

◆ toStringProperty()

def GaudiConfig2._configurables.Configurable.toStringProperty (   self)

Definition at line 243 of file _configurables.py.

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

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__
private

Definition at line 212 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name
private

Definition at line 136 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties
private

Definition at line 137 of file _configurables.py.

◆ instances

GaudiConfig2._configurables.Configurable.instances
static

Definition at line 133 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name

Definition at line 146 of file _configurables.py.


The documentation for this class was generated from the following file:
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
GaudiConfig2._configurables.opt_repr
def opt_repr(value)
Definition: _configurables.py:116
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:160
merge
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
Definition: merge.C:430
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi.CommonGaudiConfigurables.cls
cls
Definition: CommonGaudiConfigurables.py:44
GaudiAlg.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:535