CMS 3D CMS Logo

pileupParser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import json
4  def __init__(self,selectStr):
5  self.__result={}
6  self.__strresult={}
7  strresult=json.loads(selectStr)
8  for k,v in strresult.items():
9 # expandedvalues=[]
10 # print v
11  ldict={}
12  for elems in v:
13  llist = [ elems[1],elems[2],elems[3] ]
14  ldict[int(elems[0])] = llist
15 
16 
17 # for w in v:
18 # if len(w)==0:
19 # self.__result[int(k)]=expandedvalues
20 # self.__strresult[k]=[]
21 # continue
22  ###weed out [10]-like stuff just in case they exist
23 # elif len(w)==1:
24 # expandedvalues.append(w[0])
25  ##weed out [10,10]-like stuff
26 # elif len(w)==2 and w[0]==w[1]:
27 # expandedvalues.append(w[0])
28 # else:
29 # for i in range(w[0],w[1]+1):
30 # expandedvalues.append(i)
31  self.__result[int(k)]=ldict
32 # self.__strresult[k]=[str(x) for x in expandedvalues]
33  def runs(self):
34  return self.__result.keys()
35  def runsandls(self):
36  '''return expanded {run:lslist}
37  '''
38  return self.__result
39  def runsandlsStr(self):
40  '''return expanded {'run':lslist}
41  '''
42  return self.__strresult
43  def numruns(self):
44  return len(self.__result.keys())
45  def numls(self,run):
46  return len(self.__result[run])
47 if __name__ == "__main__":
48 # s=pileupParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
49  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]]}')
50 
51  print 'runs : ',s.runs()
52  print 'full result : ',s.runsandls()
53 # print 'str result : ',s.runsandlsStr()
54 # print 'num runs : ',s.numruns()
55 # print 'numls in run : ',s.numls(1)
def __init__(self, selectStr)
Definition: pileupParser.py:4