Belle II Software light-2406-ragdoll
createLookUpTable_mc.py
1#!/usr/bin/env python3
2
3
10
11import os
12import sys
13from tools import getMaxRunNo_mc, getBelleUrl_mc, readConfigFile_mc, countEventsInUrl, addLine
14
15# print debug messages ?
16debug = False
17debugCounter = 0
18
19if len(sys.argv) == 1:
20 sys.exit('Need one argument: path of config file with job parameters !')
21
22# read jobs parameters from config file
23thresholdEventsNo, expNoList, eventTypeList, dataTypeList, belleLevelList =\
24 readConfigFile_mc()
25
26# create output directory for tables if it doesn't exist
27if not os.path.exists('tables'):
28 os.makedirs('tables')
29
30# open table and write in it
31# table name contains threshold for events number of each job
32tableName = 'tables/lookUpTable_mc_' + \
33 str(int(thresholdEventsNo / 1000)) + 'k.txt'
34f = open(tableName, 'w')
35
36# write one line for each job we submit
37# grouping the smallest set of runs that has more than Nthreshold events
38for expNo in expNoList:
39
40 absMaxRunNo = getMaxRunNo_mc(expNo)
41 if absMaxRunNo is None:
42 sys.exit('ExpNo ' + str(expNo) + ' not found. Does it exist ?')
43
44 if debug:
45 print('For expNo ' + str(expNo) + ' max runNo is ' + str(absMaxRunNo))
46
47 if expNo in range(7, 28):
48 streamNo_dummy = 10
49 elif expNo in range(31, 66):
50 streamNo_dummy = 0
51
52 for eventType in eventTypeList:
53 for dataType in dataTypeList:
54 for belleLevel in belleLevelList:
55
56 minRunNo = 1
57 while minRunNo < absMaxRunNo: # stop searching for runs after maxRunNo
58
59 maxRunNo = minRunNo + 1
60
61 # create the smallest set of runs that has more than
62 # Nthreshold events
63 for add in range(1, 1000):
64
65 maxRunNo = minRunNo + add
66
67 thisUrl = getBelleUrl_mc(expNo, minRunNo, maxRunNo,
68 eventType, dataType,
69 belleLevel, streamNo_dummy)
70
71 if debug:
72 print('Checking up url: ' + thisUrl)
73
74 thisUrlCount = countEventsInUrl(thisUrl)
75 if debug:
76 print('Count is up to: ' + str(thisUrlCount))
77
78 if maxRunNo > absMaxRunNo or thisUrlCount > thresholdEventsNo:
79 break
80
81 addLine(f, [expNo, eventType,
82 dataType, belleLevel,
83 minRunNo, maxRunNo])
84
85 debugCounter += 1
86 if debug and debugCounter > 2:
87 f.close()
88 sys.exit('Debug')
89
90 minRunNo = maxRunNo + 1
91
92f.close()