Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:20

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