Ion trapping in high intensity linear accelerators