Skip to content

Commit

Permalink
Add consumes interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wmtan committed Mar 6, 2015
1 parent eddeddf commit eefc228
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"

//PG #include "TH2.h"
//PG #include "TFile.h"
//PG #include "TCanvas.h"
Expand Down Expand Up @@ -75,10 +78,10 @@ class AlCaECALRecHitReducer : public edm::EDProducer {
// ----------member data ---------------------------


edm::InputTag ebRecHitsLabel_;
edm::InputTag eeRecHitsLabel_;
edm::InputTag esRecHitsLabel_;
edm::InputTag electronLabel_;
edm::EDGetTokenT<EBRecHitCollection> ebRecHitsToken_;
edm::EDGetTokenT<EERecHitCollection> eeRecHitsToken_;
edm::EDGetTokenT<ESRecHitCollection> esRecHitsToken_;
edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
std::string alcaBarrelHitsCollection_;
std::string alcaEndcapHitsCollection_;
std::string alcaPreshowerHitsCollection_;
Expand Down
34 changes: 21 additions & 13 deletions Calibration/EcalAlCaRecoProducers/src/AlCaECALRecHitReducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
AlCaECALRecHitReducer::AlCaECALRecHitReducer(const edm::ParameterSet& iConfig)
{

ebRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("ebRecHitsLabel");
eeRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("eeRecHitsLabel");
// esRecHitsLabel_ = iConfig.getParameter< edm::InputTag > ("esRecHitsLabel");
electronLabel_ = iConfig.getParameter< edm::InputTag > ("electronLabel");
ebRecHitsToken_ = consumes<EBRecHitCollection>(iConfig.getParameter< edm::InputTag > ("ebRecHitsLabel"));
eeRecHitsToken_ = consumes<EERecHitCollection>(iConfig.getParameter< edm::InputTag > ("eeRecHitsLabel"));
// esRecHitsToken_ = consumes<ESRecHitCollection>(iConfig.getParameter< edm::InputTag > ("esRecHitsLabel"));
electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter< edm::InputTag > ("electronLabel"));

alcaBarrelHitsCollection_ = iConfig.getParameter<std::string>("alcaBarrelHitCollection");
alcaEndcapHitsCollection_ = iConfig.getParameter<std::string>("alcaEndcapHitCollection");
Expand Down Expand Up @@ -83,10 +83,12 @@ AlCaECALRecHitReducer::produce (edm::Event& iEvent,

// Get GSFElectrons
Handle<reco::GsfElectronCollection> pElectrons;
iEvent.getByLabel(electronLabel_, pElectrons);
iEvent.getByToken(electronToken_, pElectrons);
if (!pElectrons.isValid()) {
edm::LogError ("reading") << electronLabel_ << " not found" ;
// std::cerr << "[AlCaECALRecHitReducer]" << electronLabel_ << " not found" ;
edm::EDConsumerBase::Labels labels;
labelsForToken(electronToken_, labels);
edm::LogError ("reading") << labels.module << " not found" ;
// std::cerr << "[AlCaECALRecHitReducer]" << labels.module_ << " not found" ;
return ;
}

Expand All @@ -97,9 +99,11 @@ AlCaECALRecHitReducer::produce (edm::Event& iEvent,
Handle<EBRecHitCollection> barrelRecHitsHandle;
bool barrelIsFull = true ;

iEvent.getByLabel(ebRecHitsLabel_,barrelRecHitsHandle);
iEvent.getByToken(ebRecHitsToken_,barrelRecHitsHandle);
if (!barrelRecHitsHandle.isValid()) {
edm::LogError ("reading") << ebRecHitsLabel_ << " not found" ;
edm::EDConsumerBase::Labels labels;
labelsForToken(ebRecHitsToken_, labels);
edm::LogError ("reading") << labels.module << " not found" ;
barrelIsFull = false ;
}

Expand All @@ -111,9 +115,11 @@ AlCaECALRecHitReducer::produce (edm::Event& iEvent,
Handle<EERecHitCollection> endcapRecHitsHandle;
bool endcapIsFull = true ;

iEvent.getByLabel(eeRecHitsLabel_,endcapRecHitsHandle);
iEvent.getByToken(eeRecHitsToken_,endcapRecHitsHandle);
if (!endcapRecHitsHandle.isValid()) {
edm::LogError ("reading") << eeRecHitsLabel_ << " not found" ;
edm::EDConsumerBase::Labels labels;
labelsForToken(eeRecHitsToken_, labels);
edm::LogError ("reading") << labels.module << " not found" ;
endcapIsFull = false ;
}

Expand All @@ -126,9 +132,11 @@ AlCaECALRecHitReducer::produce (edm::Event& iEvent,
// Handle<ESRecHitCollection> preshowerRecHitsHandle;
// bool preshowerIsFull = true ;

// iEvent.getByLabel(esRecHitsLabel_,preshowerRecHitsHandle);
// iEvent.getByToken(esRecHitsToken_,preshowerRecHitsHandle);
// if (!preshowerRecHitsHandle.isValid()) {
// edm::LogError ("reading") << esRecHitsLabel_ << " not found" ;
// edm::EDConsumerBase::Labels labels;
// labelsForToken(esRecHitsToken_, labels);
// edm::LogError ("reading") << labels.module << " not found" ;
// preshowerIsFull = false ;
// }

Expand Down
21 changes: 13 additions & 8 deletions Calibration/EcalAlCaRecoProducers/src/AlCaElectronsTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
//#include "Calibration/EcalAlCaRecoProducers/interface/AlCaElectronsProducer.h"
#include "DataFormats/EgammaCandidates/interface/SiStripElectron.h"
#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
Expand Down Expand Up @@ -47,8 +48,8 @@ class AlCaElectronsTest : public edm::EDAnalyzer {

private:

edm::InputTag m_barrelAlCa ;
edm::InputTag m_endcapAlCa ;
edm::EDGetTokenT<EBRecHitCollection> m_barrelAlCa ;
edm::EDGetTokenT<EERecHitCollection> m_endcapAlCa ;
std::string m_outputFileName ;

//! ECAL map
Expand Down Expand Up @@ -78,8 +79,8 @@ class AlCaElectronsTest : public edm::EDAnalyzer {


AlCaElectronsTest::AlCaElectronsTest (const edm::ParameterSet& iConfig) :
m_barrelAlCa (iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection")) ,
m_endcapAlCa (iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection")) ,
m_barrelAlCa (consumes<EBRecHitCollection>(iConfig.getParameter<edm::InputTag> ("alcaBarrelHitCollection"))) ,
m_endcapAlCa (consumes<EERecHitCollection>(iConfig.getParameter<edm::InputTag> ("alcaEndcapHitCollection"))) ,
m_outputFileName (iConfig.getUntrackedParameter<std::string>
("HistOutFile",std::string ("AlCaElectronsTest.root")))
{}
Expand Down Expand Up @@ -142,10 +143,12 @@ AlCaElectronsTest::analyze (const edm::Event& iEvent,
//PG get the collections
// get Barrel RecHits
edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
iEvent.getByLabel (m_barrelAlCa, barrelRecHitsHandle) ;
iEvent.getByToken (m_barrelAlCa, barrelRecHitsHandle) ;
if (!barrelRecHitsHandle.isValid()) {
edm::EDConsumerBase::Labels labels;
labelsForToken(m_barrelAlCa, labels);
std::cerr << "[AlCaElectronsTest] caught std::exception "
<< " in rertieving " << m_barrelAlCa
<< " in rertieving " << labels.module
<< std::endl ;
return ;
} else {
Expand All @@ -171,10 +174,12 @@ AlCaElectronsTest::analyze (const edm::Event& iEvent,

// get Endcap RecHits
edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
iEvent.getByLabel (m_endcapAlCa,endcapRecHitsHandle) ;
iEvent.getByToken (m_endcapAlCa,endcapRecHitsHandle) ;
if (!endcapRecHitsHandle.isValid()) {
edm::EDConsumerBase::Labels labels;
labelsForToken(m_endcapAlCa, labels);
std::cerr << "[AlCaElectronsTest] caught std::exception "
<< " in rertieving " << m_endcapAlCa
<< " in rertieving " << labels.module
<< std::endl ;
return ;
} else {
Expand Down

0 comments on commit eefc228

Please sign in to comment.