Belle II Software  release-08-01-10
caf_multiple_collections.py
1 
11 
12 import basf2 as b2
13 
14 import os
15 import sys
16 
17 from ROOT.Belle2 import TestCalibrationAlgorithm
18 
19 from caf.framework import Calibration, CAF, Collection
20 from caf import backends
21 
22 b2.set_log_level(b2.LogLevel.INFO)
23 
24 
25 def main(argv):
26  if len(argv) == 2:
27  data_dir_1 = argv[0]
28  data_dir_2 = argv[1]
29  else:
30  print("Usage: python3 caf_multiple_collections.py <data directory 1> <data directory 2>")
31  sys.exit(1)
32 
33  # In this script we want to use two different sources of input data, and reconstruct them
34  # differently before the Collector module runs. So we will need
35  #
36  # 1) Two sets of input data files
37  # 2) Two pre_collector paths for reconstruction
38  # 3) Two instances of a Collector module (using the same prefix/name)
39  # 4) Two database chains to use
40 
41 
45  input_files_1 = [os.path.join(os.path.abspath(data_dir_1), '*.root')]
46  input_files_2 = [os.path.join(os.path.abspath(data_dir_2), '*.root')]
47 
48 
52 
53  col_test_1 = b2.register_module('CaTest')
54  col_test_1.set_name('Test') # Sets the prefix of collected data
55  col_test_1.param('granularity', 'all')
56  col_test_1.param('spread', 1)
57 
58  col_test_2 = b2.register_module('CaTest')
59  col_test_2.set_name('Test') # Sets the prefix of collected data
60  col_test_2.param('granularity', 'all')
61  col_test_2.param('spread', 20)
62 
63 
67  rec_path_1 = b2.create_path()
68  rec_path_1.add_module('Gearbox')
69  rec_path_1.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'ARICH', 'BeamPipe', 'EKLM'])
70  # could now add reconstruction modules dependent on the type on input data
71 
72  # Excluded CDC instead of ARICH
73  rec_path_2 = b2.create_path()
74  rec_path_2.add_module('Gearbox')
75  rec_path_2.add_module('Geometry', excludedComponents=['SVD', 'PXD', 'CDC', 'BeamPipe', 'EKLM'])
76  # could now add reconstruction modules dependent on the type on input data
77 
78 
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 
151 if __name__ == "__main__":
152  main(sys.argv[1:])
Definition: main.py:1
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91