The Gaudi Framework  v37r0 (b608885e)
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 130 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

def 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 = "{}.{}".format(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__()

def 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__()

def 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__()

def 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 "{}/{}".format(self.__cpp_type__, self.name)
219 

◆ __repr__()

def 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("{}={!r}".format(*item) for item in self._properties.items())
200  return "{}({})".format(type(self).__name__, ", ".join(args))
201 

◆ __setstate__()

def 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()

def 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()

def 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()

def 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()

def GaudiConfig2._configurables.Configurable.getFullJobOptName (   self)

Definition at line 244 of file _configurables.py.

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

◆ getGaudiType()

def GaudiConfig2._configurables.Configurable.getGaudiType (   cls)

Definition at line 234 of file _configurables.py.

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

◆ getInstance()

def 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()

def GaudiConfig2._configurables.Configurable.getName (   self)

Definition at line 241 of file _configurables.py.

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

◆ getType()

def 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()

def 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()

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 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  "cannot merge instance of {} into an instance of {}".format(
275  type(other).__name__, type(self).__name__
276  )
277  )
278  if hasattr(self, "name") != hasattr(other, "name"):
279  raise ValueError("cannot merge a named configurable with an unnamed one")
280  if hasattr(self, "name") and (self.name != other.name):
281  raise ValueError(
282  "cannot merge configurables with different names ({} and {})".format(
283  self.name, other.name
284  )
285  )
286 
287  for name in other._properties:
288  if (
289  name in self._properties
290  and self._properties[name] == other._properties[name]
291  ):
292  continue
293  try:
294  setattr(
295  self,
296  name,
297  self._descriptors[name].__merge__(
298  self, type(self), getattr(other, name)
299  ),
300  )
301  except ValueError as err:
302  raise ValueError(
303  "conflicting settings for property {} of {}: {}".format(
304  name,
305  self.name if hasattr(self, "name") else type(self).__name__,
306  str(err),
307  )
308  )
309 
310  return self
311 
312 

◆ name() [1/3]

def 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  "{!r} instance was not named yet".format(type(self).__name__)
163  )
164  return self._name
165 

◆ name() [2/3]

def 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]

def 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(
172  "expected string, got {} instead".format(type(value).__name__)
173  )
174  if _GLOBAL_INSTANCES:
175  if value in self.instances:
176  raise ValueError("name {!r} already used".format(value))
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()

def GaudiConfig2._configurables.Configurable.toStringProperty (   self)

Definition at line 247 of file _configurables.py.

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

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__
private

Definition at line 216 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name
private

Definition at line 138 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties
private

Definition at line 139 of file _configurables.py.

◆ instances

GaudiConfig2._configurables.Configurable.instances
static

Definition at line 135 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name

Definition at line 148 of file _configurables.py.


The documentation for this class was generated from the following file:
bug_34121.name
name
Definition: bug_34121.py:20
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: details.h:440
GaudiConfig2._configurables.opt_repr
def opt_repr(value)
Definition: _configurables.py:118
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:162
merge
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
Definition: merge.C:430
Gaudi.CommonGaudiConfigurables.cls
cls
Definition: CommonGaudiConfigurables.py:44
GaudiAlg.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:536
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546