Thread safe fixes DataFormats/PatCandidates

This replaces PR #1375. The replacement was needed since I had to merge in code from a different PR which made github think I had changed 99 files insteasd of just 13. This is the same modifications but using a rebase instead of a merge.