File indexing completed on 2025-02-20 03:45:31
0001 from .Mixins import PrintOptions, _SimpleParameterTypeBase, _ParameterTypeBase, _Parameterizable, _ConfigureComponent, _Labelable, _TypedParameterizable, _Unlabelable, _modifyParametersFromDict
0002 from .Mixins import _ValidatingParameterListBase, specialImportRegistry
0003 from .Mixins import saveOrigin
0004 from .ExceptionHandling import format_typename, format_outerframe
0005 import codecs
0006 import copy
0007 import math
0008 import builtins
0009
0010 long = int
0011 _builtin_bool = bool
0012
0013 class _Untracked(object):
0014 """Class type for 'untracked' to allow nice syntax"""
0015 __name__ = "untracked"
0016 @staticmethod
0017 def __call__(param):
0018 """used to set a 'param' parameter to be 'untracked'"""
0019 param.setIsTracked(False)
0020 return param
0021 def __getattr__(self,name:str):
0022 """A factory which allows syntax untracked.name(value) to construct an
0023 instance of 'name' class which is set to be untracked"""
0024 if name == "__bases__": raise AttributeError
0025 class Factory(object):
0026 def __init__(self,name):
0027 self.name = name
0028 def __call__(self,*value,**params):
0029 param = globals()[self.name](*value,**params)
0030 return _Untracked.__call__(param)
0031 return Factory(name)
0032
0033 untracked = _Untracked()
0034
0035
0036 class _ProxyParameter(_ParameterTypeBase):
0037 """Base class for Parameters which are proxies for other Parameter types"""
0038 def __init__(self,type):
0039 super(_ProxyParameter,self).__init__()
0040 self.__dict__["_ProxyParameter__type"] = type
0041 self.__dict__["_ProxyParameter__value"] = None
0042 if hasattr(self.__type,"_default") and self.__type._default is not None:
0043 self.setValue(self.__type._default)
0044 def setValue(self, value):
0045 v = self.__type(value)
0046 if not _ParameterTypeBase.isTracked(self):
0047 v = untracked(v)
0048 self.__dict__["_ProxyParameter__value"] = v
0049 def _checkAndReturnValueWithType(self, valueWithType):
0050 if isinstance(valueWithType, type(self)):
0051 return valueWithType
0052 if isinstance(self.__type, type):
0053 if isinstance(valueWithType, self.__type):
0054 self.__dict__["_ProxyParameter__value"] = valueWithType
0055 return self
0056 else:
0057 raise TypeError("type {bad} does not match {expected}".format(bad=str(type(valueWithType)), expected = str(self.__type)))
0058 v = self.__type._setValueWithType(valueWithType)
0059 if not _ParameterTypeBase.isTracked(self):
0060 v = untracked(v)
0061 self.__dict__["_ProxyParameter__value"] = v
0062 return self
0063 def __getattr__(self, name:str):
0064 v =self.__dict__.get('_ProxyParameter__value', None)
0065 if name == '_ProxyParameter__value':
0066 return v
0067 if (not name.startswith('_')) and v is not None:
0068 return getattr(v, name)
0069 else:
0070 return object.__getattribute__ (self, name)
0071 def __setattr__(self,name:str, value):
0072 v = self.__dict__.get('_ProxyParameter__value',None)
0073 if v is not None:
0074 return setattr(v,name,value)
0075 else:
0076 if not name.startswith('_'):
0077 raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name))
0078 return object.__setattr__(self, name, value)
0079
0080 def __len__(self):
0081 v =self.__dict__.get('_ProxyParameter__value', None)
0082 if v is not None:
0083 return v.__len__()
0084 else:
0085 raise TypeError("'_ProxyParameter' object has no len()")
0086
0087 def __iter__(self):
0088 v =self.__dict__.get('_ProxyParameter__value', None)
0089 if v is not None:
0090 return v.__iter__()
0091 else:
0092 raise TypeError("'_ProxyParameter' object is not iterable")
0093 def __setitem__(self, key, value):
0094 v =self.__dict__.get('_ProxyParameter__value', None)
0095 if v is not None:
0096 return v.__setitem__(key,value)
0097 else:
0098 raise TypeError("'_ProxyParameter' object does not support item assignment")
0099 def __getitem__(self, key):
0100 v =self.__dict__.get('_ProxyParameter__value', None)
0101 if v is not None:
0102 return v.__getitem__(key)
0103 else:
0104 raise TypeError("'_ProxyParameter' object is not subscriptable")
0105 def __bool__(self):
0106 v = self.__dict__.get('_ProxyParameter__value',None)
0107 return _builtin_bool(v)
0108 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
0109 v =self.__dict__.get('_ProxyParameter__value',None)
0110 if v is not None:
0111 return v.dumpPython(options)
0112 specialImportRegistry.registerUse(self)
0113 v = "cms."+self._dumpPythonName()
0114 if not _ParameterTypeBase.isTracked(self):
0115 v+=".untracked"
0116 if hasattr(self.__type, "__name__"):
0117 return v+'.'+self.__type.__name__
0118 return v+'.'+self.__type.dumpPython(options)
0119 def validate_(self,value) -> bool:
0120 return isinstance(value,self.__type)
0121 def convert_(self,value):
0122 v = self.__type(value)
0123 if not _ParameterTypeBase.isTracked(self):
0124 v = untracked(v)
0125 return v
0126 def isCompatibleCMSType(self,aType) -> bool:
0127 v = self.__dict__.get('_ProxyParameter__value',None)
0128 if v is not None:
0129 return v.isCompatibleCMSType(aType)
0130 return self.__type == aType
0131
0132 class _RequiredParameter(_ProxyParameter):
0133 @staticmethod
0134 def _dumpPythonName() -> str:
0135 return 'required'
0136 def insertInto(self, parameterSet, myname:str):
0137 v = self.__dict__.get('_ProxyParameter__value', None)
0138 if v is None:
0139 raise RuntimeError("Required parameter "+myname+" was not set")
0140 v.insertInto(parameterSet,myname)
0141
0142 class _OptionalParameter(_ProxyParameter):
0143 @staticmethod
0144 def _dumpPythonName() -> str:
0145 return 'optional'
0146 def insertInto(self, parameterSet, myname:str):
0147 v = self.__dict__.get('_ProxyParameter__value', None)
0148 if v is not None:
0149 v.insertInto(parameterSet,myname)
0150 def value(self):
0151 v = self.__dict__.get('_ProxyParameter__value', None)
0152 if v is not None:
0153 return v.value()
0154 return None
0155
0156 class _ObsoleteParameter(_OptionalParameter):
0157 @staticmethod
0158 def _dumpPythonName() -> str:
0159 return 'obsolete'
0160
0161 class _AllowedParameterTypes(object):
0162 def __init__(self, *args, default=None):
0163 self.__dict__['_AllowedParameterTypes__types'] = args
0164 self.__dict__['_default'] = None
0165 self.__dict__['__name__'] = self.dumpPython()
0166 if default is not None:
0167 self.__dict__['_default'] = self._setValueWithType(default)
0168 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
0169 specialImportRegistry.registerUse(self)
0170 return "allowed("+','.join( ("cms."+t.__name__ if not isinstance(t, _PSetTemplate) else "cms."+t.dumpPython() for t in self.__types))+')'
0171 def __call__(self,value):
0172 chosenType = None
0173 for t in self.__types:
0174 if not isinstance(t, _PSetTemplate) and isinstance(value, t):
0175 return value
0176 if t._isValid(value):
0177 if chosenType is not None:
0178 raise RuntimeError("Ambiguous type conversion for 'allowed' parameter")
0179 chosenType = t
0180 if chosenType is None:
0181 raise RuntimeError("Cannot convert "+str(value)+" to 'allowed' type")
0182 return chosenType(value)
0183 def _setValueWithType(self, valueWithType):
0184 for t in self.__types:
0185 if isinstance(t, _PSetTemplate):
0186 if isinstance(valueWithType, PSet):
0187 return valueWithType
0188 elif isinstance(valueWithType, t):
0189 return valueWithType
0190 raise TypeError("type {bad} is not one of 'allowed' types {types}".format(bad=str(type(valueWithType)), types = ",".join( (str(t) for t in self.__types))) )
0191
0192
0193
0194 class _PSetTemplate(object):
0195 def __init__(self, *args, **kargs):
0196 self._pset = PSet(*args,**kargs)
0197 def __call__(self, value):
0198 self.__dict__
0199 return self._pset.clone(**value)
0200 def _isEmpty(self) -> bool:
0201 return self._pset.hasNoParameters()
0202 def _isValid(self, value) -> bool:
0203 return isinstance(value,dict) or isinstance(value, PSet)
0204 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
0205 return "PSetTemplate(\n"+_Parameterizable.dumpPython(self._pset, options)+options.indentation()+")"
0206 def _setValueWithType(self, valueWithType):
0207 if not isinstance(valueWithType, PSet):
0208 raise TypeError("type {bad} is not a PSet".format(bas=str(type(valueWithType))))
0209 return valueWithType
0210
0211 PSetTemplate = _PSetTemplate
0212
0213 class _VPSetTemplate(object):
0214 def __init__(self, template:_PSetTemplate=None):
0215 self._template = template
0216 def __call__(self, *value):
0217 self.__dict__
0218 if self._template:
0219 return VPSet(template = self._template, *value)
0220 return VPSet(*value)
0221 def _isValid(self, value) -> bool:
0222 if isinstance(value,list) or isinstance(value, VPSet):
0223 return True
0224 try:
0225 iter(value)
0226 except TypeError:
0227 return False
0228 return True
0229 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
0230 if self._template:
0231 options.indent()
0232 ret = "VPSetTemplate(\n"+options.indentation()+self._template.dumpPython(options)+'\n'
0233 options.unindent()
0234 ret += options.indentation()+")"
0235 return ret
0236 return "VPSetTemplate()"
0237 def _setValueWithType(self, valueWithType):
0238 if not isinstance(valueWithType, VPSet):
0239 raise TypeError("type {bad} is not a VPSet".format(bas=str(type(valueWithType))))
0240 return valueWithType
0241
0242 VPSetTemplate = _VPSetTemplate
0243
0244 class _ProxyParameterFactory(object):
0245 """Class type for ProxyParameter types to allow nice syntax"""
0246 def __init__(self, type, isUntracked:bool = False):
0247 self.__isUntracked = isUntracked
0248 self.__type = type
0249 def __getattr__(self,name:str):
0250 if name[0] == '_':
0251 return object.__getattribute__(self,name)
0252 if name == 'untracked':
0253 return _ProxyParameterFactory(self.__type,isUntracked=True)
0254 if name == 'allowed':
0255 class _AllowedWrapper(object):
0256 def __init__(self, untracked, type):
0257 self.untracked = untracked
0258 self.type = type
0259 def __call__(self, *args, **kargs):
0260 if self.untracked:
0261 return untracked(self.type(_AllowedParameterTypes(*args, **kargs)))
0262 return self.type(_AllowedParameterTypes(*args, **kargs))
0263
0264 return _AllowedWrapper(self.__isUntracked, self.__type)
0265 if name == 'PSetTemplate':
0266 class _PSetTemplateWrapper(object):
0267 def __init__(self, untracked, type):
0268 self.untracked = untracked
0269 self.type = type
0270 def __call__(self,*args,**kargs):
0271 if self.untracked:
0272 return untracked(self.type(_PSetTemplate(*args,**kargs)))
0273 return self.type(_PSetTemplate(*args,**kargs))
0274 return _PSetTemplateWrapper(self.__isUntracked, self.__type)
0275 if name == 'VPSetTemplate':
0276 class _VPSetTemplateWrapper(object):
0277 def __init__(self, untracked, type):
0278 self.untracked = untracked
0279 self.type = type
0280 def __call__(self,*args,**kargs):
0281 if self.untracked:
0282 return untracked(self.type(_VPSetTemplate(*args,**kargs)))
0283 return self.type(_VPSetTemplate(*args,**kargs))
0284 return _VPSetTemplateWrapper(self.__isUntracked, self.__type)
0285
0286 type = globals()[name]
0287 if not issubclass(type, _ParameterTypeBase):
0288 raise AttributeError
0289 if self.__isUntracked:
0290 return untracked(self.__type(type))
0291 return self.__type(type)
0292
0293 required = _ProxyParameterFactory(_RequiredParameter)
0294 optional = _ProxyParameterFactory(_OptionalParameter)
0295 obsolete = _ProxyParameterFactory(_ObsoleteParameter)
0296
0297 class int32(_SimpleParameterTypeBase):
0298 @staticmethod
0299 def _isValid(value) -> bool:
0300 return isinstance(value,int)
0301 @staticmethod
0302 def _valueFromString(value:str):
0303 """only used for cfg-parsing"""
0304 if len(value) >1 and '0x' == value[:2]:
0305 return int32(int(value,16))
0306 return int32(int(value))
0307 def insertInto(self, parameterSet, myname:str):
0308 parameterSet.addInt32(self.isTracked(), myname, self.value())
0309 def __nonzero__(self) -> bool:
0310 return self.value()!=0
0311 def __bool__(self) -> bool:
0312 return self.__nonzero__()
0313
0314
0315 class uint32(_SimpleParameterTypeBase):
0316 @staticmethod
0317 def _isValid(value) -> bool:
0318 return ((isinstance(value,int) and value >= 0) or
0319 (isinstance(value,long) and value >= 0) and value <= 0xFFFFFFFF)
0320 @staticmethod
0321 def _valueFromString(value:str):
0322 """only used for cfg-parsing"""
0323 if len(value) >1 and '0x' == value[:2]:
0324 return uint32(long(value,16))
0325 return uint32(long(value))
0326 def insertInto(self, parameterSet, myname):
0327 parameterSet.addUInt32(self.isTracked(), myname, self.value())
0328 def __nonzero__(self) -> bool:
0329 return self.value()!=0
0330 def __bool__(self) -> bool:
0331 return self.__nonzero__()
0332
0333
0334
0335 class int64(_SimpleParameterTypeBase):
0336 @staticmethod
0337 def _isValid(value) -> bool:
0338 return isinstance(value,int) or (
0339 isinstance(value,long) and
0340 (-0x7FFFFFFFFFFFFFFF < value <= 0x7FFFFFFFFFFFFFFF) )
0341 @staticmethod
0342 def _valueFromString(value:str):
0343 """only used for cfg-parsing"""
0344 if len(value) >1 and '0x' == value[:2]:
0345 return uint32(long(value,16))
0346 return int64(long(value))
0347 def insertInto(self, parameterSet, myname:str):
0348 parameterSet.addInt64(self.isTracked(), myname, self.value())
0349 def __nonzero__(self) -> bool:
0350 return self.value()!=0
0351
0352
0353
0354 class uint64(_SimpleParameterTypeBase):
0355 @staticmethod
0356 def _isValid(value) -> bool:
0357 return ((isinstance(value,int) and value >= 0) or
0358 (isinstance(value,long) and value >= 0) and value <= 0xFFFFFFFFFFFFFFFF)
0359 @staticmethod
0360 def _valueFromString(value:str):
0361 """only used for cfg-parsing"""
0362 if len(value) >1 and '0x' == value[:2]:
0363 return uint32(long(value,16))
0364 return uint64(long(value))
0365 def insertInto(self, parameterSet, myname:str):
0366 parameterSet.addUInt64(self.isTracked(), myname, self.value())
0367 def __nonzero__(self) -> bool:
0368 return self.value()!=0
0369
0370
0371
0372 class double(_SimpleParameterTypeBase):
0373 @staticmethod
0374 def _isValid(value) -> bool:
0375 return isinstance(value, (int, long, float))
0376 @staticmethod
0377 def _valueFromString(value:str):
0378 """only used for cfg-parsing"""
0379 return double(float(value))
0380 def insertInto(self, parameterSet, myname:str):
0381 parameterSet.addDouble(self.isTracked(), myname, float(self.value()))
0382 def __nonzero__(self) -> bool:
0383 return self.value()!=0.
0384 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
0385 return double._pythonValue(self._value)
0386 @staticmethod
0387 def _pythonValue(value) -> str:
0388 if math.isinf(value):
0389 if value > 0:
0390 return "float('inf')"
0391 else:
0392 return "-float('inf')"
0393 if math.isnan(value):
0394 return "float('nan')"
0395 return str(value)
0396
0397
0398
0399 class bool(_SimpleParameterTypeBase):
0400 @staticmethod
0401 def _isValid(value) -> builtins.bool:
0402 return (isinstance(value,type(False)) or isinstance(value,type(True)))
0403 @staticmethod
0404 def _valueFromString(value:str):
0405 """only used for cfg-parsing"""
0406 if value.lower() in ('true', 't', 'on', 'yes', '1'):
0407 return bool(True)
0408 if value.lower() in ('false','f','off','no', '0'):
0409 return bool(False)
0410 try:
0411 return bool(builtins.bool(eval(value)))
0412 except:
0413 pass
0414 raise RuntimeError('can not make bool from string '+value)
0415 def insertInto(self, parameterSet, myname:str):
0416 parameterSet.addBool(self.isTracked(), myname, self.value())
0417 def __nonzero__(self) -> builtins.bool:
0418 return self.value()
0419 def __bool__(self) -> builtins.bool:
0420 return self.__nonzero__()
0421
0422
0423 class string(_SimpleParameterTypeBase):
0424 def __init__(self,value):
0425 super(string,self).__init__(value)
0426 @staticmethod
0427 def _isValid(value) -> builtins.bool:
0428 return isinstance(value,type(''))
0429 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
0430 return self.formatValueForConfig(self.value())
0431 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0432 return self.configValue(options)
0433 @staticmethod
0434 def formatValueForConfig(value) -> str:
0435 l = len(value)
0436 import sys
0437 if sys.version_info >= (3, 0):
0438 import codecs
0439 t=codecs.escape_encode(value.encode('utf-8'))
0440 value = t[0].decode('utf-8')
0441 else:
0442 value = value.encode("string-escape")
0443 newL = len(value)
0444 if l != newL:
0445
0446 value=value.replace('\\x0','\\')
0447 if "'" in value:
0448 return '"'+value+'"'
0449 return "'"+value+"'"
0450 @staticmethod
0451 def _valueFromString(value:str):
0452 """only used for cfg-parsing"""
0453 return string(value)
0454 def insertInto(self, parameterSet, myname:str):
0455 value = self.value()
0456
0457
0458
0459 parameterSet.addString(self.isTracked(), myname, value)
0460 def __nonzero__(self) -> builtins.bool:
0461 return len(self.value()) !=0
0462 def __bool__(self) -> builtins.bool:
0463 return self.__nonzero__()
0464
0465
0466 class EventID(_ParameterTypeBase):
0467 def __init__(self, run, *args):
0468 super(EventID,self).__init__()
0469 if isinstance(run, str):
0470 v = self._valueFromString(run)
0471 self.__run = v.__run
0472 self.__luminosityBlock = v.__luminosityBlock
0473 self.__event = v.__event
0474 else:
0475 self.__run = run
0476 if len(args) == 1:
0477 self.__luminosityBlock = 0
0478 self.__event = args[0]
0479 elif len(args) == 2:
0480 self.__luminosityBlock = args[0]
0481 self.__event = args[1]
0482 else:
0483 raise RuntimeError('EventID ctor must have 2 or 3 arguments')
0484 def setValue(self, value):
0485 if isinstance(value, str):
0486 v = self._valueFromString(value)
0487 self.__run = v.__run
0488 self.__luminosityBlock = v.__luminosityBlock
0489 self.__event = v.__event
0490 else:
0491 try:
0492 iter(value)
0493 self.__run = value[0]
0494 if len(value) == 2:
0495 self.__luminosityBlock = 0
0496 self.__event = value[1]
0497 elif len(value) == 3:
0498 self.__luminosityBlock = value[1]
0499 self.__event = value[2]
0500 else:
0501 raise RuntimeError('EventID setValue takes container of 2 or 3 elements')
0502 except TypeError:
0503
0504 raise RuntimeError('EventID setValue takes container of 2 or 3 elements')
0505 def run(self) -> int:
0506 return self.__run
0507 def luminosityBlock(self) -> int:
0508 return self.__luminosityBlock
0509 def event(self) -> int:
0510 return self.__event
0511 @staticmethod
0512 def _isValid(value) -> builtins.bool:
0513 return isinstance(value, str) or isinstance(value, EventID) or len(value) == 2 or len(value) == 3
0514 @staticmethod
0515 def _valueFromString(value:str):
0516 parts = value.split(":")
0517 run = parts[0]
0518 try:
0519 lumi = parts[1]
0520 event = parts[2]
0521 except IndexError:
0522 lumi = 0
0523 event = parts[1]
0524 return EventID(int(run), int(lumi), int(event))
0525 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0526 return str(self.__run)+ ', '+str(self.__luminosityBlock)+ ', '+str(self.__event)
0527 def cppID(self, parameterSet):
0528 return parameterSet.newEventID(self.run(), self.luminosityBlock(), self.event())
0529 def insertInto(self, parameterSet, myname:str):
0530 parameterSet.addEventID(self.isTracked(), myname, self.cppID(parameterSet))
0531 def value(self) -> str:
0532 return str(self.__run)+':'+str(self.__luminosityBlock)+":"+str(self.__event)
0533
0534 class LuminosityBlockID(_ParameterTypeBase):
0535 def __init__(self, run, block=None):
0536 super(LuminosityBlockID,self).__init__()
0537 if isinstance(run, str):
0538 v = self._valueFromString(run)
0539 self.__run = v.__run
0540 self.__block = v.__block
0541 else:
0542 self.__run = run
0543 self.__block = block
0544 def setValue(self, value):
0545 if isinstance(value, str):
0546 v = self._valueFromString(value)
0547 self.__run = v.__run
0548 self.__block = v.__block
0549 else:
0550 self.__run = value[0]
0551 self.__block = value[1]
0552 def run(self) -> int:
0553 return self.__run
0554 def luminosityBlock(self) -> int:
0555 return self.__block
0556 @staticmethod
0557 def _isValid(value) -> builtins.bool:
0558 return isinstance(value,str) or isinstance(value, LuminosityBlockID) or len(value) == 2
0559 @staticmethod
0560 def _valueFromString(value:str):
0561 """only used for cfg-parsing"""
0562 parts = value.split(":")
0563 return LuminosityBlockID(int(parts[0]), int(parts[1]))
0564 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0565 return str(self.__run)+ ', '+str(self.__block)
0566 def cppID(self, parameterSet):
0567 return parameterSet.newLuminosityBlockID(self.run(), self.luminosityBlock())
0568 def insertInto(self, parameterSet, myname:str):
0569 parameterSet.addLuminosityBlockID(self.isTracked(), myname, self.cppID(parameterSet))
0570 def value(self) -> str:
0571 return str(self.__run)+":"+str(self.__block)
0572
0573
0574 class LuminosityBlockRange(_ParameterTypeBase):
0575 def __init__(self, start, startSub=None, end=None, endSub=None):
0576 super(LuminosityBlockRange,self).__init__()
0577 if isinstance(start, str):
0578 parsed = self._valueFromString(start)
0579 self.__start = parsed.__start
0580 self.__startSub = parsed.__startSub
0581 self.__end = parsed.__end
0582 self.__endSub = parsed.__endSub
0583 else:
0584 if startSub is not None and end is None:
0585 self._valueFromContainer((start, startSub))
0586 else:
0587 self._valueFromContainer(( start, startSub, end, endSub))
0588 if self.__end < self.__start:
0589 raise RuntimeError('LuminosityBlockRange '+str(self.__start)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endSub)+' out of order')
0590
0591 if self.__end == self.__start and (self.__endSub != 0 and self.__endSub < self.__startSub):
0592 raise RuntimeError('LuminosityBlockRange '+str(self.__start)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endSub)+' out of order')
0593 def setValue(self,value):
0594 if isinstance(value, str):
0595 parsed = self._valueFromString(value)
0596 self.__start = parsed.__start
0597 self.__startSub = parsed.__startSub
0598 self.__end = parsed.__end
0599 self.__endSub = parsed.__endSub
0600 else:
0601 self._valueFromContainer(value)
0602 if self.__end < self.__start:
0603 raise RuntimeError('LuminosityBlockRange '+str(self.__start)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endSub)+' out of order')
0604
0605 if self.__end == self.__start and (self.__endSub != 0 and self.__endSub < self.__startSub):
0606 raise RuntimeError('LuminosityBlockRange '+str(self.__start)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endSub)+' out of order')
0607
0608 def start(self) -> int:
0609 return self.__start
0610 def startSub(self) -> int:
0611 return self.__startSub
0612 def end(self) -> int:
0613 return self.__end
0614 def endSub(self) -> int:
0615 return self.__endSub
0616 @staticmethod
0617 def _isValid(value) -> builtins.bool:
0618 if isinstance(value, str):
0619 return True
0620 if isinstance(value, LuminosityBlockRange):
0621 return True
0622 try:
0623 if len(value) == 2:
0624 return len(value[0])==2 and len(value[1])==2
0625 return len(value) == 4
0626 except:
0627 return False
0628 return False
0629 def _valueFromContainer(self, value):
0630 if len(value) == 2:
0631 if len(value[0]) != 2 or len(value[1]) != 2:
0632 raise RuntimeError('LuminosityBlockRange set by a container must then contain elements which are len == 2')
0633 self.__start = value[0][0]
0634 self.__startSub = value[0][1]
0635 self.__end = value[1][0]
0636 self.__endSub = value[1][1]
0637 else:
0638 self.__start = value[0]
0639 self.__startSub = value[1]
0640 self.__end = value[2]
0641 self.__endSub = value[3]
0642 @staticmethod
0643 def _valueFromString(value:str):
0644 """only used for cfg-parsing"""
0645 value = value.replace(' ','')
0646 parts = value.split("-")
0647 startParts = parts[0].split(":")
0648 try:
0649 endParts = parts[1].split(":")
0650 except IndexError:
0651 endParts = parts[0].split(":")
0652
0653 if startParts[1].lower() == "0":
0654 startParts[1] = "1"
0655 elif startParts[1].lower() == "max":
0656 startParts[1] = "0"
0657 elif startParts[1].lower() == "min":
0658 startParts[1] = "1"
0659 if endParts[1].lower() == "max":
0660 endParts[1] = "0"
0661 elif endParts[1].lower() == "min":
0662 endParts[1] = "1"
0663 return LuminosityBlockRange(int(startParts[0]), int(startParts[1]),
0664 int(endParts[0]), int(endParts[1]))
0665 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0666 return str(self.__start) + ', ' + str(self.__startSub) + ', ' \
0667 + str(self.__end) + ', ' + str(self.__endSub)
0668 def cppID(self, parameterSet):
0669 return parameterSet.newLuminosityBlockRange(self.start(), self.startSub(),self.end(), self.endSub())
0670 def insertInto(self, parameterSet, myname:str):
0671 parameterSet.addLuminosityBlockRange(self.isTracked(), myname, self.cppID(parameterSet))
0672 def value(self) -> str:
0673 return str(self.__start)+":"+str(self.__startSub)+"-"+str(self.__end)+":"+str(self.__endSub)
0674
0675 class EventRange(_ParameterTypeBase):
0676 def __init__(self, start, *args):
0677 super(EventRange,self).__init__()
0678 if isinstance(start, str):
0679 parsed = self._valueFromString(start)
0680 self.__start = parsed.__start
0681 self.__startLumi = parsed.__startLumi
0682 self.__startSub = parsed.__startSub
0683 self.__end = parsed.__end
0684 self.__endLumi = parsed.__endLumi
0685 self.__endSub = parsed.__endSub
0686 else:
0687 if len(args) == 0:
0688 self._valueFromContainer(start)
0689 else:
0690 v = [start]
0691 v.extend(args)
0692 self._valueFromContainer(v)
0693 if self.__end < self.__start or (self.__end == self.__start and self.__endLumi < self.__startLumi):
0694 raise RuntimeError('EventRange '+str(self.__start)+':'+str(self.__startLumi)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endLumi)+':'+str(self.__endSub)+' out of order')
0695
0696 if self.__end == self.__start and self.__endLumi == self.__startLumi and (self.__endSub != 0 and self.__endSub < self.__startSub):
0697 raise RuntimeError('EventRange '+str(self.__start)+':'+str(self.__startLumi)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endLumi)+':'+str(self.__endSub)+' out of order')
0698 def setValue(self, value):
0699 if isinstance(value, str):
0700 parsed = self._valueFromString(value)
0701 self.__start = parsed.__start
0702 self.__startLumi = parsed.__startLumi
0703 self.__startSub = parsed.__startSub
0704 self.__end = parsed.__end
0705 self.__endLumi = parsed.__endLumi
0706 self.__endSub = parsed.__endSub
0707 else:
0708 self._valueFromContainer(value)
0709 if self.__end < self.__start or (self.__end == self.__start and self.__endLumi < self.__startLumi):
0710 raise RuntimeError('EventRange '+str(self.__start)+':'+str(self.__startLumi)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endLumi)+':'+str(self.__endSub)+' out of order')
0711
0712 if self.__end == self.__start and self.__endLumi == self.__startLumi and (self.__endSub != 0 and self.__endSub < self.__startSub):
0713 raise RuntimeError('EventRange '+str(self.__start)+':'+str(self.__startLumi)+':'+str(self.__startSub)+'-'+str(self.__end)+':'+str(self.__endLumi)+':'+str(self.__endSub)+' out of order')
0714
0715 def start(self) -> int:
0716 return self.__start
0717 def startLumi(self) -> int:
0718 return self.__startLumi
0719 def startSub(self) -> int:
0720 return self.__startSub
0721 def end(self) -> int:
0722 return self.__end
0723 def endLumi(self) -> int:
0724 return self.__endLumi
0725 def endSub(self) -> int:
0726 return self.__endSub
0727 @staticmethod
0728 def _isValid(value) -> builtins.bool:
0729 return True
0730 def _valueFromContainer(self, value):
0731 length = len(value)
0732 if length == 2:
0733 if len(value[0]) != 3 or len(value[1]) != 3:
0734 raise RuntimeError('EventRange set with 2 arguments require the arguments to be a container with 3 elements')
0735 else:
0736 self.__start = value[0][0]
0737 self.__startLumi = value[0][1]
0738 self.__startSub = value[0][2]
0739 self.__end = value[1][0]
0740 self.__endLumi = value[1][1]
0741 self.__endSub = value[1][2]
0742 elif length == 4:
0743 self.__start = value[0]
0744 self.__startLumi = 0
0745 self.__startSub = value[1]
0746 self.__end = value[2]
0747 self.__endLumi = 0
0748 self.__endSub = value[3]
0749 elif len(value) == 6:
0750 self.__start = value[0]
0751 self.__startLumi = value[1]
0752 self.__startSub = value[2]
0753 self.__end = value[3]
0754 self.__endLumi = value[4]
0755 self.__endSub = value[5]
0756 else:
0757 raise RuntimeError('EventRange setValue must be set using 2, 4, or 6 arguments')
0758
0759 @staticmethod
0760 def _valueFromString(value:str):
0761 """only used for cfg-parsing"""
0762 value = value.replace(' ','')
0763 parts = value.split("-")
0764 startParts = parts[0].split(":")
0765 try:
0766 endParts = parts[1].split(":")
0767 except IndexError:
0768 endParts = parts[0].split(":")
0769
0770 brun = startParts[0]
0771 erun = endParts[0]
0772 s = len(startParts)
0773 e = len(endParts)
0774 if s != e or s < 2 or s > 3:
0775 raise RuntimeError('EventRange ctor must have 4 or 6 arguments')
0776 i = s - 1
0777 if startParts[i].lower() == "0":
0778 startParts[i] = "1"
0779 elif startParts[i].lower() == "max":
0780 startParts[i] = "0"
0781 elif startParts[i].lower() == "min":
0782 startParts[i] = "1"
0783 if endParts[i].lower() == "max":
0784 endParts[i] = "0"
0785 elif endParts[i].lower() == "min":
0786 endParts[i] = "1"
0787 if s == 3:
0788 blumi = startParts[1]
0789 elumi = endParts[1]
0790 bevent = startParts[2]
0791 eevent = endParts[2]
0792 elif s == 2:
0793 blumi = 0
0794 elumi = 0
0795 bevent = startParts[1]
0796 eevent = endParts[1]
0797 else:
0798 raise RuntimeError('EventRange ctor must have 4 or 6 arguments')
0799
0800
0801 return EventRange(int(brun), int(blumi), int(bevent),
0802 int(erun), int(elumi), int(eevent))
0803
0804 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0805 return str(self.__start) + ', ' + str(self.__startLumi) + ', ' + str(self.__startSub) + ', ' \
0806 + str(self.__end) + ', ' + str(self.__endLumi) + ', ' + str(self.__endSub)
0807 def cppID(self, parameterSet):
0808 return parameterSet.newEventRange(self.start(), self.startLumi(), self.startSub(), self.end(), self.endLumi(), self.endSub())
0809 def insertInto(self, parameterSet, myname:str):
0810 parameterSet.addEventRange(self.isTracked(), myname, self.cppID(parameterSet))
0811 def value(self) -> str:
0812 return str(self.__start) + ":" + str(self.__startLumi) + ":" + str(self.__startSub) + "-" + \
0813 str(self.__end) + ":" + str(self.__endLumi) + ":" + str(self.__endSub)
0814
0815 class InputTag(_ParameterTypeBase):
0816 def __init__(self,moduleLabel:str,productInstanceLabel:str='',processName:str=''):
0817 super(InputTag,self).__init__()
0818 self._setValues(moduleLabel, productInstanceLabel, processName)
0819 def getModuleLabel(self) -> str:
0820 return self.__moduleLabel
0821 def setModuleLabel(self,label:str):
0822 if self.__moduleLabel != label:
0823 self.__moduleLabel = label
0824 self._isModified=True
0825 moduleLabel = property(getModuleLabel,setModuleLabel,"module label for the product")
0826 def getProductInstanceLabel(self) -> str:
0827 return self.__productInstance
0828 def setProductInstanceLabel(self,label:str):
0829 if self.__productInstance != label:
0830 self.__productInstance = label
0831 self._isModified=True
0832 productInstanceLabel = property(getProductInstanceLabel,setProductInstanceLabel,"product instance label for the product")
0833 def getProcessName(self) -> str:
0834 return self.__processName
0835 def setProcessName(self,label:str):
0836 if self.__processName != label:
0837 self.__processName = label
0838 self._isModified=True
0839 processName = property(getProcessName,setProcessName,"process name for the product")
0840 @staticmethod
0841 def skipCurrentProcess() -> str:
0842 """When used as the process name this value will make the framework skip the current process
0843 when looking backwards in time for the data product.
0844 """
0845 return "@skipCurrentProcess"
0846 @staticmethod
0847 def currentProcess() -> str:
0848 """When used as the process name this value will make the framework use the current process
0849 as the process when looking for the data product.
0850 """
0851 return "@currentProcess"
0852 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
0853 result = self.__moduleLabel
0854 if self.__productInstance != "" or self.__processName != "":
0855 result += ':' + self.__productInstance
0856 if self.__processName != "":
0857 result += ':' + self.__processName
0858 if result == "":
0859 result = '\"\"'
0860 return result;
0861 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0862 cfgValue = self.configValue(options)
0863
0864 if cfgValue == '\"\"':
0865 return cfgValue
0866 colonedValue = "\""+cfgValue+"\""
0867
0868 return colonedValue.replace(":","\",\"")
0869 @staticmethod
0870 def _isValid(value) -> builtins.bool:
0871 return True
0872 def __eq__(self,other) -> builtins.bool:
0873 return ((self.__moduleLabel,self.__productInstance,self.__processName) ==
0874 (other.moduleLabel,other.productInstanceLabel,other.processName))
0875 def __ne__(self,other) -> builtins.bool:
0876 return ((self.__moduleLabel,self.__productInstance,self.__processName) !=
0877 (other.moduleLabel,other.productInstanceLabel,other.processName))
0878 def __lt__(self,other) -> builtins.bool:
0879 return ((self.__moduleLabel,self.__productInstance,self.__processName) <
0880 (other.moduleLabel,other.productInstanceLabel,other.processName))
0881 def __gt__(self,other) -> builtins.bool:
0882 return ((self.__moduleLabel,self.__productInstance,self.__processName) >
0883 (other.moduleLabel,other.productInstanceLabel,other.processName))
0884 def __le__(self,other) -> builtins.bool:
0885 return ((self.__moduleLabel,self.__productInstance,self.__processName) <=
0886 (other.moduleLabel,other.productInstanceLabel,other.processName))
0887 def __ge__(self,other) -> builtins.bool:
0888 return ((self.__moduleLabel,self.__productInstance,self.__processName) >=
0889 (other.moduleLabel,other.productInstanceLabel,other.processName))
0890
0891
0892 def value(self) -> str:
0893 "Return the string rep"
0894 return self.configValue()
0895 @staticmethod
0896 def formatValueForConfig(value):
0897 return value.configValue()
0898 @staticmethod
0899 def _valueFromString(string:str):
0900 parts = string.split(":")
0901 return InputTag(*parts)
0902 @staticmethod
0903 def _stringFromArgument(arg):
0904 if isinstance(arg, InputTag):
0905 return arg
0906 elif isinstance(arg, str):
0907 if arg.count(":") > 2:
0908 raise RuntimeError("InputTag may have at most 3 elements")
0909 return arg
0910 else:
0911 if len(arg) > 3:
0912 raise RuntimeError("InputTag may have at most 3 elements")
0913 return ":".join(arg)
0914 def setValue(self,v):
0915 self._setValues(v)
0916 self._isModified=True
0917 def _setValues(self,moduleLabel,productInstanceLabel:str='',processName:str=''):
0918 self.__moduleLabel = InputTag._stringFromArgument(moduleLabel)
0919 self.__productInstance = productInstanceLabel
0920 self.__processName=processName
0921 if -1 != self.__moduleLabel.find(":"):
0922 toks = self.__moduleLabel.split(":")
0923 if len(toks) > 3:
0924 raise RuntimeError("InputTag may have at most 3 elements")
0925 self.__moduleLabel = toks[0]
0926 if len(toks) > 1:
0927 self.__productInstance = toks[1]
0928 if len(toks) > 2:
0929 self.__processName=toks[2]
0930
0931 def cppTag(self, parameterSet):
0932 return parameterSet.newInputTag(self.getModuleLabel(),
0933 self.getProductInstanceLabel(),
0934 self.getProcessName())
0935 def insertInto(self, parameterSet, myname:str):
0936 parameterSet.addInputTag(self.isTracked(), myname, self.cppTag(parameterSet))
0937
0938 class ESInputTag(_ParameterTypeBase):
0939 def __init__(self,module='',data= None):
0940 super(ESInputTag,self).__init__()
0941 self._setValues(module, data)
0942 def getModuleLabel(self) -> str:
0943 return self.__moduleLabel
0944 def setModuleLabel(self,label:str):
0945 if self.__moduleLabel != label:
0946 self.__moduleLabel = label
0947 self._isModified=True
0948 moduleLabel = property(getModuleLabel,setModuleLabel,"module label for the product")
0949 def getDataLabel(self):
0950 return self.__data
0951 def setDataLabel(self,label:str):
0952 if self.__data != label:
0953 self.__data = label
0954 self._isModified=True
0955 dataLabel = property(getDataLabel,setDataLabel,"data label for the product")
0956 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
0957 result = self.__moduleLabel + ':' + self.__data
0958 if result == "":
0959 result = '\"\"'
0960 return result;
0961 def pythonValue(self, options:PrintOptions=PrintOptions()) -> str:
0962 cfgValue = self.configValue(options)
0963
0964 if cfgValue == '\"\"':
0965 return cfgValue
0966 colonedValue = "\""+cfgValue+"\""
0967
0968 return colonedValue.replace(":","\",\"")
0969 @staticmethod
0970 def _isValid(value) -> builtins.bool:
0971 return True
0972 def __eq__(self,other) -> builtins.bool:
0973 return ((self.__moduleLabel,self.__data) == (other.__moduleLabel,other.__data))
0974 def __ne__(self,other) -> builtins.bool:
0975 return ((self.__moduleLabel,self.__data) != (other.__moduleLabel,other.__data))
0976 def __lt__(self,other) -> builtins.bool:
0977 return ((self.__moduleLabel,self.__data) < (other.__moduleLabel,other.__data))
0978 def __gt__(self,other) -> builtins.bool:
0979 return ((self.__moduleLabel,self.__data) > (other.__moduleLabel,other.__data))
0980 def __le__(self,other) -> builtins.bool:
0981 return ((self.__moduleLabel,self.__data) <= (other.__moduleLabel,other.__data))
0982 def __ge__(self,other) -> builtins.bool:
0983 return ((self.__moduleLabel,self.__data) >= (other.__moduleLabel,other.__data))
0984 def value(self):
0985 "Return the string rep"
0986 return self.configValue()
0987 @staticmethod
0988 def formatValueForConfig(value):
0989 return value.configValue()
0990 @staticmethod
0991 def _valueFromString(string:str):
0992 parts = string.split(":")
0993 return ESInputTag(*parts)
0994 @staticmethod
0995 def _stringFromArgument(arg, dataLabel=None):
0996 if isinstance(arg, ESInputTag):
0997 return arg
0998 elif isinstance(arg, str):
0999 if arg:
1000 cnt = arg.count(":")
1001 if dataLabel is None and cnt == 0:
1002 raise RuntimeError("ESInputTag passed one string '"+str(arg)+"' which does not contain a ':'. Please add ':' to explicitly separate the module (1st) and data (2nd) label or use two strings.")
1003 elif arg.count(":") >= 2:
1004 raise RuntimeError("an ESInputTag was passed the value'"+arg+"' which contains more than one ':'")
1005 return arg
1006 else:
1007 if len(arg) > 2 or len(arg) == 1:
1008 raise RuntimeError("ESInputTag must have either 2 or 0 elements")
1009 if len(arg) == 2:
1010 return ":".join(arg)
1011 return ":"
1012 def setValue(self,v):
1013 self._setValues(v)
1014 self._isModified=True
1015 def _setValues(self,moduleLabel='',dataLabel=None):
1016 self.__moduleLabel = ESInputTag._stringFromArgument(moduleLabel, dataLabel)
1017 self.__data = dataLabel
1018 if dataLabel is None:
1019 if self.__moduleLabel:
1020 toks = self.__moduleLabel.split(":")
1021 self.__moduleLabel = toks[0]
1022 if len(toks) > 1:
1023 self.__data = toks[1]
1024 else:
1025 self.__data = ''
1026
1027
1028
1029 def cppTag(self, parameterSet):
1030 return parameterSet.newESInputTag(self.getModuleLabel(),
1031 self.getDataLabel())
1032 def insertInto(self, parameterSet, myname:str):
1033 parameterSet.addESInputTag(self.isTracked(), myname, self.cppTag(parameterSet))
1034
1035 class FileInPath(_SimpleParameterTypeBase):
1036 def __init__(self,value:str=""):
1037 super(FileInPath,self).__init__(value)
1038 @staticmethod
1039 def _isValid(value) -> builtins.bool:
1040 return True
1041 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
1042 return string.formatValueForConfig(self.value())
1043 @staticmethod
1044 def formatValueForConfig(value):
1045 return string.formatValueForConfig(value)
1046 @staticmethod
1047 def _valueFromString(value:str):
1048 return FileInPath(value)
1049 def insertInto(self, parameterSet, myname:str):
1050 parameterSet.addNewFileInPath( self.isTracked(), myname, self.value() )
1051
1052 class SecSource(_ParameterTypeBase,_TypedParameterizable,_ConfigureComponent,_Labelable):
1053 def __init__(self,type_,*arg,**args):
1054 _ParameterTypeBase.__init__(self)
1055 _TypedParameterizable.__init__(self,type_,*arg,**args)
1056 def value(self):
1057 return self
1058 @staticmethod
1059 def _isValid(value) -> builtins.bool:
1060 return True
1061 def configTypeName(self)-> str:
1062 return "secsource"
1063 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
1064 return self.dumpConfig(options)
1065 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
1066 return _TypedParameterizable.dumpPython(self, options)
1067 def copy(self):
1068
1069 return copy.copy(self)
1070 def _place(self,name:str,proc):
1071 proc._placePSet(name,self)
1072 def __str__(self) -> str:
1073 return object.__str__(self)
1074
1075 class PSet(_ParameterTypeBase,_Parameterizable,_ConfigureComponent,_Labelable):
1076 def __init__(self,*arg,**args):
1077
1078 _ParameterTypeBase.__init__(self)
1079 _Parameterizable.__init__(self,*arg,**args)
1080 def value(self):
1081 return self
1082 def isRef_(self) -> builtins.bool:
1083 """Returns true if this PSet is actually a reference to a different PSet
1084 """
1085 return hasattr(self,"refToPSet_")
1086 @staticmethod
1087 def _isValid(value) -> builtins.bool:
1088 return isinstance(value,PSet) or isinstance(value,dict)
1089 def setValue(self,value):
1090 if isinstance(value,dict):
1091 for k,v in value.items():
1092 setattr(self,k,v)
1093
1094 def configValue(self, options:PrintOptions=PrintOptions()) -> str:
1095 config = '{ \n'
1096 for name in self.parameterNames_():
1097 param = getattr(self,name)
1098 options.indent()
1099 config+=options.indentation()+param.configTypeName()+' '+name+' = '+param.configValue(options)+'\n'
1100 options.unindent()
1101 config += options.indentation()+'}\n'
1102 return config
1103 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
1104 return self.pythonTypeName()+"(\n"+_Parameterizable.dumpPython(self, options)+options.indentation()+")"
1105
1106 def directDependencies(self):
1107 return []
1108 def clone(self, **params):
1109 myparams = self.parameters_()
1110 if "allowAnyLabel_" in params:
1111 raise AttributeError("Not allowed to change `allowAnyLabel_` value in call to clone")
1112 _modifyParametersFromDict(myparams, params, self._Parameterizable__raiseBadSetAttr)
1113 if self._Parameterizable__validator is not None:
1114 myparams["allowAnyLabel_"] = self._Parameterizable__validator
1115 returnValue = PSet(**myparams)
1116 returnValue.setIsTracked(self.isTracked())
1117 returnValue._isModified = False
1118 returnValue._isFrozen = False
1119 return returnValue
1120 def copy(self):
1121 return copy.copy(self)
1122 def _place(self,name:str,proc):
1123 proc._placePSet(name,self)
1124 def __str__(self) -> str:
1125 return object.__str__(self)
1126 def insertInto(self, parameterSet, myname:str):
1127 newpset = parameterSet.newPSet()
1128 self.insertContentsInto(newpset)
1129 parameterSet.addPSet(self.isTracked(), myname, newpset)
1130 def insertContentsInto(self, parameterSet):
1131 if self.isRef_():
1132 ref = parameterSet.getTopPSet_(self.refToPSet_.value())
1133 ref.insertContentsInto(parameterSet)
1134 else:
1135 super(PSet, self).insertContentsInto(parameterSet)
1136
1137
1138 class vint32(_ValidatingParameterListBase):
1139 def __init__(self,*arg,**args):
1140 super(vint32,self).__init__(*arg,**args)
1141
1142 @classmethod
1143 def _itemIsValid(cls,item) -> builtins.bool:
1144 return int32._isValid(item)
1145 @staticmethod
1146 def _valueFromString(value:str):
1147 return vint32(*_ValidatingParameterListBase._itemsFromStrings(value,int32._valueFromString))
1148 def insertInto(self, parameterSet, myname:str):
1149 parameterSet.addVInt32(self.isTracked(), myname, self.value())
1150
1151
1152
1153 class vuint32(_ValidatingParameterListBase):
1154 def __init__(self,*arg,**args):
1155 super(vuint32,self).__init__(*arg,**args)
1156 @classmethod
1157 def _itemIsValid(cls,item) -> builtins.bool:
1158 return uint32._isValid(item)
1159 @staticmethod
1160 def _valueFromString(value:str):
1161 return vuint32(*_ValidatingParameterListBase._itemsFromStrings(value,uint32._valueFromString))
1162 def insertInto(self, parameterSet, myname:str):
1163 parameterSet.addVUInt32(self.isTracked(), myname, self.value())
1164
1165
1166
1167 class vint64(_ValidatingParameterListBase):
1168 def __init__(self,*arg,**args):
1169 super(vint64,self).__init__(*arg,**args)
1170 @classmethod
1171 def _itemIsValid(cls,item) -> builtins.bool:
1172 return int64._isValid(item)
1173 @staticmethod
1174 def _valueFromString(value:str):
1175 return vint64(*_ValidatingParameterListBase._itemsFromStrings(value,int64._valueFromString))
1176 def insertInto(self, parameterSet, myname):
1177 parameterSet.addVInt64(self.isTracked(), myname, self.value())
1178
1179
1180
1181 class vuint64(_ValidatingParameterListBase):
1182 def __init__(self,*arg,**args):
1183 super(vuint64,self).__init__(*arg,**args)
1184 @classmethod
1185 def _itemIsValid(cls,item) -> builtins.bool:
1186 return uint64._isValid(item)
1187 @staticmethod
1188 def _valueFromString(value:str):
1189 return vuint64(*_ValidatingParameterListBase._itemsFromStrings(value,vuint64._valueFromString))
1190 def insertInto(self, parameterSet, myname:str):
1191 parameterSet.addVUInt64(self.isTracked(), myname, self.value())
1192
1193
1194
1195 class vdouble(_ValidatingParameterListBase):
1196 def __init__(self,*arg,**args):
1197 super(vdouble,self).__init__(*arg,**args)
1198 @classmethod
1199 def _itemIsValid(cls,item) -> builtins.bool:
1200 return double._isValid(item)
1201 @staticmethod
1202 def _valueFromString(value:str):
1203 return vdouble(*_ValidatingParameterListBase._itemsFromStrings(value,double._valueFromString))
1204 def insertInto(self, parameterSet, myname:str):
1205 parameterSet.addVDouble(self.isTracked(), myname, self.value())
1206 def pythonValueForItem(self,item, options) -> str:
1207 return double._pythonValue(item)
1208
1209
1210
1211
1212 class vbool(_ValidatingParameterListBase):
1213 def __init__(self,*arg,**args):
1214 super(vbool,self).__init__(*arg,**args)
1215 @classmethod
1216 def _itemIsValid(cls,item) -> builtins.bool:
1217 return bool._isValid(item)
1218 @staticmethod
1219 def _valueFromString(value:str):
1220 return vbool(*_ValidatingParameterListBase._itemsFromStrings(value,bool._valueFromString))
1221 def insertInto(self, parameterSet, myname:str):
1222 parameterSet.addVBool(self.isTracked(), myname, self.value())
1223
1224
1225
1226 class vstring(_ValidatingParameterListBase):
1227 def __init__(self,*arg,**args):
1228 super(vstring,self).__init__(*arg,**args)
1229 self._nPerLine = 1
1230 @classmethod
1231 def _itemIsValid(cls,item) -> builtins.bool:
1232 return string._isValid(item)
1233 def configValueForItem(self,item,options) -> str:
1234 return string.formatValueForConfig(item)
1235 @staticmethod
1236 def _valueFromString(value:str):
1237 return vstring(*_ValidatingParameterListBase._itemsFromStrings(value,string._valueFromString))
1238 def insertInto(self, parameterSet, myname:str):
1239 parameterSet.addVString(self.isTracked(), myname, self.value())
1240
1241 class VLuminosityBlockID(_ValidatingParameterListBase):
1242 def __init__(self,*arg,**args):
1243 super(VLuminosityBlockID,self).__init__(*arg,**args)
1244 @classmethod
1245 def _itemIsValid(cls,item):
1246 return LuminosityBlockID._isValid(item)
1247 def configValueForItem(self,item,options:PrintOptions) -> str:
1248 return LuminosityBlockID.formatValueForConfig(item)
1249 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1250 if isinstance(item,str):
1251 return '"'+item+'"'
1252 elif isinstance(item, _Parameterizable):
1253 return item.dumpPython(options)
1254 return str(item)
1255 @staticmethod
1256 def _valueFromString(value:str):
1257 return VLuminosityBlockID(*_ValidatingParameterListBase._itemsFromStrings(value,LuminosityBlockID._valueFromString))
1258 def insertInto(self, parameterSet, myname:str):
1259 cppIDs = list()
1260 for i in self:
1261 item = i
1262 if isinstance(item, str):
1263 item = LuminosityBlockID._valueFromString(item)
1264 cppIDs.append(item.cppID(parameterSet))
1265 parameterSet.addVLuminosityBlockID(self.isTracked(), myname, cppIDs)
1266
1267
1268 class VInputTag(_ValidatingParameterListBase):
1269 def __init__(self,*arg,**args):
1270 if len(arg) == 1 and not isinstance(arg[0], str):
1271 try:
1272 arg = iter(arg[0])
1273 except TypeError:
1274 pass
1275 super(VInputTag,self).__init__((InputTag._stringFromArgument(x) for x in arg),**args)
1276 @classmethod
1277 def _itemIsValid(cls,item) -> builtins.bool:
1278 return InputTag._isValid(item)
1279 def configValueForItem(self,item,options:PrintOptions) -> str:
1280
1281 if isinstance(item, str):
1282 return '"'+item+'"'
1283 else:
1284 return InputTag.formatValueForConfig(item)
1285 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1286
1287 if isinstance(item, str):
1288 return '"'+item+'"'
1289 else:
1290 return item.dumpPython(options)
1291 @staticmethod
1292 def _valueFromString(value:str):
1293 return VInputTag(*_ValidatingParameterListBase._itemsFromStrings(value,InputTag._valueFromString))
1294 def _itemFromArgument(self, x):
1295 return InputTag._stringFromArgument(x)
1296 def insertInto(self, parameterSet, myname:str):
1297 cppTags = list()
1298 for i in self:
1299 item = i
1300 if isinstance(item, str):
1301 item = InputTag(i)
1302 cppTags.append(item.cppTag(parameterSet))
1303 parameterSet.addVInputTag(self.isTracked(), myname, cppTags)
1304
1305 class VESInputTag(_ValidatingParameterListBase):
1306 def __init__(self,*arg,**args):
1307 if len(arg) == 1 and not isinstance(arg[0], str):
1308 try:
1309 arg = iter(arg[0])
1310 except TypeError:
1311 pass
1312 super(VESInputTag,self).__init__((ESInputTag._stringFromArgument(x) for x in arg),**args)
1313 @classmethod
1314 def _itemIsValid(cls,item) -> builtins.bool:
1315 return ESInputTag._isValid(item)
1316 def configValueForItem(self,item,options:PrintOptions) -> str:
1317
1318 if isinstance(item, str):
1319 return '"'+item+'"'
1320 else:
1321 return ESInputTag.formatValueForConfig(item)
1322 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1323
1324 if isinstance(item, str):
1325 return '"'+item+'"'
1326 else:
1327 return item.dumpPython(options)
1328 @staticmethod
1329 def _valueFromString(value:str):
1330 return VESInputTag(*_ValidatingParameterListBase._itemsFromStrings(value,ESInputTag._valueFromString))
1331 def _itemFromArgument(self, x) -> str:
1332 return ESInputTag._stringFromArgument(x)
1333 def insertInto(self, parameterSet, myname:str):
1334 cppTags = list()
1335 for i in self:
1336 item = i
1337 if isinstance(item, str):
1338 item = ESInputTag(i)
1339 cppTags.append(item.cppTag(parameterSet))
1340 parameterSet.addVESInputTag(self.isTracked(), myname, cppTags)
1341
1342 class VEventID(_ValidatingParameterListBase):
1343 def __init__(self,*arg,**args):
1344 super(VEventID,self).__init__(*arg,**args)
1345 @classmethod
1346 def _itemIsValid(cls,item):
1347 return EventID._isValid(item)
1348 def configValueForItem(self,item,options:PrintOptions) -> str:
1349 return EventID.formatValueForConfig(item)
1350 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1351
1352 if isinstance(item, str):
1353 return '"'+item+'"'
1354 else:
1355 return item.dumpPython(options)
1356 @staticmethod
1357 def _valueFromString(value:str):
1358 return VEventID(*_ValidatingParameterListBase._itemsFromStrings(value,EventID._valueFromString))
1359 def insertInto(self, parameterSet, myname:str):
1360 cppIDs = list()
1361 for i in self:
1362 item = i
1363 if isinstance(item, str):
1364 item = EventID._valueFromString(item)
1365 cppIDs.append(item.cppID(parameterSet))
1366 parameterSet.addVEventID(self.isTracked(), myname, cppIDs)
1367
1368
1369 class VLuminosityBlockRange(_ValidatingParameterListBase):
1370 def __init__(self,*arg,**args):
1371 super(VLuminosityBlockRange,self).__init__(*arg,**args)
1372 @classmethod
1373 def _itemIsValid(cls,item) -> builtins.bool:
1374 return LuminosityBlockRange._isValid(item)
1375 def configValueForItem(self,item,options:PrintOptions) -> str:
1376 return LuminosityBlockRange.formatValueForConfig(item)
1377 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1378 if isinstance(item, str):
1379 return '"'+item+'"'
1380 elif isinstance(item, _Parameterizable):
1381 return item.dumpPython(options)
1382 return str(item)
1383 @staticmethod
1384 def _valueFromString(value:str):
1385 return VLuminosityBlockRange(*_ValidatingParameterListBase._itemsFromStrings(value,LuminosityBlockRange._valueFromString))
1386 def insertInto(self, parameterSet, myname:str):
1387 cppIDs = list()
1388 for i in self:
1389 item = i
1390 if isinstance(item, str):
1391 item = LuminosityBlockRange._valueFromString(item)
1392 cppIDs.append(item.cppID(parameterSet))
1393 parameterSet.addVLuminosityBlockRange(self.isTracked(), myname, cppIDs)
1394
1395
1396 class VEventRange(_ValidatingParameterListBase):
1397 def __init__(self,*arg,**args):
1398 super(VEventRange,self).__init__(*arg,**args)
1399 @classmethod
1400 def _itemIsValid(cls,item) -> builtins.bool:
1401 return EventRange._isValid(item)
1402 def configValueForItem(self,item,options:PrintOptions) -> str:
1403 return EventRange.formatValueForConfig(item)
1404 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1405 if isinstance(item, str):
1406 return '"'+item+'"'
1407 elif isinstance(item, _Parameterizable):
1408 return item.dumpPython(options)
1409 return str(item)
1410 @staticmethod
1411 def _valueFromString(value:str):
1412 return VEventRange(*_ValidatingParameterListBase._itemsFromStrings(value,EventRange._valueFromString))
1413 def insertInto(self, parameterSet, myname:str):
1414 cppIDs = list()
1415 for i in self:
1416 item = i
1417 if isinstance(item, str):
1418 item = EventRange._valueFromString(item)
1419 cppIDs.append(item.cppID(parameterSet))
1420 parameterSet.addVEventRange(self.isTracked(), myname, cppIDs)
1421
1422
1423 class VPSet(_ValidatingParameterListBase,_ConfigureComponent,_Labelable):
1424 def __init__(self,*arg, **args):
1425 """Takes a group of PSets plus an optional named argument `template` of type PSetTemplate.
1426 `template` is used to convert a `dict` passed to the VPSet to a `PSet` via the PSetTemplate."""
1427 _template = None
1428 if "template" in args:
1429 _template = args["template"]
1430 del args["template"]
1431 if not isinstance(_template, _PSetTemplate):
1432 raise TypeError("type of template is not PSetTemplate")
1433 self._template = _template
1434 self._nPerLine = 1
1435 if _template:
1436
1437 if len(arg) == 1 and not isinstance(arg[0], dict):
1438 try:
1439 arg = iter(arg[0])
1440 except TypeError:
1441 pass
1442 super(VPSet,self).__init__((self._itemFromArgument(x) for x in arg), **args)
1443 else:
1444 super(VPSet,self).__init__(*arg, **args)
1445 @classmethod
1446 def _itemIsValid(cls,item) -> builtins.bool:
1447 return (isinstance(item, PSet) and PSet._isValid(item)) or (isinstance(item,dict))
1448 def _itemFromArgument(self, x):
1449
1450
1451 if not isinstance(x, PSet) and hasattr(self, "_template") and self._template is not None:
1452 return self._template(x)
1453 else:
1454 return super()._itemFromArgument(x)
1455 def configValueForItem(self,item, options:PrintOptions) -> str:
1456 return PSet.configValue(item, options)
1457 def pythonValueForItem(self,item, options:PrintOptions) -> str:
1458 return PSet.dumpPython(item,options)
1459 def template(self):
1460 return self._template
1461 def copy(self):
1462 return copy.copy(self)
1463 def _additionalInitArguments(self, options):
1464 if self._template and not self._template._isEmpty():
1465
1466 return 'template = cms.'+self._template.dumpPython(options)
1467 return None
1468 def _place(self,name:str,proc):
1469 proc._placeVPSet(name,self)
1470 def insertInto(self, parameterSet, myname:str):
1471
1472 parametersets = list()
1473 for pset in self:
1474 newparameterset = parameterSet.newPSet()
1475 pset.insertContentsInto(newparameterset)
1476 parametersets.append(newparameterset)
1477 parameterSet.addVPSet(self.isTracked(), myname, parametersets)
1478
1479 def directDependencies(self):
1480 return []
1481 def __repr__(self) -> str:
1482 return self.dumpPython()
1483
1484 def makeCppPSet(module,cppPSetMaker):
1485 """Extracts all PSets from the module and makes C++ equivalent
1486 """
1487
1488 if not isinstance(module,dict):
1489 module = dict( ( (x,getattr(module,x)) for x in dir(module)) )
1490
1491 for x,p in module.items():
1492 if isinstance(p,PSet):
1493 p.insertInto(cppPSetMaker,x)
1494 return cppPSetMaker
1495
1496 class _ConvertToPSet(object):
1497 def __init__(self):
1498 self.pset = PSet()
1499 def addInt32(self,tracked:bool,label:str,value):
1500 v = int32(value)
1501 v.setIsTracked(tracked)
1502 setattr(self.pset,label,v)
1503 def addUInt32(self,tracked:bool,label:str,value):
1504 v = uint32(value)
1505 v.setIsTracked(tracked)
1506 setattr(self.pset,label,v)
1507 def addInt64(self,tracked:bool,label:str,value):
1508 v = int64(value)
1509 v.setIsTracked(tracked)
1510 setattr(self.pset,label,v)
1511 def addUInt64(self,tracked:bool,label:str,value):
1512 v = uint64(value)
1513 v.setIsTracked(tracked)
1514 setattr(self.pset,label,v)
1515 def addBool(self,tracked:bool,label:str,value):
1516 v = bool(value)
1517 v.setIsTracked(tracked)
1518 setattr(self.pset,label,v)
1519 def addDouble(self,tracked:bool,label:str,value):
1520 v = double(value)
1521 v.setIsTracked(tracked)
1522 setattr(self.pset,label,v)
1523 def addString(self,tracked:bool,label:str,value):
1524 v = string(value)
1525 v.setIsTracked(tracked)
1526 setattr(self.pset,label,v)
1527 def addInputTag(self,tracked:bool,label:str,value):
1528 v = copy.deepcopy(value)
1529 v.setIsTracked(tracked)
1530 setattr(self.pset,label,v)
1531 def addESInputTag(self,tracked:bool,label:str,value):
1532 v = copy.deepcopy(value)
1533 v.setIsTracked(tracked)
1534 setattr(self.pset,label,v)
1535 def addEventID(self,tracked:bool,label:str,value):
1536 v = copy.deepcopy(value)
1537 v.setIsTracked(tracked)
1538 setattr(self.pset,label,v)
1539 def addEventRange(self,tracked:bool,label:str,value):
1540 v = copy.deepcopy(value)
1541 v.setIsTracked(tracked)
1542 setattr(self.pset,label,v)
1543 def addLuminosityBlockID(self,tracked:bool,label:str,value):
1544 v = copy.deepcopy(value)
1545 v.setIsTracked(tracked)
1546 setattr(self.pset,label,v)
1547 def addLuminosityBlockRange(self,tracked:bool,label:str,value):
1548 v = copy.deepcopy(value)
1549 v.setIsTracked(tracked)
1550 setattr(self.pset,label,v)
1551 def addVInt32(self,tracked:bool,label:str,value):
1552 v = vint32(value)
1553 v.setIsTracked(tracked)
1554 setattr(self.pset,label,v)
1555 def addVUInt32(self,tracked:bool,label:str,value):
1556 v = vuint32(value)
1557 v.setIsTracked(tracked)
1558 setattr(self.pset,label,v)
1559 def addVInt64(self,tracked:bool,label:str,value):
1560 v = vint64(value)
1561 v.setIsTracked(tracked)
1562 setattr(self.pset,label,v)
1563 def addVUInt64(self,tracked:bool,label:str,value):
1564 v = vuint64(value)
1565 v.setIsTracked(tracked)
1566 setattr(self.pset,label,v)
1567 def addVBool(self,tracked:bool,label:str,value):
1568 v = vbool(value)
1569 v.setIsTracked(tracked)
1570 setattr(self.pset,label,v)
1571 def addVDouble(self,tracked:bool,label:str,value):
1572 v = vdouble(value)
1573 v.setIsTracked(tracked)
1574 setattr(self.pset,label,v)
1575 def addVString(self,tracked:bool,label:str,value):
1576 v = vstring(value)
1577 v.setIsTracked(tracked)
1578 setattr(self.pset,label,v)
1579 def addVInputTag(self,tracked:bool,label:str,value):
1580 v = VInputTag(value)
1581 v.setIsTracked(tracked)
1582 setattr(self.pset,label,v)
1583 def addVESInputTag(self,tracked:bool,label:str,value):
1584 v = VESInputTag(value)
1585 v.setIsTracked(tracked)
1586 setattr(self.pset,label,v)
1587 def addVEventID(self,tracked:bool,label:str,value):
1588 v = VEventID(value)
1589 v.setIsTracked(tracked)
1590 setattr(self.pset,label,v)
1591 def addVEventRange(self,tracked:bool,label:str,value):
1592 v = VEventRange(value)
1593 v.setIsTracked(tracked)
1594 setattr(self.pset,label,v)
1595 def addVLuminosityBlockID(self,tracked:bool,label:str,value):
1596 v = VLuminosityBlockID(value)
1597 v.setIsTracked(tracked)
1598 setattr(self.pset,label,v)
1599 def addVLuminosityBlockRange(self,tracked:bool,label:str,value):
1600 v = VLuminosityBlockRange(value)
1601 v.setIsTracked(tracked)
1602 setattr(self.pset,label,v)
1603 def addNewFileInPath(self,tracked:bool,label:str,value):
1604 v = FileInPath(value)
1605 v.setIsTracked(tracked)
1606 setattr(self.pset,label,v)
1607 def newInputTag(self, label, instance, process):
1608 return InputTag(label,instance,process)
1609 def newESInputTag(self,moduleLabel,dataLabel):
1610 return ESInputTag(moduleLabel,dataLabel)
1611 def newEventID(self,r,l,e):
1612 return EventID(r,l,e)
1613 def newLuminosityBlockID(self,r,l):
1614 return LuminosityBlockID(r,l)
1615 def newEventRange(self,r,l,e,r2,l2,e2):
1616 return EventRange(r,l,e,r2,l2,e2)
1617 def newLuminosityBlockRange(self,r,l,r2,l2):
1618 return LuminosityBlockRange(r,l,r2,l2)
1619 def newPSet(self):
1620 return _ConvertToPSet()
1621 def addPSet(self,tracked,label,value):
1622
1623
1624 value.pset.setIsTracked(tracked)
1625 setattr(self.pset,label,value.pset)
1626 def addVPSet(self,tracked,label,value):
1627
1628 v = VPSet()
1629 v.extend([x.pset for x in value])
1630 v.setIsTracked(tracked)
1631 setattr(self.pset,label,v)
1632
1633 def convertToPSet(name:str,module):
1634 convert = _ConvertToPSet()
1635 module.insertInto(convert,name)
1636 return getattr(convert.pset,name)
1637
1638 def convertToVPSet( **kw ):
1639 returnValue = VPSet()
1640 for name,module in kw.items():
1641 returnValue.append(convertToPSet(name,module))
1642 return returnValue
1643
1644
1645 class EDAlias(_ConfigureComponent,_Labelable,_Parameterizable):
1646 def __init__(self,*arg,**kargs):
1647 super(EDAlias,self).__init__(**kargs)
1648
1649 @staticmethod
1650 def allProducts():
1651 """A helper to specify that all products of a module are to be aliased for. Example usage:
1652 process.someAlias = cms.EDAlias(
1653 aliasForModuleLabel = cms.EDAlias.allProducts()
1654 )
1655 """
1656 return VPSet(PSet(type = string('*')))
1657
1658 def clone(self, *args, **params):
1659 returnValue = EDAlias.__new__(type(self))
1660 myparams = self.parameters_()
1661 if len(myparams) == 0 and len(params) and len(args):
1662 args.append(None)
1663
1664 _modifyParametersFromDict(myparams, params, self._Parameterizable__raiseBadSetAttr)
1665
1666 returnValue.__init__(*args, **myparams)
1667 saveOrigin(returnValue, 1)
1668 return returnValue
1669
1670 def _place(self,name:str,proc):
1671 proc._placeAlias(name,self)
1672
1673 def nameInProcessDesc_(self, myname:str):
1674 return myname;
1675
1676 def appendToProcessDescList_(self, lst, myname:str):
1677 lst.append(self.nameInProcessDesc_(myname))
1678
1679 def insertInto(self, parameterSet, myname:str):
1680 newpset = parameterSet.newPSet()
1681 newpset.addString(True, "@module_label", myname)
1682 newpset.addString(True, "@module_type", type(self).__name__)
1683 newpset.addString(True, "@module_edm_type", type(self).__name__)
1684 for name in self.parameterNames_():
1685 param = getattr(self,name)
1686 param.insertInto(newpset, name)
1687 parameterSet.addPSet(True, self.nameInProcessDesc_(myname), newpset)
1688
1689 def dumpPython(self, options:PrintOptions=PrintOptions()) -> str:
1690 specialImportRegistry.registerUse(self)
1691 resultList = ['cms.EDAlias(']
1692 separator = ""
1693 for name in self.parameterNames_():
1694 resultList[-1] = resultList[-1] + separator
1695 separator=","
1696 param = self.__dict__[name]
1697 options.indent()
1698 resultList.append(options.indentation()+name+' = '+param.dumpPython(options))
1699 options.unindent()
1700 return '\n'.join(resultList) + '\n' + options.indentation() + ')'
1701
1702
1703 def directDependencies(self):
1704 return []
1705
1706 if __name__ == "__main__":
1707
1708 import unittest
1709 class PSetTester(object):
1710 def addEventID(self,*pargs,**kargs):
1711 pass
1712 def newEventID(self,*pargs,**kargs):
1713 pass
1714 def addVEventID(self,*pargs,**kargs):
1715 pass
1716 def newLuminosityBlockID(self,*pargs,**kargs):
1717 pass
1718 def addLuminosityBlockID(self,*pargs,**kargs):
1719 pass
1720 def addVLuminosityBlockID(self,*pargs,**kargs):
1721 pass
1722 def addEventRange(self,*pargs,**kargs):
1723 pass
1724 def newEventRange(self,*pargs,**kargs):
1725 pass
1726 def addVEventRange(self,*pargs,**kargs):
1727 pass
1728 def newVEventRange(self,*pargs,**kargs):
1729 pass
1730 def addLuminosityBlockRange(self,*pargs,**kargs):
1731 pass
1732 def newLuminosityBlockRange(self,*pargs,**kargs):
1733 pass
1734 def addVLuminosityBlockRange(self,*pargs,**kargs):
1735 pass
1736 def newVLuminosityBlockRange(self,*pargs,**kargs):
1737 pass
1738 class testTypes(unittest.TestCase):
1739 def testint32(self):
1740 i = int32(1)
1741 self.assertEqual(i.value(),1)
1742 self.assertTrue(i)
1743 self.assertRaises(ValueError,int32,"i")
1744 i = int32._valueFromString("0xA")
1745 self.assertEqual(i.value(),10)
1746 self.assertTrue(not int32(0))
1747
1748 def testuint32(self):
1749 i = uint32(1)
1750 self.assertEqual(i.value(),1)
1751 self.assertTrue(i)
1752 i = uint32(0)
1753 self.assertEqual(i.value(),0)
1754 self.assertTrue(not i)
1755 self.assertRaises(ValueError,uint32,"i")
1756 self.assertRaises(ValueError,uint32,-1)
1757 i = uint32._valueFromString("0xA")
1758 self.assertEqual(i.value(),10)
1759
1760 def testdouble(self):
1761 d = double(1)
1762 self.assertEqual(d.value(),1)
1763 self.assertEqual(d.pythonValue(),'1')
1764 d = double(float('Inf'))
1765 self.assertEqual(d,float('Inf'))
1766 self.assertEqual(d.pythonValue(),"float('inf')")
1767 d = double(-float('Inf'))
1768 self.assertEqual(d,-float('Inf'))
1769 self.assertEqual(d.pythonValue(),"-float('inf')")
1770 d = double(float('Nan'))
1771 self.assertTrue(math.isnan(d.value()))
1772 self.assertEqual(d.pythonValue(),"float('nan')")
1773 def testvdouble(self):
1774 d = vdouble(1)
1775 self.assertEqual(d.value(),[1])
1776 self.assertEqual(d.dumpPython(),'cms.vdouble(1)')
1777 d = vdouble(float('inf'))
1778 self.assertEqual(d,[float('inf')])
1779 self.assertEqual(d.dumpPython(),"cms.vdouble(float('inf'))")
1780 d = vdouble(-float('Inf'))
1781 self.assertEqual(d,[-float('inf')])
1782 self.assertEqual(d.dumpPython(),"cms.vdouble(-float('inf'))")
1783 d = vdouble(float('nan'))
1784 self.assertTrue(math.isnan(d[0]))
1785 self.assertEqual(d.dumpPython(),"cms.vdouble(float('nan'))")
1786 def testvint32(self):
1787 v = vint32()
1788 self.assertEqual(len(v),0)
1789 self.assertTrue(not v)
1790 v.append(1)
1791 self.assertEqual(len(v),1)
1792 self.assertEqual(v[0],1)
1793 self.assertTrue(v)
1794 v.append(2)
1795 v.insert(1,3)
1796 self.assertEqual(v[1],3)
1797 v[1]=4
1798 self.assertEqual(v[1],4)
1799 v[1:1]=[5]
1800 self.assertEqual(len(v),4)
1801 self.assertEqual([1,5,4,2],list(v))
1802 self.assertEqual(repr(v), "cms.vint32(1, 5, 4, 2)")
1803 self.assertRaises(TypeError,v.append,('blah'))
1804 def testbool(self):
1805 b = bool(True)
1806 self.assertEqual(b.value(),True)
1807 self.assertTrue(b)
1808 b = bool(False)
1809 self.assertEqual(b.value(),False)
1810 self.assertTrue(not b)
1811 b = bool._valueFromString("2")
1812 self.assertEqual(b.value(),True)
1813 self.assertEqual(repr(b), "cms.bool(True)")
1814 self.assertRaises(ValueError, lambda: bool("False"))
1815 def testString(self):
1816 s=string('this is a test')
1817 self.assertEqual(s.value(),'this is a test')
1818 self.assertEqual(repr(s), "cms.string(\'this is a test\')")
1819 self.assertTrue(s)
1820 s=string('\0')
1821 self.assertEqual(s.value(),'\0')
1822 self.assertEqual(s.configValue(),"'\\0'")
1823 s2=string('')
1824 self.assertEqual(s2.value(),'')
1825 self.assertTrue(not s2)
1826 def testvstring(self):
1827 a = vstring("", "Barack", "John", "Sarah", "Joe")
1828 self.assertEqual(len(a), 5)
1829 self.assertEqual(a[0], "")
1830 self.assertEqual(a[3], "Sarah")
1831 self.assertEqual(a.dumpPython(), "cms.vstring(\n '',\n 'Barack',\n 'John',\n 'Sarah',\n 'Joe'\n)")
1832 ps = PSet(v = vstring('a', 'b'))
1833 ps.v = ['loose']
1834 def testUntracked(self):
1835 p=untracked(int32(1))
1836 self.assertRaises(TypeError,untracked,(1),{})
1837 self.assertFalse(p.isTracked())
1838 p=untracked.int32(1)
1839 self.assertEqual(repr(p), "cms.untracked.int32(1)")
1840 self.assertRaises(TypeError,untracked,(1),{})
1841 self.assertFalse(p.isTracked())
1842 p=untracked.vint32(1,5,3)
1843 self.assertRaises(TypeError,untracked,(1,5,3),{})
1844 self.assertFalse(p.isTracked())
1845 p = untracked.PSet(b=int32(1))
1846 self.assertFalse(p.isTracked())
1847 self.assertEqual(p.b.value(),1)
1848 def testInputTag(self):
1849 it = InputTag._valueFromString("label::proc")
1850 self.assertEqual(it.getModuleLabel(), "label")
1851 self.assertEqual(it.getProductInstanceLabel(), "")
1852 self.assertEqual(it.getProcessName(), "proc")
1853
1854
1855 it=InputTag('label',processName='proc')
1856 self.assertEqual(it.getModuleLabel(), "label")
1857 self.assertEqual(it.getProductInstanceLabel(), "")
1858 self.assertEqual(it.getProcessName(), "proc")
1859 self.assertEqual(repr(it), "cms.InputTag(\"label\",\"\",\"proc\")")
1860 vit = VInputTag(InputTag("label1"), InputTag("label2"))
1861 self.assertEqual(repr(vit), "cms.VInputTag(cms.InputTag(\"label1\"), cms.InputTag(\"label2\"))")
1862 vit = VInputTag("label1", "label2:label3")
1863 self.assertEqual(repr(vit), "cms.VInputTag(\"label1\", \"label2:label3\")")
1864 vit = VInputTag("label1", "label2", "label3")
1865 self.assertEqual(repr(vit), "cms.VInputTag(\"label1\", \"label2\", \"label3\")")
1866 vit = VInputTag(["label1", "label2", "label3"])
1867 self.assertEqual(repr(vit), "cms.VInputTag(\"label1\", \"label2\", \"label3\")")
1868 it=InputTag('label',processName=InputTag.skipCurrentProcess())
1869 self.assertEqual(it.getModuleLabel(), "label")
1870 self.assertEqual(it.getProductInstanceLabel(), "")
1871 self.assertEqual(it.getProcessName(), "@skipCurrentProcess")
1872 it=InputTag('label','x',InputTag.skipCurrentProcess())
1873 self.assertEqual(it.getModuleLabel(), "label")
1874 self.assertEqual(it.getProductInstanceLabel(), "x")
1875 self.assertEqual(it.getProcessName(), "@skipCurrentProcess")
1876 it = InputTag("label:in:@skipCurrentProcess")
1877 self.assertEqual(it.getModuleLabel(), "label")
1878 self.assertEqual(it.getProductInstanceLabel(), "in")
1879 self.assertEqual(it.getProcessName(), "@skipCurrentProcess")
1880 with self.assertRaises(RuntimeError):
1881 it = InputTag("label:too:many:elements")
1882 with self.assertRaises(RuntimeError):
1883 vit = VInputTag("label:too:many:elements")
1884
1885 pset = PSet(it = InputTag("something"))
1886
1887 pset.it = "label"
1888 self.assertEqual(pset.it.getModuleLabel(), "label")
1889 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1890 self.assertEqual(pset.it.getProcessName(), "")
1891 pset.it = "label:in"
1892 self.assertEqual(pset.it.getModuleLabel(), "label")
1893 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1894 self.assertEqual(pset.it.getProcessName(), "")
1895 pset.it = "label:in:proc"
1896 self.assertEqual(pset.it.getModuleLabel(), "label")
1897 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1898 self.assertEqual(pset.it.getProcessName(), "proc")
1899 pset.it = "label::proc"
1900 self.assertEqual(pset.it.getModuleLabel(), "label")
1901 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1902 self.assertEqual(pset.it.getProcessName(), "proc")
1903 with self.assertRaises(RuntimeError):
1904 pset.it = "label:too:many:elements"
1905
1906 pset.it = ()
1907 self.assertEqual(pset.it.getModuleLabel(), "")
1908 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1909 self.assertEqual(pset.it.getProcessName(), "")
1910 pset.it = ("label",)
1911 self.assertEqual(pset.it.getModuleLabel(), "label")
1912 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1913 self.assertEqual(pset.it.getProcessName(), "")
1914 pset.it = ("label", "in")
1915 self.assertEqual(pset.it.getModuleLabel(), "label")
1916 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1917 self.assertEqual(pset.it.getProcessName(), "")
1918 pset.it = ("label", "in", "proc")
1919 self.assertEqual(pset.it.getModuleLabel(), "label")
1920 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1921 self.assertEqual(pset.it.getProcessName(), "proc")
1922 pset.it = ("label", "", "proc")
1923 self.assertEqual(pset.it.getModuleLabel(), "label")
1924 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1925 self.assertEqual(pset.it.getProcessName(), "proc")
1926 with self.assertRaises(RuntimeError):
1927 pset.it = ("label", "too", "many", "elements")
1928
1929 pset.it = []
1930 self.assertEqual(pset.it.getModuleLabel(), "")
1931 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1932 self.assertEqual(pset.it.getProcessName(), "")
1933 pset.it = ["label"]
1934 self.assertEqual(pset.it.getModuleLabel(), "label")
1935 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1936 self.assertEqual(pset.it.getProcessName(), "")
1937 pset.it = ["label", "in"]
1938 self.assertEqual(pset.it.getModuleLabel(), "label")
1939 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1940 self.assertEqual(pset.it.getProcessName(), "")
1941 pset.it = ["label", "in", "proc"]
1942 self.assertEqual(pset.it.getModuleLabel(), "label")
1943 self.assertEqual(pset.it.getProductInstanceLabel(), "in")
1944 self.assertEqual(pset.it.getProcessName(), "proc")
1945 pset.it = ["label", "", "proc"]
1946 self.assertEqual(pset.it.getModuleLabel(), "label")
1947 self.assertEqual(pset.it.getProductInstanceLabel(), "")
1948 self.assertEqual(pset.it.getProcessName(), "proc")
1949 with self.assertRaises(RuntimeError):
1950 pset.it = ["label", "too", "many", "elements"]
1951
1952 vit = VInputTag(("a2",), ("b2", "i"), ("c2", "i", "p"))
1953 self.assertEqual(repr(vit), "cms.VInputTag(\"a2\", \"b2:i\", \"c2:i:p\")")
1954
1955 pset = PSet(vit = VInputTag())
1956 pset.vit = ["a", "b:i", "c:i:p"]
1957 self.assertEqual(repr(pset.vit), "cms.VInputTag(\"a\", \"b:i\", \"c:i:p\")")
1958 pset.vit = [("a2",), ("b2", "i"), ("c2", "i", "p")]
1959 self.assertEqual(repr(pset.vit), "cms.VInputTag(\"a2\", \"b2:i\", \"c2:i:p\")")
1960 pset.vit = [["a3"], ["b3", "i"], ["c3", "i", "p"]]
1961 self.assertEqual(repr(pset.vit), "cms.VInputTag(\"a3\", \"b3:i\", \"c3:i:p\")")
1962 with self.assertRaises(RuntimeError):
1963 pset.vit = [("label", "too", "many", "elements")]
1964 def testInputTagModified(self):
1965 a=InputTag("a")
1966 self.assertEqual(a.isModified(),False)
1967 a.setModuleLabel("a")
1968 self.assertEqual(a.isModified(),False)
1969 a.setModuleLabel("b")
1970 self.assertEqual(a.isModified(),True)
1971 a.resetModified()
1972 a.setProductInstanceLabel("b")
1973 self.assertEqual(a.isModified(),True)
1974 a.resetModified()
1975 a.setProcessName("b")
1976 self.assertEqual(a.isModified(),True)
1977 a.resetModified()
1978 a.setValue("b")
1979 self.assertEqual(a.isModified(),True)
1980 def testESInputTag(self):
1981 it = ESInputTag._valueFromString("label:data")
1982 self.assertEqual(it.getModuleLabel(), "label")
1983 self.assertEqual(it.getDataLabel(), "data")
1984
1985
1986 it=ESInputTag(data='data')
1987 self.assertEqual(it.getModuleLabel(), "")
1988 self.assertEqual(it.getDataLabel(), "data")
1989 self.assertEqual(repr(it), "cms.ESInputTag(\"\",\"data\")")
1990 vit = VESInputTag(ESInputTag("label1:"), ESInputTag("label2:"))
1991 self.assertEqual(repr(vit), 'cms.VESInputTag(cms.ESInputTag("label1",""), cms.ESInputTag("label2",""))')
1992 vit = VESInputTag("label1:", "label2:label3")
1993 self.assertEqual(repr(vit), "cms.VESInputTag(\"label1:\", \"label2:label3\")")
1994 vit = VESInputTag(["label1:", "label2:label3"])
1995 self.assertEqual(repr(vit), "cms.VESInputTag(\"label1:\", \"label2:label3\")")
1996
1997 with self.assertRaises(RuntimeError):
1998 it = ESInputTag("label:too:many:elements")
1999 with self.assertRaises(RuntimeError):
2000 vit = VESInputTag("label:too:many:elements")
2001
2002 pset = PSet(it = ESInputTag("something:"))
2003
2004 pset.it = ""
2005 self.assertEqual(pset.it.getModuleLabel(), "")
2006 self.assertEqual(pset.it.getDataLabel(), "")
2007 pset.it = "label:"
2008 self.assertEqual(pset.it.getModuleLabel(), "label")
2009 self.assertEqual(pset.it.getDataLabel(), "")
2010 pset.it = "label:data"
2011 self.assertEqual(pset.it.getModuleLabel(), "label")
2012 self.assertEqual(pset.it.getDataLabel(), "data")
2013 pset.it = ":data"
2014 self.assertEqual(pset.it.getModuleLabel(), "")
2015 self.assertEqual(pset.it.getDataLabel(), "data")
2016 with self.assertRaises(RuntimeError):
2017 pset.it = "too:many:elements"
2018 with self.assertRaises(RuntimeError):
2019 pset.it = "too_few_elements"
2020
2021 pset.it = ()
2022 self.assertEqual(pset.it.getModuleLabel(), "")
2023 self.assertEqual(pset.it.getDataLabel(), "")
2024 pset.it = ("label", "")
2025 self.assertEqual(pset.it.getModuleLabel(), "label")
2026 self.assertEqual(pset.it.getDataLabel(), "")
2027 pset.it = ("label", "data")
2028 self.assertEqual(pset.it.getModuleLabel(), "label")
2029 self.assertEqual(pset.it.getDataLabel(), "data")
2030 pset.it = ("", "data")
2031 self.assertEqual(pset.it.getModuleLabel(), "")
2032 self.assertEqual(pset.it.getDataLabel(), "data")
2033 with self.assertRaises(RuntimeError):
2034 pset.it = ("too", "many", "elements")
2035 with self.assertRaises(RuntimeError):
2036 pset.it = ("too_few_elements",)
2037
2038 pset.it = []
2039 self.assertEqual(pset.it.getModuleLabel(), "")
2040 self.assertEqual(pset.it.getDataLabel(), "")
2041 pset.it = ["label", ""]
2042 self.assertEqual(pset.it.getModuleLabel(), "label")
2043 self.assertEqual(pset.it.getDataLabel(), "")
2044 pset.it = ["label", "data"]
2045 self.assertEqual(pset.it.getModuleLabel(), "label")
2046 self.assertEqual(pset.it.getDataLabel(), "data")
2047 pset.it = ["", "data"]
2048 self.assertEqual(pset.it.getModuleLabel(), "")
2049 self.assertEqual(pset.it.getDataLabel(), "data")
2050 with self.assertRaises(RuntimeError):
2051 pset.it = ["too", "many", "elements"]
2052 with self.assertRaises(RuntimeError):
2053 pset.it = ["too_few_elements"]
2054
2055 vit = VESInputTag(("a2", ""), ("b2", "d"), ("", "c"))
2056 self.assertEqual(repr(vit), "cms.VESInputTag(\"a2:\", \"b2:d\", \":c\")")
2057
2058 pset = PSet(vit = VESInputTag())
2059 pset.vit = ["a:", "b:d", ":c"]
2060 self.assertEqual(repr(pset.vit), "cms.VESInputTag(\"a:\", \"b:d\", \":c\")")
2061 pset.vit = [("a2", ""), ("b2", "d2"), ("", "c2")]
2062 self.assertEqual(repr(pset.vit), "cms.VESInputTag(\"a2:\", \"b2:d2\", \":c2\")")
2063 pset.vit = [["a3", ""], ["b3", "d3"], ["", "c3"]]
2064 self.assertEqual(repr(pset.vit), "cms.VESInputTag(\"a3:\", \"b3:d3\", \":c3\")")
2065 with self.assertRaises(RuntimeError):
2066 pset.vit = [("too", "many", "elements")]
2067 with self.assertRaises(RuntimeError):
2068 pset.vit = ["too_few_elements"]
2069 with self.assertRaises(RuntimeError):
2070 pset.vit = [("too_few_elements")]
2071
2072 def testPSet(self):
2073 p1 = PSet(anInt = int32(1), a = PSet(b = int32(1)))
2074 self.assertRaises(ValueError, PSet, "foo")
2075 self.assertRaises(TypeError, PSet, foo = "bar")
2076 self.assertEqual(repr(p1), "cms.PSet(\n a = cms.PSet(\n b = cms.int32(1)\n ),\n anInt = cms.int32(1)\n)")
2077 vp1 = VPSet(PSet(i = int32(2)))
2078
2079 self.assertEqual(repr(vp1), "cms.VPSet(cms.PSet(\n i = cms.int32(2)\n))")
2080 self.assertTrue(p1.hasParameter(['a', 'b']))
2081 self.assertFalse(p1.hasParameter(['a', 'c']))
2082 self.assertEqual(p1.getParameter(['a', 'b']).value(), 1)
2083
2084 p3 = untracked.PSet(i = int32(1), ui=untracked.int32(2), a = PSet(b = untracked.int32(1)), b = untracked.PSet(b = int32(1)))
2085 p4 = p3.clone()
2086 self.assertFalse(p4.isTracked())
2087 self.assertTrue(p4.i.isTracked())
2088 self.assertFalse(p4.ui.isTracked())
2089 self.assertTrue(p4.a.isTracked())
2090 self.assertFalse(p4.b.isTracked())
2091 self.assertFalse(p4.a.b.isTracked())
2092 self.assertTrue(p4.b.b.isTracked())
2093 p4 = p3.clone( i = None, b = dict(b = 5))
2094 self.assertEqual(p3.i.value(), 1)
2095 self.assertEqual(hasattr(p4,"i"), False)
2096 self.assertEqual(p3.b.b.value(), 1)
2097 self.assertEqual(p4.b.b.value(), 5)
2098 self.assertEqual(p4.a.b.value(), 1)
2099 self.assertEqual(p4.ui.value(), 2)
2100
2101 self.assertRaises(TypeError, p4.clone, dict(b = None))
2102 self.assertRaises(TypeError, p4.clone, [])
2103 self.assertRaises(TypeError, p4.clone, 42)
2104 p5 = PSet(p = PSet(anInt = int32(1), aString=string("foo") ) )
2105 p5.p=dict(aString = "bar")
2106 self.assertEqual(p5.p.aString.value(), "bar")
2107 self.assertEqual(p5.p.anInt.value(), 1)
2108 p5.p = dict(aDouble = double(3.14))
2109 self.assertEqual(p5.p.aString.value(), "bar")
2110 self.assertEqual(p5.p.anInt.value(), 1)
2111 self.assertEqual(p5.p.aDouble, 3.14)
2112 self.assertRaises(TypeError, p5.p , dict(bar = 3) )
2113 def testRequired(self):
2114 p1 = PSet(anInt = required.int32)
2115 self.assertTrue(hasattr(p1,"anInt"))
2116 self.assertEqual(p1.dumpPython(),'cms.PSet(\n anInt = cms.required.int32\n)')
2117 p1.anInt = 3
2118 self.assertEqual(p1.dumpPython(),'cms.PSet(\n anInt = cms.int32(3)\n)')
2119 self.assertEqual(p1.anInt.value(), 3)
2120 p1 = PSet(anInt = required.int32)
2121 p1.anInt.setValue(3)
2122 self.assertEqual(p1.anInt.value(), 3)
2123 p1.anInt = 4
2124 self.assertEqual(p1.anInt.value(), 4)
2125 p1 = PSet(anInt = required.untracked.int32)
2126 p1.anInt = 5
2127 self.assertEqual(p1.anInt.value(), 5)
2128 self.assertFalse(p1.anInt.isTracked())
2129 p1 = PSet(anInt = required.untracked.int32)
2130 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n anInt = cms.required.untracked.int32\n)')
2131 p1.anInt = 6
2132 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n anInt = cms.untracked.int32(6)\n)')
2133 self.assertTrue(p1.anInt.isCompatibleCMSType(int32))
2134 self.assertFalse(p1.anInt.isCompatibleCMSType(uint32))
2135 p1 = PSet(allowAnyLabel_ = required.int32)
2136 self.assertFalse(p1.hasParameter(['allowAnyLabel_']))
2137 p1.foo = 3
2138 self.assertEqual(p1.foo.value(),3)
2139 self.assertRaises(ValueError,setattr,p1, 'bar', 'bad')
2140 self.assertTrue(p1.foo.isTracked())
2141 p1 = PSet(allowAnyLabel_ = required.untracked.int32)
2142 self.assertFalse(p1.hasParameter(['allowAnyLabel_']))
2143 p1.foo = 3
2144 self.assertEqual(p1.foo.value(),3)
2145 self.assertFalse(p1.foo.isTracked())
2146 self.assertRaises(ValueError,setattr,p1, 'bar', 'bad')
2147
2148 p1 = PSet(aPSet = required.PSetTemplate())
2149 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.required.PSetTemplate(\n\n )\n)')
2150 p1.aPSet = dict()
2151 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.PSet(\n\n )\n)')
2152 p1 = PSet(aPSet=required.PSetTemplate(a=required.int32))
2153 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.required.PSetTemplate(\n a = cms.required.int32\n )\n)')
2154 p1.aPSet = dict(a=5)
2155 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.PSet(\n a = cms.int32(5)\n )\n)')
2156 self.assertEqual(p1.aPSet.a.value(), 5)
2157 p1 = PSet(aPSet=required.PSetTemplate(a=required.int32))
2158 p1.aPSet = PSet(a=int32(5))
2159 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.PSet(\n a = cms.int32(5)\n )\n)')
2160 self.assertEqual(p1.aPSet.a.value(), 5)
2161 p1 = PSet(aPSet=required.untracked.PSetTemplate(a=required.int32))
2162 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.required.untracked.PSetTemplate(\n a = cms.required.int32\n )\n)')
2163 p1.aPSet = dict(a=5)
2164 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.untracked.PSet(\n a = cms.int32(5)\n )\n)')
2165 self.assertEqual(p1.aPSet.a.value(), 5)
2166 p1 = PSet(allowAnyLabel_=required.PSetTemplate(a=required.int32))
2167 p1Clone = p1.clone()
2168 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n allowAnyLabel_=cms.required.PSetTemplate(\n a = cms.required.int32\n )\n)')
2169 self.assertEqual(p1Clone.dumpPython(), 'cms.PSet(\n allowAnyLabel_=cms.required.PSetTemplate(\n a = cms.required.int32\n )\n)')
2170 with self.assertRaises(AttributeError):
2171 p1.clone(allowAnyLabel_=optional.double)
2172 p1.foo = dict(a=5)
2173 self.assertEqual(p1.dumpPython(),'cms.PSet(\n foo = cms.PSet(\n a = cms.int32(5)\n ),\n allowAnyLabel_=cms.required.PSetTemplate(\n a = cms.required.int32\n )\n)')
2174 self.assertEqual(p1.foo.a.value(), 5)
2175 p1 = PSet(anInt = required.int32)
2176 self.assertRaises(TypeError, setattr, p1,'anInt', uint32(2))
2177 p1 = PSet(aVPSet = required.VPSetTemplate())
2178 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aVPSet = cms.required.VPSetTemplate()\n)')
2179 p1.aVPSet =[PSet()]
2180 self.assertEqual(len(p1.aVPSet), 1)
2181 p1 = PSet(aVPSet = required.VPSetTemplate(PSetTemplate(a=required.int32)))
2182 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aVPSet = cms.required.VPSetTemplate(\n PSetTemplate(\n a = cms.required.int32\n )\n )\n)')
2183 p1.aVPSet = [dict(a=3)]
2184 self.assertEqual(len(p1.aVPSet), 1)
2185 self.assertEqual(p1.aVPSet[0].a.value(),3)
2186 p1 = PSet(aVPSet = required.VPSetTemplate())
2187 p1.aVPSet = VPSet()
2188 self.assertEqual(len(p1.aVPSet),0)
2189 p1.aVPSet.append(PSet())
2190 self.assertEqual(len(p1.aVPSet),1)
2191 p1 = PSet(aVPSet = required.VPSetTemplate())
2192 p1.aVPSet = (PSet(),)
2193 self.assertEqual(len(p1.aVPSet), 1)
2194 p1 = PSet(aVPSet = required.VPSetTemplate(PSetTemplate(a=required.int32)))
2195 p1.aVPSet = (dict(a=i) for i in range(0,5))
2196 self.assertEqual(len(p1.aVPSet), 5)
2197
2198 def testOptional(self):
2199 p1 = PSet(anInt = optional.int32)
2200 self.assertTrue(hasattr(p1,"anInt"))
2201 self.assertEqual(p1.dumpPython(),'cms.PSet(\n anInt = cms.optional.int32\n)')
2202 p1.anInt = 3
2203 self.assertEqual(p1.anInt.value(), 3)
2204 self.assertEqual(p1.dumpPython(),'cms.PSet(\n anInt = cms.int32(3)\n)')
2205 p1 = PSet(anInt = optional.int32)
2206 p1.anInt.setValue(3)
2207 self.assertEqual(p1.anInt.value(), 3)
2208 p1.anInt = 4
2209 self.assertEqual(p1.anInt.value(), 4)
2210 p1 = PSet(anInt = optional.untracked.int32)
2211 p1.anInt = 5
2212 self.assertEqual(p1.anInt.value(), 5)
2213 self.assertFalse(p1.anInt.isTracked())
2214 p1 = PSet(anInt = optional.untracked.int32)
2215 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n anInt = cms.optional.untracked.int32\n)')
2216 p1.anInt = 6
2217 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n anInt = cms.untracked.int32(6)\n)')
2218 self.assertTrue(p1.anInt.isCompatibleCMSType(int32))
2219 self.assertFalse(p1.anInt.isCompatibleCMSType(uint32))
2220 p1 = PSet(f = required.vint32)
2221 self.assertFalse(p1.f)
2222 p1.f = []
2223 self.assertFalse(p1.f)
2224 p1.f.append(3)
2225 self.assertTrue(p1.f)
2226
2227 p1 = PSet(aPSet = optional.PSetTemplate())
2228 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.optional.PSetTemplate(\n\n )\n)')
2229 p1.aPSet = dict()
2230 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.PSet(\n\n )\n)')
2231 p1 = PSet(aPSet=optional.PSetTemplate(a=optional.int32))
2232 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.optional.PSetTemplate(\n a = cms.optional.int32\n )\n)')
2233 p1.aPSet = dict(a=5)
2234 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.PSet(\n a = cms.int32(5)\n )\n)')
2235 self.assertEqual(p1.aPSet.a.value(), 5)
2236 p1 = PSet(aPSet=optional.untracked.PSetTemplate(a=optional.int32))
2237 p1Clone = p1.clone()
2238 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.optional.untracked.PSetTemplate(\n a = cms.optional.int32\n )\n)')
2239 self.assertEqual(p1Clone.dumpPython(),'cms.PSet(\n aPSet = cms.optional.untracked.PSetTemplate(\n a = cms.optional.int32\n )\n)')
2240 p1.aPSet = dict(a=5)
2241 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aPSet = cms.untracked.PSet(\n a = cms.int32(5)\n )\n)')
2242 self.assertEqual(p1.aPSet.a.value(), 5)
2243 p1 = PSet(allowAnyLabel_=optional.PSetTemplate(a=optional.int32))
2244 self.assertEqual(p1.dumpPython(), 'cms.PSet(\n allowAnyLabel_=cms.optional.PSetTemplate(\n a = cms.optional.int32\n )\n)')
2245 p1.foo = dict(a=5)
2246 self.assertEqual(p1.dumpPython(),'cms.PSet(\n foo = cms.PSet(\n a = cms.int32(5)\n ),\n allowAnyLabel_=cms.optional.PSetTemplate(\n a = cms.optional.int32\n )\n)')
2247 self.assertEqual(p1.foo.a.value(), 5)
2248
2249 p1 = PSet(anInt = optional.int32)
2250 self.assertRaises(TypeError, lambda : setattr(p1,'anInt', uint32(2)))
2251 p1 = PSet(aVPSet = optional.VPSetTemplate())
2252 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aVPSet = cms.optional.VPSetTemplate()\n)')
2253 p1.aVPSet =[PSet()]
2254 self.assertEqual(len(p1.aVPSet), 1)
2255 p1 = PSet(aVPSet = optional.VPSetTemplate(PSetTemplate(a=required.int32)))
2256 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aVPSet = cms.optional.VPSetTemplate(\n PSetTemplate(\n a = cms.required.int32\n )\n )\n)')
2257 p1.aVPSet = [dict(a=3)]
2258 self.assertEqual(len(p1.aVPSet), 1)
2259 self.assertEqual(p1.aVPSet[0].a.value(),3)
2260
2261 def testAllowed(self):
2262 p1 = PSet(aValue = required.allowed(int32, string))
2263 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.required.allowed(cms.int32,cms.string)\n)')
2264 p1.aValue = 1
2265 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.int32(1)\n)')
2266 self.assertTrue(p1.aValue.isCompatibleCMSType(int32))
2267 self.assertFalse(p1.aValue.isCompatibleCMSType(uint32))
2268 self.assertRaises(RuntimeError, lambda: setattr(p1,'aValue',1.3))
2269 p1 = PSet(aValue = required.allowed(int32, string))
2270 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.required.allowed(cms.int32,cms.string)\n)')
2271 p1.aValue = "foo"
2272 self.assertEqual(p1.dumpPython(),"cms.PSet(\n aValue = cms.string('foo')\n)")
2273 self.assertTrue(p1.aValue.isCompatibleCMSType(string))
2274 self.assertFalse(p1.aValue.isCompatibleCMSType(uint32))
2275 p1 = PSet(aValue = required.allowed(int32, string))
2276
2277 self.assertRaises(TypeError, lambda: setattr(p1, 'aValue', double(3.1)))
2278
2279 p1 = PSet(aValue = required.allowed(int32, string, default=int32(3)))
2280 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.int32(3)\n)')
2281 p1.aValue = "foo"
2282 self.assertEqual(p1.dumpPython(),"cms.PSet(\n aValue = cms.string('foo')\n)")
2283
2284 p1 = PSet(aValue = required.untracked.allowed(int32, string, default=int32(3)))
2285 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.untracked.int32(3)\n)')
2286
2287 p1 = PSet(aValue = required.untracked.allowed(int32, string))
2288 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.required.untracked.allowed(cms.int32,cms.string)\n)')
2289 p1.aValue = 1
2290 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.untracked.int32(1)\n)')
2291 self.assertRaises(RuntimeError, lambda: setattr(p1,'aValue',1.3))
2292 p1 = PSet(aValue = required.untracked.allowed(int32, string))
2293 self.assertEqual(p1.dumpPython(),'cms.PSet(\n aValue = cms.required.untracked.allowed(cms.int32,cms.string)\n)')
2294 p1.aValue = "foo"
2295 self.assertEqual(p1.dumpPython(),"cms.PSet(\n aValue = cms.untracked.string('foo')\n)")
2296
2297 p2 = PSet(aValue=optional.allowed(int32,PSet))
2298 self.assertEqual(p2.dumpPython(),'cms.PSet(\n aValue = cms.optional.allowed(cms.int32,cms.PSet)\n)')
2299 p2.aValue = 2
2300 self.assertEqual(p2.aValue.value(),2)
2301 p2 = PSet(aValue=optional.allowed(int32,PSet))
2302 p2.aValue = PSet(i = int32(3))
2303 self.assertEqual(p2.aValue.i.value(),3)
2304 p2 = PSet(aValue=optional.allowed(int32,PSet))
2305 p2.aValue = dict(i = int32(3))
2306 self.assertEqual(p2.aValue.i.value(),3)
2307
2308 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2309 self.assertEqual(p2.dumpPython(),'cms.PSet(\n aValue = cms.optional.allowed(cms.int32,cms.PSetTemplate(\n b = cms.optional.int32\n))\n)')
2310 p2.aValue = 2
2311 self.assertEqual(p2.aValue.value(),2)
2312 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2313 p2.aValue = PSet(b = int32(3))
2314 self.assertEqual(p2.aValue.b.value(),3)
2315 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2316 p2.aValue = dict(b = 3)
2317 self.assertEqual(p2.aValue.b.value(),3)
2318 self.assertEqual(p2.dumpPython(), 'cms.PSet(\n aValue = cms.PSet(\n b = cms.int32(3)\n )\n)')
2319 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2320 self.assertRaises(TypeError, lambda: setattr(p2, "aValue", dict(i = 1)) )
2321 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2322 self.assertRaises(TypeError, lambda: setattr(p2, "aValue", double(3.14)) )
2323 self.assertRaises(ValueError, lambda: setattr(p2, "aValue", dict(b=3.14)) )
2324 p2 = PSet(aValue=optional.allowed(int32,PSetTemplate(b=optional.int32)))
2325 p2.aValue = PSet(b=double(3.14))
2326 self.assertEqual(p2.aValue.b.value(),3.14)
2327
2328
2329
2330 p2 = PSet(aValue=optional.untracked.allowed(int32,PSet))
2331 self.assertEqual(p2.dumpPython(),'cms.PSet(\n aValue = cms.optional.untracked.allowed(cms.int32,cms.PSet)\n)')
2332 p2.aValue = 2
2333 self.assertEqual(p2.aValue.value(),2)
2334 p2 = PSet(aValue=optional.untracked.allowed(int32,PSet))
2335 p2.aValue = PSet(i = int32(3))
2336 self.assertEqual(p2.aValue.i.value(),3)
2337 p2 = PSet(aValue=optional.untracked.allowed(int32,PSet))
2338 p2.aValue = dict(i = int32(3))
2339 self.assertEqual(p2.aValue.i.value(),3)
2340
2341 p3 = PSet(aValue=required.allowed(int32,uint32))
2342 p3.aValue = -42
2343 self.assertEqual(p3.aValue.value(), -42)
2344 p3 = PSet(aValue=required.allowed(int32,uint32))
2345 self.assertRaises(RuntimeError, lambda: setattr(p3, "aValue", 42))
2346
2347 p3 = PSet(aValue=required.untracked.allowed(int32,uint32))
2348 p3.aValue = -42
2349 self.assertEqual(p3.aValue.value(), -42)
2350 p3 = PSet(aValue=required.untracked.allowed(int32,uint32))
2351 self.assertRaises(RuntimeError, lambda: setattr(p3, "aValue", 42))
2352
2353 p3 = PSet(aValue=optional.allowed(int32,uint32))
2354 p3.aValue = -42
2355 self.assertEqual(p3.aValue.value(), -42)
2356 p3 = PSet(aValue=optional.allowed(int32,uint32))
2357 self.assertRaises(RuntimeError, lambda: setattr(p3, "aValue", 42))
2358
2359 p3 = PSet(aValue=optional.untracked.allowed(int32,uint32))
2360 p3.aValue = -42
2361 self.assertEqual(p3.aValue.value(), -42)
2362 p3 = PSet(aValue=optional.untracked.allowed(int32,uint32))
2363 self.assertRaises(RuntimeError, lambda: setattr(p3, "aValue", 42))
2364
2365 p1 = PSet(aValue = required.allowed(int32, string))
2366 self.assertRaises(TypeError, lambda : setattr(p1,'aValue', uint32(2)))
2367
2368 p1 = PSet(aValue = required.allowed(InputTag, VInputTag, default=InputTag("blah")))
2369 p1.aValue.setValue("foo")
2370 self.assertEqual(p1.aValue.value(), "foo")
2371
2372
2373 def testVPSet(self):
2374 p1 = VPSet(PSet(anInt = int32(1)), PSet(anInt=int32(2)))
2375 self.assertEqual(len(p1),2)
2376 self.assertEqual(p1[0].anInt.value(), 1)
2377 self.assertEqual(p1[1].anInt.value(), 2)
2378 self.assertRaises(TypeError, lambda : VPSet(3))
2379 self.assertRaises(TypeError, lambda : VPSet(int32(3)))
2380 self.assertRaises(SyntaxError, lambda : VPSet(foo=PSet()))
2381 p2 = VPSet([PSet(anInt = int32(1)), PSet(anInt=int32(2))])
2382 self.assertEqual(len(p2),2)
2383 self.assertEqual(p2[0].anInt.value(), 1)
2384 self.assertEqual(p2[1].anInt.value(), 2)
2385
2386 def testVPSetWithTemplate(self):
2387 p1 = VPSet(template=PSetTemplate(a=required.int32))
2388 self.assertEqual(len(p1),0)
2389 p1.append(dict(a=1))
2390 self.assertEqual(len(p1),1)
2391 self.assertEqual(p1[0].a.value(), 1)
2392 p1.append(PSet(foo= untracked.bool(True)))
2393 self.assertEqual(len(p1), 2)
2394 self.assertTrue(p1[1].foo.value())
2395 self.assertEqual(p1.dumpPython(), '''cms.VPSet(
2396 cms.PSet(
2397 a = cms.int32(1)
2398 ),
2399 cms.PSet(
2400 foo = cms.untracked.bool(True)
2401 ),
2402 template = cms.PSetTemplate(
2403 a = cms.required.int32
2404 )
2405 )''')
2406 self.assertRaises(TypeError, lambda : p1.append(dict(b=3)) )
2407 p2 = VPSet(dict(a=3), dict(a=1), template = PSetTemplate(a=required.int32))
2408 self.assertEqual(len(p2), 2)
2409 self.assertEqual(p2[0].a.value(), 3)
2410 self.assertEqual(p2[1].a.value(), 1)
2411 p3 = VPSet([dict(a=3), dict(a=1)], template = PSetTemplate(a=required.int32))
2412 self.assertEqual(len(p3), 2)
2413 self.assertEqual(p3[0].a.value(), 3)
2414 self.assertEqual(p3[1].a.value(), 1)
2415 p4 = VPSet(dict(a=3), template = PSetTemplate(a=required.int32))
2416 self.assertEqual(len(p4), 1)
2417 self.assertEqual(p4[0].a.value(), 3)
2418 p5 = VPSet(PSet(a=int32(3)), template = PSetTemplate(a=required.int32))
2419 self.assertEqual(len(p5), 1)
2420 self.assertEqual(p5[0].a.value(), 3)
2421 self.assertRaises(TypeError, lambda : VPSet(dict(b=3), template = PSetTemplate(a=required.int32)) )
2422 ptest = VPSet(PSet(b=int32(3)), template = PSetTemplate(a=required.int32))
2423 self.assertEqual(len(ptest), 1)
2424 self.assertEqual(ptest[0].b.value(), 3)
2425 self.assertEqual(ptest.dumpPython(),"cms.VPSet(cms.PSet(\n b = cms.int32(3)\n), \ntemplate = cms.PSetTemplate(\n a = cms.required.int32\n))"
2426 )
2427 ptest = VPSet(template=PSetTemplate())
2428 self.assertEqual(ptest.dumpPython(),"cms.VPSet()")
2429
2430 ptest = VPSet(dict(), template = PSetTemplate(a=required.int32))
2431 self.assertEqual(len(ptest), 1)
2432 self.assertTrue(hasattr(ptest[0], "a"))
2433 ptest[0].a = 4
2434 self.assertEqual(ptest[0].a.value(), 4)
2435
2436 ptest = VPSet(PSet(), template = PSetTemplate(a=required.int32))
2437 self.assertEqual(len(ptest), 1)
2438 self.assertTrue(not hasattr(ptest[0], "a"))
2439
2440 self.assertRaises(TypeError, lambda: VPSet(dict(a=3)))
2441
2442
2443 def testEDAlias(self):
2444 aliasfoo2 = EDAlias(foo2 = VPSet(PSet(type = string("Foo2"))))
2445 self.assertTrue(hasattr(aliasfoo2,"foo2"))
2446 del aliasfoo2.foo2
2447 self.assertTrue(not hasattr(aliasfoo2,"foo2"))
2448 self.assertTrue("foo2" not in aliasfoo2.parameterNames_())
2449
2450 aliasfoo2 = EDAlias(foo2 = VPSet(PSet(type = string("Foo2"))))
2451 aliasfoo3 = aliasfoo2.clone(
2452 foo2 = {0: dict(type = "Foo4")},
2453 foo3 = VPSet(PSet(type = string("Foo3")))
2454 )
2455 self.assertTrue(hasattr(aliasfoo3, "foo2"))
2456 self.assertTrue(hasattr(aliasfoo3, "foo3"))
2457 self.assertEqual(aliasfoo3.foo2[0].type, "Foo4")
2458 self.assertEqual(aliasfoo3.foo3[0].type, "Foo3")
2459
2460 aliasfoo4 = aliasfoo3.clone(foo2 = None)
2461 self.assertFalse(hasattr(aliasfoo4, "foo2"))
2462 self.assertTrue(hasattr(aliasfoo4, "foo3"))
2463 self.assertEqual(aliasfoo4.foo3[0].type, "Foo3")
2464
2465 aliasfoo5 = EDAlias(foo5 = EDAlias.allProducts())
2466 self.assertEqual(len(aliasfoo5.foo5), 1)
2467 self.assertEqual(aliasfoo5.foo5[0].type.value(), "*")
2468 self.assertFalse(hasattr(aliasfoo5.foo5[0], "fromProductInstance"))
2469 self.assertFalse(hasattr(aliasfoo5.foo5[0], "toProductInstance"))
2470
2471 aliasfoo6 = aliasfoo5.clone(foo5 = None, foo6 = EDAlias.allProducts())
2472 self.assertFalse(hasattr(aliasfoo6, "foo5"))
2473 self.assertTrue(hasattr(aliasfoo6, "foo6"))
2474 self.assertEqual(len(aliasfoo6.foo6), 1)
2475 self.assertEqual(aliasfoo6.foo6[0].type.value(), "*")
2476
2477 aliasfoo7 = EDAlias(foo5 = EDAlias.allProducts(), foo6 = EDAlias.allProducts())
2478 self.assertEqual(len(aliasfoo7.foo5), 1)
2479 self.assertEqual(len(aliasfoo7.foo6), 1)
2480
2481 def testFileInPath(self):
2482 f = FileInPath("FWCore/ParameterSet/python/Types.py")
2483 self.assertEqual(f.configValue(), "'FWCore/ParameterSet/python/Types.py'")
2484 f = FileInPath()
2485 self.assertEqual(f.configValue(), "''")
2486
2487 def testSecSource(self):
2488 s1 = SecSource("EmbeddedRootSource", fileNames = vstring("foo.root"))
2489 self.assertEqual(s1.type_(), "EmbeddedRootSource")
2490 self.assertEqual(s1.configValue(),
2491 """EmbeddedRootSource { """+"""
2492 vstring fileNames = {
2493 'foo.root'
2494 }
2495
2496 }
2497 """)
2498 s1=SecSource("EmbeddedRootSource",type=int32(1))
2499 self.assertEqual(s1.type.value(),1)
2500 def testEventID(self):
2501 eid = EventID(2, 0, 3)
2502 self.assertEqual( repr(eid), "cms.EventID(2, 0, 3)" )
2503 pset = PSetTester()
2504 eid.insertInto(pset,'foo')
2505 eid2 = EventID._valueFromString('3:4')
2506 eid2.insertInto(pset,'foo2')
2507 eid = EventID(0,0,0)
2508 eid.setValue("2:0:3")
2509 self.assertEqual( repr(eid), "cms.EventID(2, 0, 3)" )
2510 eid.setValue( (4,1))
2511 self.assertEqual( repr(eid), "cms.EventID(4, 0, 1)" )
2512 eid.setValue( (5,1,2))
2513 self.assertEqual( repr(eid), "cms.EventID(5, 1, 2)" )
2514 self.assertEqual(eid.value(), "5:1:2")
2515 other = EventID(1,1,1)
2516 other.setValue(eid.value())
2517 self.assertEqual(other.value(), "5:1:2")
2518 def testVEventID(self):
2519 veid = VEventID(EventID(2, 0, 3))
2520 veid2 = VEventID("1:2", "3:4")
2521 self.assertEqual( repr(veid[0]), "cms.EventID(2, 0, 3)" )
2522 self.assertEqual( repr(veid2[0]), "'1:2'" )
2523 self.assertEqual( veid2.dumpPython(), 'cms.VEventID("1:2", "3:4")')
2524 pset = PSetTester()
2525 veid.insertInto(pset,'foo')
2526
2527 def testLuminosityBlockID(self):
2528 lid = LuminosityBlockID(2, 3)
2529 self.assertEqual( repr(lid), "cms.LuminosityBlockID(2, 3)" )
2530 pset = PSetTester()
2531 lid.insertInto(pset,'foo')
2532 lid2 = LuminosityBlockID._valueFromString('3:4')
2533 lid2.insertInto(pset,'foo2')
2534 lid3 = LuminosityBlockID(1)
2535 lid3.setValue((2,3))
2536 self.assertEqual(repr(lid3), "cms.LuminosityBlockID(2, 3)")
2537 self.assertEqual(lid3.value(), "2:3")
2538 other = LuminosityBlockID(1,1)
2539 other.setValue(lid3.value())
2540 self.assertEqual(other.value(), "2:3")
2541
2542 def testVLuminosityBlockID(self):
2543 vlid = VLuminosityBlockID(LuminosityBlockID(2, 3))
2544 vlid2 = VLuminosityBlockID("1:2", "3:4")
2545 self.assertEqual( repr(vlid[0]), "cms.LuminosityBlockID(2, 3)" )
2546 self.assertEqual( repr(vlid2[0]), "'1:2'" )
2547 self.assertEqual( vlid2.dumpPython(), 'cms.VLuminosityBlockID("1:2", "3:4")')
2548 vlid3 = VLuminosityBlockID((1,2),(3,4))
2549 self.assertEqual( repr(vlid3[0]), '(1, 2)' )
2550 self.assertEqual( vlid3.dumpPython(), 'cms.VLuminosityBlockID((1, 2), (3, 4))')
2551 pset = PSetTester()
2552 vlid.insertInto(pset,'foo')
2553 vlid4 = VLuminosityBlockID()
2554 vlid4.setValue(["1:2"])
2555 self.assertEqual( vlid4.dumpPython(), 'cms.VLuminosityBlockID("1:2")' )
2556 p = PSet(v = VLuminosityBlockID())
2557 p.v = VLuminosityBlockID()
2558 p.v = ["1:2"]
2559 self.assertEqual( p.v.dumpPython(), 'cms.VLuminosityBlockID("1:2")' )
2560 p = PSet( v = VLuminosityBlockID())
2561 p.v = [(3,1)]
2562 self.assertEqual( p.v.dumpPython(), 'cms.VLuminosityBlockID((3, 1))' )
2563
2564 def testEventRange(self):
2565 range1 = EventRange(1, 0, 2, 3, 0, 4)
2566 range2 = EventRange._valueFromString("1:2 - 3:4")
2567 range3 = EventRange._valueFromString("1:MIN - 3:MAX")
2568 self.assertEqual(repr(range1), repr(range2))
2569 self.assertEqual(range1.value(), "1:0:2-3:0:4")
2570 self.assertEqual(repr(range3), "cms.EventRange(1, 0, 1, 3, 0, 0)")
2571 pset = PSetTester()
2572 range1.insertInto(pset,'foo')
2573 range2.insertInto(pset,'bar')
2574 range4 = EventRange((1,2,3), (4,5,6))
2575 self.assertEqual(repr(range4), "cms.EventRange(1, 2, 3, 4, 5, 6)")
2576 other = EventRange(1,1,1,2,2,2)
2577 other.setValue(range1.value())
2578 self.assertEqual(range1.value(), other.value())
2579
2580 def testVEventRange(self):
2581 v1 = VEventRange(EventRange(1, 0, 2, 3, 0, 4))
2582 v2 = VEventRange("1:2-3:4", "5:MIN-7:MAX")
2583 self.assertEqual( v2.dumpPython(), 'cms.VEventRange("1:2-3:4", "5:MIN-7:MAX")')
2584 self.assertEqual( repr(v1[0]), "cms.EventRange(1, 0, 2, 3, 0, 4)" )
2585 pset = PSetTester()
2586 v2.insertInto(pset,'foo')
2587 v3 = VEventRange(((1,2,3), (4,5,6)), ((7,1,1),(8,0,0)))
2588 self.assertEqual(v3.dumpPython(), "cms.VEventRange(((1, 2, 3), (4, 5, 6)), ((7, 1, 1), (8, 0, 0)))")
2589 p = PSet(v = VEventRange())
2590 p.v = [((3,2,1), (7,8,9))]
2591 self.assertEqual(p.v[0], ((3,2,1), (7,8,9)))
2592
2593 def testLuminosityBlockRange(self):
2594 range1 = LuminosityBlockRange(1, 2, 3, 4)
2595 range2 = LuminosityBlockRange._valueFromString("1:2 - 3:4")
2596 range3 = LuminosityBlockRange._valueFromString("1:MIN - 3:MAX")
2597 self.assertEqual(repr(range1), repr(range2))
2598 self.assertEqual(range1.value(), "1:2-3:4")
2599 self.assertEqual(repr(range3), "cms.LuminosityBlockRange(1, 1, 3, 0)")
2600 pset = PSetTester()
2601 range1.insertInto(pset,'foo')
2602 range2.insertInto(pset,'bar')
2603 range4 = LuminosityBlockRange(1, 2, 3, 4)
2604 range4.setValue((2,3,4,5))
2605 self.assertEqual(repr(range4), "cms.LuminosityBlockRange(2, 3, 4, 5)")
2606 range5 = LuminosityBlockRange((1,2), (3,4))
2607 self.assertEqual(repr(range5), "cms.LuminosityBlockRange(1, 2, 3, 4)")
2608 other = LuminosityBlockRange(1,1,2,2)
2609 other.setValue(range1.value())
2610 self.assertEqual(range1.value(), other.value())
2611 def testVLuminosityBlockRange(self):
2612 v1 = VLuminosityBlockRange(LuminosityBlockRange(1, 2, 3, 4))
2613 v2 = VLuminosityBlockRange("1:2-3:4", "5:MIN-7:MAX")
2614 self.assertEqual( repr(v1[0]), "cms.LuminosityBlockRange(1, 2, 3, 4)" )
2615 pset = PSetTester()
2616 v2.insertInto(pset,'foo')
2617 v3 = VLuminosityBlockRange(((1,2), (3,4)), ((5,6), (7,8)))
2618 self.assertEqual( v3.dumpPython(), "cms.VLuminosityBlockRange(((1, 2), (3, 4)), ((5, 6), (7, 8)))")
2619 p = PSet(v = VLuminosityBlockRange())
2620 p.v = [((3,2), (7,8))]
2621 self.assertEqual(p.v[0], ((3,2), (7,8)))
2622 self.assertRaises(TypeError, lambda x: VLuminosityBlockRange(x), 1)
2623
2624 self.assertRaises(TypeError, lambda x: VLuminosityBlockRange(x), ((1,2,3),(1,2)))
2625
2626 def testPSetConversion(self):
2627 p = PSet(a = untracked.int32(7),
2628 b = untracked.InputTag("b:"),
2629 c = untracked.ESInputTag("c:"),
2630 d = EventID(1,1,1),
2631 e = LuminosityBlockID(1,1),
2632 f = EventRange(1,1,1,8,8,8),
2633 g = LuminosityBlockRange(1,1,8,8),
2634 h = untracked.string('dummy'),
2635 i = untracked.bool(False),
2636 j = untracked.uint32(7),
2637 k = untracked.int64(7),
2638 l = untracked.uint64(7),
2639 m = untracked.double(7.0),
2640 n = FileInPath("xxx"),
2641 o = untracked.vint32(7,8),
2642 p = untracked.VInputTag(InputTag("b:"),InputTag("c:")),
2643 q = untracked.VESInputTag(ESInputTag("c:"),ESInputTag("d:")),
2644 r = untracked.VEventID(EventID(1,1,1),EventID(2,2,2)),
2645 s = untracked.VLuminosityBlockID(LuminosityBlockID(1,1),LuminosityBlockID(2,3)),
2646 t = untracked.VEventRange(EventRange(1,1,1,8,8,8), EventRange(9,9,9,18,18,18)),
2647 u = untracked.VLuminosityBlockRange(LuminosityBlockRange(1,1,8,8), LuminosityBlockRange(9,9,18,18)),
2648 v = untracked.vstring('dummy','anotherdummy'),
2649 w = untracked.vbool(False,True),
2650 x = untracked.vuint32(7,8),
2651 y = untracked.vint64(7,8),
2652 z = untracked.vuint64(7,8),
2653 A = vdouble(7.0,8.0)
2654 )
2655 convert = _ConvertToPSet()
2656 p.insertInto(convert,"p")
2657 self.assertTrue(hasattr(convert.pset,'p'))
2658 self.assertTrue(hasattr(convert.pset.p,'a'))
2659 self.assertEqual(p.a,convert.pset.p.a)
2660 self.assertEqual(p.a.isTracked(),convert.pset.p.a.isTracked())
2661
2662 q = PSet(b = int32(1), p = p)
2663 q.insertInto(convert,"q")
2664 self.assertTrue(hasattr(convert.pset,'q'))
2665 self.assertTrue(hasattr(convert.pset.q,'b'))
2666 self.assertEqual(q.b,convert.pset.q.b)
2667 self.assertTrue(hasattr(convert.pset.q,'p'))
2668 self.assertTrue(hasattr(convert.pset.q.p,'a'))
2669 self.assertEqual(p.a,convert.pset.q.p.a)
2670 for i in p.parameterNames_():
2671 self.assertEqual(str(getattr(p,i)),str(getattr(convert.pset.p,i)))
2672 def testVPSetConversion(self):
2673 p = PSet(a = untracked.int32(7))
2674 q = PSet(b = int32(1), p = p)
2675 v = VPSet(p,q)
2676 convert = _ConvertToPSet()
2677 v.insertInto(convert,'v')
2678 self.assertTrue(hasattr(convert.pset,'v'))
2679 self.assertTrue(len(convert.pset.v)==2)
2680 self.assertEqual(v[0].a,convert.pset.v[0].a)
2681 self.assertEqual(v[1].b,convert.pset.v[1].b)
2682 self.assertEqual(v[1].p.a, convert.pset.v[1].p.a)
2683
2684 class testInequalities(unittest.TestCase):
2685 def testnumbers(self):
2686 self.assertGreater(int32(5), int32(-1))
2687 self.assertGreater(int64(100), 99)
2688 self.assertLess(3, uint32(4))
2689 self.assertLess(6.999999999, uint64(7))
2690 self.assertLessEqual(-5, int32(-5))
2691 self.assertLessEqual(int32(-5), uint32(1))
2692 self.assertGreaterEqual(double(5.3), uint32(5))
2693 self.assertGreater(double(5.3), uint64(5))
2694 self.assertGreater(double(5.3), uint64(5))
2695 self.assertGreater(6, double(5))
2696 self.assertLess(uint64(0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF+1)
2697 self.assertEqual(double(5.0), double(5))
2698 def teststring(self):
2699 self.assertGreater(string("I am a string"), "I am a strinf")
2700 self.assertGreaterEqual("I am a string", string("I am a string"))
2701 def testincompatibletypes(self):
2702 import sys
2703 if sys.version_info < (3, 0):
2704 self.assertLess(double(3), "I am a string")
2705 self.assertLess(3, string("I am a string"))
2706 self.assertLess(double(5), "4")
2707 else:
2708 with self.assertRaises(TypeError):
2709 double(3) < "I am a string"
2710 with self.assertRaises(TypeError):
2711 3 < string("I am a string")
2712 def testinfinity(self):
2713 self.assertLess(1e99, double(float("inf")))
2714 self.assertLess(double(1e99), float("inf"))
2715 self.assertGreater(1e99, double(float("-inf")))
2716 self.assertEqual(double(float("inf")), float("inf"))
2717 def testnan(self):
2718 nan = double(float("nan"))
2719 self.assertNotEqual(nan, nan)
2720 self.assertFalse(nan > 3 or nan < 3 or nan == 3)
2721
2722 unittest.main()