Belle II Software development
caf_strategies.py
1
12
13import basf2 as b2
14
15import os
16import sys
17
18from ROOT.Belle2 import TestCalibrationAlgorithm
19from caf.framework import Calibration, CAF
20
21b2.set_log_level(b2.LogLevel.INFO)
22# add time stamp to all INFO messages
23# currentInfo = logging.get_info(LogLevel.INFO)
24# logging.set_info(LogLevel.INFO, currentInfo | LogInfo.TIMESTAMP)
25
26
27def main(argv):
28 if len(argv) == 1:
29 data_dir = argv[0]
30 else:
31 print("Usage: basf2 CAF_simplest.py <data directory>")
32 sys.exit(1)
33
34
39 input_files_test = []
40 input_files_test.append(os.path.join(os.path.abspath(data_dir), '*.root'))
41
42
44 alg_test = TestCalibrationAlgorithm() # Getting a calibration algorithm instance
45 alg_test.setMinEntries(15000) # This algorithm provides a setting to change when c_NotEnoughData is returned
46
47 # Create a single calibration from a collector module name + algorithm + input files
48 cal_test = Calibration(name="TestCalibration", collector="CaTest", algorithms=alg_test, input_files=input_files_test)
49
50 # Here we set the AlgorithmStrategy for our algorithm
51 from caf.strategies import SingleIOV, SequentialRunByRun, SimpleRunByRun, SequentialBoundaries # noqa
52 # The default value is SingleIOV, you don't have to set this, it is done automatically.
53 # SingleIOV just takes all of the runs as one big IoV and executes the algorithm once on all of their data.
54 # You can use granularity='run' or granularity='all' for the collector when using this strategy.
55
56 # cal_test.strategies = SingleIOV
57
58 # The SequentialRunByRun strategy executes your algorithm over runs
59 # individually to give you payloads for each one (if successful)
60 # If there wasn't enough data in a run to give a success, it tries to merge with the next run's data
61 # and re-execute.
62 # You should only use granularity='run' for the collector when using this strategy.
63
64 cal_test.strategies = SequentialRunByRun
65
66 # The SimpleRunByRun strategy executes your algorithm over runs
67 # individually to give you payloads for each one (if successful)
68 # It will not do any merging of runs which didn't contain enough data.
69 # So failure is expected if your algorithm requires a large amount of data compared to run length.
70 # You should only use granularity='run' for the collector when using this strategy.
71
72 # cal_test.strategies = SimpleRunByRun
73
74 # The SequentialBoundaries strategy executes your algorithm over all
75 # the runs in a time period contained between two boundaries to give
76 # you payloads for each one time period (if successful)
77 # If there wasn't enough data in a run to give a success, it tries to
78 # merge with the next time period's data and re-execute.
79 # You should only use granularity='run' for the collector when using this strategy.
80 # The run Boundaries can be either passed directy in the parameter dictionary
81 # of the algorithm (key `payload_boundaries`) or calculated by the algorithm itself
82 # in the function `isBoundaryRequired`.
83
84 # cal_test.strategies = SequentialBoundaries
85 # cal_test.algorithms[0].params = {"payload_boundaries" : [(0,1), (0,4), (0,7)]}
86
87
89 cal_fw = CAF()
90 cal_fw.add_calibration(cal_test)
91 cal_fw.run()
92 print("End of CAF processing.")
93
94
95if __name__ == "__main__":
96 main(sys.argv[1:])
Definition: main.py:1