Belle II Software development
klm_strategies_common.py
1
8
9"""Common functions for KLM calibration strategies."""
10
11import basf2
12from caf.utils import ExpRun
13
14
15def calibration_result_string(result):
16 """
17 Convert calibration result to text message.
18 Parameters:
19 result (int): Calibration result.
20 """
21 if (result == 0):
22 res = 'successful'
23 elif (result == 1):
24 res = 'iteration is necessary'
25 elif (result == 2):
26 res = 'not enough data'
27 elif (result == 3):
28 res = 'failure'
29 elif (result == 4):
30 res = 'undefined'
31 return res
32
33
34def get_lowest_exprun(number_of_experiments, experiment_index, run_list,
35 iov_coverage):
36 """
37 Get lowest experiment and run numbers.
38 Parameters:
39 number_of_experiments (int): Number of experiments.
40 experiment_index (int): 1-based experiment index.
41 run_list (list[ExpRun]): List of runs for the selected experiment.
42 iov_coverage (IoV): IOV coverage.
43 """
44 if iov_coverage and experiment_index == 1:
45 lowest_exprun = ExpRun(iov_coverage.exp_low, iov_coverage.run_low)
46 if lowest_exprun > run_list[0]:
47 basf2.B2WARNING(f'The lowest run {run_list[0]} of input data is '
48 f'smaller than the lowest run {lowest_exprun} of '
49 'the requested IOV coverage. The IOV coverage is '
50 'extended.')
51 lowest_exprun = run_list[0]
52 else:
53 lowest_exprun = run_list[0]
54 # Start from the beginning of experiments except the first one.
55 if (experiment_index > 1):
56 lowest_exprun = ExpRun(lowest_exprun.exp, 0)
57 return lowest_exprun
58
59
60def get_highest_exprun(number_of_experiments, experiment_index, run_list,
61 iov_coverage):
62 """
63 Get highest experiment and run numbers.
64 Parameters:
65 number_of_experiments (int): Number of experiments.
66 experiment_index (int): 1-based experiment index.
67 run_list (list[ExpRun]): List of runs for the selected experiment.
68 iov_coverage (IoV): IOV coverage.
69 """
70 if iov_coverage and experiment_index == number_of_experiments:
71 highest_exprun = ExpRun(iov_coverage.exp_high, iov_coverage.run_high)
72 if (highest_exprun < run_list[-1] and
73 not ((iov_coverage.exp_high == -1) or
74 (iov_coverage.exp_high == run_list[-1].exp and
75 iov_coverage.run_high == -1))):
76 basf2.B2WARNING(f'The highest run {run_list[-1]} of input data is '
77 f'larger than the highest run {highest_exprun} of '
78 'the requested IOV coverage. The IOV coverage is '
79 'extended.')
80 highest_exprun = run_list[-1]
81 else:
82 highest_exprun = run_list[-1]
83 # Extend the IOV to the end of experiments except the last one.
84 if (experiment_index < number_of_experiments):
85 highest_exprun = ExpRun(highest_exprun.exp, -1)
86 return highest_exprun