Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:19

0001 from __future__ import print_function
0002 from builtins import range
0003 import json
0004 class selectionParser(object):
0005     def __init__(self,selectStr):
0006         self.__result={}
0007         self.__strresult={}
0008         strresult=json.loads(selectStr)
0009         for k,v in strresult.items():
0010             expandedvalues=[]
0011             for w in v:
0012                 if len(w)==0:
0013                     self.__result[int(k)]=expandedvalues
0014                     self.__strresult[k]=[]
0015                     continue
0016             ###weed out [10]-like stuff just in case they exist
0017                 elif len(w)==1:
0018                     expandedvalues.append(w[0])
0019             ##weed out [10,10]-like stuff
0020                 elif len(w)==2 and w[0]==w[1]:
0021                     expandedvalues.append(w[0])
0022                 else:
0023                     for i in range(w[0],w[1]+1):
0024                         expandedvalues.append(i)
0025             self.__result[int(k)]=expandedvalues
0026             self.__strresult[k]=[str(x) for x in expandedvalues]
0027     def runs(self):
0028         return self.__result.keys()
0029     def runsandls(self):
0030         '''return expanded {run:lslist}
0031         '''
0032         return self.__result
0033     def runsandlsStr(self):
0034         '''return expanded {'run':lslist}
0035         '''
0036         return self.__strresult
0037     def numruns(self):
0038         return len(self.__result)
0039     def numls(self,run):
0040         return len(self.__result[run])
0041 if __name__ == "__main__":
0042     s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
0043     print('runs : ',s.runs())
0044     print('full result : ',s.runsandls())
0045     print('str result : ',s.runsandlsStr())
0046     print('num runs : ',s.numruns())
0047     print('numls in run : ',s.numls(1))