parameters: (reduction_packages, save_can, additional_run_numbers, event_slice_optimisation=False)
docstring: Extracts all workspace names which need to be saved and saves them into a file.
  
      :param reduction_packages: a list of reduction packages which contain all the relevant information for saving
      :type reduction_packages: list
      :param save_can: When true save the unsubtracted can and sample workspaces
      :type save_can: bool
      :param additional_run_numbers: Workspace type to run number
      :type additional_run_numbers: dict
      :param event_slice_optimisation: optional. If true then reduction packages contain event slice data
      :type event_slice_optimisation: bool
docstring_summary: Extracts all workspace names which need to be saved and saves them into a file.
docstring_tokens: Extracts all workspace names which need to be saved and saves them into a file .
function: def save_to_file(reduction_packages, save_can, additional_run_numbers, event_slice_optimisation=False):
      """
      Extracts all workspace names which need to be saved and saves them into a file.
  
      :param reduction_packages: a list of reduction packages which contain all the relevant information for saving
      :type reduction_packages: list
      :param save_can: When true save the unsubtracted can and sample workspaces
      :type save_can: bool
      :param additional_run_numbers: Workspace type to run number
      :type additional_run_numbers: dict
      :param event_slice_optimisation: optional. If true then reduction packages contain event slice data
      :type event_slice_optimisation: bool
      """
      if not event_slice_optimisation:
          workspaces_names_to_save = get_all_names_to_save(reduction_packages, save_can=save_can)
      else:
          workspaces_names_to_save = get_event_slice_names_to_save(reduction_packages, save_can=save_can)
  
      state = reduction_packages[0].state
      save_info = state.save
      file_formats = save_info.file_format
      for to_save in workspaces_names_to_save:
          if isinstance(to_save, tuple):
              for i, ws_name_to_save in enumerate(to_save[0]):
                  transmission = to_save[1][i] if to_save[1] else ''
                  transmission_can = to_save[2][i] if to_save[2] else ''
                  save_workspace_to_file(ws_name_to_save, file_formats, ws_name_to_save, additional_run_numbers,
                                         transmission, transmission_can)
          else:
              save_workspace_to_file(to_save, file_formats, to_save, additional_run_numbers)
function_tokens: def save_to_file ( reduction_packages , save_can , additional_run_numbers , event_slice_optimisation = False ) : if not event_slice_optimisation : workspaces_names_to_save = get_all_names_to_save ( reduction_packages , save_can = save_can ) else : workspaces_names_to_save = get_event_slice_names_to_save ( reduction_packages , save_can = save_can ) state = reduction_packages [ 0 ] . state save_info = state . save file_formats = save_info . file_format for to_save in workspaces_names_to_save : if isinstance ( to_save , tuple ) : for i , ws_name_to_save in enumerate ( to_save [ 0 ] ) : transmission = to_save [ 1 ] [ i ] if to_save [ 1 ] else '' transmission_can = to_save [ 2 ] [ i ] if to_save [ 2 ] else '' save_workspace_to_file ( ws_name_to_save , file_formats , ws_name_to_save , additional_run_numbers , transmission , transmission_can ) else : save_workspace_to_file ( to_save , file_formats , to_save , additional_run_numbers )