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