ATLAS Offline Software
Public Member Functions | Public Attributes | Properties | Private Attributes | List of all members
python.PropertyProxy.GaudiHandlePropertyProxyBase Class Reference
Inheritance diagram for python.PropertyProxy.GaudiHandlePropertyProxyBase:
Collaboration diagram for python.PropertyProxy.GaudiHandlePropertyProxyBase:

Public Member Functions

def __init__ (self, descr, docString, default, handleType, allowedType)
 
def __get__ (self, obj, type=None)
 
def __set__ (self, obj, value)
 
def isHandle (self, value)
 
def isConfig (self, value)
 
def getDefaultConfigurable (self, typeAndName, requester)
 
def convertDefaultToBeSet (self, obj, default)
 
def convertValueToBeSet (self, obj, value)
 
def setDefault (self, value)
 
def getDefault (self)
 
def fullPropertyName (self, obj)
 
def __delete__ (self, obj)
 

Public Attributes

 history
 
 descr
 

Properties

 default = property( getDefault, setDefault )
 

Private Attributes

 _handleType
 
 _confTypeName
 
 __doc__
 
 __default
 

Detailed Description

A class with some utilities for GaudiHandles and GaudiHandleArrays

Definition at line 179 of file PropertyProxy.py.

Constructor & Destructor Documentation

◆ __init__()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.__init__ (   self,
  descr,
  docString,
  default,
  handleType,
  allowedType 
)
<descr>: the real property in the object instance (from __slots__)
<docString>: the documentation string of this property
<default>: default value from C++ (via python generated by genconf)
<handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
<allowedType>: allowed instance type for default

Definition at line 182 of file PropertyProxy.py.

182  def __init__(self, descr, docString, default, handleType, allowedType ):
183  """<descr>: the real property in the object instance (from __slots__)
184  <docString>: the documentation string of this property
185  <default>: default value from C++ (via python generated by genconf)
186  <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...)
187  <allowedType>: allowed instance type for default
188  """
189  # check that default is of allowed type for this proxy
190  if not isinstance(default,allowedType):
191  raise TypeError( "%s: %s default: %r is not a %s" % \
192  ( descr.__name__, self.__class__.__name__, default, allowedType.__name__ ) )
193  PropertyProxy.__init__( self, descr, docString, default )
194  self._handleType = handleType
195  self._confTypeName = 'Configurable' + handleType.componentType
196 # print "%s: %r (%s)" % (self.__class__.__name__,self._handleType,self._confTypeName)
197 
198 

Member Function Documentation

◆ __delete__()

def python.PropertyProxy.PropertyProxy.__delete__ (   self,
  obj 
)
inherited

Definition at line 172 of file PropertyProxy.py.

172  def __delete__( self, obj ):
173  if obj in self.history:
174  del self.history[ obj ]
175  self.descr.__delete__( obj )
176 
177 
178 

◆ __get__()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.__get__ (   self,
  obj,
  type = None 
)

Reimplemented from python.PropertyProxy.PropertyProxy.

Definition at line 199 of file PropertyProxy.py.

199  def __get__( self, obj, type = None ):
200  try:
201  return self.descr.__get__( obj, type )
202  except AttributeError:
203  # Get default
204  try:
205  default = obj.__class__.getDefaultProperty( self.descr.__name__ )
206  # if printing, just show the toolhandle. No need to auto-retrieve default configurable instance
207  if obj.isPrinting(): return default
208  default = self.convertDefaultToBeSet( obj, default )
209  # special case if default is auto-retrieved configurable instance
210  if self.isConfig(default):
211  if obj.isLocked():
212  # return a locked copy to produce error in case of setting any property
213  # rather then changing the value of the default
214  default = copy.deepcopy(default)
215  default.lock()
216  return default
217  else:
218  # Set to default configurable instance to allow MyTool.MySubTool.MyProperty = MyValue
219  self.__set__( obj, default )
220  elif isinstance(default,GaudiHandleArray):
221  if obj.isLocked():
222  # return a locked copy to produce error in case of setting any property
223  # rather then changing the value of the default
224  default = copy.deepcopy(default)
225  for c in default:
226  if self.isConfig(c):
227  c.lock()
228  return default
229  else:
230  # Set array to allow to add to default with syntax: MyTool.MyArray.append()
231  self.__set__( obj, default )
232  else:
233  return default
234  except AttributeError as e:
235  import traceback
236  traceback.print_exc()
237  # change type of exception to avoid false error message
238  raise RuntimeError("AttributeError(%s)" % e.args)
239 
240  return self.descr.__get__( obj, type )
241 
242 

