Belle II Software  release-06-02-00
caf_arich.py
1 # -*- coding: utf-8 -*-
2 
3 
10 
11 """A simple example calibration that takes one input data list from raw data and performs
12 a single calibration."""
13 
14 from prompt import CalibrationSettings, INPUT_DATA_FILTERS
15 
16 
17 settings = CalibrationSettings(
18  name="ARICH channel masks",
19  expert_username="luka",
20  description=__doc__,
21  input_data_formats=["raw"],
22  input_data_names=["bhabha_all_calib"],
23  input_data_filters={
24  "bhabha_all_calib": [
25  INPUT_DATA_FILTERS["Data Tag"]["bhabha_all_calib"],
26  INPUT_DATA_FILTERS["Run Type"]["physics"],
27  INPUT_DATA_FILTERS["Data Quality Tag"]["Good Or Recoverable"]]},
28  depends_on=[])
29 
30 
31 
32 
33 def get_calibrations(input_data, **kwargs):
34  """
35  Parameters:
36  input_data (dict): Should contain every name from the 'input_data_names' variable as a key.
37  Each value is a dictionary with {"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful for
38  assigning to calibration.files_to_iov
39 
40  **kwargs: Configuration options to be sent in. Since this may change we use kwargs as a way to help prevent
41  backwards compatibility problems. But you could use the correct arguments in b2caf-prompt-run for this
42  release explicitly if you want to.
43 
44  Currently only kwargs["output_iov"] is used. This is the output IoV range that your payloads should
45  correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
46 
47  Returns:
48  list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
49  """
50  import basf2
51  # Set up config options
52 
53  # In this script we want to use one sources of input data.
54  # Get the input files from the input_data variable
55  file_to_iov_physics = input_data["bhabha_all_calib"]
56 
57  # We might have requested an enormous amount of data across a run range.
58  # There's a LOT more files than runs!
59  # Lets set some limits because this calibration doesn't need that much to run.
60  max_files_per_run = 100
61 
62  # We filter out any more than 100 files per run. The input data files are sorted alphabetically by b2caf-prompt-run
63  # already. This procedure respects that ordering
64  from prompt.utils import filter_by_max_files_per_run
65 
66  reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
67  input_files_physics = list(reduced_file_to_iov_physics.keys())
68  basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_physics)}")
69 
70  # Get the overall IoV we our process should cover. Includes the end values that we may want to ignore since our output
71  # IoV should be open ended. We could also use this as part of the input data selection in some way.
72  requested_iov = kwargs.get("requested_iov", None)
73 
74  from caf.utils import IoV
75  # The actual value our output IoV payload should have. Notice that we've set it open ended.
76  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
77 
78 
80 
81  from basf2 import create_path
82  from ROOT.Belle2 import ARICHChannelMaskMaker
83 
84  alg_arich = ARICHChannelMaskMaker()
85 
86 
88 
89  from caf.framework import Calibration
90  from caf.strategies import SequentialRunByRun
91 
92  # module to be run prior the collector
93  rec_path_1 = create_path()
94  rec_path_1.add_module('ARICHUnpacker')
95 
96  cal_test = Calibration("ARICHChannelMasks",
97  collector="ARICHChannelMask",
98  algorithms=[alg_arich],
99  input_files=input_files_physics,
100  pre_collector_path=rec_path_1
101  )
102 
103  cal_test.strategies = SequentialRunByRun
104 
105  # Do this for the default AlgorithmStrategy to force the output payload IoV
106  # It may be different if you are using another strategy like SequentialRunByRun
107  for algorithm in cal_test.algorithms:
108  algorithm.params = {"iov_coverage": output_iov}
109 
110  # Most other options like database chain and backend args will be overwritten by b2caf-prompt-run.
111  # So we don't bother setting them.
112 
113  # You must return all calibrations you want to run in the prompt process, even if it's only one
114  return [cal_test]
115 
116