17 'PropertyProxy',
'GaudiHandlePropertyProxy',
18 'GaudiHandleArrayPropertyProxy' 24 from GaudiKernel
import ConfigurableDb
28 log = logging.getLogger(
'PropertyProxy')
35 """A string version of isinstance(). 36 <derived> is either an object instance, or a type 37 <base> is a string containing the name of the base class (or <derived> class)""" 38 if not isinstance(derived, type):
39 derived =
type(derived)
40 if derived.__name__ == base:
42 for b
in derived.__bases__:
50 errmsg =
"received an instance of %s, but %s expected" % (
type(value), tp)
59 elif isinstance(value, DataObjectHandleBase):
64 raise ValueError(errmsg)
65 elif (tp
in [list, tuple, dict]):
66 if (
type(value)
is tp):
71 raise ValueError(errmsg)
78 except (TypeError, ValueError):
79 raise ValueError(errmsg)
85 def __init__(self, descr, docString=None, default=None):
91 if '[[deprecated]]' in docString:
93 if default
is not None:
102 default = property(getDefault, setDefault)
105 return (obj.getJobOptName()
106 or obj.getName()) +
'.' + self.
descr.__name__
111 except AttributeError:
114 if self.
__default.__class__
in [list, dict]:
126 log.warning(
'Property %s is deprecated: %s',
130 proptype, allowcompat =
None,
False 131 if hasattr(self,
'default'):
133 if self.
descr.__name__ ==
'OutputLevel':
142 if proptype
and proptype !=
type(
None)
and \
156 except AttributeError:
159 except ValueError
as e:
161 log.error(
'inconsistent value types for %s.%s (%s)' %
162 (obj.getName(), self.
descr.__name__, str(e)))
168 if not obj._isInSetDefaults()
or not obj
in self.
history:
170 if hasattr(self,
'default')
and self.
default ==
None:
171 obj.__iadd__(value, self.
descr)
174 self.
history.setdefault(obj, []).append(value)
183 """A class with some utilities for GaudiHandles and GaudiHandleArrays""" 185 def __init__(self, descr, docString, default, handleType, allowedType):
186 """<descr>: the real property in the object instance (from __slots__) 187 <docString>: the documentation string of this property 188 <default>: default value from C++ (via python generated by genconf) 189 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...) 190 <allowedType>: allowed instance type for default 193 if not isinstance(default, allowedType):
194 raise TypeError(
"%s: %s default: %r is not a %s" %
195 (descr.__name__, self.__class__.__name__, default,
196 allowedType.__name__))
197 PropertyProxy.__init__(self, descr, docString, default)
205 except AttributeError:
208 default = obj.__class__.getDefaultProperty(self.
descr.__name__)
212 except AttributeError
as e:
214 raise RuntimeError(*e.args)
221 if not obj._isInSetDefaults()
or not obj
in self.
history:
226 self.
history.setdefault(obj, []).append(value)
229 """Check if <value> is a handle of the correct type""" 233 """Check if <value> is a configurable of the correct type""" 237 """Return the configurable instance corresponding to the toolhandle if possible. 238 Otherwise return None""" 241 typeAndNameTuple = typeAndName.split(
'/')
242 confType = typeAndNameTuple[0]
243 confClass = ConfigurableDb.getConfigurable(confType)
246 log.error(
"%s: Configurable %s is not a %s", requester, confType,
250 confName = typeAndNameTuple[1]
254 return confClass(confName)
258 isString =
type(default) == str
259 if not isString
and self.
isConfig(default):
262 elif isString
or self.
isHandle(default):
265 typeAndName = default
268 typeAndName = default.typeAndName
279 except AttributeError
as e:
281 raise RuntimeError(*e.args)
284 "%s: Default configurable for class %s not found in ConfigurableDb.CfgDb" 288 raise TypeError(
"%s: default value %r is not of type %s or %s" %
297 isString =
type(value) == str
308 if not value.isInToolSvc():
309 suggestion =
'You may need to add jobOptions lines something like:' + os.linesep + \
310 'from AthenaCommon.AppMgr import ToolSvc' + os.linesep + \
312 if value.getName() == value.getType(
314 suggestion +=
'%s()' % value.__class__.__name__
316 suggestion +=
'%s(%r)' % (value.__class__.__name__,
320 ': Public tool %s is not yet in ToolSvc. %s' %
321 (value.getJobOptName(), suggestion))
324 elif value.hasParent(obj.getJobOptName()):
329 value = obj.copyChildAndSetParent(value, obj.getJobOptName())
331 obj.allConfigurables[value.name()] = value
335 "Property %s value %r is not a %s nor a %s nor a string" %
344 GaudiHandlePropertyProxyBase.__init__(self, descr, docString, default,
345 type(default), GaudiHandle)
350 """<descr>: the real property in the object instance (from __slots__) 351 <confTypeName>: string indicating the (base) class of allowed Configurables to be assigned. 352 <handleType>: real python handle type (e.g. PublicToolHandle, PrivateToolHandle, ...) 354 GaudiHandlePropertyProxyBase.__init__(self, descr, docString, default,
355 type(default).handleType,
360 if not isinstance(value, list)
and not isinstance(
363 "%s: Value %r is not a list nor a %s" %
370 cd = GaudiHandlePropertyProxyBase.convertDefaultToBeSet(
373 newDefault.append(cd)
381 cv = GaudiHandlePropertyProxyBase.convertValueToBeSet(self, obj, v)
390 PropertyProxy.__init__(self, descr, docString, default)
395 except AttributeError:
398 default = obj.__class__.getDefaultProperty(self.
descr.__name__)
402 except AttributeError
as e:
404 raise RuntimeError(*e.args)
409 if not obj._isInSetDefaults()
or not obj
in self.
history:
414 self.
history.setdefault(obj, []).append(value)
420 mode = obj.__class__.getDefaultProperty(self.
descr.__name__).mode()
421 _type = obj.__class__.getDefaultProperty(self.
descr.__name__).
type()
422 if type(value) == str:
424 elif isinstance(value, DataObjectHandleBase):
427 raise ValueError(
"received an instance of %s, but %s expected" %
428 (
type(value),
'str or DataObjectHandleBase'))
434 if isinstance(default, GaudiHandleArray):
437 if isinstance(default, GaudiHandle):
440 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)