def wrap_par_to_det(parameter, control='soft'):
    '''
    Takes in a QCoDeS Parameter instance and returns a PycQED DetectorFunction
    that wraps around the Parameter.

    The following attributes of the QCoDes parameter are used
        par.name    -> detector.name
        par.label   -> detector.value_names (either string or list of strings)
        par.unit    ->  detector.value_units
        par.get     -> detector.acquire_data_point
                    -> detector.get_values

    The following attributes are not taken from the parameter
        det.prepare             <- pass_function
        det.finish              <- pass_function
        det.detector_control    <- input argument of this function

    '''
    detector_function = det.Detector_Function()
    detector_function.detector_control = control
    detector_function.name = parameter.name
    if isinstance(parameter.label, list):
        detector_function.value_names = parameter.label
        detector_function.value_units = parameter.unit
    else:
        detector_function.value_names = [parameter.label]
        detector_function.value_units = [parameter.unit]

    detector_function.prepare = pass_function
    detector_function.finish = pass_function
    detector_function.acquire_data_point = parameter.get
    detector_function.get_values = parameter.get
    return detector_function
def wrap_func_to_det(func, name, value_names, units, control='soft', **kw):
    detector_function = det.Detector_Function()
    detector_function.detector_control = control
    detector_function.name = name
    detector_function.value_names = value_names
    detector_function.value_units = units

    detector_function.prepare = pass_function
    detector_function.finish = pass_function

    def wrapped_func():
        return func(**kw)

    detector_function.acquire_data_point = wrapped_func
    detector_function.get_values = wrapped_func
    return detector_function