Backport of https://github.com/cms-sw/cmssw/pull/6925 to 7.1.x