Belle II Software  release-06-02-00
CalibrationSettings Class Reference
Inheritance diagram for CalibrationSettings:
Collaboration diagram for CalibrationSettings:

Public Member Functions

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)
 
def json_dumps (self)
 
def __str__ (self)
 

Static Public Attributes

 allowed_data_formats = frozenset({"raw", "cdst", "mdst", "udst"})
 Allowed data file formats. More...
 

Detailed Description

Simple class to hold and display required information for a prompt calibration script (process).

Parameters:
    name (str): The unique calibration name, not longer than 64 characters.

    expert_username (str): The JIRA username of the expert to contact about this script.
        This username will be used to assign the default responsible person for submitting and checking prompt
        calibration jobs.

    description (str): Long form description of the calibration and what it does. Feel free to make this as long as you need.

    input_data_formats (frozenset(str)): The data formats {'raw', 'cdst', 'mdst', 'udst'} of the input files
        that should be used as input to the process. Used to figure out if this calibration should occur
        before the relevant data production e.g. before cDST files are created.

    input_data_names (frozenset(str)): The names that you will use when accessing the input data given to the
        prompt calibration process i.e. Use these in the ``get_calibrations`` function to access the correct input
        data files. e.g. input_data_names=["all_events", "offres_photon_events"]

    input_data_filters (dict): The data selection for the data input names, used for automated calibration.
        The keys should correspond to one of the ``input_data_names`` with the values being a list of the various data
        filters, e.g. Data Tag, Beam Energy, Run Type, Run Quality Tag and Magnet. All available filters can be found in the
        input_data_filters dictionary e.g. from prompt import input_data_filters with details about data tags and run quality
        tags found at: https://calibration.belle2.org/belle2/data_tags/list/.
        To exclude specific filters, pre-append with *NOT* e.g.
        {"all_events": ["mumu_tight_or_highm_calib", "hadron_calib", "Good", "On"],
        "offres_photon_events": ["gamma_gamma_calib", "Good", "NOT On"]}.
        Not selecting a specfic filters (e.g. Magnet) is equivalent to not having any requirements, e.g. (Either)

    depends_on (list(CalibrationSettings)): The settings variables of the other prompt calibrations that you want
        want to depend on. This will allow the external automatic system to understand the overall ordering of
        scripts to run. If you encounter an import error when trying to run your prompt calibration script, it is
        likely that you have introduced a circular dependency.

    expert_config (dict): Default expert configuration for this calibration script. This is an optional dictionary
        (which must be JSON compliant) of configuration options for your get_calibrations(...) function.
        This is supposed to be used as a catch-all place to send in options for your calibration setup. For example,
        you may want to have an optional list of IoV boundaries so that your prompt script knows that it should split the
        input data between different IoV ranges. Or you might want to send if options like the maximum events per
        input file to process. The value in your settings object will be the *default*, but you can override the value via
        the caf_config.json sent into ``b2caf-prompt-run``.

Definition at line 51 of file __init__.py.

Member Function Documentation

◆ __new__()

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 
)
The special method to create the tuple instance. Returning the instance
calls the __init__ method

Definition at line 109 of file __init__.py.

110  input_data_formats=None, input_data_names=None, input_data_filters=None, depends_on=None, expert_config=None):
111  """
112  The special method to create the tuple instance. Returning the instance
113  calls the __init__ method
114  """
115  if len(name) > 64:
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))
120  if input_data_formats.difference(cls.allowed_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)
125 
126  # The input data names in the filters MUST correspond to the input data names for the calibration.
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'!")
130  # Requested input data filters MUST exist in the ones we defined in the global dictionary.
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)}")
137  else:
138  input_data_filters = {}
139 
140  if expert_config:
141  # Check that it's a dictionary and not some other valid JSON object
142  if not isinstance(expert_config, dict):
143  raise TypeError("expert_config must be a dictionary")
144  # Check if it is JSONable since people might put objects in there by mistake
145  try:
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.")
150  raise e
151  else:
152  expert_config = {}
153 
154  if depends_on:
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.")
158  else:
159  depends_on = []
160 
161  return super().__new__(cls, name, expert_username, description,
162  input_data_formats, input_data_names, input_data_filters, depends_on, expert_config)
163 

◆ json_dumps()

def json_dumps (   self)
Returns:
     str: A valid JSON format string of the attributes.

Definition at line 164 of file __init__.py.

Member Data Documentation

◆ allowed_data_formats

allowed_data_formats = frozenset({"raw", "cdst", "mdst", "udst"})
static

Allowed data file formats.

You should use these values for CalibrationSettings.input_data_formats. Right now you should only use "raw" or "cdst" because we don't actually run calibrations on "mdst" or "udst". They are here for completeness.

Definition at line 107 of file __init__.py.


The documentation for this class was generated from the following file: