Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #!/usr/bin/env python
0002 from __future__ import print_function
0003 import json
0004 class pileupParser(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 #            print v
0012             ldict={}
0013             for elems in v:
0014                 llist = [ elems[1],elems[2],elems[3] ]
0015                 ldict[int(elems[0])] = llist
0016 
0017 
0018 #            for w in v:
0019 #                if len(w)==0:
0020 #                    self.__result[int(k)]=expandedvalues
0021 #                    self.__strresult[k]=[]
0022 #                    continue
0023             ###weed out [10]-like stuff just in case they exist
0024 #                elif len(w)==1:
0025 #                    expandedvalues.append(w[0])
0026             ##weed out [10,10]-like stuff
0027 #                elif len(w)==2 and w[0]==w[1]:
0028 #                    expandedvalues.append(w[0])
0029 #                else:
0030 #                    for i in range(w[0],w[1]+1):
0031 #                        expandedvalues.append(i)
0032             self.__result[int(k)]=ldict
0033 #            self.__strresult[k]=[str(x) for x in expandedvalues]
0034     def runs(self):
0035         return self.__result.keys()
0036     def runsandls(self):
0037         '''return expanded {run:lslist}
0038         '''
0039         return self.__result
0040     def runsandlsStr(self):
0041         '''return expanded {'run':lslist}
0042         '''
0043         return self.__strresult
0044     def numruns(self):
0045         return len(self.__result)
0046     def numls(self,run):
0047         return len(self.__result[run])
0048 if __name__ == "__main__":
0049 #    s=pileupParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
0050     s=pileupParser('{"179434": [[21,38.140,7.2,2.220e-04],[22,49.032,7.2,2.218e-04]],"179435": [[21,38.140,7.2,2.220e-04],[22,49.032,7.2,2.218e-04]]}')
0051 
0052     print('runs : ',s.runs())
0053     print('full result : ',s.runsandls())
0054 #    print 'str result : ',s.runsandlsStr()
0055 #    print 'num runs : ',s.numruns()
0056 #    print 'numls in run : ',s.numls(1)