Skip to content

Commit

Permalink
Consumes migration for the modules I had added to PhysicsTools/TagAnd…
Browse files Browse the repository at this point in the history
…Probe in this PR
  • Loading branch information
gpetruc committed Apr 21, 2015
1 parent a61a226 commit 98cd7c2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
62 changes: 40 additions & 22 deletions PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<reco::Candidate> Collection;
template<typename T> struct AssoVec { typedef typename edm::AssociationVector<reco::CandidateBaseRefProd, typename std::vector<T> > 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<edm::ValueMap<double> >(in)),
tokenVMf_(iC.consumes<edm::ValueMap<float> >(in)),
tokenVMi_(iC.consumes<edm::ValueMap<int> >(in)),
tokenVMb_(iC.consumes<edm::ValueMap<bool> >(in)),
tokenAVd_(iC.consumes<AssoVec<double>::type >(in)),
tokenAVf_(iC.consumes<AssoVec<float>::type >(in)),
tokenAVi_(iC.consumes<AssoVec<int>::type >(in)),
tokenAVb_(iC.consumes<AssoVec<bool>::type >(in))
{ }

const std::string & label() { return label_; }

bool run(const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) {
switch (type_) {
case Uninitialized:
if (run_<edm::ValueMap<double> >(iEvent, coll, ret)) { type_ = ValueMapDouble; return true; }
if (run_<edm::ValueMap<float> >(iEvent, coll, ret)) { type_ = ValueMapFloat; return true; }
if (run_<edm::ValueMap<int> >(iEvent, coll, ret)) { type_ = ValueMapInt; return true; }
if (run_<edm::ValueMap<bool> >(iEvent, coll, ret)) { type_ = ValueMapBool; return true; }
if (run_<AssoVec<double>::type >(iEvent, coll, ret)) { type_ = AssoVecDouble; return true; }
if (run_<AssoVec<float>::type >(iEvent, coll, ret)) { type_ = AssoVecFloat; return true; }
if (run_<AssoVec<int>::type >(iEvent, coll, ret)) { type_ = AssoVecInt; return true; }
if (run_<AssoVec<bool>::type >(iEvent, coll, ret)) { type_ = AssoVecBool; return true; }
if (run_<edm::ValueMap<double> >(tokenVMd_, iEvent, coll, ret)) { type_ = ValueMapDouble; return true; }
if (run_<edm::ValueMap<float> >(tokenVMf_, iEvent, coll, ret)) { type_ = ValueMapFloat; return true; }
if (run_<edm::ValueMap<int> >(tokenVMi_, iEvent, coll, ret)) { type_ = ValueMapInt; return true; }
if (run_<edm::ValueMap<bool> >(tokenVMb_, iEvent, coll, ret)) { type_ = ValueMapBool; return true; }
if (run_<AssoVec<double>::type >(tokenAVd_, iEvent, coll, ret)) { type_ = AssoVecDouble; return true; }
if (run_<AssoVec<float>::type >(tokenAVf_, iEvent, coll, ret)) { type_ = AssoVecFloat; return true; }
if (run_<AssoVec<int>::type >(tokenAVi_, iEvent, coll, ret)) { type_ = AssoVecInt; return true; }
if (run_<AssoVec<bool>::type >(tokenAVb_, iEvent, coll, ret)) { type_ = AssoVecBool; return true; }
type_ = Nothing; return false;
break;
case ValueMapDouble : return run_<edm::ValueMap<double> >(iEvent, coll, ret);
case ValueMapFloat : return run_<edm::ValueMap<float> >(iEvent, coll, ret);
case ValueMapInt : return run_<edm::ValueMap<int> >(iEvent, coll, ret);
case ValueMapBool : return run_<edm::ValueMap<bool> >(iEvent, coll, ret);
case AssoVecDouble : return run_<AssoVec<double>::type >(iEvent, coll, ret);
case AssoVecFloat : return run_<AssoVec<float>::type >(iEvent, coll, ret);
case AssoVecInt : return run_<AssoVec<int>::type >(iEvent, coll, ret);
case AssoVecBool : return run_<AssoVec<bool>::type >(iEvent, coll, ret);
case ValueMapDouble : return run_<edm::ValueMap<double> >(tokenVMd_, iEvent, coll, ret);
case ValueMapFloat : return run_<edm::ValueMap<float> >(tokenVMf_, iEvent, coll, ret);
case ValueMapInt : return run_<edm::ValueMap<int> >(tokenVMi_, iEvent, coll, ret);
case ValueMapBool : return run_<edm::ValueMap<bool> >(tokenVMb_, iEvent, coll, ret);
case AssoVecDouble : return run_<AssoVec<double>::type >(tokenAVd_, iEvent, coll, ret);
case AssoVecFloat : return run_<AssoVec<float>::type >(tokenAVf_, iEvent, coll, ret);
case AssoVecInt : return run_<AssoVec<int>::type >(tokenAVi_, iEvent, coll, ret);
case AssoVecBool : return run_<AssoVec<bool>::type >(tokenAVb_, iEvent, coll, ret);
case Nothing : return false;
}
return false;
Expand All @@ -46,18 +57,25 @@ class AnyNumberAssociationAdaptor {
ValueMapDouble, ValueMapFloat, ValueMapInt, ValueMapBool,
AssoVecDouble , AssoVecFloat, AssoVecInt, AssoVecBool,
Nothing };
template<typename T> struct AssoVec { typedef typename edm::AssociationVector<reco::CandidateBaseRefProd, typename std::vector<T> > type; };
template<typename T> bool run_(const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) ;
template<typename T> bool run_(const edm::EDGetTokenT<T> & token, const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) ;
Type type_;
edm::InputTag in_;
std::string label_;
edm::EDGetTokenT<edm::ValueMap<double> > tokenVMd_;
edm::EDGetTokenT<edm::ValueMap<float> > tokenVMf_;
edm::EDGetTokenT<edm::ValueMap<int> > tokenVMi_;
edm::EDGetTokenT<edm::ValueMap<bool> > tokenVMb_;
edm::EDGetTokenT<AssoVec<double>::type > tokenAVd_;
edm::EDGetTokenT<AssoVec<float>::type > tokenAVf_;
edm::EDGetTokenT<AssoVec<int>::type > tokenAVi_;
edm::EDGetTokenT<AssoVec<bool>::type > tokenAVb_;

};

