The Gaudi Framework  v36r3 (83a1ddab)
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 merge (self, other)
 

Public Attributes

 name
 

Static Public Attributes

dictionary instances = {}
 

Private Attributes

 _name
 
 _properties
 
 __cpp_type__
 

Detailed Description

Base class for all configurable instances.

Definition at line 143 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 150 of file _configurables.py.

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

Member Function Documentation

◆ __getstate__()

def GaudiConfig2._configurables.Configurable.__getstate__ (   self)

Definition at line 218 of file _configurables.py.

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

◆ __opt_properties__()

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

Definition at line 236 of file _configurables.py.

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

◆ __opt_value__()

def GaudiConfig2._configurables.Configurable.__opt_value__ (   self)

Definition at line 231 of file _configurables.py.

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

◆ __repr__()

def GaudiConfig2._configurables.Configurable.__repr__ (   self)

Definition at line 209 of file _configurables.py.

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

◆ __setstate__()

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

Definition at line 226 of file _configurables.py.

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

◆ getDefaultProperties()

def GaudiConfig2._configurables.Configurable.getDefaultProperties (   cls)

Definition at line 267 of file _configurables.py.

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

◆ getDefaultProperty()

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

Definition at line 271 of file _configurables.py.

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

◆ getFullJobOptName()

def GaudiConfig2._configurables.Configurable.getFullJobOptName (   self)

Definition at line 260 of file _configurables.py.

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

◆ getGaudiType()

def GaudiConfig2._configurables.Configurable.getGaudiType (   cls)

Definition at line 250 of file _configurables.py.

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

◆ getInstance()

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

Definition at line 168 of file _configurables.py.

168  def getInstance(cls, name):
169  return cls.instances.get(name) or cls(name)
170 

◆ getName()

def GaudiConfig2._configurables.Configurable.getName (   self)

Definition at line 257 of file _configurables.py.

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

◆ getType()

def GaudiConfig2._configurables.Configurable.getType (   cls)

Definition at line 254 of file _configurables.py.

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

◆ is_property_set()

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

Definition at line 246 of file _configurables.py.

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

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

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

◆ name() [1/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 172 of file _configurables.py.

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

◆ name() [2/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 201 of file _configurables.py.

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

◆ name() [3/3]

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

Definition at line 180 of file _configurables.py.

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

◆ toStringProperty()

def GaudiConfig2._configurables.Configurable.toStringProperty (   self)

Definition at line 263 of file _configurables.py.

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

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__
private

Definition at line 232 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name
private

Definition at line 151 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties
private

Definition at line 152 of file _configurables.py.

◆ instances

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

Definition at line 148 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name

Definition at line 161 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:412
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:160
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