Skip to content

Commit

Permalink
Merge pull request #18991 from Dr15Jones/fixMemoryLinkInDQMOfflineTri…
Browse files Browse the repository at this point in the history
…gger

Fix memory leaks in DQMOffline/Trigger
  • Loading branch information
cmsbuild committed May 30, 2017
2 parents 26c8e20 + cfc2db6 commit 32812a6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 66 deletions.
32 changes: 14 additions & 18 deletions DQMOffline/Trigger/interface/TopDiLeptonHLTOfflineDQM.h
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <vector>
#include <memory>

#include "FWCore/Framework/interface/Event.h"
#include "DQMServices/Core/interface/DQMStore.h"
Expand Down Expand Up @@ -71,9 +72,9 @@ namespace HLTOfflineDQMTopDiLepton {
std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };

/// set labels for event logging histograms
void loggerBinLabels(std::string hist);
void loggerBinLabels(const std::string& hist);
/// set configurable labels for trigger monitoring histograms
void triggerBinLabels(std::string channel, const std::vector<std::string>& labels);
void triggerBinLabels(const std::string& channel, const std::vector<std::string>& labels);
/// fill trigger monitoring histograms
void fill(const edm::Event& event, const edm::TriggerResults& triggerTable, std::string channel, const std::vector<std::string>& labels) const;

