9"""A complicated example calibration that takes several input data lists from raw data and performs
10multiple calibrations. Only the second calibration will have its payloads placed into the final
11outputdb directory by b2caf-prompt-run.
13We make it so that this calibration depends on the result of a completely
14different one 'example_simple'. Even though that calibration will not be run in this process, the automated
15system can discover this dependency and use it when submitting tasks."""
17from prompt
import CalibrationSettings, INPUT_DATA_FILTERS
29from prompt.calibrations.example_simple
import settings
as example_simple
32settings = CalibrationSettings(name=
"Example Complex",
33 expert_username=
"ddossett",
35 input_data_formats=[
"raw"],
36 input_data_names=[
"physics",
"cosmics",
"Bcosmics"],
37 input_data_filters={
"physics": [f
"NOT {INPUT_DATA_FILTERS['Magnet']['On']}",
38 INPUT_DATA_FILTERS[
"Data Tag"][
"hadron_calib"],
39 INPUT_DATA_FILTERS[
"Data Quality Tag"][
"Good"],
40 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"],
41 INPUT_DATA_FILTERS[
"Run Type"][
"physics"]],
42 "cosmics": [INPUT_DATA_FILTERS[
'Magnet'][
'Off'],
43 INPUT_DATA_FILTERS[
"Data Tag"][
"cosmic_calib"],
44 INPUT_DATA_FILTERS[
"Data Quality Tag"][
"Bad For Alignment"],
45 INPUT_DATA_FILTERS[
"Beam Energy"][
"Continuum"],
46 f
"NOT {INPUT_DATA_FILTERS['Run Type']['physics']}"],
47 "Bcosmics": [INPUT_DATA_FILTERS[
"Data Tag"][
"cosmic_calib"],
48 INPUT_DATA_FILTERS[
"Data Quality Tag"][
"Good"],
49 INPUT_DATA_FILTERS[
"Beam Energy"][
"4S"]]},
50 depends_on=[example_simple],
52 "physics_prescale": 0.2,
53 "max_events_per_file": 100,
54 "max_files_per_run": 2,
55 "payload_boundaries": []
76def get_calibrations(input_data, **kwargs):
79 input_data (dict): Should contain every name from the
'input_data_names' variable
as a key.
80 Each value
is a dictionary
with {
"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful
for
81 assigning to calibration.files_to_iov
83 **kwargs: Configuration options to be sent
in. Since this may change we use kwargs
as a way to help prevent
84 backwards compatibility problems. But you could use the correct arguments
in b2caf-prompt-run
for this
85 release explicitly
if you want to.
87 Currently only kwargs[
"requested_iov"]
and kwargs[
"expert_config"] are used.
89 "requested_iov" is the IoV range of the bucket
and your payloads should correspond to this range.
90 However your highest payload IoV should be open ended e.g. IoV(3,4,-1,-1)
92 "expert_config" is the input configuration. It takes default values
from your `CalibrationSettings` but these are
93 overwritten by values
from the
'expert_config' key
in your input `caf_config.json` file when running ``b2caf-prompt-run``.
96 list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
100 from basf2
import register_module, create_path
101 from ROOT
import Belle2
102 from ROOT.Belle2
import TestCalibrationAlgorithm, TestBoundarySettingAlgorithm
103 from caf.framework
import Calibration, Collection
104 from caf.strategies
import SequentialBoundaries
105 from caf.utils
import vector_from_runs, ExpRun, IoV
111 file_to_iov_physics = input_data[
"physics"]
112 file_to_iov_cosmics = input_data[
"cosmics"]
113 file_to_iov_Bcosmics = input_data[
"Bcosmics"]
118 expert_config = kwargs.get(
"expert_config")
119 max_files_per_run = expert_config[
"max_files_per_run"]
120 basf2.B2INFO(f
"Reducing to a maximum of {max_files_per_run} files per run.")
126 reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
127 input_files_physics = list(reduced_file_to_iov_physics.keys())
128 basf2.B2INFO(f
"Total number of physics files actually used as input = {len(input_files_physics)}")
130 reduced_file_to_iov_cosmics = filter_by_max_files_per_run(file_to_iov_cosmics, max_files_per_run)
131 input_files_cosmics = list(reduced_file_to_iov_cosmics.keys())
132 basf2.B2INFO(f
"Total number of cosmics files actually used as input = {len(input_files_cosmics)}")
134 reduced_file_to_iov_Bcosmics = filter_by_max_files_per_run(file_to_iov_Bcosmics, max_files_per_run)
135 input_files_Bcosmics = list(reduced_file_to_iov_Bcosmics.keys())
136 basf2.B2INFO(f
"Total number of Bcosmics files actually used as input = {len(input_files_Bcosmics)}")
140 requested_iov = kwargs.get(
"requested_iov",
None)
143 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
148 col_test_physics = register_module(
"CaTest")
151 col_test_physics.param(
"granularity",
"run")
152 col_test_physics.param(
"spread", 4)
154 col_test_Bcosmics = register_module(
"CaTest")
155 col_test_Bcosmics.param(
"granularity",
"all")
156 col_test_Bcosmics.param(
"spread", 1)
158 col_test_cosmics = register_module(
"CaTest")
159 col_test_cosmics.param(
"granularity",
"all")
160 col_test_cosmics.param(
"spread", 10)
169 max_events = expert_config[
"max_events_per_file"]
170 root_input = register_module(
"RootInput",
171 entrySequences=[f
"0:{max_events}"]
179 prescale = expert_config[
"physics_prescale"]
180 prescale_mod = register_module(
"Prescale", prescale=prescale)
181 empty_path = create_path()
182 prescale_mod.if_false(empty_path, basf2.AfterConditionPath.END)
184 rec_path_physics = create_path()
185 rec_path_physics.add_module(root_input)
186 rec_path_physics.add_module(prescale_mod)
189 rec_path_cosmics = create_path()
190 rec_path_cosmics.add_module(root_input)
193 rec_path_Bcosmics = create_path()
194 rec_path_Bcosmics.add_module(root_input)
200 alg_test1 = TestCalibrationAlgorithm()
201 alg_test2 = TestBoundarySettingAlgorithm()
212 payload_boundaries = [ExpRun(output_iov.exp_low, output_iov.run_low)]
215 payload_boundaries.extend([ExpRun(*boundary)
for boundary
in expert_config[
"payload_boundaries"]])
216 basf2.B2INFO(f
"Expert set payload boundaries are: {expert_config['payload_boundaries']}")
218 alg_test2.setBoundaries(vector_from_runs(payload_boundaries))
225 collection_physics =
Collection(collector=col_test_physics,
226 input_files=input_files_physics,
227 pre_collector_path=rec_path_physics,
231 collection_cosmics =
Collection(collector=col_test_cosmics,
232 input_files=input_files_cosmics,
233 pre_collector_path=rec_path_cosmics,
237 collection_Bcosmics =
Collection(collector=col_test_Bcosmics,
238 input_files=input_files_Bcosmics,
239 pre_collector_path=rec_path_Bcosmics,
253 cal_test1.add_collection(name=
"cosmics", collection=collection_cosmics)
254 cal_test1.add_collection(name=
"Bcosmics", collection=collection_Bcosmics)
255 cal_test1.algorithms = [alg_test1]
257 cal_test1.algorithms[0].params = {
"apply_iov": output_iov}
259 cal_test1.save_payloads =
False
263 cal_test2.add_collection(name=
"physics", collection=collection_physics)
264 cal_test2.algorithms = [alg_test2]
266 cal_test2.strategies = SequentialBoundaries
268 cal_test2.algorithms[0].params[
"iov_coverage"] = output_iov
270 cal_test2.depends_on(cal_test1)
273 return [cal_test1, cal_test2]