Skip to content

Commit

Permalink
Avoid ESHandle where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterdavid committed Oct 24, 2020
1 parent 75d3207 commit d854f37
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ void SiStripProcessedRawDigiProducer::produce(edm::Event& e, const edm::EventSet
edm::Handle<edm::DetSetVector<SiStripDigi> > inputDigis;
edm::Handle<edm::DetSetVector<SiStripRawDigi> > inputRawdigis;

gainHandle_ = es.getHandle(gainToken_);
const auto& gain = es.getData(gainToken_);
subtractorPed_->init(es);
subtractorCMN_->init(es);

std::string label = findInput(inputRawdigis, inputTokensRawDigi_, e);
if ("VirginRaw" == label)
vr_process(*inputRawdigis, *output);
vr_process(*inputRawdigis, *output, gain);
else if ("ProcessedRaw" == label)
pr_process(*inputRawdigis, *output);
pr_process(*inputRawdigis, *output, gain);
else if ("ZeroSuppressed" == findInput(inputDigis, inputTokensDigi_, e))
zs_process(*inputDigis, *output);
zs_process(*inputDigis, *output, gain);
else
edm::LogError("Input Not Found");

Expand All @@ -63,47 +63,51 @@ inline std::string SiStripProcessedRawDigiProducer::findInput(edm::Handle<T>& ha
}

void SiStripProcessedRawDigiProducer::zs_process(const edm::DetSetVector<SiStripDigi>& input,
edm::DetSetVector<SiStripProcessedRawDigi>& output) {
edm::DetSetVector<SiStripProcessedRawDigi>& output,
const SiStripGain& gain) {
std::vector<float> digis;
for (edm::DetSetVector<SiStripDigi>::const_iterator detset = input.begin(); detset != input.end(); ++detset) {
digis.clear();
for (edm::DetSet<SiStripDigi>::const_iterator digi = detset->begin(); digi != detset->end(); ++digi) {
digis.resize(digi->strip(), 0);
digis.push_back(digi->adc());
}
common_process(detset->id, digis, output);
common_process(detset->id, digis, output, gain);
}
}

void SiStripProcessedRawDigiProducer::pr_process(const edm::DetSetVector<SiStripRawDigi>& input,
edm::DetSetVector<SiStripProcessedRawDigi>& output) {
edm::DetSetVector<SiStripProcessedRawDigi>& output,
const SiStripGain& gain) {
for (edm::DetSetVector<SiStripRawDigi>::const_iterator detset = input.begin(); detset != input.end(); ++detset) {
std::vector<float> digis;
transform(
detset->begin(), detset->end(), back_inserter(digis), std::bind(&SiStripRawDigi::adc, std::placeholders::_1));
subtractorCMN_->subtract(detset->id, 0, digis);
common_process(detset->id, digis, output);
common_process(detset->id, digis, output, gain);
}
}

void SiStripProcessedRawDigiProducer::vr_process(const edm::DetSetVector<SiStripRawDigi>& input,
edm::DetSetVector<SiStripProcessedRawDigi>& output) {
edm::DetSetVector<SiStripProcessedRawDigi>& output,
const SiStripGain& gain) {
for (edm::DetSetVector<SiStripRawDigi>::const_iterator detset = input.begin(); detset != input.end(); ++detset) {
std::vector<int16_t> int_digis(detset->size());
subtractorPed_->subtract(*detset, int_digis);
std::vector<float> digis(int_digis.begin(), int_digis.end());
subtractorCMN_->subtract(detset->id, 0, digis);
common_process(detset->id, digis, output);
common_process(detset->id, digis, output, gain);
}
}

void SiStripProcessedRawDigiProducer::common_process(const uint32_t detId,
std::vector<float>& digis,
edm::DetSetVector<SiStripProcessedRawDigi>& output) {
edm::DetSetVector<SiStripProcessedRawDigi>& output,
const SiStripGain& gain) {
//Apply Gains
SiStripApvGain::Range detGainRange = gainHandle_->getRange(detId);
SiStripApvGain::Range detGainRange = gain.getRange(detId);
for (std::vector<float>::iterator it = digis.begin(); it < digis.end(); ++it)
(*it) /= (gainHandle_->getStripGain(it - digis.begin(), detGainRange));
(*it) /= (gain.getStripGain(it - digis.begin(), detGainRange));

//Insert as DetSet
edm::DetSet<SiStripProcessedRawDigi> ds(detId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "RecoLocalTracker/SiStripZeroSuppression/interface/SiStripPedestalsSubtractor.h"
Expand All @@ -30,16 +29,24 @@ class SiStripProcessedRawDigiProducer : public edm::EDProducer {
template <class T>
std::string findInput(edm::Handle<T>& handle, const std::vector<edm::EDGetTokenT<T> >& tokens, const edm::Event& e);

void vr_process(const edm::DetSetVector<SiStripRawDigi>&, edm::DetSetVector<SiStripProcessedRawDigi>&);
void pr_process(const edm::DetSetVector<SiStripRawDigi>&, edm::DetSetVector<SiStripProcessedRawDigi>&);
void zs_process(const edm::DetSetVector<SiStripDigi>&, edm::DetSetVector<SiStripProcessedRawDigi>&);
void common_process(const uint32_t, std::vector<float>&, edm::DetSetVector<SiStripProcessedRawDigi>&);
void vr_process(const edm::DetSetVector<SiStripRawDigi>&,
edm::DetSetVector<SiStripProcessedRawDigi>&,
const SiStripGain&);
void pr_process(const edm::DetSetVector<SiStripRawDigi>&,
edm::DetSetVector<SiStripProcessedRawDigi>&,
const SiStripGain&);
void zs_process(const edm::DetSetVector<SiStripDigi>&,
edm::DetSetVector<SiStripProcessedRawDigi>&,
const SiStripGain&);
void common_process(const uint32_t,
std::vector<float>&,
edm::DetSetVector<SiStripProcessedRawDigi>&,
const SiStripGain&);

std::vector<edm::InputTag> inputTags_;
std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > > inputTokensDigi_;
std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > > inputTokensRawDigi_;
edm::ESGetToken<SiStripGain, SiStripGainRcd> gainToken_;
edm::ESHandle<SiStripGain> gainHandle_;

std::unique_ptr<SiStripPedestalsSubtractor> subtractorPed_;
std::unique_ptr<SiStripCommonModeNoiseSubtractor> subtractorCMN_;
Expand Down
7 changes: 3 additions & 4 deletions DPGAnalysis/SiStripTools/interface/Multiplicities.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef DPGAnalysis_SiStripTools_Multiplicities_H
#define DPGAnalysis_SiStripTools_Multiplicities_H

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
Expand Down Expand Up @@ -87,16 +86,16 @@ template <class T>
void SingleMultiplicity<T>::getEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
m_mult = 0;

edm::ESHandle<SiStripQuality> qualityHandle;
const SiStripQuality* quality = nullptr;
if (m_useQuality) {
qualityHandle = iSetup.getHandle(m_qualityToken);
quality = &iSetup.getData(m_qualityToken);
}

edm::Handle<T> digis;
iEvent.getByToken(m_collection, digis);

for (typename T::const_iterator it = digis->begin(); it != digis->end(); it++) {
if (!m_useQuality || !qualityHandle->IsModuleBad(it->detId())) {
if (!m_useQuality || !quality->IsModuleBad(it->detId())) {
if (m_modthr < 0 || int(it->size()) < m_modthr) {
m_mult += it->size();
// mult += it->size();
Expand Down
1 change: 0 additions & 1 deletion DPGAnalysis/SiStripTools/plugins/APVShotsFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
1 change: 0 additions & 1 deletion DPGAnalysis/SiStripTools/plugins/CommonModeAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
5 changes: 2 additions & 3 deletions DPGAnalysis/SiStripTools/plugins/LargeEvents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down Expand Up @@ -66,7 +65,7 @@ class LargeEvents : public edm::EDFilter {
int _absthr;
int _modthr;
bool _useQuality;
edm::ESHandle<SiStripQuality> _qualityHandle;
const SiStripQuality* _qualityHandle = nullptr;
edm::ESWatcher<SiStripQualityRcd> _qualityWatcher;
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> _qualityToken;
};
Expand Down Expand Up @@ -109,7 +108,7 @@ bool LargeEvents<T>::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {

if (_useQuality) {
if (_qualityWatcher.check(iSetup)) {
_qualityHandle = iSetup.getHandle(_qualityToken);
_qualityHandle = &iSetup.getData(_qualityToken);
LogDebug("SiStripQualityUpdated") << "SiStripQuality has changed and it will be updated";
}
}
Expand Down
12 changes: 5 additions & 7 deletions DPGAnalysis/SiStripTools/plugins/TrackerDpgAnalysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/transform.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand Down Expand Up @@ -164,8 +163,7 @@ class TrackerDpgAnalysis : public edm::EDAnalyzer {
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
edm::ESHandle<SiStripFedCabling> cabling_;
edm::ESHandle<TrackerGeometry> tracker_;
const TrackerGeometry* tracker_;
std::multimap<const uint32_t, const FedChannelConnection*> connections_;
bool functionality_offtrackClusters_, functionality_ontrackClusters_, functionality_pixclusters_,
functionality_pixvertices_, functionality_missingHits_, functionality_tracks_, functionality_vertices_,
Expand Down Expand Up @@ -1025,7 +1023,7 @@ void TrackerDpgAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup
// ------------ method called once each job just before starting event loop ------------
void TrackerDpgAnalysis::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
const auto& tTopo = iSetup.getData(tTopoToken_);
tracker_ = iSetup.getHandle(tkGeomToken_);
tracker_ = &iSetup.getData(tkGeomToken_);

//HLT names
bool changed(true);
Expand All @@ -1045,10 +1043,10 @@ void TrackerDpgAnalysis::beginRun(const edm::Run& iRun, const edm::EventSetup& i
TrackerMap tmap("Delays");

// cabling I (readout)
cabling_ = iSetup.getHandle(fedCablingToken_);
auto feds = cabling_->fedIds();
const auto& cabling = iSetup.getData(fedCablingToken_);
auto feds = cabling.fedIds();
for (auto fedid = feds.begin(); fedid < feds.end(); ++fedid) {
auto connections = cabling_->fedConnections(*fedid);
auto connections = cabling.fedConnections(*fedid);
for (auto conn = connections.begin(); conn < connections.end(); ++conn) {
// Fill the "old" map to be used for lookup during analysis
if (conn->isConnected())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ namespace sistrip {
std::stringstream sss;
sss << "[sistrip::RawToDigiModule::" << __func__ << "]"
<< " Summary of FED cabling:" << std::endl;
edm::ESHandle<TrackerTopology> tTopo;
setup.get<TrackerTopologyRcd>().get(tTopo);
cabling_->summary(sss, &setup.getData(tTopoToken_));
LogTrace("SiStripRawToDigi") << sss.str();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
#include "CalibTracker/Records/interface/SiStripQualityRcd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

Expand Down Expand Up @@ -34,8 +33,8 @@ class IteratedMedianCMNSubtractor : public SiStripCommonModeNoiseSubtractor {
int iterations_;
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> noiseToken_;
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> qualityToken_;
edm::ESHandle<SiStripNoises> noiseHandle;
edm::ESHandle<SiStripQuality> qualityHandle;
const SiStripNoises* noiseHandle;
const SiStripQuality* qualityHandle;
edm::ESWatcher<SiStripNoisesRcd> noiseWatcher_;
edm::ESWatcher<SiStripQualityRcd> qualityWatcher_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
#include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
Expand Down Expand Up @@ -87,9 +86,9 @@ class SiStripAPVRestorer {
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> qualityToken_;
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> noiseToken_;
edm::ESGetToken<SiStripPedestals, SiStripPedestalsRcd> pedestalToken_;
edm::ESHandle<SiStripQuality> qualityHandle;
edm::ESHandle<SiStripNoises> noiseHandle;
edm::ESHandle<SiStripPedestals> pedestalHandle;
const SiStripQuality* qualityHandle;
const SiStripNoises* noiseHandle;
const SiStripPedestals* pedestalHandle;
edm::ESWatcher<SiStripQualityRcd> qualityWatcher_;
edm::ESWatcher<SiStripNoisesRcd> noiseWatcher_;
edm::ESWatcher<SiStripPedestalsRcd> pedestalWatcher_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef RECOLOCALTRACKER_SISTRIPZEROSUPPRESSION_SISTRIPPEDESTALSSUBTRACTOR_H
#define RECOLOCALTRACKER_SISTRIPZEROSUPPRESSION_SISTRIPPEDESTALSSUBTRACTOR_H

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
Expand All @@ -25,7 +24,7 @@ class SiStripPedestalsSubtractor {
: pedestalsToken_(iC.esConsumes<SiStripPedestals, SiStripPedestalsRcd>()), fedmode_(mode) {}
edm::ESGetToken<SiStripPedestals, SiStripPedestalsRcd> pedestalsToken_;
edm::ESWatcher<SiStripPedestalsRcd> pedestalsWatcher_;
edm::ESHandle<SiStripPedestals> pedestalsHandle;
const SiStripPedestals* pedestalsHandle;
std::vector<int> pedestals;
bool fedmode_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
#include "CalibTracker/Records/interface/SiStripQualityRcd.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
class SiStripNoises;
Expand All @@ -29,8 +28,8 @@ class TT6CMNSubtractor : public SiStripCommonModeNoiseSubtractor {
double cut_to_avoid_signal_;
edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> noiseToken_;
edm::ESGetToken<SiStripQuality, SiStripQualityRcd> qualityToken_;
edm::ESHandle<SiStripNoises> noiseHandle;
edm::ESHandle<SiStripQuality> qualityHandle;
const SiStripNoises* noiseHandle;
const SiStripQuality* qualityHandle;
edm::ESWatcher<SiStripNoisesRcd> noiseWatcher_;
edm::ESWatcher<SiStripQualityRcd> qualityWatcher_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

void IteratedMedianCMNSubtractor::init(const edm::EventSetup& es) {
if (noiseWatcher_.check(es)) {
noiseHandle = es.getHandle(noiseToken_);
noiseHandle = &es.getData(noiseToken_);
}
if (qualityWatcher_.check(es)) {
qualityHandle = es.getHandle(qualityToken_);
qualityHandle = &es.getData(qualityToken_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ SiStripAPVRestorer::SiStripAPVRestorer(const edm::ParameterSet& conf, edm::Consu

void SiStripAPVRestorer::init(const edm::EventSetup& es) {
if (noiseWatcher_.check(es)) {
noiseHandle = es.getHandle(noiseToken_);
noiseHandle = &es.getData(noiseToken_);
}
if (qualityWatcher_.check(es)) {
qualityHandle = es.getHandle(qualityToken_);
qualityHandle = &es.getData(qualityToken_);
}
if (pedestalWatcher_.check(es)) {
pedestalHandle = es.getHandle(pedestalToken_);
pedestalHandle = &es.getData(pedestalToken_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void SiStripPedestalsSubtractor::init(const edm::EventSetup& es) {
if (pedestalsWatcher_.check(es)) {
pedestalsHandle = es.getHandle(pedestalsToken_);
pedestalsHandle = &es.getData(pedestalsToken_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
#include <cmath>

// FIXME use ESWatcher auto-call to get rid of init (here and in IteratedMedian
void TT6CMNSubtractor::init(const edm::EventSetup& es) {
if (noiseWatcher_.check(es)) {
noiseHandle = es.getHandle(noiseToken_);
noiseHandle = &es.getData(noiseToken_);
}
if (qualityWatcher_.check(es)) {
qualityHandle = es.getHandle(qualityToken_);
qualityHandle = &es.getData(qualityToken_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/DetSet.h"
#include "DataFormats/Common/interface/DetSetVector.h"
Expand Down Expand Up @@ -83,7 +82,7 @@ class SiStripBaselineAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedReso

std::unique_ptr<SiStripPedestalsSubtractor> subtractorPed_;
edm::ESGetToken<SiStripPedestals, SiStripPedestalsRcd> pedestalsToken_;
edm::ESHandle<SiStripPedestals> pedestalsHandle;
const SiStripPedestals* pedestalsHandle;
edm::ESWatcher<SiStripPedestalsRcd> pedestalsWatcher_;
std::vector<int> pedestals;

Expand Down Expand Up @@ -165,7 +164,7 @@ void SiStripBaselineAnalyzer::analyze(const edm::Event& e, const edm::EventSetup
using namespace edm;
if (plotPedestals_ && actualModule_ == 0) {
if (pedestalsWatcher_.check(es)) {
pedestalsHandle = es.getHandle(pedestalsToken_);
pedestalsHandle = &es.getData(pedestalsToken_);
}

std::vector<uint32_t> detIdV;
Expand Down
Loading

0 comments on commit d854f37

Please sign in to comment.