Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-11 04:33:53

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