Belle II Software development
tools.py
1#!/usr/bin/env python3
2
3
10
11import configparser
12import urllib.request
13import re
14import sys
15
16
17def readConfigFile_mc():
18
19 config = configparser.ConfigParser()
20 config.read(sys.argv[1])
21
22 thresholdEventsNo = int(config['Config']['thresholdEventsNo'])
23 expNoList = list(map(int, config['Config']['expNo'].split(',')))
24 eventTypeList = list(map(str, config['Config']['eventType'].split(',')))
25 dataTypeList = list(map(str, config['Config']['dataType'].split(',')))
26 belleLevelList = list(map(str, config['Config']['belleLevel'].split(',')))
27
28 return thresholdEventsNo, expNoList, eventTypeList, dataTypeList, belleLevelList
29
30
31def readConfigFile_data():
32
33 config = configparser.ConfigParser()
34 config.read(sys.argv[1])
35
36 runsPerJob = int(config['Config']['runsPerJob'])
37 expNoList = list(map(int, config['Config']['expNo'].split(',')))
38 skimTypeList = list(map(str, config['Config']['skimType'].split(',')))
39 dataTypeList = list(map(str, config['Config']['dataType'].split(',')))
40 belleLevelList = list(map(str, config['Config']['belleLevel'].split(',')))
41
42 return runsPerJob, expNoList, skimTypeList, dataTypeList, belleLevelList
43
44
45def countEventsInUrl(link):
46 aFile = urllib.request.urlopen(link)
47 # put webpage content into string format
48 fileStr = str(aFile.read(), 'utf-8')
49 # get everything after 'Total events' string
50 nEventsStr = fileStr.split("Total events: ")[1].split()[0]
51 # get the actual number of events
52 nEvents = int(re.search(r'\d+', nEventsStr).group())
53 return nEvents
54
55
56def getBelleUrl_mc(expNo, startRun, endRun, eventType, dataType, belleLevel, streamNo):
57 header = 'http://bweb3/montecarlo.php?'
58 return header +\
59 'ex=' + str(expNo) +\
60 '&rs=' + str(startRun) +\
61 '&re=' + str(endRun) +\
62 '&ty=' + eventType +\
63 '&dt=' + dataType +\
64 '&bl=' + belleLevel +\
65 '&st=' + str(streamNo)
66
67
68def getBelleUrl_data(expNo, startRun, endRun, skimType, dataType, belleLevel):
69
70 header = 'http://bweb3/mdst.php?'
71 return header +\
72 'ex=' + str(expNo) +\
73 '&rs=' + str(startRun) +\
74 '&re=' + str(endRun) +\
75 '&skm=' + skimType +\
76 '&dt=' + dataType +\
77 '&bl=' + belleLevel
78
79
80def addLine(tableFile, aList):
81 writeStr = ''
82 for el in aList:
83 writeStr += str(el) + '\t'
84 writeStr += '\n'
85 tableFile.write(writeStr)
86 print('Added line to table: ' + writeStr)
87
88
89def getMaxRunNo_mc(expNo):
90
91 maxRunNoDict = {
92 65: 900,
93 63: 800,
94 61: 1300,
95 55: 1800,
96 51: 1900,
97 49: 1000,
98 47: 900,
99 45: 500,
100 43: 1200,
101 41: 1300,
102 39: 1400,
103 37: 2000,
104 35: 700,
105 33: 900,
106 31: 1800,
107 27: 1700,
108 25: 2200,
109 23: 700,
110 21: 400,
111 19: 1800,
112 17: 1000,
113 15: 1500,
114 13: 1700,
115 11: 1400,
116 9: 1300,
117 7: 2900}
118
119 return int(maxRunNoDict.get(expNo))
120
121
122def getMaxRunNo_data(expNo):
123
124 maxRunNoDict = {
125
126 7: 2865,
127 9: 1220,
128 11: 1367,
129 13: 1627,
130 15: 1437,
131 17: 937,
132 19: 1709,
133 21: 324,
134 23: 607,
135 25: 2122,
136 27: 1632,
137 31: 1715,
138 33: 870,
139 35: 687,
140 37: 1913,
141 39: 1357,
142 41: 1261,
143 43: 1149,
144 45: 450,
145 47: 881,
146 49: 1227,
147 51: 1805,
148 53: 272,
149 55: 1749,
150 61: 1373,
151 63: 783,
152 65: 1232,
153 67: 1123,
154 69: 1397,
155 71: 2292,
156 73: 916}
157
158 return int(maxRunNoDict.get(expNo))