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