The Gaudi Framework  v36r1 (3e2fb5a8)
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 138 of file _configurables.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 144 of file _configurables.py.

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

Member Function Documentation

◆ __getstate__()

def GaudiConfig2._configurables.Configurable.__getstate__ (   self)

Definition at line 210 of file _configurables.py.

210  def __getstate__(self):
211  state = {'properties': self._properties}
212  try:
213  state['name'] = self.name
214  except AttributeError:
215  pass # no name
216  return state
217 

◆ __opt_properties__()

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

Definition at line 228 of file _configurables.py.

228  def __opt_properties__(self, explicit_defaults=False):
229  name = self.name
230  out = {}
231  for p in self._descriptors.values():
232  if explicit_defaults or p.__is_set__(self, type(self)):
233  out['.'.join([name, p.name])] = opt_repr(
234  p.__opt_value__(self, type(self)))
235  return out
236 

◆ __opt_value__()

def GaudiConfig2._configurables.Configurable.__opt_value__ (   self)

Definition at line 223 of file _configurables.py.

223  def __opt_value__(self):
224  if self.__cpp_type__ == self.name:
225  return self.__cpp_type__
226  return '{}/{}'.format(self.__cpp_type__, self.name)
227 

◆ __repr__()

def GaudiConfig2._configurables.Configurable.__repr__ (   self)

Definition at line 200 of file _configurables.py.

200  def __repr__(self):
201  args = []
202  try:
203  args.append(repr(self.name))
204  except AttributeError:
205  pass # no name
206  args.extend(
207  '{}={!r}'.format(*item) for item in self._properties.items())
208  return '{}({})'.format(type(self).__name__, ', '.join(args))
209 

◆ __setstate__()

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

Definition at line 218 of file _configurables.py.

218  def __setstate__(self, state):
219  self._name = None
220  self.name = state.get('name')
221  self._properties = state['properties']
222 

◆ getDefaultProperties()

def GaudiConfig2._configurables.Configurable.getDefaultProperties (   cls)

Definition at line 258 of file _configurables.py.

258  def getDefaultProperties(cls):
259  return {k: v.default for k, v in cls._descriptors.items()}
260 

◆ getDefaultProperty()

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

Definition at line 262 of file _configurables.py.

262  def getDefaultProperty(cls, name):
263  return cls._descriptors[name].default
264 

◆ getFullJobOptName()

def GaudiConfig2._configurables.Configurable.getFullJobOptName (   self)

Definition at line 251 of file _configurables.py.

251  def getFullJobOptName(self):
252  return "{}/{}".format(self.__cpp_type__, self.name)
253 

◆ getGaudiType()

def GaudiConfig2._configurables.Configurable.getGaudiType (   cls)

Definition at line 241 of file _configurables.py.

241  def getGaudiType(cls):
242  return cls.__component_type__
243 

◆ getInstance()

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

Definition at line 163 of file _configurables.py.

163  def getInstance(cls, name):
164  return cls.instances.get(name) or cls(name)
165 

◆ getName()

def GaudiConfig2._configurables.Configurable.getName (   self)

Definition at line 248 of file _configurables.py.

248  def getName(self):
249  return self.name
250 

◆ getType()

def GaudiConfig2._configurables.Configurable.getType (   cls)

Definition at line 245 of file _configurables.py.

245  def getType(cls):
246  return cls.__cpp_type__
247 

◆ is_property_set()

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

Definition at line 237 of file _configurables.py.

237  def is_property_set(self, propname):
238  return self._descriptors[propname].__is_set__(self, type(self))
239 

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

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

◆ name() [1/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 167 of file _configurables.py.

167  def name(self):
168  if not self._name:
169  raise AttributeError('{!r} instance was not named yet'.format(
170  type(self).__name__))
171  return self._name
172 

◆ name() [2/3]

def GaudiConfig2._configurables.Configurable.name (   self)

Definition at line 192 of file _configurables.py.

192  def name(self):
193  if _GLOBAL_INSTANCES:
194  # check if it was set
195  del self.instances[self.name]
196  self._name = None
197  else:
198  raise TypeError('name attribute cannot be deleted')
199 

◆ name() [3/3]

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

Definition at line 174 of file _configurables.py.

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

◆ toStringProperty()

def GaudiConfig2._configurables.Configurable.toStringProperty (   self)

Definition at line 254 of file _configurables.py.

254  def toStringProperty(self):
255  return "{}/{}".format(self.__cpp_type__, self.name)
256 

Member Data Documentation

◆ __cpp_type__

GaudiConfig2._configurables.Configurable.__cpp_type__
private

Definition at line 224 of file _configurables.py.

◆ _name

GaudiConfig2._configurables.Configurable._name
private

Definition at line 145 of file _configurables.py.

◆ _properties

GaudiConfig2._configurables.Configurable._properties
private

Definition at line 146 of file _configurables.py.

◆ instances

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

Definition at line 142 of file _configurables.py.

◆ name

GaudiConfig2._configurables.Configurable.name

Definition at line 156 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:391
TimingHistograms.name
name
Definition: TimingHistograms.py:23
GaudiPython.HistoUtils.__repr__
__repr__
Definition: HistoUtils.py:519
GaudiConfig2._configurables.opt_repr
def opt_repr(value)
Definition: _configurables.py:120
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
gaudirun.type
type
Definition: gaudirun.py:154
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:35
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:526