CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoLuminosity/LumiDB/python/pileupParser.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import json
00003 class pileupParser(object):
00004     def __init__(self,selectStr):
00005         self.__result={}
00006         self.__strresult={}
00007         strresult=json.loads(selectStr)
00008         for k,v in strresult.items():
00009 #            expandedvalues=[]
00010 #            print v
00011             ldict={}
00012             for elems in v:
00013                 llist = [ elems[1],elems[2],elems[3] ]
00014                 ldict[int(elems[0])] = llist
00015 
00016 
00017 #            for w in v:
00018 #                if len(w)==0:
00019 #                    self.__result[int(k)]=expandedvalues
00020 #                    self.__strresult[k]=[]
00021 #                    continue
00022             ###weed out [10]-like stuff just in case they exist
00023 #                elif len(w)==1:
00024 #                    expandedvalues.append(w[0])
00025             ##weed out [10,10]-like stuff
00026 #                elif len(w)==2 and w[0]==w[1]:
00027 #                    expandedvalues.append(w[0])
00028 #                else:
00029 #                    for i in range(w[0],w[1]+1):
00030 #                        expandedvalues.append(i)
00031             self.__result[int(k)]=ldict
00032 #            self.__strresult[k]=[str(x) for x in expandedvalues]
00033     def runs(self):
00034         return self.__result.keys()
00035     def runsandls(self):
00036         '''return expanded {run:lslist}
00037         '''
00038         return self.__result
00039     def runsandlsStr(self):
00040         '''return expanded {'run':lslist}
00041         '''
00042         return self.__strresult
00043     def numruns(self):
00044         return len(self.__result.keys())
00045     def numls(self,run):
00046         return len(self.__result[run])
00047 if __name__ == "__main__":
00048 #    s=pileupParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
00049     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]]}')
00050 
00051     print 'runs : ',s.runs()
00052     print 'full result : ',s.runsandls()
00053 #    print 'str result : ',s.runsandlsStr()
00054 #    print 'num runs : ',s.numruns()
00055 #    print 'numls in run : ',s.numls(1)