Optimal data processing for quantum measurements