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