Expand Down Expand Up @@ -126,21 +127,21 @@ namespace HLTOfflineDQMTopDiLepton {
/// As described on https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
int eidPattern_;
/// extra isolation criterion on electron
StringCutObjectSelector<reco::GsfElectron>* elecIso_;
std::unique_ptr<StringCutObjectSelector<reco::GsfElectron>> elecIso_;
/// extra selection on electrons
StringCutObjectSelector<reco::GsfElectron>* elecSelect_;
std::unique_ptr<StringCutObjectSelector<reco::GsfElectron>> elecSelect_;

/// extra isolation criterion on muon
StringCutObjectSelector<reco::Muon>* muonIso_;
std::unique_ptr<StringCutObjectSelector<reco::Muon>> muonIso_;
/// extra selection on muons
StringCutObjectSelector<reco::Muon>* muonSelect_;
std::unique_ptr<StringCutObjectSelector<reco::Muon>> muonSelect_;

/// jetCorrector
std::string jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_;
/// extra jetID selection on calo jets
StringCutObjectSelector<reco::JetID>* jetIDSelect_;
std::unique_ptr<StringCutObjectSelector<reco::JetID>> jetIDSelect_;
/// extra selection on jets (here given as std::string as it depends
/// on the the jet type, which selections are valid and which not)
std::string jetSelect_;
Expand All @@ -161,7 +162,7 @@ namespace HLTOfflineDQMTopDiLepton {
};

inline void
MonitorDiLepton::loggerBinLabels(std::string hist)
MonitorDiLepton::loggerBinLabels(const std::string& hist)
{
// set axes titles for selected events
hists_[hist.c_str()]->getTH1()->SetOption("TEXT");
Expand All @@ -188,7 +189,7 @@ namespace HLTOfflineDQMTopDiLepton {
}

inline void
MonitorDiLepton::triggerBinLabels(std::string channel, const std::vector<std::string>& labels)
MonitorDiLepton::triggerBinLabels(const std::string& channel, const std::vector<std::string>& labels)
{
for(unsigned int idx=0; idx<labels.size(); ++idx){
hists_[(channel+"Mon_").c_str()]->setBinLabel( idx+1, "["+monitorPath(labels[idx])+"]", 1);
Expand Down Expand Up @@ -253,11 +254,6 @@ class TopDiLeptonHLTOfflineDQM : public DQMEDAnalyzer {
public:
/// default constructor
TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg);
/// default destructor
~TopDiLeptonHLTOfflineDQM(){
if( beamspotSelect_ ) delete beamspotSelect_;
if( vertexSelect_ ) delete vertexSelect_;
}

/// do this during the event loop
virtual void dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) override;
Expand All @@ -280,11 +276,11 @@ class TopDiLeptonHLTOfflineDQM : public DQMEDAnalyzer {
/// primary vertex
edm::EDGetTokenT< std::vector<reco::Vertex> > vertex_;
/// string cut selector
StringCutObjectSelector<reco::Vertex>* vertexSelect_;
std::unique_ptr<StringCutObjectSelector<reco::Vertex>> vertexSelect_;
/// beamspot
edm::EDGetTokenT< reco::BeamSpot > beamspot_;
/// string cut selector
StringCutObjectSelector<reco::BeamSpot>* beamspotSelect_;
std::unique_ptr<StringCutObjectSelector<reco::BeamSpot>> beamspotSelect_;

HLTConfigProvider hltConfig_;

Expand All @@ -296,9 +292,9 @@ class TopDiLeptonHLTOfflineDQM : public DQMEDAnalyzer {
/// the configuration of the selection for the SelectionStep class,
/// MonitoringEnsemble keeps an instance of the MonitorDiLepton class to
/// be filled _after_ each selection step
std::map<std::string, std::pair<edm::ParameterSet, HLTOfflineDQMTopDiLepton::MonitorDiLepton*> > selection_;
std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<HLTOfflineDQMTopDiLepton::MonitorDiLepton>> > selection_;

std::map<std::string, SelectionStepHLTBase*> selectmap_;
std::map<std::string, std::unique_ptr<SelectionStepHLTBase>> selectmap_;
};

#endif
26 changes: 11 additions & 15 deletions DQMOffline/Trigger/interface/TopSingleLeptonHLTOfflineDQM.h
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <vector>
#include <memory>

#include "FWCore/Framework/interface/Event.h"
#include "DQMServices/Core/interface/DQMStore.h"
Expand Down Expand Up @@ -117,24 +118,24 @@ namespace HLTOfflineDQMTopSingleLepton {
/// As described on https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
int eidPattern_;
/// extra isolation criterion on electron
StringCutObjectSelector<reco::GsfElectron>* elecIso_;
std::unique_ptr<StringCutObjectSelector<reco::GsfElectron>> elecIso_;
/// extra selection on electrons
StringCutObjectSelector<reco::GsfElectron>* elecSelect_;
std::unique_ptr<StringCutObjectSelector<reco::GsfElectron>> elecSelect_;

/// extra selection on primary vertices; meant to investigate the pile-up effect
StringCutObjectSelector<reco::Vertex>* pvSelect_;
std::unique_ptr<StringCutObjectSelector<reco::Vertex>> pvSelect_;

/// extra isolation criterion on muon
StringCutObjectSelector<reco::Muon>* muonIso_;
std::unique_ptr<StringCutObjectSelector<reco::Muon>> muonIso_;
/// extra selection on muons
StringCutObjectSelector<reco::Muon>* muonSelect_;
std::unique_ptr<StringCutObjectSelector<reco::Muon>> muonSelect_;

/// jetCorrector
std::string jetCorrector_;
/// jetID as an extra selection type
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_;
/// extra jetID selection on calo jets
StringCutObjectSelector<reco::JetID>* jetIDSelect_;
std::unique_ptr<StringCutObjectSelector<reco::JetID>> jetIDSelect_;
/// extra selection on jets (here given as std::string as it depends
/// on the the jet type, which selections are valid and which not)
std::string jetSelect_;
Expand Down Expand Up @@ -231,11 +232,6 @@ class TopSingleLeptonHLTOfflineDQM : public DQMEDAnalyzer {
public:
/// default constructor
TopSingleLeptonHLTOfflineDQM(const edm::ParameterSet& cfg);
/// default destructor
~TopSingleLeptonHLTOfflineDQM(){
if( vertexSelect_ ) delete vertexSelect_;
if( beamspotSelect_ ) delete beamspotSelect_;
};

/// do this during the event loop
virtual void dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) override;
Expand All @@ -258,12 +254,12 @@ class TopSingleLeptonHLTOfflineDQM : public DQMEDAnalyzer {
/// primary vertex
edm::EDGetTokenT< std::vector<reco::Vertex> > vertex_;
/// string cut selector
StringCutObjectSelector<reco::Vertex>* vertexSelect_;
std::unique_ptr<StringCutObjectSelector<reco::Vertex>> vertexSelect_;

/// beamspot
edm::EDGetTokenT< reco::BeamSpot > beamspot_;
/// string cut selector
StringCutObjectSelector<reco::BeamSpot>* beamspotSelect_;
std::unique_ptr<StringCutObjectSelector<reco::BeamSpot>> beamspotSelect_;

HLTConfigProvider hltConfig_;

Expand All @@ -277,9 +273,9 @@ class TopSingleLeptonHLTOfflineDQM : public DQMEDAnalyzer {
/// the configuration of the selection for the SelectionStep class,
/// MonitoringEnsemble keeps an instance of the MonitorSingleLepton class to
/// be filled _after_ each selection step
std::map<std::string, std::pair<edm::ParameterSet, HLTOfflineDQMTopSingleLepton::MonitorSingleLepton*> > selection_;
std::map<std::string, std::pair<edm::ParameterSet, std::unique_ptr<HLTOfflineDQMTopSingleLepton::MonitorSingleLepton>> > selection_;

std::map<std::string, SelectionStepHLTBase*> selectmap_;
std::map<std::string, std::unique_ptr<SelectionStepHLTBase>> selectmap_;
};

#endif
32 changes: 16 additions & 16 deletions DQMOffline/Trigger/src/TopDiLeptonHLTOfflineDQM.cc
Expand Up @@ -26,7 +26,7 @@ namespace HLTOfflineDQMTopDiLepton {
static const double DRMIN = 0.05;

MonitorDiLepton::MonitorDiLepton(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC) :
label_(label), eidPattern_(0), elecIso_(0), elecSelect_(0), muonIso_(0), muonSelect_(0), jetIDSelect_(0),
label_(label), eidPattern_(0), elecIso_(nullptr), elecSelect_(nullptr), muonIso_(nullptr), muonSelect_(nullptr), jetIDSelect_(nullptr),
lowerEdge_(-1.), upperEdge_(-1.), elecMuLogged_(0), diMuonLogged_(0), diElecLogged_(0)
{
// sources have to be given; this PSet is not optional
Expand All @@ -46,12 +46,12 @@ namespace HLTOfflineDQMTopDiLepton {
// select is optional; in case it's not found no
// selection will be applied
if( elecExtras.existsAs<std::string>("select") ){
elecSelect_= new StringCutObjectSelector<reco::GsfElectron>(elecExtras.getParameter<std::string>("select"));
elecSelect_= std::make_unique<StringCutObjectSelector<reco::GsfElectron>>(elecExtras.getParameter<std::string>("select"));
}
// isolation is optional; in case it's not found no
// isolation will be applied
if( elecExtras.existsAs<std::string>("isolation") ){
elecIso_= new StringCutObjectSelector<reco::GsfElectron>(elecExtras.getParameter<std::string>("isolation"));
elecIso_= std::make_unique<StringCutObjectSelector<reco::GsfElectron>>(elecExtras.getParameter<std::string>("isolation"));
}
// electronId is optional; in case it's not found the
// InputTag will remain empty
Expand All @@ -67,12 +67,12 @@ namespace HLTOfflineDQMTopDiLepton {
// select is optional; in case it's not found no
// selection will be applied
if( muonExtras.existsAs<std::string>("select") ){
muonSelect_= new StringCutObjectSelector<reco::Muon>(muonExtras.getParameter<std::string>("select"));
muonSelect_= std::make_unique<StringCutObjectSelector<reco::Muon>>(muonExtras.getParameter<std::string>("select"));
}
// isolation is optional; in case it's not found no
// isolation will be applied
if( muonExtras.existsAs<std::string>("isolation") ){
muonIso_= new StringCutObjectSelector<reco::Muon>(muonExtras.getParameter<std::string>("isolation"));
muonIso_= std::make_unique<StringCutObjectSelector<reco::Muon>>(muonExtras.getParameter<std::string>("isolation"));
}
}
// jetExtras are optional; they may be omitted or empty
Expand All @@ -87,7 +87,7 @@ namespace HLTOfflineDQMTopDiLepton {
if(jetExtras.existsAs<edm::ParameterSet>("jetID")){
edm::ParameterSet jetID=jetExtras.getParameter<edm::ParameterSet>("jetID");
jetIDLabel_ = iC.consumes< reco::JetIDValueMap >(jetID.getParameter<edm::InputTag>("label"));
jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
jetIDSelect_= std::make_unique<StringCutObjectSelector<reco::JetID>>(jetID.getParameter<std::string>("select"));
}
// select is optional; in case it's not found no
// selection will be applied (only implemented for
Expand Down Expand Up @@ -792,7 +792,7 @@ namespace HLTOfflineDQMTopDiLepton {

}

TopDiLeptonHLTOfflineDQM::TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg): vertexSelect_(0), beamspotSelect_(0)
TopDiLeptonHLTOfflineDQM::TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg): vertexSelect_(nullptr), beamspotSelect_(nullptr)
{
// configure the preselection
edm::ParameterSet presel=cfg.getParameter<edm::ParameterSet>("preselection");
Expand All @@ -804,19 +804,19 @@ TopDiLeptonHLTOfflineDQM::TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg)
if( presel.existsAs<edm::ParameterSet>("vertex" ) ){
edm::ParameterSet vertex=presel.getParameter<edm::ParameterSet>("vertex");
vertex_= consumes< std::vector<reco::Vertex> >(vertex.getParameter<edm::InputTag>("src"));
vertexSelect_= new StringCutObjectSelector<reco::Vertex>(vertex.getParameter<std::string>("select"));
vertexSelect_= std::make_unique<StringCutObjectSelector<reco::Vertex>>(vertex.getParameter<std::string>("select"));
}
if( presel.existsAs<edm::ParameterSet>("beamspot" ) ){
edm::ParameterSet beamspot=presel.getParameter<edm::ParameterSet>("beamspot");
beamspot_= consumes< reco::BeamSpot >(beamspot.getParameter<edm::InputTag>("src"));
beamspotSelect_= new StringCutObjectSelector<reco::BeamSpot>(beamspot.getParameter<std::string>("select"));
beamspotSelect_= std::make_unique<StringCutObjectSelector<reco::BeamSpot>>(beamspot.getParameter<std::string>("select"));
}

// configure the selection
std::vector<edm::ParameterSet> sel=cfg.getParameter<std::vector<edm::ParameterSet> >("selection");
for(unsigned int i=0; i<sel.size(); ++i){
selectionOrder_.push_back(sel.at(i).getParameter<std::string>("label"));
selection_[selectionStep(selectionOrder_.back())] = std::make_pair(sel.at(i), new HLTOfflineDQMTopDiLepton::MonitorDiLepton(selectionStep(selectionOrder_.back()).c_str(), cfg.getParameter<edm::ParameterSet>("setup"), consumesCollector()));
selection_[selectionStep(selectionOrder_.back())] = std::make_pair(sel.at(i), std::make_unique<HLTOfflineDQMTopDiLepton::MonitorDiLepton>(selectionStep(selectionOrder_.back()).c_str(), cfg.getParameter<edm::ParameterSet>("setup"), consumesCollector()));
}

for (const std::string& s: selectionOrder_) {
Expand All @@ -826,22 +826,22 @@ TopDiLeptonHLTOfflineDQM::TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg)
continue;

if (type == "muons"){
selectmap_[type] = new SelectionStepHLT<reco::Muon>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::Muon>>(selection_[key].first, consumesCollector());
}
if (type == "elecs"){
selectmap_[type] = new SelectionStepHLT<reco::GsfElectron>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::GsfElectron>>(selection_[key].first, consumesCollector());
}
if (type == "jets"){
selectmap_[type] = new SelectionStepHLT<reco::Jet>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::Jet>>(selection_[key].first, consumesCollector());
}
if (type == "jets/pf"){
selectmap_[type] = new SelectionStepHLT<reco::PFJet>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::PFJet>>(selection_[key].first, consumesCollector());
}
if (type == "jets/calo"){
selectmap_[type] = new SelectionStepHLT<reco::CaloJet>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::CaloJet>>(selection_[key].first, consumesCollector());
}
if (type == "met"){
selectmap_[type] = new SelectionStepHLT<reco::MET>(selection_[key].first, consumesCollector());
selectmap_[type] = std::make_unique<SelectionStepHLT<reco::MET>>(selection_[key].first, consumesCollector());
}
}
}
Expand Down

0 comments on commit 32812a6

Please sign in to comment.