2 from collections
import namedtuple
6 prompt_script_package =
"prompt.calibrations."
7 prompt_script_dir =
"calibration/scripts/prompt/calibrations"
9 prompt_validation_script_package =
"prompt.validations."
10 prompt_validation_script_dir =
"calibration/scripts/prompt/validations"
13 class CalibrationSettings(namedtuple(
'CalSet_Factory', [
"name",
"expert_username",
"description",
14 "input_data_formats",
"input_data_names",
"depends_on",
"expert_config"])):
16 Simple class to hold and display required information for a prompt calibration script (process).
19 name (str): The unique calibration name, not longer than 64 characters.
21 expert_username (str): The JIRA username of the expert to contact about this script.
22 This username will be used to assign the default responsible person for submitting and checking prompt
25 description (str): Long form description of the calibration and what it does. Feel free to make this as long as you need.
27 input_data_formats (frozenset(str)): The data formats {'raw', 'cdst', 'mdst', 'udst'} of the input files
28 that should be used as input to the process. Used to figure out if this calibration should occur
29 before the relevant data production e.g. before cDST files are created.
31 input_data_names (frozenset(str)): The names that you will use when accessing the input data given to the
32 prompt calibration process i.e. Use these in the ``get_calibrations`` function to access the correct input
35 depends_on list(CalibrationSettings): The settings variables of the other prompt calibrations that you want
36 want to depend on. This will allow the external automatic system to understand the overall ordering of
37 scripts to run. If you encounter an import error when trying to run your prompt calibration script, it is
38 likely that you have introduced a circular dependency.
40 expert_config (dict): Default expert configuration for this calibration script. This is an optional dictionary
41 (which must be JSON compliant) of configuration options for your get_calibrations(...) function.
42 This is supposed to be used as a catch-all place to send in options for your calibration setup. For example,
43 you may want to have an optional list of IoV boundaries so that your prompt script knows that it should split the
44 input data between different IoV ranges. Or you might want to send if options like the maximum events per
45 input file to process. The value in your settings object will be the *default*, but you can override the value via
46 the caf_config.json sent into ``b2caf-prompt-run``.
52 allowed_data_formats = frozenset({
"raw",
"cdst",
"mdst",
"udst"})
54 def __new__(cls, name, expert_username, description,
55 input_data_formats=None, input_data_names=None, depends_on=None, expert_config=None):
57 The special method to create the tuple instance. Returning the instance
58 calls the __init__ method
61 raise ValueError(
"name cannot be longer than 64 characters!")
62 if not input_data_formats:
63 raise ValueError(
"You must specify at least one input data format")
64 input_data_formats = frozenset(map(
lambda x: x.lower(), input_data_formats))
66 raise ValueError(
"There was a data format that is not in the allowed_data_formats attribute.")
67 if not input_data_names:
68 raise ValueError(
"You must specify at least one input data name")
69 input_data_names = frozenset(input_data_names)
73 if not isinstance(expert_config, dict):
74 raise TypeError(
"expert_config must be a dictionary")
77 json.dumps(expert_config)
78 except TypeError
as e:
79 basf2.B2ERROR(
"expert_config could not be serialised to JSON. "
80 "Most likely you used a non-supported type e.g. datetime.")
86 for calibration_settings
in depends_on:
87 if not isinstance(calibration_settings, cls):
88 raise TypeError(f
"A list of {str(cls)} object is required when setting the 'depends_on' keyword.")
92 return super().
__new__(cls, name, expert_username, description,
93 input_data_formats, input_data_names, depends_on, expert_config)
98 str: A valid JSON format string of the attributes.
100 depends_on_names = [calibration_settings.name
for calibration_settings
in self.depends_on]
101 return json.dumps({
"name": self.name,
102 "expert_username": self.expert_username,
103 "input_data_formats": list(self.input_data_formats),
104 "input_data_names": list(self.input_data_names),
105 "depends_on": list(depends_on_names),
106 "description": self.description,
107 "expert_config": self.expert_config
111 depends_on_names = [calibration_settings.name
for calibration_settings
in self.depends_on]
112 output_str = str(self.__class__.__name__) + f
"(name='{self.name}'):\n"
113 output_str += f
" expert_username='{self.expert_username}'\n"
114 output_str += f
" input_data_formats={list(self.input_data_formats)}\n"
115 output_str += f
" input_data_names={list(self.input_data_names)}\n"
116 output_str += f
" depends_on={list(depends_on_names)}\n"
117 output_str += f
" description='{self.description}'\n"
118 output_str += f
" expert_config={self.expert_config}"
122 class ValidationSettings(namedtuple(
'ValSet_Factory', [
"name",
"description",
"download_files",
"expert_config"])):
124 Simple class to hold and display required information for a validation calibration script (process).
127 name (str): The unique name that must match the corresponding calibration, not longer than 64 characters.
129 description (str): Long form description of the validation and what it does. Feel free to make this as long as you need.
131 download_files (list): The names of the files you want downloaded, e.g. mycalibration_stdout. If multiple files of
132 the same name are found, all files are downloaded and appended with the folder they were in.
134 expert_config (dict): Default expert configuration for this validation script. This is an optional dictionary
135 (which must be JSON compliant) of configuration options for validation script.
136 This is supposed to be used as a catch-all place to send in options for your calibration setup. For example,
137 you may want to have an optional list of IoV boundaries so that your validation script knows that it should split the
138 input data between different IoV ranges. Or you might want to send if options like the maximum events per
139 input file to process. The value in your settings object will be the *default*, but you can override the value via
140 the caf_config.json sent into ``b2caf-prompt-run``.
143 def __new__(cls, name, description, download_files=None, expert_config=None):
145 The special method to create the tuple instance. Returning the instance
146 calls the __init__ method
149 raise ValueError(
"name cannot be longer than 64 characters!")
153 if not isinstance(expert_config, dict):
154 raise TypeError(
"expert_config must be a dictionary")
157 json.dumps(expert_config)
158 except TypeError
as e:
159 basf2.B2ERROR(
"expert_config could not be serialised to JSON. "
160 "Most likely you used a non-supported type e.g. datetime.")
165 return super().
__new__(cls, name, description, download_files, expert_config)
170 str: A valid JSON format string of the attributes.
172 return json.dumps({
"name": self.name,
173 "description": self.description,
174 "download_files": self.download_files,
175 "expert_config": self.expert_config
179 output_str = str(self.__class__.__name__) + f
"(name='{self.name}'):\n"
180 output_str += f
" description='{self.description}'\n"
181 output_str += f
" download_files='{self.download_files}'\n"
182 output_str += f
" expert_config={self.expert_config}"