Skip to content

Commit 64ec912

Browse files
authored
Merge pull request #48682 from Dr15Jones/modifyInputTag
Cache EDGetToken in InputTag
2 parents 85d0267 + ca812a4 commit 64ec912

18 files changed

+169
-206
lines changed

CalibTracker/SiStripCommon/plugins/ShallowDigisProducer.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
#include "FWCore/Framework/interface/EventSetup.h"
55
#include "FWCore/MessageLogger/interface/MessageLogger.h"
66
#include "FWCore/ParameterSet/interface/ParameterSet.h"
7-
#include "DataFormats/Common/interface/DetSetVector.h"
8-
#include "DataFormats/Common/interface/DetSetVectorNew.h"
9-
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
7+
#include "FWCore/Utilities/interface/InputTag.h"
108

11-
ShallowDigisProducer::ShallowDigisProducer(const edm::ParameterSet& conf)
12-
: inputTags(conf.getParameter<std::vector<edm::InputTag> >("DigiProducersList")), noisesToken_(esConsumes()) {
13-
produces<std::vector<unsigned> >("id");
14-
produces<std::vector<unsigned> >("subdet");
15-
produces<std::vector<unsigned> >("strip");
16-
produces<std::vector<unsigned> >("adc");
17-
produces<std::vector<float> >("noise");
9+
ShallowDigisProducer::ShallowDigisProducer(const edm::ParameterSet& conf) : noisesToken_(esConsumes()) {
10+
for (auto const& tag : conf.getParameter<std::vector<edm::InputTag>>("DigiProducersList")) {
11+
oldTokens_.emplace_back(consumes<edm::DetSetVector<SiStripDigi>>(tag));
12+
newTokens_.emplace_back(consumes<edmNew::DetSetVector<SiStripDigi>>(tag));
13+
}
14+
produces<std::vector<unsigned>>("id");
15+
produces<std::vector<unsigned>>("subdet");
16+
produces<std::vector<unsigned>>("strip");
17+
produces<std::vector<unsigned>>("adc");
18+
produces<std::vector<float>>("noise");
1819
}
1920

2021
void ShallowDigisProducer::insert(products& p, edm::Event& e) {
@@ -41,24 +42,25 @@ inline void ShallowDigisProducer::recordDigis(const T& digiCollection, products&
4142

4243
void ShallowDigisProducer::produce(edm::Event& e, const edm::EventSetup& es) {
4344
products p;
44-
edm::Handle<edm::DetSetVector<SiStripDigi> > inputOld;
45-
edm::Handle<edmNew::DetSetVector<SiStripDigi> > inputNew;
45+
edm::Handle<edm::DetSetVector<SiStripDigi>> inputOld;
46+
edm::Handle<edmNew::DetSetVector<SiStripDigi>> inputNew;
4647
const auto& noises = es.getData(noisesToken_);
47-
if (findInput(inputOld, e))
48+
if (findInput(inputOld, oldTokens_, e))
4849
recordDigis(*inputOld, p, noises);
49-
else if (findInput(inputNew, e))
50+
else if (findInput(inputNew, newTokens_, e))
5051
recordDigis(*inputNew, p, noises);
5152
else
5253
edm::LogWarning("Input Not Found");
5354
insert(p, e);
5455
}
5556

5657
template <class T>
57-
inline bool ShallowDigisProducer::findInput(edm::Handle<T>& handle, const edm::Event& e) {
58-
for (auto const& inputTag : inputTags) {
59-
e.getByLabel(inputTag, handle);
58+
inline bool ShallowDigisProducer::findInput(edm::Handle<T>& handle,
59+
std::vector<edm::EDGetTokenT<T>> const& tokens,
60+
const edm::Event& e) {
61+
for (auto const& token : tokens) {
62+
handle = e.getHandle(token);
6063
if (handle.isValid() && !handle->empty()) {
61-
LogDebug("Input") << inputTag;
6264
return true;
6365
}
6466
}

CalibTracker/SiStripCommon/plugins/ShallowDigisProducer.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33

44
#include "FWCore/Framework/interface/stream/EDProducer.h"
55
#include "FWCore/Framework/interface/Frameworkfwd.h"
6-
#include "FWCore/Utilities/interface/InputTag.h"
6+
#include "FWCore/Utilities/interface/EDGetToken.h"
77
#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
88
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
9+
#include "DataFormats/Common/interface/DetSetVector.h"
10+
#include "DataFormats/Common/interface/DetSetVectorNew.h"
11+
#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
912

1013
class ShallowDigisProducer : public edm::stream::EDProducer<> {
1114
public:
1215
explicit ShallowDigisProducer(const edm::ParameterSet &);
1316

1417
private:
1518
struct products {
16-
std::unique_ptr<std::vector<unsigned> > id;
17-
std::unique_ptr<std::vector<unsigned> > subdet;
18-
std::unique_ptr<std::vector<unsigned> > strip;
19-
std::unique_ptr<std::vector<unsigned> > adc;
20-
std::unique_ptr<std::vector<float> > noise;
19+
std::unique_ptr<std::vector<unsigned>> id;
20+
std::unique_ptr<std::vector<unsigned>> subdet;
21+
std::unique_ptr<std::vector<unsigned>> strip;
22+
std::unique_ptr<std::vector<unsigned>> adc;
23+
std::unique_ptr<std::vector<float>> noise;
2124
products()
2225
: id(new std::vector<unsigned>()),
2326
subdet(new std::vector<unsigned>()),
2427
strip(new std::vector<unsigned>()),
2528
adc(new std::vector<unsigned>()),
2629
noise(new std::vector<float>()) {}
2730
};
28-
std::vector<edm::InputTag> inputTags;
31+
std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripDigi>>> oldTokens_;
32+
std::vector<edm::EDGetTokenT<edmNew::DetSetVector<SiStripDigi>>> newTokens_;
2933
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> noisesToken_;
3034

3135
void produce(edm::Event &, const edm::EventSetup &) override;
3236
template <class T>
33-
bool findInput(edm::Handle<T> &, const edm::Event &);
37+
bool findInput(edm::Handle<T> &, std::vector<edm::EDGetTokenT<T>> const &, const edm::Event &);
3438
template <class T>
3539
void recordDigis(const T &, products &, const SiStripNoises &noises);
3640
void insert(products &, edm::Event &);

DQM/Physics/src/SingleTopTChannelLeptonDQM.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ namespace SingleTopTChannelLepton {
6767
}
6868

6969
if (elecExtras.existsAs<std::string>("rho")) {
70-
rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
70+
auto rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
71+
rhoToken_ = iC.consumes(rhoTag);
7172
}
7273
// electronId is optional; in case it's not found the
7374
// InputTag will remain empty
@@ -356,7 +357,9 @@ namespace SingleTopTChannelLepton {
356357
edm::Handle<edm::View<reco::GsfElectron>> elecs;
357358
reco::GsfElectron e;
358359
edm::Handle<double> _rhoHandle;
359-
event.getByLabel(rhoTag, _rhoHandle);
360+
if (!rhoToken_.isUninitialized()) {
361+
_rhoHandle = event.getHandle(rhoToken_);
362+
}
360363
if (!event.getByToken(elecs_, elecs))
361364
return;
362365

DQM/Physics/src/SingleTopTChannelLeptonDQM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace SingleTopTChannelLepton {
150150
std::string elecIso_;
151151
/// extra selection on electrons
152152
std::unique_ptr<StringCutObjectSelector<reco::GsfElectron>> elecSelect_;
153-
edm::InputTag rhoTag;
153+
edm::EDGetTokenT<double> rhoToken_;
154154

155155
/// extra selection on primary vertices; meant to investigate the pile-up
156156
/// effect

DQM/Physics/src/SingleTopTChannelLeptonDQM_miniAOD.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ namespace SingleTopTChannelLepton_miniAOD {
6969
}
7070

7171
if (elecExtras.existsAs<std::string>("rho")) {
72-
rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
72+
auto rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
73+
rhoToken_ = iC.consumes(rhoTag);
7374
}
7475
// electronId is optional; in case it's not found the
7576
// InputTag will remain empty
@@ -416,8 +417,9 @@ namespace SingleTopTChannelLepton_miniAOD {
416417
return;
417418

418419
edm::Handle<double> _rhoHandle;
419-
event.getByLabel(rhoTag, _rhoHandle);
420-
//if (!event.getByToken(elecs_, elecs)) return;
420+
if (!rhoToken_.isUninitialized()) {
421+
_rhoHandle = event.getHandle(rhoToken_);
422+
}
421423

422424
// check availability of electron id
423425
edm::Handle<edm::ValueMap<float>> electronId;

DQM/Physics/src/SingleTopTChannelLeptonDQM_miniAOD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace SingleTopTChannelLepton_miniAOD {
9494
/// to be of form signalPath:MonitorPath
9595
std::vector<std::string> triggerPaths_;
9696

97-
edm::InputTag rhoTag;
97+
edm::EDGetTokenT<double> rhoToken_;
9898

9999
/// electronId label
100100
edm::EDGetTokenT<edm::ValueMap<float> > electronId_;

DQM/Physics/src/TopSingleLeptonDQM.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ namespace TopSingleLepton {
6161
}
6262

6363
if (elecExtras.existsAs<std::string>("rho")) {
64-
rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
64+
auto rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
65+
rhoToken_ = iC.consumes(rhoTag);
6566
}
6667
// electronId is optional; in case it's not found the
6768
// InputTag will remain empty
@@ -371,8 +372,6 @@ namespace TopSingleLepton {
371372

372373
// fill monitoring plots for electrons
373374
edm::Handle<edm::View<reco::GsfElectron>> elecs;
374-
edm::Handle<double> _rhoHandle;
375-
event.getByLabel(rhoTag, _rhoHandle);
376375
if (!event.getByToken(elecs_, elecs))
377376
return;
378377

@@ -383,6 +382,10 @@ namespace TopSingleLepton {
383382
return;
384383
}
385384
}
385+
edm::Handle<double> _rhoHandle;
386+
if (!rhoToken_.isUninitialized()) {
387+
_rhoHandle = event.getHandle(rhoToken_);
388+
}
386389
// loop electron collection
387390
unsigned int eMult = 0, eMultIso = 0;
388391
std::vector<const reco::GsfElectron*> isoElecs;

DQM/Physics/src/TopSingleLeptonDQM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace TopSingleLepton {
137137
double eidCutValue_;
138138
// electron ISO things
139139

140-
edm::InputTag rhoTag;
140+
edm::EDGetTokenT<double> rhoToken_;
141141

142142
/// extra selection on electrons
143143

DQM/Physics/src/TopSingleLeptonDQM_miniAOD.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ namespace TopSingleLepton_miniAOD {
7070
}
7171

7272
if (elecExtras.existsAs<std::string>("rho")) {
73-
rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
73+
auto rhoTag = elecExtras.getParameter<edm::InputTag>("rho");
74+
rhoToken_ = iC.consumes(rhoTag);
7475
}
7576
// electronId is optional; in case it's not found the
7677
// InputTag will remain empty
@@ -406,8 +407,9 @@ namespace TopSingleLepton_miniAOD {
406407
return;
407408

408409
edm::Handle<double> _rhoHandle;
409-
event.getByLabel(rhoTag, _rhoHandle);
410-
//if (!event.getByToken(elecs_, elecs)) return;
410+
if (!rhoToken_.isUninitialized()) {
411+
_rhoHandle = event.getHandle(rhoToken_);
412+
}
411413

412414
// check availability of electron id
413415
edm::Handle<edm::ValueMap<float>> electronId;

DQM/Physics/src/TopSingleLeptonDQM_miniAOD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace TopSingleLepton_miniAOD {
9494
/// to be of form signalPath:MonitorPath
9595
std::vector<std::string> triggerPaths_;
9696

97-
edm::InputTag rhoTag;
97+
edm::EDGetTokenT<double> rhoToken_;
9898

9999
/// electronId label
100100
edm::EDGetTokenT<edm::ValueMap<float> > electronId_;

0 commit comments

Comments
 (0)