Belle II Software development
caf_lsf_backend.py
1
12
13# Not all of the configuration is strictly necessary, it's just to show some options
14
15import basf2 as b2
16
17import os
18import sys
19
20from caf.framework import Calibration, CAF
21from caf import backends
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_lsf_backend.py <data directory>")
31 sys.exit(1)
32
33
37 input_files_test = [os.path.join(os.path.abspath(data_dir), '*.root')]
38
39 from caf.strategies import SequentialRunByRun
40
43 calibrations = []
44 for i in range(1, 3):
45 col_test = b2.register_module('CaTest')
46 col_test.set_name(f'Test{i}') # Sets the prefix of the collected data in the datastore
47 col_test.param('spread', 15) # Proportional to the probability of algorithm requesting iteration
48 col_test.param('granularity', 'run') # Allows us to execute algorithm over all data, in one big IoV
49
50 from ROOT import Belle2 # noqa: make the Belle2 namespace available
51 from ROOT.Belle2 import TestCalibrationAlgorithm
52 alg_test = TestCalibrationAlgorithm()
53 # Since we're using several instances of the same test algorithm here, we still want the database entries to have
54 # different names. TestCalibrationAlgorithm outputs to the database using the prefix name so we change it
55 # slightly for each calibration. Not something you'd usually have to do.
56 alg_test.setPrefix(f'Test{i}') # Must be the same as colllector prefix
57
58 cal_test = Calibration(name=f'TestCalibration{i}',
59 collector=col_test,
60 algorithms=alg_test,
61 input_files=input_files_test)
62
63 # Some optional configuration ####
64 # By default all input files are placed in one big job (-1), this allows you to specify a maximum so that
65 # subjobs for each set of input files will be created
66 cal_test.max_files_per_collector_job = 1
67 # Some backends can have arguments passed to them e.g. queue type
68 cal_test.backend_args = {"queue": "s"}
69 # The maximum iteration number you will be allowed to reach before the Calibration just completes
70 cal_test.max_iterations = 2
71 # Since we're using the LSF batch system we'll up the heartbeat from the default to query for when the jobs are all finished
72 # No point spamming it
73 cal_test.heartbeat = 15
74 # The interval in seconds between full updates of the remaining collector jobs, default = 30
75 # Checking every subjob can be a long process when you have a lot of them so it's best not to do it too often
76 # After this interval the finished/remaining collector jobs will be printed
77 cal_test.collector_full_update_interval = 30
78 # Choosing an AlgorithmStrategy for each algorithm (here we just use the same for all of them)
79 cal_test.strategies = SequentialRunByRun
80 # The collector output file patterns you want to make sure are tracked by the CAF. By default only CollectorOutput.root
81 # is used. All files are passed to the Algorithm.data_input function in order to set the input files of the algorithm
82 cal_test.output_patterns.append("*.mille")
83
84 calibrations.append(cal_test)
85
86
88 cal_fw = CAF()
89 # Add in our list of calibrations
90 for cal in calibrations:
91 cal_fw.add_calibration(cal)
92
93 cal_fw.backend = backends.LSF()
94 # Start running
95 cal_fw.run()
96 print("End of CAF processing.")
97
98
99if __name__ == "__main__":
100 main(sys.argv[1:])
Definition: main.py:1