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