Belle II Software  release-05-01-25
caf_multiple_collections.py
1 # This steering file shows off how you can configure a single Calibration to run
2 # multiple different Collector configurations. Using different database chains,
3 # different Collector module configs, different input files etc.
4 
5 import basf2 as b2
6 
7 import os
8 import sys
9 
10 from ROOT.Belle2 import TestCalibrationAlgorithm
11 
12 from caf.framework import Calibration, CAF, Collection
13 from caf import backends
14 
15 b2.set_log_level(b2.LogLevel.INFO)
16 
17 
18 def main(argv):
19  if len(argv) == 2:
20  data_dir_1 = argv[0]
21  data_dir_2 = argv[1]
22  else:
23  print("Usage: python3 caf_multiple_collections.py <data directory 1> <data directory 2>")
24  sys.exit(1)
25 
26  # In this script we want to use two different sources of input data, and reconstruct them
27  # differently before the Collector module runs. So we will need
28  #
29  # 1) Two sets of input data files
30  # 2) Two pre_collector paths for reconstruction
31  # 3) Two instances of a Collector module (using the same prefix/name)
32  # 4) Two database chains to use
33 
34 
38  input_files_1 = [os.path.join(os.path.abspath(data_dir_1), '*.root')]
39  input_files_2 = [os.path.join(os.path.abspath(data_dir_2), '*.root')]
40 
41 
45 
46  col_test_1 = b2.register_module('CaTest')
47  col_test_1.set_name('Test') # Sets the prefix of collected data
48  col_test_1.param('granularity', 'all')
49  col_test_1.param('spread', 1)
50 
51  col_test_2 = b2.register_module('CaTest')
52  col_test_2.set_name('Test') # Sets the prefix of collected data
53  col_test_2.param('granularity', 'all')
54  col_test_2.param('spread', 20)
55 
56 
60  rec_path_1 = b2.create_path()
61  rec_path_1.add_module('Gearbox')
62  rec_path_1.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'ARICH', 'BeamPipe', 'EKLM'])
63  # could now add reconstruction modules dependent on the type on input data
64 
65  # Excluded CDC instead of ARICH
66  rec_path_2 = b2.create_path()
67  rec_path_2.add_module('Gearbox')
68  rec_path_2.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'CDC', 'BeamPipe', 'EKLM'])
69  # could now add reconstruction modules dependent on the type on input data
70 
71 
74  alg_test = TestCalibrationAlgorithm()
75  # Must have the same prefix as colllector prefixes. By default this algorithm and collectors
76  # have the correct prefixes if we hadn't changed anything. So this is unnecessary, but we're just showing you how it's done.
77  alg_test.setPrefix('Test')
78 
79 
87  collection_1 = Collection(collector=col_test_1,
88  input_files=input_files_1,
89  pre_collector_path=rec_path_1,
90  max_files_per_collector_job=1
91  # database_chain=[LocalDatabase('path/to/database.txt'), CentralDatabase('global_tag')],
92  # output_patterns=["CollectorOutput.root"], Does your collector output something else
93  # you want passed to the algorithm?
94  # backend_args={'queue': 's'} Only necessary for LSF/PBS backends
95  )
96  # If you have some local databases or want to override the default global tag for this Collection you can do that
97  # with these functions
98  # collection_1.reset_database()
99  # collection_1.use_local_database("mylocaldb/database.txt")
100  # collection_1.use_central_database("BelleII_GlobalTag_Tutorial")
101 
102  collection_2 = Collection(collector=col_test_2,
103  input_files=input_files_2,
104  pre_collector_path=rec_path_2,
105  max_files_per_collector_job=1
106  )
107 
108 
113  cal_test = Calibration('TestCalibration')
114  # Add collections in with unique names
115  cal_test.add_collection(name='collection_1', collection=collection_1)
116  cal_test.add_collection(name='collection_2', collection=collection_2)
117  cal_test.algorithms = alg_test
118 
119 
134 
135 
137  cal_fw = CAF()
138  cal_fw.add_calibration(cal_test)
139  cal_fw.backend = backends.Local(max_processes=4)
140  cal_fw.run()
141  print("End of CAF processing.")
142 
143 
144 if __name__ == "__main__":
145  main(sys.argv[1:])
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Collection
Definition: Collection.py:1
Calibration
Definition: Calibration.py:1
backends.Local
Definition: backends.py:878