Belle II Software development
caf_htcondor_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_htcondor_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
42 from ROOT import Belle2 # noqa: make the Belle2 namespace available
43 from ROOT.Belle2 import TestCalibrationAlgorithm
44 # Make a bunch of test calibrations
45 calibrations = []
46 for i in range(1, 3):
47 col_test = b2.register_module('CaTest')
48 col_test.set_name(f'Test{i}') # Sets the prefix of the collected data in the datastore
49 col_test.param('spread', 15) # Proportional to the probability of algorithm requesting iteration
50 col_test.param('granularity', 'run') # Allows us to execute algorithm over all data, in one big IoV
51
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 collector 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. requested job memory
68 cal_test.backend_args = {"request_memory": "2 GB"}
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 = 300
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 # Use the HTCondor backend setup, can view the default options in calibration/data/backends.cfg
93 cal_fw.backend = backends.HTCondor()
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