From 890a9e4126c76a926f7294c9bbc5a1911be35e8b Mon Sep 17 00:00:00 2001 From: maria Date: Wed, 8 Mar 2017 09:59:56 +0100 Subject: [PATCH 1/3] fixMemLeakM2 --- .../PulseShapeFitOOTPileupCorrection.h | 2 ++ .../src/PulseShapeFitOOTPileupCorrection.cc | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h index c3af33d98ac51..5b27367709e24 100644 --- a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h +++ b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h @@ -117,6 +117,7 @@ class PulseShapeFitOOTPileupCorrection double iTMin, double iTMax, const std::vector & its4Chi2, HcalTimeSlew::BiasSetting slewFlavor, int iFitTimes); + const HcalPulseShapes::Shape* currentPulseShape_; void setChi2Term( bool isHPD ); void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps, bool isHPD); @@ -164,6 +165,7 @@ class PulseShapeFitOOTPileupCorrection double noiseSiPM_; HcalTimeSlew::BiasSetting slewFlavor_; + bool isCurrentChannelHPD_; }; #endif // PulseShapeFitOOTPileupCorrection_h diff --git a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc index e75500ec4ebb4..47f08156a1b32 100644 --- a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc +++ b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc @@ -278,15 +278,15 @@ void PulseShapeFitOOTPileupCorrection::setPUParams(bool iPedestalConstraint, b } void PulseShapeFitOOTPileupCorrection::setPulseShapeTemplate(const HcalPulseShapes::Shape& ps, bool isHPD) { - // initialize for every hit now to avoid incorrect settings for different channel types (HPD vs SiPM) - // FIXME: keep this as a reminder to improve and reduce CPU use - // if( cntsetPulseShape ) return; - - // set the M2 parameters before defining the shape - setChi2Term(isHPD); - - resetPulseShapeTemplate(ps); - + // initialize for every different channel types (HPD vs SiPM) + + if (!(&ps == currentPulseShape_ && isHPD == isCurrentChannelHPD_)) + { + setChi2Term(isHPD); + resetPulseShapeTemplate(ps); + currentPulseShape_ = &ps; + isCurrentChannelHPD_ = isHPD; + } } void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(const HcalPulseShapes::Shape& ps) { From a1e97319262d440d3abdce1756c68eab9deaa9c8 Mon Sep 17 00:00:00 2001 From: maria Date: Wed, 8 Mar 2017 11:51:02 +0100 Subject: [PATCH 2/3] more fix --- .../interface/PulseShapeFitOOTPileupCorrection.h | 2 +- .../HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h index 5b27367709e24..bc9b1c9126bdc 100644 --- a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h +++ b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h @@ -117,7 +117,7 @@ class PulseShapeFitOOTPileupCorrection double iTMin, double iTMax, const std::vector & its4Chi2, HcalTimeSlew::BiasSetting slewFlavor, int iFitTimes); - const HcalPulseShapes::Shape* currentPulseShape_; + const HcalPulseShapes::Shape* currentPulseShape_=NULL; void setChi2Term( bool isHPD ); void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps, bool isHPD); diff --git a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc index 47f08156a1b32..bcd4dc5efa1c2 100644 --- a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc +++ b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc @@ -293,9 +293,9 @@ void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(const HcalPulseSh ++ cntsetPulseShape; psfPtr_.reset(new FitterFuncs::PulseShapeFunctor(ps,pedestalConstraint_,timeConstraint_,addPulseJitter_,applyTimeSlew_, pulseJitter_,timeMean_,timeSig_,pedMean_,pedSig_,noise_)); - spfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3); - dpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5); - tpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7); + delete spfunctor_; spfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3); + delete dpfunctor_; dpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5); + delete tpfunctor_; tpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7); } void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs, From c395b244161eb2925c5f7acaca21e24cf6f8742f Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 9 Mar 2017 01:11:57 +0100 Subject: [PATCH 3/3] use std::unique_ptr --- .../interface/PulseShapeFitOOTPileupCorrection.h | 6 +++--- .../src/PulseShapeFitOOTPileupCorrection.cc | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h index bc9b1c9126bdc..43023659ab2ad 100644 --- a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h +++ b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h @@ -136,9 +136,9 @@ class PulseShapeFitOOTPileupCorrection int fitTimes_; std::unique_ptr psfPtr_; - ROOT::Math::Functor *spfunctor_; - ROOT::Math::Functor *dpfunctor_; - ROOT::Math::Functor *tpfunctor_; + std::unique_ptr spfunctor_; + std::unique_ptr dpfunctor_; + std::unique_ptr tpfunctor_; int TSMin_; int TSMax_; mutable double ts4Chi2_; diff --git a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc index bcd4dc5efa1c2..14eeaeebeaf23 100644 --- a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc +++ b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc @@ -219,9 +219,6 @@ PulseShapeFitOOTPileupCorrection::PulseShapeFitOOTPileupCorrection() : cntsetPul PulseShapeFitOOTPileupCorrection::~PulseShapeFitOOTPileupCorrection() { if(hybridfitter) delete hybridfitter; - if(spfunctor_) delete spfunctor_; - if(dpfunctor_) delete dpfunctor_; - if(tpfunctor_) delete tpfunctor_; } void PulseShapeFitOOTPileupCorrection::setChi2Term( bool isHPD ) { @@ -293,9 +290,10 @@ void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(const HcalPulseSh ++ cntsetPulseShape; psfPtr_.reset(new FitterFuncs::PulseShapeFunctor(ps,pedestalConstraint_,timeConstraint_,addPulseJitter_,applyTimeSlew_, pulseJitter_,timeMean_,timeSig_,pedMean_,pedSig_,noise_)); - delete spfunctor_; spfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3); - delete dpfunctor_; dpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5); - delete tpfunctor_; tpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7); + spfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3) ); + dpfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5) ); + tpfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7) ); + } void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs,