Belle II Software development
caf_multiple_collections.py
1
11
12import basf2 as b2
13
14import os
15import sys
16
17from caf.framework import Calibration, CAF, Collection
18from caf import backends
19
20b2.set_log_level(b2.LogLevel.INFO)
21
22
23def main(argv):
24 if len(argv) == 2:
25 data_dir_1 = argv[0]
26 data_dir_2 = argv[1]
27 else:
28 print("Usage: python3 caf_multiple_collections.py <data directory 1> <data directory 2>")
29 sys.exit(1)
30
31 # In this script we want to use two different sources of input data, and reconstruct them
32 # differently before the Collector module runs. So we will need
33 #
34 # 1) Two sets of input data files
35 # 2) Two pre_collector paths for reconstruction
36 # 3) Two instances of a Collector module (using the same prefix/name)
37 # 4) Two database chains to use
38
39
43 input_files_1 = [os.path.join(os.path.abspath(data_dir_1), '*.root')]
44 input_files_2 = [os.path.join(os.path.abspath(data_dir_2), '*.root')]
45
46
50
51 col_test_1 = b2.register_module('CaTest')
52 col_test_1.set_name('Test') # Sets the prefix of collected data
53 col_test_1.param('granularity', 'all')
54 col_test_1.param('spread', 1)
55
56 col_test_2 = b2.register_module('CaTest')
57 col_test_2.set_name('Test') # Sets the prefix of collected data
58 col_test_2.param('granularity', 'all')
59 col_test_2.param('spread', 20)
60
61
65 rec_path_1 = b2.create_path()
66 rec_path_1.add_module('Gearbox')
67 rec_path_1.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'ARICH', 'BeamPipe', 'EKLM'])
68 # could now add reconstruction modules dependent on the type on input data
69
70 # Excluded CDC instead of ARICH
71 rec_path_2 = b2.create_path()
72 rec_path_2.add_module('Gearbox')
73 rec_path_2.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'CDC', 'BeamPipe', 'EKLM'])
74 # could now add reconstruction modules dependent on the type on input data
75
76
79 from ROOT import Belle2 # noqa: make the Belle2 namespace available
80 from ROOT.Belle2 import TestCalibrationAlgorithm
81 alg_test = TestCalibrationAlgorithm()
82 # Must have the same prefix as colllector prefixes. By default this algorithm and collectors
83 # have the correct prefixes if we hadn't changed anything. So this is unnecessary, but we're just showing you how it's done.
84 alg_test.setPrefix('Test')
85
86
94 collection_1 = Collection(collector=col_test_1,
95 input_files=input_files_1,
96 pre_collector_path=rec_path_1,
97 max_files_per_collector_job=1
98 # database_chain=[LocalDatabase('path/to/database.txt'), CentralDatabase('global_tag')],
99 # output_patterns=["CollectorOutput.root"], Does your collector output something else
100 # you want passed to the algorithm?
101 # backend_args={'queue': 's'} Only necessary for LSF/PBS backends
102 )
103 # If you have some local databases or want to override the default global tag for this Collection you can do that
104 # with these functions
105 # collection_1.reset_database()
106 # collection_1.use_local_database("mylocaldb/database.txt")
107 # collection_1.use_central_database("BelleII_GlobalTag_Tutorial")
108
109 collection_2 = Collection(collector=col_test_2,
110 input_files=input_files_2,
111 pre_collector_path=rec_path_2,
112 max_files_per_collector_job=1
113 )
114
115
120 cal_test = Calibration('TestCalibration')
121 # Add collections in with unique names
122 cal_test.add_collection(name='collection_1', collection=collection_1)
123 cal_test.add_collection(name='collection_2', collection=collection_2)
124 cal_test.algorithms = alg_test
125
126
141
142
144 cal_fw = CAF()
145 cal_fw.add_calibration(cal_test)
146 cal_fw.backend = backends.Local(max_processes=4)
147 cal_fw.run()
148 print("End of CAF processing.")
149
150
151if __name__ == "__main__":
152 main(sys.argv[1:])
Definition: main.py:1