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