template<typename T>
bool AnyNumberAssociationAdaptor::run_(const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) {
bool AnyNumberAssociationAdaptor::run_(const edm::EDGetTokenT<T> & token, const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) {
edm::Handle<T> 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) {
Expand Down
16 changes: 8 additions & 8 deletions PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace pat { namespace helper {
typedef typename Map::Filler MapFiller;
explicit AnythingToValueMap(const edm::ParameterSet & iConfig) :
failSilently_(iConfig.getUntrackedParameter<bool>("failSilently", false)),
src_(iConfig.getParameter<edm::InputTag>("src")),
adaptor_(iConfig) {
src_(consumes<Collection>(iConfig.getParameter<edm::InputTag>("src"))),
adaptor_(iConfig,consumesCollector()) {
produces< Map >(adaptor_.label());
}
~AnythingToValueMap() { }
Expand All @@ -29,14 +29,14 @@ namespace pat { namespace helper {

private:
bool failSilently_;
edm::InputTag src_;
edm::EDGetTokenT<Collection> src_;
Adaptor adaptor_;
};

template<class Adaptor, class Collection, typename value_type>
void AnythingToValueMap<Adaptor,Collection,value_type>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
edm::Handle<Collection> handle;
iEvent.getByLabel(src_, handle);
iEvent.getByToken(src_, handle);
if (handle.failedToGet() && failSilently_) return;

bool adaptorOk = adaptor_.init(iEvent);
Expand All @@ -61,11 +61,11 @@ void AnythingToValueMap<Adaptor,Collection,value_type>::produce(edm::Event & iEv
typedef typename Map::Filler MapFiller;
explicit ManyThingsToValueMaps(const edm::ParameterSet & iConfig) :
failSilently_(iConfig.getUntrackedParameter<bool>("failSilently", false)),
src_(iConfig.getParameter<edm::InputTag>("collection")),
src_(consumes<Collection>(iConfig.getParameter<edm::InputTag>("collection"))),
inputs_(iConfig.getParameter<std::vector<edm::InputTag> >("associations"))
{
for (std::vector<edm::InputTag>::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());
}
}
Expand All @@ -75,15 +75,15 @@ void AnythingToValueMap<Adaptor,Collection,value_type>::produce(edm::Event & iEv

private:
bool failSilently_;
edm::InputTag src_;
edm::EDGetTokenT<Collection> src_;
std::vector<edm::InputTag> inputs_;
std::vector<Adaptor> adaptors_;
};

template<class Adaptor, class Collection, typename value_type>
void ManyThingsToValueMaps<Adaptor,Collection,value_type>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
edm::Handle<Collection> handle;
iEvent.getByLabel(src_, handle);
iEvent.getByToken(src_, handle);
if (handle.failedToGet() && failSilently_) return;

std::vector<value_type> ret;
Expand Down
6 changes: 3 additions & 3 deletions PhysicsTools/TagAndProbe/plugins/ProbeMulteplicityProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<reco::CandidateView> pairs_;
StringCutObjectSelector<reco::Candidate,true> pairCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
StringCutObjectSelector<reco::Candidate,true> probeCut_; // lazy parsing, to allow cutting on variables not in reco::Candidate class
};


ProbeMulteplicityProducer::ProbeMulteplicityProducer(const edm::ParameterSet & iConfig) :
pairs_(iConfig.getParameter<edm::InputTag>("pairs")),
pairs_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("pairs"))),
pairCut_(iConfig.existsAs<std::string>("pairSelection") ? iConfig.getParameter<std::string>("pairSelection") : "", true),
probeCut_(iConfig.existsAs<std::string>("probeSelection") ? iConfig.getParameter<std::string>("probeSelection") : "", true)
{
Expand All @@ -57,7 +57,7 @@ ProbeMulteplicityProducer::produce(edm::Event & iEvent, const edm::EventSetup &

// read input
Handle<View<reco::Candidate> > pairs;
iEvent.getByLabel(pairs_, pairs);
iEvent.getByToken(pairs_, pairs);

// fill
unsigned int i = 0;
Expand Down

0 comments on commit 98cd7c2

Please sign in to comment.