def pipeline_dataprep(st, candloc):
    """ Prepare (read, cal, flag) data for a given state and candloc.
    """
    from rfpipe import source
    segment, candint, dmind, dtind, beamnum = candloc
    st.prefs.segmenttimes = st._segmenttimes.tolist()
    data = source.read_segment(st, segment)
    flagversion = 'rtpipe' if hasattr(st, 'rtpipe_version') else 'latest'
    data_prep = source.data_prep(st, segment, data, flagversion=flagversion)
    return data_prep
