9 from collections
import namedtuple
12 prompt_script_package =
"prompt.calibrations."
13 prompt_script_dir =
"calibration/scripts/prompt/calibrations"
15 prompt_validation_script_package =
"prompt.validations."
16 prompt_validation_script_dir =
"calibration/scripts/prompt/validations"
18 INPUT_DATA_FILTERS = {
"Magnet": {
"On":
"On",
21 "Beam Energy": {
"No Beam":
"No Beam",
23 "Continuum":
"Continuum",
26 "Run Type": {
"beam":
"beam",
28 "debug":
"debug",
"null":
"null",
29 "physics":
"physics"},
30 "Data Tag": {
"hlt_skim":
"hlt_skim",
31 "bhabha_all_calib":
"bhabha_all_calib",
32 "cosmic_calib":
"cosmic_calib",
33 "gamma_gamma_calib":
"gamma_gamma_calib",
34 "hadron_calib":
"hadron_calib",
35 "btocharm_calib":
"btocharm_calib",
36 "mumu_tight_or_highm_calib":
"mumu_tight_or_highm_calib",
37 "offip_calib":
"offip_calib",
38 "radmumu_calib":
"radmumu_calib",
39 "random_calib":
"random_calib",
40 "single_gamma_mc":
"single_gamma_mc"},
41 "Data Quality Tag": {
">=30 Minute Run":
">=30 Minute Run",
42 "Bad For Alignment":
"Bad For Alignment",
44 "Good Shifter":
"Good Shifter",
45 "Good For PXD":
"Good For PXD",
46 "Good Or Recoverable":
"Good Or Recoverable",
47 "Good Or Recoverable Shifter":
"Good Or Recoverable Shifter"}
61 Simple class to hold and display required information for a prompt calibration script (process).
64 name (str): The unique calibration name, not longer than 64 characters.
66 expert_username (str): The JIRA username of the expert to contact about this script.
67 This username will be used to assign the default responsible person for submitting and checking prompt
70 description (str): Long form description of the calibration and what it does. Feel free to make this as long as you need.
72 input_data_formats (frozenset(str)): The data formats {'raw', 'cdst', 'mdst', 'udst'} of the input files
73 that should be used as input to the process. Used to figure out if this calibration should occur
74 before the relevant data production e.g. before cDST files are created.
76 input_data_names (frozenset(str)): The names that you will use when accessing the input data given to the
77 prompt calibration process i.e. Use these in the ``get_calibrations`` function to access the correct input
78 data files. e.g. input_data_names=["all_events", "offres_photon_events"]
80 input_data_filters (dict): The data selection for the data input names, used for automated calibration.
81 The keys should correspond to one of the ``input_data_names`` with the values being a list of the various data
82 filters, e.g. Data Tag, Beam Energy, Run Type, Run Quality Tag and Magnet. All available filters can be found in the
83 input_data_filters dictionary e.g. from prompt import input_data_filters with details about data tags and run quality
84 tags found at: https://calibration.belle2.org/belle2/data_tags/list/.
85 To exclude specific filters, pre-append with *NOT* e.g.
86 {"all_events": ["mumu_tight_or_highm_calib", "hadron_calib", "Good", "On"],
87 "offres_photon_events": ["gamma_gamma_calib", "Good", "NOT On"]}.
88 Not selecting a specfic filters (e.g. Magnet) is equivalent to not having any requirements, e.g. (Either)
90 depends_on (list(CalibrationSettings)): The settings variables of the other prompt calibrations that you want
91 want to depend on. This will allow the external automatic system to understand the overall ordering of
92 scripts to run. If you encounter an import error when trying to run your prompt calibration script, it is
93 likely that you have introduced a circular dependency.
95 expert_config (dict): Default expert configuration for this calibration script. This is an optional dictionary
96 (which must be JSON compliant) of configuration options for your get_calibrations(...) function.
97 This is supposed to be used as a catch-all place to send in options for your calibration setup. For example,
98 you may want to have an optional list of IoV boundaries so that your prompt script knows that it should split the
99 input data between different IoV ranges. Or you might want to send if options like the maximum events per
100 input file to process. The value in your settings object will be the *default*, but you can override the value via
101 the caf_config.json sent into ``b2caf-prompt-run``.
107 allowed_data_formats = frozenset({
"raw",
"cdst",
"mdst",
"udst"})
109 def __new__(cls, name, expert_username, description,
110 input_data_formats=None, input_data_names=None, input_data_filters=None, depends_on=None, expert_config=None):
112 The special method to create the tuple instance. Returning the instance
113 calls the __init__ method
116 raise ValueError(
"name cannot be longer than 64 characters!")
117 if not input_data_formats:
118 raise ValueError(
"You must specify at least one input data format")
119 input_data_formats = frozenset(map(
lambda x: x.lower(), input_data_formats))
121 raise ValueError(
"There was a data format that is not in the allowed_data_formats attribute.")
122 if not input_data_names:
123 raise ValueError(
"You must specify at least one input data name")
124 input_data_names = frozenset(input_data_names)
127 if input_data_filters:
128 if set(input_data_filters.keys()) != input_data_names:
129 raise ValueError(
"The 'input_data_filters' keys don't match the 'input_data_names'!")
131 allowed_filters = {filter_name
for category
in INPUT_DATA_FILTERS.values()
for filter_name
in category}
132 requested_filters = {filter_name.replace(
"NOT",
"", 1).lstrip()
for filters
in input_data_filters.values()
133 for filter_name
in filters}
134 if not allowed_filters.issuperset(requested_filters):
135 raise ValueError(
"The 'input_data_filters' contains unknown filter names:"
136 f
"{requested_filters.difference(allowed_filters)}")
138 input_data_filters = {}
142 if not isinstance(expert_config, dict):
143 raise TypeError(
"expert_config must be a dictionary")
146 json.dumps(expert_config)
147 except TypeError
as e:
148 basf2.B2ERROR(
"expert_config could not be serialised to JSON. "
149 "Most likely you used a non-supported type e.g. datetime.")
155 for calibration_settings
in depends_on:
156 if not isinstance(calibration_settings, cls):
157 raise TypeError(f
"A list of {str(cls)} object is required when setting the 'depends_on' keyword.")
161 return super().
__new__(cls, name, expert_username, description,
162 input_data_formats, input_data_names, input_data_filters, depends_on, expert_config)
167 str: A valid JSON format string of the attributes.
169 depends_on_names = [calibration_settings.name
for calibration_settings
in self.depends_on]
170 return json.dumps({
"name": self.name,
171 "expert_username": self.expert_username,
172 "input_data_formats": list(self.input_data_formats),
173 "input_data_names": list(self.input_data_names),
174 "input_data_filters": self.input_data_filters,
175 "depends_on": list(depends_on_names),
176 "description": self.description,
177 "expert_config": self.expert_config
181 depends_on_names = [calibration_settings.name
for calibration_settings
in self.depends_on]
182 output_str = str(self.__class__.__name__) + f
"(name='{self.name}'):\n"
183 output_str += f
" expert_username='{self.expert_username}'\n"
184 output_str += f
" input_data_formats={list(self.input_data_formats)}\n"
185 output_str += f
" input_data_names={list(self.input_data_names)}\n"
186 output_str += f
" input_data_filters={list(self.input_data_filters)}\n"
187 output_str += f
" depends_on={list(depends_on_names)}\n"
188 output_str += f
" description='{self.description}'\n"
189 output_str += f
" expert_config={self.expert_config}"
193 class ValidationSettings(namedtuple(
'ValSet_Factory', [
"name",
"description",
"download_files",
"expert_config"])):
195 Simple class to hold and display required information for a validation calibration script (process).
198 name (str): The unique name that must match the corresponding calibration, not longer than 64 characters.
200 description (str): Long form description of the validation and what it does. Feel free to make this as long as you need.
202 download_files (list): The names of the files you want downloaded, e.g. mycalibration_stdout. If multiple files of
203 the same name are found, all files are downloaded and appended with the folder they were in.
205 expert_config (dict): Default expert configuration for this validation script. This is an optional dictionary
206 (which must be JSON compliant) of configuration options for validation script.
207 This is supposed to be used as a catch-all place to send in options for your calibration setup. For example,
208 you may want to have an optional list of IoV boundaries so that your validation script knows that it should split the
209 input data between different IoV ranges. Or you might want to send if options like the maximum events per
210 input file to process. The value in your settings object will be the *default*, but you can override the value via
211 the caf_config.json sent into ``b2caf-prompt-run``.
214 def __new__(cls, name, description, download_files=None, expert_config=None):
216 The special method to create the tuple instance. Returning the instance
217 calls the __init__ method
220 raise ValueError(
"name cannot be longer than 64 characters!")
224 if not isinstance(expert_config, dict):
225 raise TypeError(
"expert_config must be a dictionary")
228 json.dumps(expert_config)
229 except TypeError
as e:
230 basf2.B2ERROR(
"expert_config could not be serialised to JSON. "
231 "Most likely you used a non-supported type e.g. datetime.")
236 return super().
__new__(cls, name, description, download_files, expert_config)
241 str: A valid JSON format string of the attributes.
243 return json.dumps({
"name": self.name,
244 "description": self.description,
245 "download_files": self.download_files,
246 "expert_config": self.expert_config
250 output_str = str(self.__class__.__name__) + f
"(name='{self.name}'):\n"
251 output_str += f
" description='{self.description}'\n"
252 output_str += f
" download_files='{self.download_files}'\n"
253 output_str += f
" expert_config={self.expert_config}"
def __new__(cls, name, expert_username, description, input_data_formats=None, input_data_names=None, input_data_filters=None, depends_on=None, expert_config=None)
allowed_data_formats
Allowed data file formats.
def __new__(cls, name, description, download_files=None, expert_config=None)