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