diff --git a/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc b/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc index 10cfbbe0d3733..21703296bdcdd 100644 --- a/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc +++ b/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc @@ -4,39 +4,50 @@ #include "DataFormats/Common/interface/OneToValue.h" #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/Candidate/interface/Candidate.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" namespace pat { namespace helper { class AnyNumberAssociationAdaptor { public: typedef float value_type; typedef edm::View Collection; + template struct AssoVec { typedef typename edm::AssociationVector > type; }; - AnyNumberAssociationAdaptor(const edm::InputTag &in, const edm::ParameterSet & iConfig) : - type_(Uninitialized), in_(in), label_(in.label() + in.instance()) { } + AnyNumberAssociationAdaptor(const edm::InputTag &in, const edm::ParameterSet & iConfig, edm::ConsumesCollector && iC) : + type_(Uninitialized), in_(in), label_(in.label() + in.instance()), + tokenVMd_(iC.consumes >(in)), + tokenVMf_(iC.consumes >(in)), + tokenVMi_(iC.consumes >(in)), + tokenVMb_(iC.consumes >(in)), + tokenAVd_(iC.consumes::type >(in)), + tokenAVf_(iC.consumes::type >(in)), + tokenAVi_(iC.consumes::type >(in)), + tokenAVb_(iC.consumes::type >(in)) + { } const std::string & label() { return label_; } bool run(const edm::Event &iEvent, const Collection &coll, std::vector &ret) { switch (type_) { case Uninitialized: - if (run_ >(iEvent, coll, ret)) { type_ = ValueMapDouble; return true; } - if (run_ >(iEvent, coll, ret)) { type_ = ValueMapFloat; return true; } - if (run_ >(iEvent, coll, ret)) { type_ = ValueMapInt; return true; } - if (run_ >(iEvent, coll, ret)) { type_ = ValueMapBool; return true; } - if (run_::type >(iEvent, coll, ret)) { type_ = AssoVecDouble; return true; } - if (run_::type >(iEvent, coll, ret)) { type_ = AssoVecFloat; return true; } - if (run_::type >(iEvent, coll, ret)) { type_ = AssoVecInt; return true; } - if (run_::type >(iEvent, coll, ret)) { type_ = AssoVecBool; return true; } + if (run_ >(tokenVMd_, iEvent, coll, ret)) { type_ = ValueMapDouble; return true; } + if (run_ >(tokenVMf_, iEvent, coll, ret)) { type_ = ValueMapFloat; return true; } + if (run_ >(tokenVMi_, iEvent, coll, ret)) { type_ = ValueMapInt; return true; } + if (run_ >(tokenVMb_, iEvent, coll, ret)) { type_ = ValueMapBool; return true; } + if (run_::type >(tokenAVd_, iEvent, coll, ret)) { type_ = AssoVecDouble; return true; } + if (run_::type >(tokenAVf_, iEvent, coll, ret)) { type_ = AssoVecFloat; return true; } + if (run_::type >(tokenAVi_, iEvent, coll, ret)) { type_ = AssoVecInt; return true; } + if (run_::type >(tokenAVb_, iEvent, coll, ret)) { type_ = AssoVecBool; return true; } type_ = Nothing; return false; break; - case ValueMapDouble : return run_ >(iEvent, coll, ret); - case ValueMapFloat : return run_ >(iEvent, coll, ret); - case ValueMapInt : return run_ >(iEvent, coll, ret); - case ValueMapBool : return run_ >(iEvent, coll, ret); - case AssoVecDouble : return run_::type >(iEvent, coll, ret); - case AssoVecFloat : return run_::type >(iEvent, coll, ret); - case AssoVecInt : return run_::type >(iEvent, coll, ret); - case AssoVecBool : return run_::type >(iEvent, coll, ret); + case ValueMapDouble : return run_ >(tokenVMd_, iEvent, coll, ret); + case ValueMapFloat : return run_ >(tokenVMf_, iEvent, coll, ret); + case ValueMapInt : return run_ >(tokenVMi_, iEvent, coll, ret); + case ValueMapBool : return run_ >(tokenVMb_, iEvent, coll, ret); + case AssoVecDouble : return run_::type >(tokenAVd_, iEvent, coll, ret); + case AssoVecFloat : return run_::type >(tokenAVf_, iEvent, coll, ret); + case AssoVecInt : return run_::type >(tokenAVi_, iEvent, coll, ret); + case AssoVecBool : return run_::type >(tokenAVb_, iEvent, coll, ret); case Nothing : return false; } return false; @@ -46,18 +57,25 @@ class AnyNumberAssociationAdaptor { ValueMapDouble, ValueMapFloat, ValueMapInt, ValueMapBool, AssoVecDouble , AssoVecFloat, AssoVecInt, AssoVecBool, Nothing }; - template struct AssoVec { typedef typename edm::AssociationVector > type; }; - template bool run_(const edm::Event &iEvent, const Collection &coll, std::vector &ret) ; + template bool run_(const edm::EDGetTokenT & token, const edm::Event &iEvent, const Collection &coll, std::vector &ret) ; Type type_; edm::InputTag in_; std::string label_; + edm::EDGetTokenT > tokenVMd_; + edm::EDGetTokenT > tokenVMf_; + edm::EDGetTokenT > tokenVMi_; + edm::EDGetTokenT > tokenVMb_; + edm::EDGetTokenT::type > tokenAVd_; + edm::EDGetTokenT::type > tokenAVf_; + edm::EDGetTokenT::type > tokenAVi_; + edm::EDGetTokenT::type > tokenAVb_; }; template -bool AnyNumberAssociationAdaptor::run_(const edm::Event &iEvent, const Collection &coll, std::vector &ret) { +bool AnyNumberAssociationAdaptor::run_(const edm::EDGetTokenT & token, const edm::Event &iEvent, const Collection &coll, std::vector &ret) { edm::Handle handle; - iEvent.getByLabel(in_, handle); + iEvent.getByToken(token, handle); if (handle.failedToGet()) return false; for (size_t i = 0, n = coll.size(); i < n; ++i) { diff --git a/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h b/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h index cd218a14f2a8e..3614d63032d5e 100644 --- a/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h +++ b/PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h @@ -19,8 +19,8 @@ namespace pat { namespace helper { typedef typename Map::Filler MapFiller; explicit AnythingToValueMap(const edm::ParameterSet & iConfig) : failSilently_(iConfig.getUntrackedParameter("failSilently", false)), - src_(iConfig.getParameter("src")), - adaptor_(iConfig) { + src_(consumes(iConfig.getParameter("src"))), + adaptor_(iConfig,consumesCollector()) { produces< Map >(adaptor_.label()); } ~AnythingToValueMap() { } @@ -29,14 +29,14 @@ namespace pat { namespace helper { private: bool failSilently_; - edm::InputTag src_; + edm::EDGetTokenT src_; Adaptor adaptor_; }; template void AnythingToValueMap::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) { edm::Handle handle; - iEvent.getByLabel(src_, handle); + iEvent.getByToken(src_, handle); if (handle.failedToGet() && failSilently_) return; bool adaptorOk = adaptor_.init(iEvent); @@ -61,11 +61,11 @@ void AnythingToValueMap::produce(edm::Event & iEv typedef typename Map::Filler MapFiller; explicit ManyThingsToValueMaps(const edm::ParameterSet & iConfig) : failSilently_(iConfig.getUntrackedParameter("failSilently", false)), - src_(iConfig.getParameter("collection")), + src_(consumes(iConfig.getParameter("collection"))), inputs_(iConfig.getParameter >("associations")) { for (std::vector::const_iterator it = inputs_.begin(), ed = inputs_.end(); it != ed; ++it) { - adaptors_.push_back(Adaptor(*it, iConfig)); + adaptors_.push_back(Adaptor(*it, iConfig, consumesCollector())); produces< Map >(adaptors_.back().label()); } } @@ -75,7 +75,7 @@ void AnythingToValueMap::produce(edm::Event & iEv private: bool failSilently_; - edm::InputTag src_; + edm::EDGetTokenT src_; std::vector inputs_; std::vector adaptors_; }; @@ -83,7 +83,7 @@ void AnythingToValueMap::produce(edm::Event & iEv template void ManyThingsToValueMaps::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) { edm::Handle handle; - iEvent.getByLabel(src_, handle); + iEvent.getByToken(src_, handle); if (handle.failedToGet() && failSilently_) return; std::vector ret; diff --git a/PhysicsTools/TagAndProbe/plugins/ProbeMulteplicityProducer.cc b/PhysicsTools/TagAndProbe/plugins/ProbeMulteplicityProducer.cc index efd2ac747ce94..f891643471d32 100644 --- a/PhysicsTools/TagAndProbe/plugins/ProbeMulteplicityProducer.cc +++ b/PhysicsTools/TagAndProbe/plugins/ProbeMulteplicityProducer.cc @@ -30,14 +30,14 @@ class ProbeMulteplicityProducer : public edm::EDProducer { virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup); private: - edm::InputTag pairs_; + edm::EDGetTokenT pairs_; StringCutObjectSelector pairCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class StringCutObjectSelector probeCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class }; ProbeMulteplicityProducer::ProbeMulteplicityProducer(const edm::ParameterSet & iConfig) : - pairs_(iConfig.getParameter("pairs")), + pairs_(consumes(iConfig.getParameter("pairs"))), pairCut_(iConfig.existsAs("pairSelection") ? iConfig.getParameter("pairSelection") : "", true), probeCut_(iConfig.existsAs("probeSelection") ? iConfig.getParameter("probeSelection") : "", true) { @@ -57,7 +57,7 @@ ProbeMulteplicityProducer::produce(edm::Event & iEvent, const edm::EventSetup & // read input Handle > pairs; - iEvent.getByLabel(pairs_, pairs); + iEvent.getByToken(pairs_, pairs); // fill unsigned int i = 0;