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