Ejemplo n.º 1
0
    def _process_command_queue(self, data_state):
        """
        Process the command queue sequentially as FIFO structure

        @param data_state: the data state.
        @return: a SANSState object.
        """
        file_name = data_state.sample_scatter
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)

        # If we have a clean instruction in there, then we should apply it to all commands
        self._apply_clean_if_required()

        # Evaluate all commands which adds them to the _processed_state_settings dictionary,
        # except for DataCommands which we deal with separately
        for command in self._commands:
            if isinstance(command, DataCommand):
                continue
            command_id = command.command_id
            process_function = self._method_map[command_id]
            process_function(command)

        user_commands = CommandInterfaceAdapter(
            data_info=data_state,
            processed_state=self._processed_state_settings)
        run_data_parser = StateRunDataBuilder(
            file_information=file_information)

        self._state_director = StateBuilder(i_state_parser=user_commands,
                                            run_data_builder=run_data_parser)
        return self._state_director.get_all_states()
Ejemplo n.º 2
0
 def setUp(self):
     self.file_parser = mock.create_autospec(spec=IStateParser)
     self.data_parser = mock.create_autospec(spec=StateRunDataBuilder)
     self.instance = StateBuilder(run_data_builder=self.data_parser,
                                  i_state_parser=self.file_parser)
Ejemplo n.º 3
0
    def create_state(self, row_entry, file_lookup=True, user_file=""):
        # 1. Get the data settings, such as sample_scatter, etc... and create the data state.
        if file_lookup:
            file_information = row_entry.file_information
        else:
            file_information = SANSFileInformationBlank()

        data_builder = get_data_builder(self._facility, file_information)

        self._set_data_entry(data_builder.set_sample_scatter,
                             row_entry.sample_scatter)
        self._set_data_period_entry(data_builder.set_sample_scatter_period,
                                    row_entry.sample_scatter_period)
        self._set_data_entry(data_builder.set_sample_transmission,
                             row_entry.sample_transmission)
        self._set_data_period_entry(
            data_builder.set_sample_transmission_period,
            row_entry.sample_transmission_period)  # noqa
        self._set_data_entry(data_builder.set_sample_direct,
                             row_entry.sample_direct)
        self._set_data_period_entry(data_builder.set_sample_direct_period,
                                    row_entry.sample_direct_period)
        self._set_data_entry(data_builder.set_can_scatter,
                             row_entry.can_scatter)
        self._set_data_period_entry(data_builder.set_can_scatter_period,
                                    row_entry.can_scatter_period)
        self._set_data_entry(data_builder.set_can_transmission,
                             row_entry.can_transmission)
        self._set_data_period_entry(data_builder.set_can_transmission_period,
                                    row_entry.can_transmission_period)
        self._set_data_entry(data_builder.set_can_direct, row_entry.can_direct)
        self._set_data_period_entry(data_builder.set_can_direct_period,
                                    row_entry.can_direct_period)

        data = data_builder.build()

        # 2. Add elements from the options column
        state_gui_model = copy.deepcopy(self._state_gui_model)
        self._apply_column_options_to_state(row_entry, state_gui_model)

        # 3. Add other columns
        output_name = row_entry.output_name
        if output_name:
            state_gui_model.output_name = output_name

        if row_entry.sample_thickness:
            state_gui_model.sample_thickness = float(
                row_entry.sample_thickness)
        if row_entry.sample_height:
            state_gui_model.sample_height = float(row_entry.sample_height)
        if row_entry.sample_width:
            state_gui_model.sample_width = float(row_entry.sample_width)
        if row_entry.sample_shape:
            state_gui_model.sample_shape = row_entry.sample_shape

        # 4. Create the rest of the state based on the builder.
        settings = copy.deepcopy(state_gui_model.settings)
        command_interface = CommandInterfaceAdapter(data_info=data,
                                                    processed_state=settings)
        run_data_builder = StateRunDataBuilder(
            file_information=file_information)

        state = StateBuilder(
            run_data_builder=run_data_builder,
            i_state_parser=command_interface).get_all_states()
        return state