The Gaudi Framework  v36r16 (ea80daf8)
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 Attributes

 name
 

Static Public Attributes

 instances
 

Private Attributes

 _name
 
 _properties
 
 __cpp_type__
 

Detailed Description

Base class for all configurable instances.

Definition at line 145 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 152 of file _configurables.py.

152  def __init__(self, name=None, **kwargs):
153  self._name = None
154  self._properties = {}
155  if "parent" in kwargs:
156  parent = kwargs.pop("parent")
157  if isinstance(parent, str):
158  parent = self.instances[parent]
159  if not name:
160  raise TypeError("name is needed when a parent is specified")
161  name = "{}.{}".format(parent.name, name)
162  if name:
163  self.name = name
164  elif not _GLOBAL_INSTANCES:
165  self.name = self.__cpp_type__
166  for key, value in kwargs.items():
167  setattr(self, key, value)
168 

Member Function Documentation

◆ __getstate__()

def GaudiConfig2._configurables.Configurable.__getstate__ (   self)

Definition at line 217 of file _configurables.py.

217  def __getstate__(self):
218  state = {"properties": self._properties}
219  try:
220  state["name"] = self.name
221  except AttributeError:
222  pass # no name
223  return state
224 

◆ __opt_properties__()

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

Definition at line 235 of file _configurables.py.

235  def __opt_properties__(self, explicit_defaults=False):
236  name = self.name
237  out = {}
238  for p in self._descriptors.values():
239  if explicit_defaults or p.__is_set__(self, type(self)):
240  out[".".join([name, p.name])] = opt_repr(
241  p.__opt_value__(self, type(self))
242  )
243  return out
244 

◆ __opt_value__()

def GaudiConfig2._configurables.Configurable.__opt_value__ (   self)

Definition at line 230 of file _configurables.py.

230  def __opt_value__(self):
231  if self.__cpp_type__ == self.name:
232  return self.__cpp_type__
233  return "{}/{}".format(self.__cpp_type__, self.name)
234 

◆ __repr__()

def GaudiConfig2._configurables.Configurable.__repr__ (   self)

Definition at line 208 of file _configurables.py.

208  def __repr__(self):
209  args = []
210  try:
211  args.append(repr(self.name))
212  except AttributeError:
213  pass # no name
214  args.extend("{}={!r}".format(*item) for item in self._properties.items())
215  return "{}({})".format(type(self).__name__, ", ".join(args))
216 

◆ __setstate__()

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

Definition at line 225 of file _configurables.py.

225  def __setstate__(self, state):
226  self._name = None
227  self.name = state.get("name")
228  self._properties = state["properties"]
229 

◆ clone()

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

Definition at line 273 of file _configurables.py.

273  def clone(self, newname=None):
274  """Clone instance with all its properties."""
275  return self.__class__(newname, **self._properties)
276 

◆ getDefaultProperties()

def GaudiConfig2._configurables.Configurable.getDefaultProperties (   cls)

Definition at line 266 of file _configurables.py.

266  def getDefaultProperties(cls):
267  return {k: v.default for k, v in cls._descriptors.items()}
268 

◆ getDefaultProperty()

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

Definition at line 270 of file _configurables.py.

270  def getDefaultProperty(cls, name):
271  return cls._descriptors[name].default
272 

◆ getFullJobOptName()

def GaudiConfig2._configurables.Configurable.getFullJobOptName (   self)

Definition at line 259 of file _configurables.py.

259  def getFullJobOptName(self):
260  return "{}/{}".format(self.__cpp_type__, self.name)
261 

◆ getGaudiType()

def GaudiConfig2._configurables.Configurable.getGaudiType (   cls)

Definition at line 249 of file _configurables.py.

249  def getGaudiType(cls):
250  return cls.__component_type__
251 

◆ getInstance()

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

Definition at line 170 of file _configurables.py.

