test
Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
RecoLuminosity
LumiDB
python
csvSelectionParser.py
Go to the documentation of this file.
1
import
csv
2
def
is_intstr
(s):
3
try
:
4
int(s)
5
return
True
6
except
ValueError:
7
return
False
8
class
csvSelectionParser
(
object
):
9
def
__init__
(self,filename):
10
self.
__result
={}
11
self.
__strresult
={}
12
self.
__filename
=filename
13
csvReader=csv.reader(open(filename),delimiter=
','
)
14
for
row
in
csvReader:
15
field0=str(row[0]).strip()
16
try
:
17
field1=str(row[1]).strip()
18
except
Exception,e:
19
field1=
'1'
# for list with run number only, fake lsnum
20
if
not
is_intstr
(field0)
or
not
is_intstr
(field1):
21
continue
22
runnumber=int(field0)
23
lsnumber=int(field1)
24
if
self.__result.has_key(runnumber):
25
self.
__result
[runnumber].
append
(lsnumber)
26
else
:
27
self.
__result
[runnumber]=[lsnumber]
28
for
k,lsvalues
in
self.__result.items():
29
lsvalues.sort()
30
self.
__strresult
[k]=[str(x)
for
x
in
lsvalues]
31
def
runs
(self):
32
return
self.__result.keys()
33
def
runsandls
(self):
34
'''return {run:lslist}
35
'''
36
return
self.
__result
37
def
runsandlsStr
(self):
38
'''return {'run':lslist}
39
'''
40
return
self.
__strresult
41
def
numruns
(self):
42
return
len(self.__result.keys())
43
def
numls
(self,run):
44
return
len(self.
__result
[run])
45
46
if
__name__ ==
'__main__'
:
47
result={}
48
#filename='../test/lumi_by_LS_all.csv'
49
filename=
'../test/newruns.csv'
50
s=
csvSelectionParser
(filename)
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(135175)
56
csvSelectionParser.csvSelectionParser.runsandlsStr
def runsandlsStr
Definition:
csvSelectionParser.py:37
csvSelectionParser.csvSelectionParser.numruns
def numruns
Definition:
csvSelectionParser.py:41
python.multivaluedict.append
def append
Definition:
multivaluedict.py:73
csvSelectionParser.csvSelectionParser.__filename
__filename
Definition:
csvSelectionParser.py:12
csvSelectionParser.csvSelectionParser.numls
def numls
Definition:
csvSelectionParser.py:43
csvSelectionParser.is_intstr
def is_intstr
Definition:
csvSelectionParser.py:2
csvSelectionParser.csvSelectionParser.__init__
def __init__
Definition:
csvSelectionParser.py:9
csvSelectionParser.csvSelectionParser
Definition:
csvSelectionParser.py:8
dbtoconf.object
list object
Definition:
dbtoconf.py:77
csvSelectionParser.csvSelectionParser.runsandls
def runsandls
Definition:
csvSelectionParser.py:33
csvSelectionParser.csvSelectionParser.__result
__result
Definition:
csvSelectionParser.py:10
csvSelectionParser.csvSelectionParser.__strresult
__strresult
Definition:
csvSelectionParser.py:11
csvSelectionParser.csvSelectionParser.runs
def runs
Definition:
csvSelectionParser.py:31
Generated for CMSSW Reference Manual by
1.8.5