CMS 3D CMS Logo

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