◆ __set__()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.__set__ (   self,
  obj,
  value 
)

Reimplemented from python.PropertyProxy.PropertyProxy.

Definition at line 243 of file PropertyProxy.py.

243  def __set__( self, obj, value ):
244  # locked configurables can no longer be changed
245  if obj.isLocked():
246  raise RuntimeError(
247  'can not change property "%s" of locked configurable "%s"' %
248  (self.descr.__name__, obj.getJobOptName()) )
249 
250  # allow a property to be set if we're in non-default mode, or if it
251  # simply hasn't been set before
252  if not obj._isInSetDefaults() or obj not in self.history:
253  value = self.convertValueToBeSet( obj, value )
254  # assign the value
255  self.descr.__set__( obj, value )
256  log.verbose( "Setting %s = %r", self.fullPropertyName( obj ), value )
257  self.history.setdefault( obj, [] ).append( value )
258 
259 

◆ convertDefaultToBeSet()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.convertDefaultToBeSet (   self,
  obj,
  default 
)

Reimplemented in python.PropertyProxy.GaudiHandleArrayPropertyProxy.

Definition at line 291 of file PropertyProxy.py.

291  def convertDefaultToBeSet( self, obj, default ):
292  # turn string into handle
293  isString = type(default) is str
294  if not isString and self.isConfig(default):
295 # print self.fullPropertyName(obj) + ": Setting default configurable: %r" % default
296  return default
297  elif isString or self.isHandle(default):
298  if isString:
299  # convert string into handle
300  typeAndName = default
301  default = self._handleType( typeAndName )
302  else:
303  typeAndName = default.typeAndName
304  if not self._handleType.isPublic and typeAndName:
305  # Find corresponding default configurable of private handles
306  try:
307  conf = self.getDefaultConfigurable(typeAndName, self.fullPropertyName(obj))
308 # print self.fullPropertyName(obj) + ": Setting default private configurable (from default handle): %r" % conf
309  except AttributeError as e:
310  # change type of exception to avoid false error message
311  raise RuntimeError(*e.args)
312  if conf is None:
313  raise RuntimeError( "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" % \
314  (self.fullPropertyName(obj),default.getType() ) )
315  return conf
316  else: # not a config, not a handle, not a string
317  raise TypeError( "%s: default value %r is not of type %s or %s" % \
318  (self.fullPropertyName(obj),default,self._confTypeName,self._handleType.__name__) )
319 
320  return default
321 

◆ convertValueToBeSet()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.convertValueToBeSet (   self,
  obj,
  value 
)

Reimplemented in python.PropertyProxy.GaudiHandleArrayPropertyProxy.

Definition at line 322 of file PropertyProxy.py.

322  def convertValueToBeSet( self, obj, value ):
323  if value is None: value = ''
324  isString = type(value) is str
325  if isString:
326  # create an new handle
327  return self._handleType(value)
328  elif self.isHandle(value):
329  # make a copy of the handle
330  return self._handleType(value.toStringProperty())
331  elif self.isConfig(value):
332  if self._handleType.isPublic:
333  # A public tool must be registered to ToolSvc before assigning it
334  if derives_from(value,'ConfigurableAlgTool'):
335  if not value.isInToolSvc():
336  suggestion = 'You may need to add jobOptions lines something like:' + os.linesep + \
337  'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
338  'ToolSvc += '
339  if value.getName() == value.getType(): # using default name
340  suggestion += '%s()' % value.__class__.__name__
341  else: # using user-defined name
342  suggestion += '%s(%r)' % (value.__class__.__name__,value.getName())
343  raise RuntimeError( self.fullPropertyName(obj) +
344  ': Public tool %s is not yet in ToolSvc. %s' %
345  (value.getJobOptName(),suggestion) )
346  # make it read-only
347  return self._handleType(value.toStringProperty())
348  elif value.hasParent( obj.getJobOptName() ):
349  # is already a child, keep as-is
350  return value
351  else:
352  # make a copy of the configurable
353  return obj.copyChildAndSetParent( value, obj.getJobOptName() )
354  else:
355  raise TypeError( "Property %s value %r is not a %s nor a %s nor a string" % \
356  (self.fullPropertyName(obj),value,self._confTypeName,self._handleType.__name__) )
357 
358  return value
359 
360 

