Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-03 23:19:35

0001 import sys
0002 from FWCore.ParameterSet.VarParsing import VarParsing
0003 
0004 def parse(argv):
0005   sys.argv = ['test_varparsing_list.py','maxEvents=100']+argv # emulate user arguments
0006   opts = VarParsing('standard')
0007   opts.register('myInts0',   '',      VarParsing.multiplicity.list, VarParsing.varType.int)
0008   opts.register('myInts1',   [],      VarParsing.multiplicity.list, VarParsing.varType.int)
0009   opts.register('myInts2',   0,       VarParsing.multiplicity.list, VarParsing.varType.int)
0010   opts.register('myInts3',   [0],     VarParsing.multiplicity.list, VarParsing.varType.int)
0011   opts.register('myFloats0', '',      VarParsing.multiplicity.list, VarParsing.varType.float)
0012   opts.register('myFloats1', [],      VarParsing.multiplicity.list, VarParsing.varType.float)
0013   opts.register('myFloats2', 0,       VarParsing.multiplicity.list, VarParsing.varType.float)
0014   opts.register('myFloats3', [0],     VarParsing.multiplicity.list, VarParsing.varType.float)
0015   opts.register('myBools0',  '',      VarParsing.multiplicity.list, VarParsing.varType.bool)
0016   opts.register('myBools1',  [],      VarParsing.multiplicity.list, VarParsing.varType.bool)
0017   opts.register('myBools2',  True,    VarParsing.multiplicity.list, VarParsing.varType.bool)
0018   opts.register('myBools3',  [True],  VarParsing.multiplicity.list, VarParsing.varType.bool)
0019   opts.register('myStrs0',   '',      VarParsing.multiplicity.list, VarParsing.varType.string)
0020   opts.register('myStrs1',   [],      VarParsing.multiplicity.list, VarParsing.varType.string)
0021   opts.register('myStrs2',   'foo',   VarParsing.multiplicity.list, VarParsing.varType.string)
0022   opts.register('myStrs3',   ['foo'], VarParsing.multiplicity.list, VarParsing.varType.string)
0023   opts.parseArguments()
0024   #print(f">>> Parsed: {sys.argv} -> lists={opts._lists}")
0025 
0026 # parse without user arguments
0027 parse([ ])
0028 
0029 # parse with user arguments
0030 parse(['myInts1=0,1,-1','myFloats1=3.14,0,0.0,-1.0','myBools1=True,False','myStrs1=foo,bar'])