Belle II Software release-09-00-00
caf_ignoring_runs_sequential.py
1
10
11import basf2 as b2
12
13import os
14import sys
15
16from ROOT.Belle2 import TestCalibrationAlgorithm
17
18from caf.framework import Calibration, CAF
19from caf.utils import ExpRun, IoV
20from caf.strategies import SequentialRunByRun
21from caf.backends import Local
22
23b2.set_log_level(b2.LogLevel.INFO)
24
25
26def main(argv):
27 if len(argv) == 1:
28 data_dir = argv[0]
29 else:
30 print("Usage: python3 caf_ignoring_runs.py <data directory>")
31 sys.exit(1)
32
33
36 input_files_test = [os.path.join(os.path.abspath(data_dir), '*.root')]
37
38
40
41 # Make a bunch of test calibrations
42 col_test = b2.register_module('CaTest')
43 # Specific parameter to our test collector, proportional to the probability of algorithm requesting iteration.
44 col_test.param('spread', 15)
45
46 alg_test = TestCalibrationAlgorithm()
47 # We want to see what happens when c_NotEnoughData is returned
48 alg_test.setMinEntries(10000)
49
50 cal_test = Calibration(name='TestCalibration',
51 collector=col_test,
52 algorithms=alg_test,
53 input_files=input_files_test)
54
55 # We don't want to run collector jobs on these runs (if possible) and we don't want the algorithm to use data from
56 # these runs. However, the algorithm strategy may also merge IoVs across the gaps left by the ignored runs.
57 # What the strategy does with missing runs depends on the AlgorithmStrategy and any configuration you have made.
58 cal_test.ignored_runs = [ExpRun(0, 2), ExpRun(0, 3)]
59
60 # We use a different algorithm strategy for every algorithm (only one) in this Calibration
61 cal_test.strategies = SequentialRunByRun
62
63 # This parameter is used by SequentialRunByRun to define a total IoV that the combination of all IoVs defines.
64 # It must be strictly larger than the IoV of all input data, OR the IoV in cal_fw.run(iov=...) if defined.
65 # This allows us to define a larger total IoV so that the first payload IoV MUST START at the ExpRun(exp_low, run_low)
66 # and the final IoV MUST END at ExpRun(exp_high, run_high) e.g.
67 #
68 # Here we define iov_coverage = IoV(0, 1, 0, 15). This means that the first payload created will be of the form
69 # IoV(0, 1, ?, ?) where we don't yet know what the highest (exp,run) will be as it depends on the data.
70 # The last payload we create must have the form IoV(?, ?, 0, 15) but we can't yet know the lowest (exp,run)
71 #
72 # It is entirely possible that in the final database there will be only one payload of IoV(0, 1, 0, 15), or
73 # several such as [IoV(0, 1, 0, 5), IoV(0, 6, 0, 10), IoV(0, 11, 0, 15)]
74 cal_test.algorithms[0].params["iov_coverage"] = IoV(0, 1, 0, 15)
75
76 # This parameter defines the step size of the SequentialRunByRun strategy i.e. how many runs of data we add
77 # each time we execute.
78 # So initially an execution of the algorithm will use this many runs-worth of data (if possible).
79 # If c_NotEnoughData is returned on this execution, we will add the next 'step_size' number of runs and execute again.
80 # Then repeat until we get c_Iterate or c_OK.
81 #
82 # The default value is 1.
83 cal_test.algorithms[0].params["step_size"] = 1
84
85 cal_test.max_files_per_collector_job = 1
86
87
89 cal_fw = CAF()
90
91 # You could alternatively set the same ignored_runs for every Calibration by setting it here.
92 # Note that setting cal_test.ignored_runs will override the value set from here.
93
94 # cal_fw = CAF(calibration_defaults={'ignored_runs':[ExpRun(0,2), ExpRun(0, 3)])
95
96 cal_fw.add_calibration(cal_test)
97 cal_fw.backend = Local(max_processes=4)
98
99 # The iov value here allows you to set an IoV that all your input files/executed runs must overlap.
100 # Any input files not overlapping this IoV will be ignored.
101 # HOWEVER, if you have an input file containing multiple runs the file IoV may overlap this IoV. But it may still
102 # contain runs outside of it.
103 # In this case the CAF will still use the file in collector jobs, BUT any runs collected will not be used in the
104 # algorithm step if they exist outside of this IoV.
105 #
106 # To explicitly prevent certain runs from within this IoV being used, you should use the ignored_runs
107 # attribute of the Calibration. Or make sure that the input data files do not contain data from those runs at all.
108 cal_fw.run(iov=IoV(0, 3, 0, 11))
109 print("End of CAF processing.")
110
111
112if __name__ == "__main__":
113 main(sys.argv[1:])
Definition: main.py:1