示例#1
0
def get_input_workspace_as_copy_if_not_same_as_output_workspace(alg):
    """
    This function checks if the input workspace is the same as the output workspace, if so then it returns the
    workspace else it creates a copy of the input in order for it to be consumed.

    :param alg: a handle to the algorithm which has a InputWorkspace property and a OutputWorkspace property
    :return: a workspace
    """
    def _clone_input(_ws):
        clone_name = "CloneWorkspace"
        clone_options = {"InputWorkspace": _ws, "OutputWorkspace": EMPTY_NAME}
        clone_alg = create_unmanaged_algorithm(clone_name, **clone_options)
        clone_alg.execute()
        return clone_alg.getProperty("OutputWorkspace").value

    if "InputWorkspace" not in alg or "OutputWorkspace" not in alg:
        raise RuntimeError(
            "The algorithm {} does not seem to have an InputWorkspace and"
            " an OutputWorkspace property.".format(alg.name()))

    ws_in = alg.getProperty("InputWorkspace").value
    if ws_in is None:
        raise RuntimeError(
            "The input for the algorithm {} seems to be None. We need an input."
            .format(alg.name()))

    ws_out = alg.getProperty("OutputWorkspace").value

    # There are three scenarios.
    # 1. ws_out is None
    # 2. ws_in and ws_out are the same workspace
    # 3. ws_in and ws_out are not the same workspace
    if ws_out is None:
        return _clone_input(ws_in)
    elif isSameWorkspaceObject(ws_in, ws_out):
        return ws_in
    else:
        return _clone_input(ws_in)
示例#2
0
def get_input_workspace_as_copy_if_not_same_as_output_workspace(alg):
    """
    This function checks if the input workspace is the same as the output workspace, if so then it returns the
    workspace else it creates a copy of the input in order for it to be consumed.

    :param alg: a handle to the algorithm which has a InputWorkspace property and a OutputWorkspace property
    :return: a workspace
    """
    def _clone_input(_ws):
        clone_name = "CloneWorkspace"
        clone_options = {"InputWorkspace": _ws,
                         "OutputWorkspace": EMPTY_NAME}
        clone_alg = create_unmanaged_algorithm(clone_name, **clone_options)
        clone_alg.execute()
        return clone_alg.getProperty("OutputWorkspace").value

    if "InputWorkspace" not in alg or "OutputWorkspace" not in alg:
        raise RuntimeError("The algorithm {} does not seem to have an InputWorkspace and"
                           " an OutputWorkspace property.".format(alg.name()))

    ws_in = alg.getProperty("InputWorkspace").value
    if ws_in is None:
        raise RuntimeError("The input for the algorithm {} seems to be None. We need an input.".format(alg.name()))

    ws_out = alg.getProperty("OutputWorkspace").value

    # There are three scenarios.
    # 1. ws_out is None
    # 2. ws_in and ws_out are the same workspace
    # 3. ws_in and ws_out are not the same workspace
    if ws_out is None:
        return _clone_input(ws_in)
    elif isSameWorkspaceObject(ws_in, ws_out):
        return ws_in
    else:
        return _clone_input(ws_in)