7 'PropertyProxy',
'GaudiHandlePropertyProxy',
8 'GaudiHandleArrayPropertyProxy' 14 from GaudiKernel
import ConfigurableDb
18 log = logging.getLogger(
'PropertyProxy')
25 """A string version of isinstance(). 26 <derived> is either an object instance, or a type 27 <base> is a string containing the name of the base class (or <derived> class)""" 28 if not isinstance(derived, type):
29 derived =
type(derived)
30 if derived.__name__ == base:
32 for b
in derived.__bases__:
40 errmsg =
"received an instance of %s, but %s expected" % (
type(value), tp)
49 elif isinstance(value, DataObjectHandleBase):
54 raise ValueError(errmsg)
55 elif (tp
in [list, tuple, dict]):
56 if (
type(value)
is tp):
61 raise ValueError(errmsg)
68 except (TypeError, ValueError):
69 raise ValueError(errmsg)
75 def __init__(self, descr, docString=None, default=None):
81 if '[[deprecated]]' in docString:
83 if default
is not None:
92 default = property(getDefault, setDefault)
95 return (obj.getJobOptName()
96 or obj.getName()) +
'.' + self.
descr.__name__
101 except AttributeError:
104 if self.
__default.__class__
in [list, dict]:
116 log.warning(
'Property %s is deprecated: %s',
120 proptype, allowcompat =
None,
False 121 if hasattr(self,
'default'):
123 if self.
descr.__name__ ==
'OutputLevel':
132 if proptype
and proptype !=
type(
None)
and \
146 except AttributeError:
149 except ValueError
as e:
151 log.error(
'inconsistent value types for %s.%s (%s)' %
152 (obj.getName(), self.
descr.__name__, str(e)))
158 if not obj._isInSetDefaults()
or not obj
in self.
history:
160 if hasattr(self,
'default')
and self.
default ==
None:
161 obj.__iadd__(value, self.
descr)
164 self.
history.setdefault(obj, []).append(value)
173 """A class with some utilities for GaudiHandles and GaudiHandleArrays""" 175 def __init__(self, descr, docString, default, handleType, allowedType):
176 """<descr>: the real property in the object instance (from __slots__) 177 <docString>: the documentation string of this property 178 <default>: default value from C++ (via python generated by genconf) 179 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...) 180 <allowedType>: allowed instance type for default 183 if not isinstance(default, allowedType):
184 raise TypeError(
"%s: %s default: %r is not a %s" %
185 (descr.__name__, self.__class__.__name__, default,
186 allowedType.__name__))
187 PropertyProxy.__init__(self, descr, docString, default)
195 except AttributeError:
198 default = obj.__class__.getDefaultProperty(self.
descr.__name__)
202 except AttributeError
as e:
204 raise RuntimeError(*e.args)
211 if not obj._isInSetDefaults()
or not obj
in self.
history:
216 self.
history.setdefault(obj, []).append(value)
219 """Check if <value> is a handle of the correct type""" 223 """Check if <value> is a configurable of the correct type""" 227 """Return the configurable instance corresponding to the toolhandle if possible. 228 Otherwise return None""" 231 typeAndNameTuple = typeAndName.split(
'/')
232 confType = typeAndNameTuple[0]
233 confClass = ConfigurableDb.getConfigurable(confType)
236 log.error(
"%s: Configurable %s is not a %s", requester, confType,
240 confName = typeAndNameTuple[1]
244 return confClass(confName)
248 isString =
type(default) == str
249 if not isString
and self.
isConfig(default):
252 elif isString
or self.
isHandle(default):
255 typeAndName = default
258 typeAndName = default.typeAndName
269 except AttributeError
as e:
271 raise RuntimeError(*e.args)
274 "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" 278 raise TypeError(
"%s: default value %r is not of type %s or %s" %
287 isString =
type(value) == str
298 if not value.isInToolSvc():
299 suggestion =
'You may need to add jobOptions lines something like:' + os.linesep + \
300 'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
302 if value.getName() == value.getType(
304 suggestion +=
'%s()' % value.__class__.__name__
306 suggestion +=
'%s(%r)' % (value.__class__.__name__,
310 ': Public tool %s is not yet in ToolSvc. %s' %
311 (value.getJobOptName(), suggestion))
314 elif value.hasParent(obj.getJobOptName()):
319 value = obj.copyChildAndSetParent(value, obj.getJobOptName())
321 obj.allConfigurables[value.name()] = value
325 "Property %s value %r is not a %s nor a %s nor a string" %
334 GaudiHandlePropertyProxyBase.__init__(self, descr, docString, default,
335 type(default), GaudiHandle)
340 """<descr>: the real property in the object instance (from __slots__) 341 <confTypeName>: string indicating the (base) class of allowed Configurables to be assigned. 342 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...) 344 GaudiHandlePropertyProxyBase.__init__(self, descr, docString, default,
345 type(default).handleType,
350 if not isinstance(value, list)
and not isinstance(
353 "%s: Value %r is not a list nor a %s" %
360 cd = GaudiHandlePropertyProxyBase.convertDefaultToBeSet(
363 newDefault.append(cd)
371 cv = GaudiHandlePropertyProxyBase.convertValueToBeSet(self, obj, v)
380 PropertyProxy.__init__(self, descr, docString, default)
385 except AttributeError:
388 default = obj.__class__.getDefaultProperty(self.
descr.__name__)
392 except AttributeError
as e:
394 raise RuntimeError(*e.args)
399 if not obj._isInSetDefaults()
or not obj
in self.
history:
404 self.
history.setdefault(obj, []).append(value)
410 mode = obj.__class__.getDefaultProperty(self.
descr.__name__).mode()
411 _type = obj.__class__.getDefaultProperty(self.
descr.__name__).
type()
412 if type(value) == str:
414 elif isinstance(value, DataObjectHandleBase):
417 raise ValueError(
"received an instance of %s, but %s expected" %
418 (
type(value),
'str or DataObjectHandleBase'))
424 if isinstance(default, GaudiHandleArray):
427 if isinstance(default, GaudiHandle):
430 if isinstance(default, DataObjectHandleBase):
def convertValueToBeSet(self, obj, value)
def getDefaultConfigurable(self, typeAndName, requester)
def __delete__(self, obj)
def convertDefaultToBeSet(self, obj, default)
def isConfig(self, value)
def isHandle(self, value)
def __get__(self, obj, type=None)
def checkType(self, obj, value)
def convertValueToBeSet(self, obj, value)
def convertValueToBeSet(self, obj, value)
def __set__(self, obj, value)
def __get__(self, obj, type=None)
def __init__(self, descr, docString=None, default=None)
def __init__(self, descr, docString, default)
def __set__(self, obj, value)
def __init__(self, descr, docString, default, handleType, allowedType)
def __init__(self, descr, docString, default)
def __set__(self, obj, value)
def __get__(self, obj, type=None)
def derives_from(derived, base)
def PropertyProxyFactory(descr, doc, default)
def __init__(self, descr, docString, default)
def fullPropertyName(self, obj)
def convertDefaultToBeSet(self, obj, default)
def _isCompatible(tp, value)
def setDefault(self, value)