Skip to content

Commit

Permalink
Use of ESGetToken in RecoLocalCalo/HcalRecAlgos (replacing cms-sw#35234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Sep 12, 2021
1 parent 11ee6d8 commit a90d27c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
1 change: 0 additions & 1 deletion RecoLocalCalo/HcalRecAlgos/src/HBHEIsolatedNoiseAlgos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Original Author: John Paul Chou (Brown University)
#include "RecoLocalCalo/HcalRecAlgos/interface/HBHEIsolatedNoiseAlgos.h"

#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "DataFormats/METReco/interface/CaloMETCollection.h"
#include "DataFormats/METReco/interface/CaloMET.h"
Expand Down
29 changes: 12 additions & 17 deletions RecoLocalCalo/HcalRecAlgos/test/HcalRecHitReflagger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/one/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
Expand All @@ -37,7 +37,6 @@
#include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
#include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
#include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
#include "FWCore/Framework/interface/ESHandle.h"

using namespace std;
using namespace edm;
Expand All @@ -46,16 +45,15 @@ using namespace edm;
// class declaration
//

class HcalRecHitReflagger : public edm::EDProducer {
class HcalRecHitReflagger : public edm::one::EDProducer<> {
public:
explicit HcalRecHitReflagger(const edm::ParameterSet&);
~HcalRecHitReflagger();

private:
virtual void beginJob() override;
virtual void produce(edm::Event&, const edm::EventSetup&) override;
virtual void endJob() override;
virtual void beginRun(const Run& r, const EventSetup& c) override;
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

// Threshold function gets values from polynomial-parameterized functions
double GetThreshold(const int base, const std::vector<double>& params);
Expand All @@ -73,6 +71,8 @@ class HcalRecHitReflagger : public edm::EDProducer {
double GetSlope(const int ieta, const std::vector<double>& params);

// ----------member data ---------------------------
const edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tokTopo_;
const edm::ESGetToken<HcalChannelQuality, HcalChannelQualityRcd> tokChan_;
const HcalTopology* topo;
edm::InputTag hfInputLabel_;
edm::EDGetTokenT<HFRecHitCollection> tok_hf_;
Expand Down Expand Up @@ -115,7 +115,9 @@ class HcalRecHitReflagger : public edm::EDProducer {
//
// constructors and destructor
//
HcalRecHitReflagger::HcalRecHitReflagger(const edm::ParameterSet& ps) {
HcalRecHitReflagger::HcalRecHitReflagger(const edm::ParameterSet& ps)
: tokTopo_(esConsumes<HcalTopology, HcalRecNumberingRecord>()),
tokChan_(esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"))) {
//register your products
produces<HFRecHitCollection>();

Expand Down Expand Up @@ -158,9 +160,6 @@ HcalRecHitReflagger::~HcalRecHitReflagger() {
//
// member functions
//

void HcalRecHitReflagger::beginRun(const Run& r, const EventSetup& c) {}

// ------------ method called to produce the data ------------
void HcalRecHitReflagger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
// read HF RecHits
Expand All @@ -171,14 +170,10 @@ void HcalRecHitReflagger::produce(edm::Event& iEvent, const edm::EventSetup& iSe
}

//get the hcal topology
edm::ESHandle<HcalTopology> topo_;
iSetup.get<HcalRecNumberingRecord>().get(topo_);
topo = &*topo_;
topo = &iSetup.getData(tokTopo_);

//get channel quality conditions
edm::ESHandle<HcalChannelQuality> p;
iSetup.get<HcalChannelQualityRcd>().get("withTopo", p);
const HcalChannelQuality& chanquality_(*p.product());
const HcalChannelQuality& chanquality_ = iSetup.getData(tokChan_);

std::vector<DetId> mydetids = chanquality_.getAllChannels();
for (std::vector<DetId>::const_iterator i = mydetids.begin(); i != mydetids.end(); ++i) {
Expand Down
29 changes: 16 additions & 13 deletions RecoLocalCalo/HcalRecAlgos/test/HcalSevLvlAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

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

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
Expand All @@ -37,17 +36,21 @@
// class decleration
//

class HcalSevLvlAnalyzer : public edm::EDAnalyzer {
class HcalSevLvlAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit HcalSevLvlAnalyzer(const edm::ParameterSet&);
~HcalSevLvlAnalyzer();

private:
virtual void beginJob();
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void endJob();
void beginJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

// ----------member data ---------------------------
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
const edm::ESGetToken<SetupData, SetupRecord> totkSet_;
#endif
const edm::ESGetToken<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd> tokSev_;
};

//
Expand All @@ -62,8 +65,11 @@ class HcalSevLvlAnalyzer : public edm::EDAnalyzer {
// constructors and destructor
//
HcalSevLvlAnalyzer::HcalSevLvlAnalyzer(const edm::ParameterSet& iConfig)

{
:
#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
totkSet_(esConsumes()),
#endif
tokSev_(esConsumes()) {
//now do what ever initialization is needed

// initialize the severity level code
Expand All @@ -88,14 +94,11 @@ void HcalSevLvlAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup
#endif

#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
ESHandle<SetupData> pSetup;
iSetup.get<SetupRecord>().get(pSetup);
auto pSetup = &iSetup.getData(tokSet_);
#endif

// here's how to access the severity level computer:
ESHandle<HcalSeverityLevelComputer> mycomputer;
iSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
const HcalSeverityLevelComputer* myProd = mycomputer.product();
const HcalSeverityLevelComputer* myProd = &iSetup.getData(tokSev_);

// create some example cases:
std::cout << std::showbase;
Expand Down
8 changes: 4 additions & 4 deletions RecoLocalCalo/HcalRecAlgos/test/MahiDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class MahiDebugger : public edm::one::EDAnalyzer<edm::one::SharedResources> {
std::unique_ptr<MahiFit> mahi_;

edm::EDGetTokenT<HBHEChannelInfoCollection> token_ChannelInfo_;
const edm::ESGetToken<HcalTimeSlew, HcalTimeSlewRecord> tokDelay_;

const HcalTimeSlew* hcalTimeSlewDelay;

Expand Down Expand Up @@ -181,7 +182,8 @@ MahiDebugger::MahiDebugger(const edm::ParameterSet& iConfig)
nMaxItersMin_(iConfig.getParameter<int>("nMaxItersMin")),
nMaxItersNNLS_(iConfig.getParameter<int>("nMaxItersNNLS")),
deltaChiSqThresh_(iConfig.getParameter<double>("deltaChiSqThresh")),
nnlsThresh_(iConfig.getParameter<double>("nnlsThresh")) {
nnlsThresh_(iConfig.getParameter<double>("nnlsThresh")),
tokDelay_(esConsumes<HcalTimeSlew, HcalTimeSlewRecord>(edm::ESInputTag("", "HBHE"))) {
usesResource("TFileService");

mahi_ = std::make_unique<MahiFit>();
Expand Down Expand Up @@ -214,9 +216,7 @@ MahiDebugger::~MahiDebugger() {}
void MahiDebugger::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

edm::ESHandle<HcalTimeSlew> delay;
iSetup.get<HcalTimeSlewRecord>().get("HBHE", delay);
hcalTimeSlewDelay = &*delay;
hcalTimeSlewDelay = &iSetup.getData(tokDelay_);

run = iEvent.id().run();
evt = iEvent.id().event();
Expand Down

0 comments on commit a90d27c

Please sign in to comment.