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