170  def getInstance(cls, name):
171  return cls.instances.get(name) or cls(name)
172 

◆ getName()

def GaudiConfig2._configurables.Configurable.getName (   self)

Definition at line 256 of file _configurables.py.

256  def getName(self):
257  return self.name
258 

◆ getType()

def GaudiConfig2._configurables.Configurable.getType (   cls)

Definition at line 253 of file _configurables.py.

253  def getType(cls):
254  return cls.__cpp_type__
255 

◆ is_property_set()

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

Definition at line 245 of file _configurables.py.

245  def is_property_set(self, propname):
246  return self._descriptors[propname].__is_set__(self, type(self))
247 

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

277  def merge(self, other):
278  """
279  Merge the properties of the other instance into the current one.
280 
281  The two instances have to be of the same type, have the same name
282  (or both unnamed) and the settings must be mergable (according to
283  their semantics).
284  """
285  if self is other:
286  return self
287  if type(self) is not type(other):
288  raise TypeError(
289  "cannot merge instance of {} into an instance of {}".format(
290  type(other).__name__, type(self).__name__
291  )
292  )
293  if hasattr(self, "name") != hasattr(other, "name"):
294  raise ValueError("cannot merge a named configurable with an unnamed one")
295  if hasattr(self, "name") and (self.name != other.name):
296  raise ValueError(
297  "cannot merge configurables with different names ({} and {})".format(
298  self.name, other.name
299  )
300  )
301 
302  for name in other._properties:
303  if (
304  name in self._properties
305  and self._properties[name] == other._properties[name]
306  ):
307  continue
308  try:
309  setattr(
310  self,
311  name,
312  self._descriptors[name].__merge__(
313  self, type(self), getattr(other, name)
314  ),
315  )
316  except ValueError as err:
317  raise ValueError(
318  "conflicting settings for property {} of {}: {}".format(
319  name,
320  self.name if hasattr(self, "name") else type(self).__name__,
321  str(err),
322  )
323  )
324 
325  return self
326 
327 

◆ name() [1/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 174 of file _configurables.py.

174  def name(self):
175  if not self._name:
176  raise AttributeError(
177  "{!r} instance was not named yet".format(type(self).__name__)
178  )
179  return self._name
180 

◆ name() [2/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 200 of file _configurables.py.

200  def name(self):
201  if _GLOBAL_INSTANCES:
202  # check if it was set
203  del self.instances[self.name]
204  self._name = None
205  else:
206  raise TypeError("name attribute cannot be deleted")
207 

◆ name() [3/3]

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

Definition at line 182 of file _configurables.py.

182  def name(self, value):
183  if value == self._name:
184  return # it's already the name of the instance, nothing to do
185  if not isinstance(value, str) or not value:
186  raise TypeError(
187  "expected string, got {} instead".format(type(value).__name__)
188  )
189  if _GLOBAL_INSTANCES:
190  if value in self.instances:
191  raise ValueError("name {!r} already used".format(value))
192  if self._name in self.instances:
193  del self.instances[self._name]
194  self._name = value
195  self.instances[value] = self
196  else:
197  self._name = value
198 

◆ toStringProperty()

def GaudiConfig2._configurables.Configurable.toStringProperty (   self)

Definition at line 262 of file _configurables.py.

262  def toStringProperty(self):
263  return "{}/{}".format(self.__cpp_type__, self.name)
264 

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__
private

Definition at line 231 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name
private

Definition at line 153 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties
private

Definition at line 154 of file _configurables.py.

◆ instances

GaudiConfig2._configurables.Configurable.instances
static

Definition at line 150 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name

Definition at line 163 of file _configurables.py.


The documentation for this class was generated from the following file:
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:444
TimingHistograms.name
name
Definition: TimingHistograms.py:25
GaudiPython.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:536
GaudiConfig2._configurables.opt_repr
def opt_repr(value)
Definition: _configurables.py:125
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
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546