◆ fullPropertyName()

def python.PropertyProxy.PropertyProxy.fullPropertyName (   self,
  obj 
)
inherited

Definition at line 93 of file PropertyProxy.py.

93  def fullPropertyName( self, obj ):
94  return (obj.getJobOptName() or obj.getName()) + '.' + self.descr.__name__
95 

◆ getDefault()

def python.PropertyProxy.PropertyProxy.getDefault (   self)
inherited

Definition at line 88 of file PropertyProxy.py.

88  def getDefault( self ):
89  return self.__default
90 

◆ getDefaultConfigurable()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.getDefaultConfigurable (   self,
  typeAndName,
  requester 
)
Return the configurable instance corresponding to the toolhandle if possible.
Otherwise return None

Definition at line 270 of file PropertyProxy.py.

270  def getDefaultConfigurable(self,typeAndName,requester):
271  """Return the configurable instance corresponding to the toolhandle if possible.
272  Otherwise return None"""
273  global log
274  # find the module
275  typeAndNameTuple = typeAndName.split('/')
276  confType = typeAndNameTuple[0]
277  confClass = ConfigurableDb.getConfigurable(confType)
278  # check the type of the configurable
279  if not derives_from(confClass,self._confTypeName):
280  log.error( "%s: Configurable %s is not a %s",
281  requester, confType, self._confTypeName )
282  return None
283  try:
284  confName = typeAndNameTuple[1]
285  except IndexError:
286  return confClass() # use default name
287  else:
288  return confClass(confName)
289 
290 

◆ isConfig()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.isConfig (   self,
  value 
)
Check if <value> is a configurable of the correct type

Definition at line 265 of file PropertyProxy.py.

265  def isConfig(self,value):
266  """Check if <value> is a configurable of the correct type"""
267  return derives_from(value,self._confTypeName)
268 
269 

◆ isHandle()

def python.PropertyProxy.GaudiHandlePropertyProxyBase.isHandle (   self,
  value 
)
Check if <value> is a handle of the correct type

Definition at line 260 of file PropertyProxy.py.

260  def isHandle(self,value):
261  """Check if <value> is a handle of the correct type"""
262  return isinstance(value,self._handleType)
263 
264 

◆ setDefault()

def python.PropertyProxy.PropertyProxy.setDefault (   self,
  value 
)
inherited

Definition at line 85 of file PropertyProxy.py.

85  def setDefault( self, value ):
86  self.__default = value
87 

Member Data Documentation

◆ __default

python.PropertyProxy.PropertyProxy.__default
privateinherited

Definition at line 86 of file PropertyProxy.py.

◆ __doc__

python.PropertyProxy.PropertyProxy.__doc__
privateinherited

Definition at line 81 of file PropertyProxy.py.

◆ _confTypeName

python.PropertyProxy.GaudiHandlePropertyProxyBase._confTypeName
private

Definition at line 195 of file PropertyProxy.py.

◆ _handleType

python.PropertyProxy.GaudiHandlePropertyProxyBase._handleType
private

Definition at line 194 of file PropertyProxy.py.

◆ descr

python.PropertyProxy.PropertyProxy.descr
inherited

Definition at line 79 of file PropertyProxy.py.

◆ history

python.PropertyProxy.PropertyProxy.history
inherited

Definition at line 78 of file PropertyProxy.py.

Property Documentation

◆ default

python.PropertyProxy.PropertyProxy.default = property( getDefault, setDefault )
staticinherited

Definition at line 91 of file PropertyProxy.py.


The documentation for this class was generated from the following file:
python.PropertyProxy.derives_from
def derives_from(derived, base)
Definition: PropertyProxy.py:27
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78