CMS 3D CMS Logo

selectionParser.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from builtins import range
3 import json
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  for w in v:
12  if len(w)==0:
13  self.__result[int(k)]=expandedvalues
14  self.__strresult[k]=[]
15  continue
16 
17  elif len(w)==1:
18  expandedvalues.append(w[0])
19 
20  elif len(w)==2 and w[0]==w[1]:
21  expandedvalues.append(w[0])
22  else:
23  for i in range(w[0],w[1]+1):
24  expandedvalues.append(i)
25  self.__result[int(k)]=expandedvalues
26  self.__strresult[k]=[str(x) for x in expandedvalues]
27  def runs(self):
28  return self.__result.keys()
29  def runsandls(self):
30  '''return expanded {run:lslist}
31  '''
32  return self.__result
33  def runsandlsStr(self):
34  '''return expanded {'run':lslist}
35  '''
36  return self.__strresult
37  def numruns(self):
38  return len(self.__result)
39  def numls(self,run):
40  return len(self.__result[run])
41 if __name__ == "__main__":
42  s=selectionParser('{"1":[[3,45]],"2":[[4,8],[10,10]],"3":[[]]}')
43  print('runs : ',s.runs())
44  print('full result : ',s.runsandls())
45  print('str result : ',s.runsandlsStr())
46  print('num runs : ',s.numruns())
47  print('numls in run : ',s.numls(1))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def __init__(self, selectStr)