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