def _has_calibration_been_applied(load_alg): sample_workspace = load_alg.getProperty("SampleScatterWorkspace").value if sample_workspace is None: sample_workspace = load_alg.getProperty("SampleScatterWorkspace_1").value has_calibration_tag = has_tag(CALIBRATION_WORKSPACE_TAG, sample_workspace) has_file_tag = has_tag(SANS_FILE_TAG, sample_workspace) return has_calibration_tag and has_file_tag
def test_that_can_read_and_write_tag_in_sample_logs(self): # Arrange ws1 = SANSLogTaggerTest._provide_sample_workspace() tag1 = "test" value1 = 123 # Act + Assert self.assertFalse(has_tag(tag1, ws1)) set_tag(tag1, value1, ws1) self.assertTrue(has_tag(tag1, ws1)) self.assertEqual(get_tag(tag1, ws1), value1)
def test_that_can_read_and_write_tag_in_sample_logs(self): # Arrange ws1 = SANSLogTaggerTest._provide_sample_workspace() tag1 = "test" value1 = 123 # Act + Assert self.assertFalse(has_tag(tag1, ws1)) set_tag(tag1, value1, ws1) self.assertTrue(has_tag(tag1, ws1)) self.assertTrue(get_tag(tag1, ws1) == value1)
def append_to_sans_file_tag(workspace, to_append): """ Appends a string to the existing sans file tag. :param workspace: the workspace which contains the sample logs with the sans file tag. :param to_append: the additional tag """ if has_tag(SANS_FILE_TAG, workspace): value = get_tag(SANS_FILE_TAG, workspace) value += to_append set_tag(SANS_FILE_TAG, value, workspace)
def is_calibration_correct(workspace, calibration_file): """ Check if the calibration has been applied. If no calibration has been specified then none should be have been applied. :param workspace: the workspace to check. :param calibration_file: the path to the calibration file. :return: True if the calibration file matches or if none was set and the path is empty, else False """ has_calibration = has_tag(CALIBRATION_WORKSPACE_TAG, workspace) return (has_calibration and calibration_file == get_tag(CALIBRATION_WORKSPACE_TAG, workspace)) or\ (not has_calibration and not calibration_file)
def has_calibration_already_been_applied(workspace, full_file_path): """ Checks if particular calibration, defined by the file path has been applied to a workspace. :param workspace: The workspace which might have been calibrated :param full_file_path: An absolute file path to the calibration file. :return: True if the calibration has been applied else False """ has_calibration_applied = False if has_tag(CALIBRATION_WORKSPACE_TAG, workspace): value = get_tag(CALIBRATION_WORKSPACE_TAG, workspace) has_calibration_applied = value == full_file_path return has_calibration_applied
def does_can_workspace_exist_on_ads(can_workspace): """ Checks if a can workspace already exists on the ADS, based on the stored hash :param can_workspace: a handle to the can workspace :return: True if the workspace exists on the ADS else False """ if not has_tag(REDUCED_CAN_TAG, can_workspace): return False hash_value_to_compare = get_tag(REDUCED_CAN_TAG, can_workspace) for workspace in get_ads_workspace_references(): if has_hash(REDUCED_CAN_TAG, hash_value_to_compare, workspace): return True return False
def get_workspaces_from_ads_if_exist(file_tags, full_calibration_file_path, workspaces): """ Retrieves workspaces from the ADS depending on their file tags and calibration file tags which would have been set by the sans loading mechanism when they were loaded the first time. :param file_tags: a list of file tags which we look for on the workspaces on the ADS :param full_calibration_file_path: the calibration file name which we look for on the workspaces on the ADS :param workspaces: a list of workspaces which is being updated in this function. """ for workspace_name in AnalysisDataService.getObjectNames(): workspace = AnalysisDataService.retrieve(workspace_name) try: if has_tag(SANS_FILE_TAG, workspace): file_tag = get_tag(SANS_FILE_TAG, workspace) if file_tag in file_tags and is_calibration_correct(workspace, full_calibration_file_path): workspaces.append(workspace) except RuntimeError: continue
def tag_workspaces_with_file_names(workspaces, file_information, is_transmission, period, is_monitor): """ Set a sample log element for the used original file. Note that the calibration file name is set :param workspaces: a dict of workspaces :param file_information: a SANSFileInformation object :param is_transmission: if is transmission. :param period: the selected period. :param is_monitor: if we are dealing with a monitor """ # Set tag for the original file name from which the workspace was loaded file_tags = get_expected_file_tags(file_information, is_transmission, period) if len(file_tags) != len(workspaces): raise RuntimeError("Issue while tagging the loaded data. The number of tags does not match the number " "of workspaces.") for file_tag, workspace in zip(file_tags, workspaces): if not has_tag(SANS_FILE_TAG, workspace): if is_monitor: file_tag += MONITOR_SUFFIX set_tag(SANS_FILE_TAG, file_tag, workspace)