diff --git a/Reconstruction/eflowRec/eflowRec/IEFlowClusterCollectionTool.h b/Reconstruction/eflowRec/eflowRec/IEFlowClusterCollectionTool.h index a71b99f72833fa9ae99a5565f376e5bde676b63a..17ff7b53b4878f822321aad5a1e006ff85608cfe 100644 --- a/Reconstruction/eflowRec/eflowRec/IEFlowClusterCollectionTool.h +++ b/Reconstruction/eflowRec/eflowRec/IEFlowClusterCollectionTool.h @@ -19,8 +19,8 @@ class IEFlowClusterCollectionTool : virtual public IAlgTool { static const InterfaceID& interfaceID(); /** Put all clusters into a temporary container - then we use this to calculate moments, some of which depend on configuration of nearby clusters */ - virtual xAOD::CaloClusterContainer* execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) = 0; - virtual eflowRecClusterContainer* retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) = 0; + virtual std::unique_ptr<xAOD::CaloClusterContainer> execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) = 0; + virtual std::unique_ptr<eflowRecClusterContainer> retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) = 0; }; diff --git a/Reconstruction/eflowRec/eflowRec/PFMatchDistance.h b/Reconstruction/eflowRec/eflowRec/PFMatchDistance.h index 7008f01f3e19506611e91db4ecfb9b3a002a2125..7818770ec51fdeea8c78960e9ace56047ed483e6 100644 --- a/Reconstruction/eflowRec/eflowRec/PFMatchDistance.h +++ b/Reconstruction/eflowRec/eflowRec/PFMatchDistance.h @@ -42,12 +42,12 @@ public: class DistanceFactory { public: - static IDistanceProvider* Get(std::string distanceType, IPositionProvider* trackPosition, - IPositionProvider* clusterPosition) { + static std::unique_ptr<IDistanceProvider> Get(std::string distanceType, std::unique_ptr<IPositionProvider> trackPosition, + std::unique_ptr<IPositionProvider> clusterPosition) { if (distanceType == "EtaPhiSquareDistance") { - return new DistanceProvider<EtaPhi, EtaPhi>(trackPosition, clusterPosition, new EtaPhiSqDistanceCalculator()); + return std::make_unique<DistanceProvider<EtaPhi, EtaPhi> >(std::move(trackPosition), std::move(clusterPosition), std::make_unique<EtaPhiSqDistanceCalculator>()); } else if (distanceType == "EtaPhiSquareSignificance") { - return new DistanceProvider<EtaPhi, EtaPhiWithVariance>(trackPosition, clusterPosition, new EtaPhiSqSignificanceCalculator()); + return std::make_unique<DistanceProvider<EtaPhi, EtaPhiWithVariance> >(std::move(trackPosition), std::move(clusterPosition), std::make_unique<EtaPhiSqSignificanceCalculator>()); } else { std::cerr << "DistanceFactory\tERROR\tInvalid distance type: \"" << distanceType << "\"" << std::endl; assert(false); diff --git a/Reconstruction/eflowRec/eflowRec/PFMatchInterfaces.h b/Reconstruction/eflowRec/eflowRec/PFMatchInterfaces.h index ce956a7f83fcabfcf3a1197052963bf890976382..1ed07ff273cdde8cd2ce5c2cd7e97e775d1508c3 100644 --- a/Reconstruction/eflowRec/eflowRec/PFMatchInterfaces.h +++ b/Reconstruction/eflowRec/eflowRec/PFMatchInterfaces.h @@ -83,16 +83,16 @@ public: template <class ObjectType, class PositionType> class PositionProvider: public IPositionProvider { protected: - PositionProvider() { m_position = new PositionType; } - PositionProvider(const PositionProvider& originalPositionProvider) { m_position = new PositionType(*originalPositionProvider.getPosition()); } - PositionProvider& operator = (const PositionProvider& originalPositionProvider) { if (this == &originalPositionProvider) return *this; else {m_position = new PositionType(*originalPositionProvider.getPosition()); return *this;} } + PositionProvider() {} + PositionProvider(const PositionProvider& originalPositionProvider) { m_position = std::make_unique<PositionType>(*originalPositionProvider.getPosition()); } + PositionProvider& operator = (const PositionProvider& originalPositionProvider) { if (this == &originalPositionProvider) return *this; else {m_position = std::make_unique<PositionType>(*originalPositionProvider.getPosition()); return *this;} } public: - virtual ~PositionProvider() { delete m_position; } + virtual ~PositionProvider() {} virtual PositionType* getPosition(const ObjectType* cluster) = 0; protected: - PositionType* m_position; + std::unique_ptr<PositionType> m_position; }; template <class PositionType> @@ -128,31 +128,28 @@ public: template<class TrackPositionType, class ClusterPositionType> class DistanceProvider: public IDistanceProvider { public: - DistanceProvider(IPositionProvider* trackPosition, - IPositionProvider* clusterPosition, - DistanceCalculator<TrackPositionType, ClusterPositionType>* distanceCalculator): - m_distanceCalculator(distanceCalculator) { - m_trackPosition = dynamic_cast<TrackPositionProvider<TrackPositionType>*>(trackPosition); - m_clusterPosition = dynamic_cast<ClusterPositionProvider<ClusterPositionType>*>(clusterPosition); + DistanceProvider(std::unique_ptr<IPositionProvider> trackPosition, + std::unique_ptr<IPositionProvider> clusterPosition, + std::unique_ptr<DistanceCalculator<TrackPositionType, ClusterPositionType> > distanceCalculator): + m_trackPosition(std::move(trackPosition)), m_clusterPosition(std::move(clusterPosition)), m_distanceCalculator(std::move(distanceCalculator)) { assert(m_trackPosition); assert(m_clusterPosition); assert(m_distanceCalculator); } - virtual ~DistanceProvider() { - delete m_trackPosition; - delete m_clusterPosition; - delete m_distanceCalculator; - } + virtual ~DistanceProvider() {} double distanceBetween(const ITrack* track, const ICluster* cluster) { - return m_distanceCalculator->distanceBetween(m_trackPosition->getPosition(track), - m_clusterPosition->getPosition(cluster)); + TrackPositionProvider<TrackPositionType>* trackPositionProvider = dynamic_cast<TrackPositionProvider<TrackPositionType>*>(m_trackPosition.get()); + ClusterPositionProvider<ClusterPositionType>* clusterPositionProvider = dynamic_cast<ClusterPositionProvider<ClusterPositionType>*>(m_clusterPosition.get()); + return m_distanceCalculator->distanceBetween(trackPositionProvider->getPosition(track),clusterPositionProvider->getPosition(cluster)); } private: - TrackPositionProvider<TrackPositionType>* m_trackPosition; - ClusterPositionProvider<ClusterPositionType>* m_clusterPosition; - DistanceCalculator<TrackPositionType, ClusterPositionType>* m_distanceCalculator; + //std::unique_ptr<TrackPositionProvider<TrackPositionType> > m_trackPosition; + std::unique_ptr<IPositionProvider> m_trackPosition; + //ClusterPositionProvider<ClusterPositionType>* m_clusterPosition; + std::unique_ptr<IPositionProvider> m_clusterPosition; + std::unique_ptr<DistanceCalculator<TrackPositionType, ClusterPositionType> > m_distanceCalculator; }; diff --git a/Reconstruction/eflowRec/eflowRec/PFMatchPositions.h b/Reconstruction/eflowRec/eflowRec/PFMatchPositions.h index 7149f6cdfa80d4d44607106a07852cbf77548f06..d136fb0056f1497c70b8fa313ddf5b913a806a51 100644 --- a/Reconstruction/eflowRec/eflowRec/PFMatchPositions.h +++ b/Reconstruction/eflowRec/eflowRec/PFMatchPositions.h @@ -18,18 +18,6 @@ #include "eflowRec/PFMatchInterfaces.h" namespace PFMatch { -// -///* Cache position */ -// -//template <class PositionType> -//class PositionObjectCache { -//protected: -// PositionObjectCache() { m_position = new PositionType(); } -// virtual ~PositionObjectCache() { delete m_position; } -// PositionType* m_position; -//}; - - /* Position classes */ class EtaPhi: public eflowEtaPhiPosition { @@ -103,11 +91,11 @@ private: class TrackPositionFactory { public: - static IPositionProvider* Get(std::string positionType) { + static std::unique_ptr<IPositionProvider> Get(std::string positionType) { if (positionType == "EM1EtaPhi") { - return new TrackEtaPhiInFixedLayersProvider(TrackLayer::EMB1, TrackLayer::EME1); + return std::make_unique<TrackEtaPhiInFixedLayersProvider>(TrackLayer::EMB1, TrackLayer::EME1); } else if (positionType == "EM2EtaPhi") { - return new TrackEtaPhiInFixedLayersProvider(TrackLayer::EMB2, TrackLayer::EME2); + return std::make_unique<TrackEtaPhiInFixedLayersProvider>(TrackLayer::EMB2, TrackLayer::EME2); } else { std::cerr << "TrackPositionFactory\tERROR\tInvalid track position type: \"" << positionType << "\"" << std::endl; assert(false); @@ -118,11 +106,11 @@ public: class ClusterPositionFactory { public: - static IPositionProvider* Get(std::string positionType) { + static std::unique_ptr<IPositionProvider> Get(std::string positionType) { if (positionType == "PlainEtaPhi") { - return new ClusterPlainEtaPhiProvider(); + return std::make_unique<ClusterPlainEtaPhiProvider>(); } else if (positionType == "GeomCenterEtaPhi") { - return new ClusterGeometricalCenterProvider(); + return std::make_unique<ClusterGeometricalCenterProvider>(); } else { std::cerr << "ClusterPositionFactory\tERROR\tInvalid cluster position type: \"" << positionType << "\"" << std::endl; assert(false); diff --git a/Reconstruction/eflowRec/eflowRec/PFMatcher.h b/Reconstruction/eflowRec/eflowRec/PFMatcher.h index 28ad76ace7dbed9ac19432a6591538d06dce1a48..a605b6687cef014f668c36d1b2a2637d76922590 100644 --- a/Reconstruction/eflowRec/eflowRec/PFMatcher.h +++ b/Reconstruction/eflowRec/eflowRec/PFMatcher.h @@ -30,10 +30,10 @@ struct MatchDistance { class TrackClusterMatcher { public: - TrackClusterMatcher( IDistanceProvider* distanceProvider, double matchCut): - m_distanceProvider(distanceProvider), m_matchCut(matchCut) { setDRParameters(); } + TrackClusterMatcher( std::unique_ptr<IDistanceProvider> distanceProvider, double matchCut): + m_distanceProvider(std::move(distanceProvider)), m_matchCut(matchCut) { setDRParameters(); } - virtual ~TrackClusterMatcher(); + virtual ~TrackClusterMatcher() {}; MatchDistance match(const ITrack* track, const ICluster* cluster); @@ -46,7 +46,7 @@ public: private: - IDistanceProvider* m_distanceProvider; + std::unique_ptr<IDistanceProvider> m_distanceProvider; double m_matchCut; /** This stores the parameters to vary DR cut with Pt */ float m_drcut_par[8][3]; diff --git a/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h b/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h index 7ea151aea28bf0d53347874eadd85cb87093b6c5..a06e40a46f6f21f6c5135a80fe3581b5e1fe84b9 100644 --- a/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h +++ b/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h @@ -14,15 +14,13 @@ #ifndef PFMATCHINGTOOL_H_ #define PFMATCHINGTOOL_H_ +#include "eflowRec/PFMatcher.h" + class eflowRecCluster; class eflowRecTrack; class eflowRecClusterContainer; class eflowMatchCluster; -namespace PFMatch{ -class TrackClusterMatcher; -} - static const InterfaceID IID_PFTrackClusterMatchingTool("PFTrackClusterMatchingTool", 1, 0); class PFTrackClusterMatchingTool: public AthAlgTool { @@ -52,8 +50,8 @@ private: double m_matchCut; /** The track cluster matcher to perform the actual matching */ - PFMatch::TrackClusterMatcher* m_matcher; - + std::unique_ptr<PFMatch::TrackClusterMatcher> m_matcher; + /** Count the number of tracks processed -- for the summary in finalize() */ unsigned int m_tracksProcessed; /** Count the number of matches created -- for the summary in finalize() */ diff --git a/Reconstruction/eflowRec/eflowRec/eflowCellIntegrator.h b/Reconstruction/eflowRec/eflowRec/eflowCellIntegrator.h index eaab6532ba2223245f38fd1df25f3ff65939a1c7..6c76b27b055d5515c48a15fa420768387d9705f1 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowCellIntegrator.h +++ b/Reconstruction/eflowRec/eflowRec/eflowCellIntegrator.h @@ -56,6 +56,8 @@ public: } } + double getError() const {return m_error;} + private: double DoGaussLegendreIntegration(const eflowRange& range, int nOrder){ @@ -148,9 +150,17 @@ template<> inline double eflowCellIntegrand<lookupExp>::evaluate(double phi) { r */ template <int expType> class eflowCellIntegrator { public: - eflowCellIntegrator(double stdDev, double error) : m_integrand2D(new eflowCellIntegrand<(Exp_t)expType>(stdDev)), - m_outerIntegrator(this, error), m_innerIntegrator(m_integrand2D, error) { } - ~eflowCellIntegrator() { delete m_integrand2D; } + eflowCellIntegrator(double stdDev, double error) : m_integrand2D(std::make_unique<eflowCellIntegrand<(Exp_t)expType> >(stdDev)), m_outerIntegrator(this, error), m_innerIntegrator(m_integrand2D.get(), error) { } + eflowCellIntegrator(const eflowCellIntegrator& original) : m_integrand2D(std::make_unique<eflowCellIntegrand<(Exp_t)expType> >(*(original.m_integrand2D.get()))), m_outerIntegrator(this, original.m_outerIntegrator.getError()), m_innerIntegrator( m_integrand2D.get(), original.m_innerIntegrator.getError()) { + m_rangePhi = original.m_rangePhi; + } + eflowCellIntegrator& operator=(const eflowCellIntegrator& original){ + m_integrand2D(std::make_unique<eflowCellIntegrand<(Exp_t)expType> >(*(original.m_integrand2D.get()))); + m_outerIntegrator(this, original.m_outerIntegrator.getError()); + m_innerIntegrator( m_integrand2D.get(), original.m_innerIntegrator.getError()); + m_rangePhi = original.m_rangePhi; + } + ~eflowCellIntegrator() {} /* Main method, which starts the integration */ inline double integrate(const eflowRange& etaRange, const eflowRange& phiRange) { @@ -169,7 +179,7 @@ public: } private: - eflowCellIntegrand<(Exp_t)expType>* m_integrand2D; + std::unique_ptr<eflowCellIntegrand<(Exp_t)expType> > m_integrand2D; eflowRecursiveGaussLegendreIntegrator<eflowCellIntegrator<expType> > m_outerIntegrator; eflowRecursiveGaussLegendreIntegrator<eflowCellIntegrand<(Exp_t)expType> > m_innerIntegrator; eflowRange m_rangePhi; diff --git a/Reconstruction/eflowRec/eflowRec/eflowCellLevelSubtractionTool.h b/Reconstruction/eflowRec/eflowRec/eflowCellLevelSubtractionTool.h index a798da7716a57f2207e5150d083dedf01c1039cc..ab627b1af7dd5bc70afd4c214ace925e093941c0 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowCellLevelSubtractionTool.h +++ b/Reconstruction/eflowRec/eflowRec/eflowCellLevelSubtractionTool.h @@ -20,6 +20,8 @@ CREATED: 25th January, 2005 #include "GaudiKernel/ToolHandle.h" #include "eflowRec/eflowCellList.h" +#include "eflowRec/eflowLayerIntegrator.h" +#include "eflowRec/eflowEEtaBinnedParameters.h" #include "xAODCaloEvent/CaloCluster.h" #include "xAODTracking/TrackParticle.h" @@ -30,8 +32,6 @@ class eflowCaloObjectContainer; class eflowRecTrackContainer; class eflowRecClusterContainer; class IEFlowCellEOverPTool; -class eflowEEtaBinnedParameters; -class eflowLayerIntegrator; class PFTrackClusterMatchingTool; class eflowRecTrack; @@ -76,8 +76,8 @@ public: ToolHandle<PFTrackClusterMatchingTool> m_matchingToolForPull_02; /* Tools for "shower simulation" */ - eflowEEtaBinnedParameters* m_binnedParameters; - eflowLayerIntegrator* m_integrator; + std::unique_ptr<eflowEEtaBinnedParameters> m_binnedParameters; + std::unique_ptr<eflowLayerIntegrator> m_integrator; ToolHandle<IEFlowCellEOverPTool> m_theEOverPTool; //double m_rCell; diff --git a/Reconstruction/eflowRec/eflowRec/eflowClusterCollectionTool.h b/Reconstruction/eflowRec/eflowRec/eflowClusterCollectionTool.h index 95e46ff0339c83ce11f27ec2ac15f40e727d40df..3d6d75ab69b400da8fedee4dcca662f13623083f 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowClusterCollectionTool.h +++ b/Reconstruction/eflowRec/eflowRec/eflowClusterCollectionTool.h @@ -33,8 +33,8 @@ class eflowClusterCollectionTool : virtual public IEFlowClusterCollectionTool, p static const InterfaceID& interfaceID(); StatusCode initialize(); - xAOD::CaloClusterContainer* execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters); - eflowRecClusterContainer* retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters); + std::unique_ptr<xAOD::CaloClusterContainer> execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters); + std::unique_ptr<eflowRecClusterContainer> retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters); StatusCode finalize(); }; diff --git a/Reconstruction/eflowRec/eflowRec/eflowEEtaBinnedParameters.h b/Reconstruction/eflowRec/eflowRec/eflowEEtaBinnedParameters.h index 7dd57146c56fc0589bc6aec55d31aa30dea31637..d659feb5a5b2be1620f54e0d2a13eb55e81b9dd2 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowEEtaBinnedParameters.h +++ b/Reconstruction/eflowRec/eflowRec/eflowEEtaBinnedParameters.h @@ -34,27 +34,22 @@ class eflowParameters { int nSubtRegions = eflowFirstIntRegions::nRegions; m_FirstIntParameters.resize(nSubtRegions); for (int i = 0; i < nSubtRegions; i++) { - m_FirstIntParameters[i] = new eflowFirstIntParameters; + m_FirstIntParameters[i] = std::make_unique<eflowFirstIntParameters>(); } } - ~eflowParameters() { - int n = m_FirstIntParameters.size(); - for (int i = 0; i < n; i++) { - delete m_FirstIntParameters[i]; - } - } + ~eflowParameters() {} const eflowFirstIntParameters* getFirstIntBin(eflowFirstIntENUM j1st) const { - return (eflowFirstIntRegions::Unknown != j1st) ? m_FirstIntParameters[j1st] : 0; + return (eflowFirstIntRegions::Unknown != j1st) ? m_FirstIntParameters[j1st].get() : nullptr; } eflowFirstIntParameters* getFirstIntBin(eflowFirstIntENUM j1st) { - return (eflowFirstIntRegions::Unknown != j1st) ? m_FirstIntParameters[j1st] : 0; + return (eflowFirstIntRegions::Unknown != j1st) ? m_FirstIntParameters[j1st].get() : nullptr; } - + private: - std::vector<eflowFirstIntParameters*> m_FirstIntParameters; + std::vector<std::unique_ptr<eflowFirstIntParameters> > m_FirstIntParameters; }; @@ -96,7 +91,7 @@ class eflowEEtaBinnedParameters : public eflowEEtaBinBase { private: /* For different E bin, Eta bin, different (int)paramNumber, there are different (double)shapeParam */ - std::vector< std::vector<eflowParameters*> > m_bins; - + std::vector< std::vector<std::unique_ptr<eflowParameters> > > m_bins; + }; #endif diff --git a/Reconstruction/eflowRec/eflowRec/eflowLayerIntegrator.h b/Reconstruction/eflowRec/eflowRec/eflowLayerIntegrator.h index f5680939a2f397c29f100ab113e954d9199529eb..ccd7e309d9c3282ee65c2cfb4014def2ebaf0853 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowLayerIntegrator.h +++ b/Reconstruction/eflowRec/eflowRec/eflowLayerIntegrator.h @@ -64,8 +64,8 @@ class eflowLayerIntegrator { std::vector<double> m_nUnitCellPerWindowOverCellEtaPhiArea; - eflowCellIntegrator<0>* m_integrator; - eflowCellIntegrator<1>* m_integratorLookup; + std::unique_ptr<eflowCellIntegrator<0> > m_integrator; + std::unique_ptr<eflowCellIntegrator<1> > m_integratorLookup; }; #endif diff --git a/Reconstruction/eflowRec/eflowRec/eflowLookupExp.h b/Reconstruction/eflowRec/eflowRec/eflowLookupExp.h index b5c3853b5d42ee1f8526ce0a71dcc6524866599c..eaae819dfab96379c0ada79450fdbca879685ecd 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowLookupExp.h +++ b/Reconstruction/eflowRec/eflowRec/eflowLookupExp.h @@ -15,23 +15,24 @@ #include <vector> #include <stdexcept> #include <math.h> +#include <memory> /* Lookup-table based exponential function to save CPU time */ class eflowLookupExp{ public: static eflowLookupExp* getInstance(int nExpBins = 50, int nExpSubBins = 1000){ - if ( !m_instance ) { - m_instance = new eflowLookupExp(nExpBins, nExpSubBins); + if ( !m_instance) { + m_instance = std::make_unique<eflowLookupExp>(nExpBins, nExpSubBins); } else { /* Make sure the requested bin numbers are consistent with the existing instance */ if ( (m_instance->m_nExpBins != nExpBins) || (m_instance->m_nExpSubBins != nExpSubBins) ) { throw std::runtime_error("eflowLookupExp: Instance with different bin numbers than existing requested!"); } } - return m_instance; + return m_instance.get(); } - private: + //private: eflowLookupExp(int nExpBins, int nExpSubBins) : m_nExpBins(nExpBins), m_nExpSubBins(nExpSubBins), m_exp(nExpBins+1), m_subExp(nExpSubBins+1) { /* Lookup table for the integer part of a number */ @@ -43,10 +44,12 @@ public: for (int iSub = 0; iSub <= nExpSubBins; ++iSub){ m_subExp[iSub] = exp(-substep* iSub); } - m_instance = this; + //initialise to nullptr, in this explicit instance it wil never be used. + //Hence it will always be a nullptr + m_instance = nullptr; } public: - ~eflowLookupExp(){ m_instance = 0; } + ~eflowLookupExp(){ } double evaluate(double x) { int iExpBin = (int) x; @@ -63,7 +66,7 @@ private: int m_nExpSubBins; std::vector<double> m_exp; std::vector<double> m_subExp; - static eflowLookupExp* m_instance; + static std::unique_ptr<eflowLookupExp> m_instance; }; diff --git a/Reconstruction/eflowRec/eflowRec/eflowRecCluster.h b/Reconstruction/eflowRec/eflowRec/eflowRecCluster.h index 4c9d303395cc9ec25a17491f89a99e3a7723b6f3..8c2796f518fae65ace41107da0e3ce8b7ec4f862 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowRecCluster.h +++ b/Reconstruction/eflowRec/eflowRec/eflowRecCluster.h @@ -39,7 +39,7 @@ public: ElementLink<xAOD::CaloClusterContainer> getClusElementLink() const { return m_clusElementLink; } - eflowMatchCluster* getMatchCluster() const { return m_matchCluster; } + eflowMatchCluster* getMatchCluster() const { return m_matchCluster.get(); } double getSumExpectedEnergy(); double getVarianceOfSumExpectedEnergy(); @@ -68,7 +68,7 @@ private: /* for EM mode, LC weight for cells are retrieved before doing any subtraction; they will be used after subtraction */ std::map<IdentifierHash,double> m_cellsWeightMap; - eflowMatchCluster* m_matchCluster; + std::unique_ptr<eflowMatchCluster> m_matchCluster; std::vector<eflowTrackClusterLink*> m_trackMatches; void replaceClusterByCopyInContainer(xAOD::CaloClusterContainer* container); diff --git a/Reconstruction/eflowRec/eflowRec/eflowRecTrack.h b/Reconstruction/eflowRec/eflowRec/eflowRecTrack.h index 7601773a28d26d6aae2b1a812dbc8b3ece5d2cc6..2b23f3d14822d6aeb49a657523a32f26742371fc 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowRecTrack.h +++ b/Reconstruction/eflowRec/eflowRec/eflowRecTrack.h @@ -129,10 +129,9 @@ private: std::vector<double> m_caloDepthArray; - //create new class -- link from here, e.g. // eflowCellOrderingParameters* m_cellOrderingParameters; - eflowTrackCaloPoints* m_trackCaloPoints; + std::unique_ptr<eflowTrackCaloPoints> m_trackCaloPoints; eflowRingSubtractionManager m_ringSubtractionManager; std::vector<eflowTrackClusterLink*> m_clusterMatches; std::map<std::string,std::vector<eflowTrackClusterLink*> > m_alternativeClusterMatches; diff --git a/Reconstruction/eflowRec/eflowRec/eflowRecoverSplitShowersTool.h b/Reconstruction/eflowRec/eflowRec/eflowRecoverSplitShowersTool.h index 6b9d5fd0e00aa37070b5e82d98f94384010961d1..daada2986e4610838106351f67cb0a145f5b4700 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowRecoverSplitShowersTool.h +++ b/Reconstruction/eflowRec/eflowRec/eflowRecoverSplitShowersTool.h @@ -80,8 +80,8 @@ private: /** Track-Cluster matching tool */ ToolHandle<PFTrackClusterMatchingTool> m_matchingTool; - eflowEEtaBinnedParameters* m_binnedParameters; - eflowLayerIntegrator* m_integrator; + std::unique_ptr<eflowEEtaBinnedParameters> m_binnedParameters; + std::unique_ptr<eflowLayerIntegrator> m_integrator; double m_subtractionSigmaCut; diff --git a/Reconstruction/eflowRec/eflowRec/eflowTrackCaloExtensionTool.h b/Reconstruction/eflowRec/eflowRec/eflowTrackCaloExtensionTool.h index 3ca30987bac356b731afef3b29c36cafaef1745e..6691cae808337f40d60d70b767ffbbbe26346c14 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowTrackCaloExtensionTool.h +++ b/Reconstruction/eflowRec/eflowRec/eflowTrackCaloExtensionTool.h @@ -40,7 +40,7 @@ public: static const InterfaceID& interfaceID(); virtual StatusCode initialize() override; - virtual eflowTrackCaloPoints* execute(const xAOD::TrackParticle* track) const override; + virtual std::unique_ptr<eflowTrackCaloPoints> execute(const xAOD::TrackParticle* track) const override; virtual StatusCode finalize() override; private: @@ -48,7 +48,7 @@ private: ToolHandle<Trk::IParticleCaloExtensionTool> m_theTrackExtrapolatorTool; - Trk::TrackParametersIdHelper* m_trackParametersIdHelper; + std::unique_ptr<Trk::TrackParametersIdHelper> m_trackParametersIdHelper; /* Count number of tracks seen for summary report in finalize */ //int m_tracksProcessed; diff --git a/Reconstruction/eflowRec/eflowRec/eflowTrackExtrapolatorBaseAlgTool.h b/Reconstruction/eflowRec/eflowRec/eflowTrackExtrapolatorBaseAlgTool.h index 94f2f0c0a6bff7bca08d897344034781c35104d6..907b65fdc9baf69a5b463280393cf39e6fc505fb 100644 --- a/Reconstruction/eflowRec/eflowRec/eflowTrackExtrapolatorBaseAlgTool.h +++ b/Reconstruction/eflowRec/eflowRec/eflowTrackExtrapolatorBaseAlgTool.h @@ -24,7 +24,7 @@ class eflowTrackCaloPoints; class eflowTrackExtrapolatorBaseAlgTool : virtual public IAlgTool { public: - virtual eflowTrackCaloPoints* execute(const xAOD::TrackParticle* track) const = 0; + virtual std::unique_ptr<eflowTrackCaloPoints> execute(const xAOD::TrackParticle* track) const = 0; }; #endif diff --git a/Reconstruction/eflowRec/src/PFMatchPositions.cxx b/Reconstruction/eflowRec/src/PFMatchPositions.cxx index 3259a0bbbb96a0b5352026aa66e30f12f944e928..f0c3b541ce52020d7ef627f7f569d95c4a67db67 100644 --- a/Reconstruction/eflowRec/src/PFMatchPositions.cxx +++ b/Reconstruction/eflowRec/src/PFMatchPositions.cxx @@ -23,16 +23,20 @@ EtaPhi* TrackEtaPhiInFixedLayersProvider::getPosition(const ITrack* track) { if (etaphi.getEta() == -999.){ etaphi = track->etaPhiInLayer(m_endcapLayer); } - *m_position = EtaPhi(etaphi); - return m_position; + //*m_position = EtaPhi(etaphi); + m_position = std::make_unique<EtaPhi>(etaphi); + return m_position.get(); } /* Cluster position providers */ EtaPhi* ClusterPlainEtaPhiProvider::getPosition(const ICluster* cluster) { - *m_position = eflowEtaPhiPosition(cluster->eta(), cluster->phi()); - return m_position; + //*m_position = eflowEtaPhiPosition(cluster->eta(), cluster->phi()); + //m_position = std::make_unique<eflowEtaPhiPosition>(cluster->eta(), cluster->phi()); + eflowEtaPhiPosition etaphi(cluster->eta(), cluster->phi()); + m_position = std::make_unique<EtaPhi>(etaphi); + return m_position.get(); } const double ClusterGeometricalCenterProvider::m_etaPhiLowerLimit(0.0025); @@ -41,8 +45,9 @@ EtaPhiWithVariance* ClusterGeometricalCenterProvider::getPosition(const ICluster /* Check the status to make sure this function only execute once since it is expensive. */ if(cluster->calVarianceStatus()) { - *m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->etaMean(), cluster->phiMean()), cluster->etaVariance(), cluster->phiVariance()); - return m_position; + //*m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->etaMean(), cluster->phiMean()), cluster->etaVariance(), cluster->phiVariance()); + m_position = std::make_unique<EtaPhiWithVariance>(eflowEtaPhiPosition(cluster->etaMean(), cluster->phiMean()), cluster->etaVariance(), cluster->phiVariance()); + return m_position.get(); } cluster->setCalVarianceStatus(); @@ -52,8 +57,9 @@ EtaPhiWithVariance* ClusterGeometricalCenterProvider::getPosition(const ICluster if (nCells == 0){ cluster->etaVariance(m_etaPhiLowerLimit); cluster->phiVariance(m_etaPhiLowerLimit); - *m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); - return m_position; + //*m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); + m_position = std::make_unique<EtaPhiWithVariance>(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); + return m_position.get(); } assert(nCells > 0); @@ -61,8 +67,9 @@ EtaPhiWithVariance* ClusterGeometricalCenterProvider::getPosition(const ICluster if (1 == nCells){ cluster->etaVariance(m_etaPhiLowerLimit); cluster->phiVariance(m_etaPhiLowerLimit); - *m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); - return m_position; + //*m_position = EtaPhiWithVariance(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); + m_position = std::make_unique<EtaPhiWithVariance>(eflowEtaPhiPosition(cluster->eta(), cluster->phi()), cluster->etaVariance(), cluster->phiVariance()); + return m_position.get(); } @@ -95,8 +102,9 @@ EtaPhiWithVariance* ClusterGeometricalCenterProvider::getPosition(const ICluster cluster->phiMean(phiMean); cluster->etaVariance(etaVariance); cluster->phiVariance(phiVariance); - *m_position = EtaPhiWithVariance(eflowEtaPhiPosition(etaMean, phiMean), cluster->etaVariance(), cluster->phiVariance()); - return m_position; + //*m_position = EtaPhiWithVariance(eflowEtaPhiPosition(etaMean, phiMean), cluster->etaVariance(), cluster->phiVariance()); + m_position = std::make_unique<EtaPhiWithVariance>(eflowEtaPhiPosition(etaMean, phiMean), cluster->etaVariance(), cluster->phiVariance()); + return m_position.get(); } } diff --git a/Reconstruction/eflowRec/src/PFMatcher.cxx b/Reconstruction/eflowRec/src/PFMatcher.cxx index 258ac18bd6adaffd5d8f570da08e6e7eb782b928..235875b6ca5dd59bee065d9b3c68d0f48ee9c63f 100644 --- a/Reconstruction/eflowRec/src/PFMatcher.cxx +++ b/Reconstruction/eflowRec/src/PFMatcher.cxx @@ -14,8 +14,6 @@ #include <fstream> namespace PFMatch { -TrackClusterMatcher::~TrackClusterMatcher() { delete m_distanceProvider; } - MatchDistance TrackClusterMatcher::match(const ITrack* track, const ICluster* cluster) { double distance = m_distanceProvider->distanceBetween(track, cluster); return MatchDistance(cluster, distance, distance<m_matchCut); diff --git a/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx b/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx index d280019a1c07ad2b7c471fdf7b217350731a0e63..8480712d64ede8cc7cce6d93684a49be66e1ac4f 100644 --- a/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx +++ b/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx @@ -38,17 +38,15 @@ PFTrackClusterMatchingTool::PFTrackClusterMatchingTool(const std::string& type, } StatusCode PFTrackClusterMatchingTool::initialize() { - IDistanceProvider* distanceProvider = DistanceFactory::Get(m_distanceType, TrackPositionFactory::Get(m_trackPositionType), ClusterPositionFactory::Get(m_clusterPositionType)); - m_matcher = new PFMatch::TrackClusterMatcher(distanceProvider, m_matchCut); + m_matcher = std::make_unique<PFMatch::TrackClusterMatcher>(DistanceFactory::Get(m_distanceType, TrackPositionFactory::Get(m_trackPositionType), ClusterPositionFactory::Get(m_clusterPositionType)),m_matchCut); + msg(MSG::INFO) << "In initialize:" << endmsg; msg(MSG::INFO) << "Track position type is \"" << m_trackPositionType << "\"" << endmsg; msg(MSG::INFO) << "Cluster position type is \"" << m_clusterPositionType << "\"" << endmsg; msg(MSG::INFO) << "Distance type is \"" << m_distanceType << "\"" << endmsg; msg(MSG::INFO) << "Match cut is " << m_matchCut << endmsg; - //delete distanceProvider; - return StatusCode::SUCCESS; } @@ -57,8 +55,6 @@ StatusCode PFTrackClusterMatchingTool::finalize() { msg(MSG::INFO) << "Processed " << m_tracksProcessed << " tracks." << endmsg; msg(MSG::INFO) << "Produced " << m_tracksMatched<< " matches." << endmsg; - delete m_matcher; - return StatusCode::SUCCESS; } diff --git a/Reconstruction/eflowRec/src/eflowCaloObjectMaker.cxx b/Reconstruction/eflowRec/src/eflowCaloObjectMaker.cxx index 95291573f9f3e335a735da7c44918fbd89fbba70..e54537266bc0b58dbb7d7d8c3b6d4febe8785d76 100644 --- a/Reconstruction/eflowRec/src/eflowCaloObjectMaker.cxx +++ b/Reconstruction/eflowRec/src/eflowCaloObjectMaker.cxx @@ -47,9 +47,9 @@ int eflowCaloObjectMaker::makeTrkCluCaloObjects(std::vector<eflowRecTrack*> trac for (unsigned int iTrack=0; iTrack<nTrack; ++iTrack) { eflowRecTrack *thisEflowRecTrack = static_cast<eflowRecTrack*>(tracksToRecover.at(iTrack)); if(thisEflowRecTrack->getClusterMatches().empty()) { - eflowCaloObject* calob = new eflowCaloObject(); + std::unique_ptr<eflowCaloObject> calob = std::make_unique<eflowCaloObject>(); calob->addTrack(thisEflowRecTrack); - caloObjectContainer->push_back(calob); + caloObjectContainer->push_back(std::move(calob)); result++; } else { tracksToConsider.push_back(thisEflowRecTrack); @@ -61,9 +61,9 @@ int eflowCaloObjectMaker::makeTrkCluCaloObjects(std::vector<eflowRecTrack*> trac for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) { eflowRecCluster* thisEFRecCluster = clustersToConsider.at(iCluster); if(thisEFRecCluster->getTrackMatches().empty()) { - eflowCaloObject* thisEflowCaloObject = new eflowCaloObject(); + std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>(); thisEflowCaloObject->addCluster(thisEFRecCluster); - caloObjectContainer->push_back(thisEflowCaloObject); + caloObjectContainer->push_back(std::move(thisEflowCaloObject)); result++; } } @@ -97,14 +97,14 @@ int eflowCaloObjectMaker::makeTrkCluCaloObjects(std::vector<eflowRecTrack*> trac } while (++time); /* store this eflowCaloObject */ - eflowCaloObject* thisEflowCaloObject = new eflowCaloObject(); + std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>(); thisEflowCaloObject->addTracks(trackList); thisEflowCaloObject->addClusters(clusterList); for(std::vector<eflowRecCluster*>::const_iterator itr_cluster = clusterList.begin(); itr_cluster != clusterList.end(); ++itr_cluster) { thisEflowCaloObject->addTrackClusterLinks((*itr_cluster)->getTrackMatches()); } - caloObjectContainer->push_back(thisEflowCaloObject); + caloObjectContainer->push_back(std::move(thisEflowCaloObject)); /* update tracksToConsider */ updateTracksToConsider(tracksToConsider, trackList); diff --git a/Reconstruction/eflowRec/src/eflowCellLevelSubtractionTool.cxx b/Reconstruction/eflowRec/src/eflowCellLevelSubtractionTool.cxx index 871d6bffab2e84dc1b8385be44907ea33c081ea2..1ee19e941a7afde30dc13ec749ce01fdaf019cde 100644 --- a/Reconstruction/eflowRec/src/eflowCellLevelSubtractionTool.cxx +++ b/Reconstruction/eflowRec/src/eflowCellLevelSubtractionTool.cxx @@ -88,8 +88,6 @@ eflowCellLevelSubtractionTool::eflowCellLevelSubtractionTool(const std::string& } eflowCellLevelSubtractionTool::~eflowCellLevelSubtractionTool() { - delete m_integrator; - delete m_binnedParameters; } StatusCode eflowCellLevelSubtractionTool::initialize(){ @@ -111,10 +109,10 @@ StatusCode eflowCellLevelSubtractionTool::initialize(){ msg(MSG::WARNING) << "Cannot find PFTrackClusterMatchingTool_2" << endmsg; } - m_integrator = new eflowLayerIntegrator(0.032, 1.0e-3, 3.0); - m_binnedParameters = new eflowEEtaBinnedParameters(); - - sc = m_theEOverPTool->execute(m_binnedParameters); + m_integrator = std::make_unique<eflowLayerIntegrator>(0.032, 1.0e-3, 3.0); + m_binnedParameters = std::make_unique<eflowEEtaBinnedParameters>(); + + sc = m_theEOverPTool->execute(m_binnedParameters.get()); if (sc.isFailure()) { msg(MSG::WARNING) << "Could not execute eflowCellEOverPTool " << endmsg; @@ -195,7 +193,7 @@ int eflowCellLevelSubtractionTool::matchAndCreateEflowCaloObj(int n) { for (unsigned int iCalo=0; iCalo<m_eflowCaloObjectContainer->size(); ++iCalo) { eflowCaloObject *thisEflowCaloObject = static_cast<eflowCaloObject*>(m_eflowCaloObjectContainer->at(iCalo)); - thisEflowCaloObject->simulateShower(m_integrator, m_binnedParameters, m_useUpdated2015ChargedShowerSubtraction); + thisEflowCaloObject->simulateShower(m_integrator.get(), m_binnedParameters.get(), m_useUpdated2015ChargedShowerSubtraction); } return nMatches; diff --git a/Reconstruction/eflowRec/src/eflowClusterCollectionTool.cxx b/Reconstruction/eflowRec/src/eflowClusterCollectionTool.cxx index 33f362faafa16b840eacf9c4456efb4088b29cef..c153007742b80c499c7e7c7f3f70ec6771785414 100644 --- a/Reconstruction/eflowRec/src/eflowClusterCollectionTool.cxx +++ b/Reconstruction/eflowRec/src/eflowClusterCollectionTool.cxx @@ -16,9 +16,9 @@ StatusCode eflowClusterCollectionTool::initialize(){ return StatusCode::SUCCESS; } -eflowRecClusterContainer* eflowClusterCollectionTool::retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) { +std::unique_ptr<eflowRecClusterContainer> eflowClusterCollectionTool::retrieve(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) { - eflowRecClusterContainer* result = new eflowRecClusterContainer(); + std::unique_ptr<eflowRecClusterContainer> result = std::make_unique<eflowRecClusterContainer>(); /* Loop over all eflowCaloObjects */ eflowCaloObjectContainer::iterator itEFCaloObject = theEflowCaloObjectContainer->begin(); @@ -40,13 +40,13 @@ eflowRecClusterContainer* eflowClusterCollectionTool::retrieve(eflowCaloObjectCo result->push_back(thisEfRecCluster); } } - return result; + return std::move(result); } -xAOD::CaloClusterContainer* eflowClusterCollectionTool::execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) { +std::unique_ptr<xAOD::CaloClusterContainer> eflowClusterCollectionTool::execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, bool useNonModifiedClusters) { - xAOD::CaloClusterContainer* result = new xAOD::CaloClusterContainer(SG::VIEW_ELEMENTS); + std::unique_ptr<xAOD::CaloClusterContainer> result = std::make_unique<xAOD::CaloClusterContainer>(SG::VIEW_ELEMENTS); /* Loop over all eflowCaloObjects */ eflowCaloObjectContainer::iterator itEFCaloObject = theEflowCaloObjectContainer->begin(); @@ -72,7 +72,7 @@ xAOD::CaloClusterContainer* eflowClusterCollectionTool::execute(eflowCaloObjectC << thisCluster->e() << ", " << thisCluster->eta() << " and " << thisCluster->phi() << endmsg; } } - return result; + return std::move(result); } StatusCode eflowClusterCollectionTool::finalize(){ diff --git a/Reconstruction/eflowRec/src/eflowEEtaBinnedParameters.cxx b/Reconstruction/eflowRec/src/eflowEEtaBinnedParameters.cxx index a425274ae6a44636b5f4a7da62c59635bfeae798..e3999ed0df22ea841628615208e652dcdf751862 100644 --- a/Reconstruction/eflowRec/src/eflowEEtaBinnedParameters.cxx +++ b/Reconstruction/eflowRec/src/eflowEEtaBinnedParameters.cxx @@ -31,13 +31,6 @@ using namespace std; /////////////////////////////////// eflowEEtaBinnedParameters::~eflowEEtaBinnedParameters() { - int nEBins = m_bins.size(); - for (int i = 0; i < nEBins; i++) { - int nEtaBins = m_bins[i].size(); - for (int j = 0; j < nEtaBins; j++) { - delete m_bins[i][j]; - } - } } void eflowEEtaBinnedParameters::initialise(const std::vector<double>& eBinBounds, const std::vector<double>& etaBinBounds, bool useAbsEta) { @@ -48,12 +41,14 @@ void eflowEEtaBinnedParameters::initialise(const std::vector<double>& eBinBounds /* Create all the bins */ int nEBins = getNumEBins(); int nEtaBins = getNumEtaBins()-1; - eflowParameters* dummy = nullptr; - m_bins.assign(nEBins, std::vector<eflowParameters*>(nEtaBins, dummy)); + m_bins.reserve(nEBins); for (int iEBin = 0; iEBin < nEBins; iEBin++) { + std::vector<std::unique_ptr<eflowParameters> > tempVector; + tempVector.reserve(nEtaBins); for (int iEtaBin = 0; iEtaBin < nEtaBins; iEtaBin++) { - m_bins[iEBin][iEtaBin] = new eflowParameters(); + tempVector.push_back(std::make_unique<eflowParameters>()); } + m_bins.push_back(std::move(tempVector)); } } @@ -75,8 +70,8 @@ void eflowEEtaBinnedParameters::initialise(const std::vector<double>& eBinBounds if ((0 == eBin && e <= m_eBinBounds[eBin]) || (eBin == getNumEBins() - 1 && e >= m_eBinBounds[getNumEBins() - 1])) { /* If e is below the lowest (above the highest) pinpoint, just return the lowest (highest) bin; no interpolation in this case. */ - *bin1 = m_bins[eBin][etaBin]; - *bin2 = m_bins[eBin][etaBin]; + *bin1 = m_bins[eBin][etaBin].get(); + *bin2 = m_bins[eBin][etaBin].get(); weight = 1.0; } else { /* The "normal" case: interpolate between two energies */ @@ -89,8 +84,8 @@ void eflowEEtaBinnedParameters::initialise(const std::vector<double>& eBinBounds lowEBin = eBin - 1; } - *bin1 = m_bins[lowEBin][etaBin]; - *bin2 = m_bins[highEBin][etaBin]; + *bin1 = m_bins[lowEBin][etaBin].get(); + *bin2 = m_bins[highEBin][etaBin].get(); if (LIN == m_mode) { weight = (m_eBinBounds[highEBin] - e) / (m_eBinBounds[highEBin] - m_eBinBounds[lowEBin]); diff --git a/Reconstruction/eflowRec/src/eflowLCCalibTool.cxx b/Reconstruction/eflowRec/src/eflowLCCalibTool.cxx index deba559f678384d4645ada5fd0e9e1ac5f1e97c7..bbdeeb7ff0d3f11c5b86bc43ef803afdc2ce2028 100644 --- a/Reconstruction/eflowRec/src/eflowLCCalibTool.cxx +++ b/Reconstruction/eflowRec/src/eflowLCCalibTool.cxx @@ -55,7 +55,7 @@ StatusCode eflowLCCalibTool::initialize() { void eflowLCCalibTool::execute(eflowCaloObjectContainer* theEflowCaloObjectContainer) { if (m_useLocalWeight) { - eflowRecClusterContainer* theEFRecCluster = m_clusterCollectionTool->retrieve(theEflowCaloObjectContainer, true); + std::unique_ptr<eflowRecClusterContainer> theEFRecCluster = m_clusterCollectionTool->retrieve(theEflowCaloObjectContainer, true); /* Calibrate each cluster */ eflowRecClusterContainer::iterator itCluster = theEFRecCluster->begin(); eflowRecClusterContainer::iterator endCluster = theEFRecCluster->end(); @@ -63,12 +63,9 @@ void eflowLCCalibTool::execute(eflowCaloObjectContainer* theEflowCaloObjectConta eflowRecCluster* cluster = (*itCluster); applyLocalWeight(cluster); } - - /* Don't delete the container, container doesn't own its elements) */ - } else { /* Collect all the clusters in a temporary container (with VIEW_ELEMENTS!) */ - xAOD::CaloClusterContainer* tempClusterContainer = m_clusterCollectionTool->execute( + std::unique_ptr<xAOD::CaloClusterContainer> tempClusterContainer = m_clusterCollectionTool->execute( theEflowCaloObjectContainer, true); /* Calibrate each cluster */ @@ -88,8 +85,6 @@ void eflowLCCalibTool::execute(eflowCaloObjectContainer* theEflowCaloObjectConta } - /* Delete the container again (clusters are not deleted, as the container doesn't own its elements) */ - delete tempClusterContainer; } } diff --git a/Reconstruction/eflowRec/src/eflowLayerIntegrator.cxx b/Reconstruction/eflowRec/src/eflowLayerIntegrator.cxx index 496601041b5f512251bff46511a21905e640a653..5e18eb7a250047220ab2c1a3d2d9a0d1cd549aca 100644 --- a/Reconstruction/eflowRec/src/eflowLayerIntegrator.cxx +++ b/Reconstruction/eflowRec/src/eflowLayerIntegrator.cxx @@ -32,8 +32,8 @@ eflowLayerIntegrator::eflowLayerIntegrator(double stdDev, double error, double r m_rMax(rMaxOverStdDev * stdDev), m_allClustersIntegral(eflowCalo::nRegions, 0.0), m_nUnitCellPerWindowOverCellEtaPhiArea(eflowCalo::nRegions), - m_integrator(new eflowCellIntegrator<0>(stdDev, error)), - m_integratorLookup(new eflowCellIntegrator<1>(stdDev, error)) { + m_integrator(std::make_unique<eflowCellIntegrator<0> >(stdDev, error)), + m_integratorLookup(std::make_unique<eflowCellIntegrator<1> >(stdDev, error)) { eflowDatabase database; /* Set up density conversion factors */ @@ -60,8 +60,8 @@ eflowLayerIntegrator::eflowLayerIntegrator(const eflowLayerIntegrator& originalE m_rMax = originalEflowLayerIntegrator.m_rMax; m_allClustersIntegral = originalEflowLayerIntegrator.m_allClustersIntegral; m_nUnitCellPerWindowOverCellEtaPhiArea = originalEflowLayerIntegrator.m_nUnitCellPerWindowOverCellEtaPhiArea; - m_integrator = new eflowCellIntegrator<0>(*originalEflowLayerIntegrator.m_integrator); - m_integratorLookup = new eflowCellIntegrator<1>(*originalEflowLayerIntegrator.m_integratorLookup); + m_integrator = std::make_unique<eflowCellIntegrator<0> >(*originalEflowLayerIntegrator.m_integrator); + m_integratorLookup = std::make_unique<eflowCellIntegrator<1> >(*originalEflowLayerIntegrator.m_integratorLookup); for (int i = 0; i < eflowCalo::nRegions; i++){ m_densityConversion[i] = originalEflowLayerIntegrator.m_densityConversion[i]; @@ -76,10 +76,8 @@ eflowLayerIntegrator& eflowLayerIntegrator::operator=(const eflowLayerIntegrator m_rMax = originalEflowLayerIntegrator.m_rMax; m_allClustersIntegral = originalEflowLayerIntegrator.m_allClustersIntegral; m_nUnitCellPerWindowOverCellEtaPhiArea = originalEflowLayerIntegrator.m_nUnitCellPerWindowOverCellEtaPhiArea; - if (m_integrator) delete m_integrator; - m_integrator = new eflowCellIntegrator<0>(*originalEflowLayerIntegrator.m_integrator); - if (m_integratorLookup) delete m_integratorLookup; - m_integratorLookup = new eflowCellIntegrator<1>(*originalEflowLayerIntegrator.m_integratorLookup); + m_integrator = std::make_unique<eflowCellIntegrator<0> >(*originalEflowLayerIntegrator.m_integrator); + m_integratorLookup = std::make_unique<eflowCellIntegrator<1> >(*originalEflowLayerIntegrator.m_integratorLookup); for (int i = 0; i < eflowCalo::nRegions; i++){ m_densityConversion[i] = originalEflowLayerIntegrator.m_densityConversion[i]; @@ -90,8 +88,6 @@ eflowLayerIntegrator& eflowLayerIntegrator::operator=(const eflowLayerIntegrator } eflowLayerIntegrator::~eflowLayerIntegrator() { - delete m_integrator; - delete m_integratorLookup; } void eflowLayerIntegrator::resetAllClustersIntegralForNewTrack(const eflowTrackCaloPoints& trackCalo) { diff --git a/Reconstruction/eflowRec/src/eflowLookupExp.cxx b/Reconstruction/eflowRec/src/eflowLookupExp.cxx index 6f901d20a3704f9aba7fcc3de9de3837475039da..32bf9c4e015c8d32252a6e841a87fdf80fae1d9e 100644 --- a/Reconstruction/eflowRec/src/eflowLookupExp.cxx +++ b/Reconstruction/eflowRec/src/eflowLookupExp.cxx @@ -11,7 +11,7 @@ #include "eflowRec/eflowLookupExp.h" -eflowLookupExp* eflowLookupExp::m_instance = nullptr; - +//eflowLookupExp* eflowLookupExp::m_instance = nullptr; +std::unique_ptr<eflowLookupExp> eflowLookupExp::m_instance = nullptr; diff --git a/Reconstruction/eflowRec/src/eflowMomentCalculatorTool.cxx b/Reconstruction/eflowRec/src/eflowMomentCalculatorTool.cxx index c95871993d46b3ab62b2cd16686f53fe2efe80f3..08797cd550440cc29e2c32660ef896ff5803ab6b 100644 --- a/Reconstruction/eflowRec/src/eflowMomentCalculatorTool.cxx +++ b/Reconstruction/eflowRec/src/eflowMomentCalculatorTool.cxx @@ -38,7 +38,7 @@ void eflowMomentCalculatorTool::execute(eflowCaloObjectContainer* theEflowCaloOb /* Collect all the clusters in a temporary container (with VIEW_ELEMENTS!) */ bool useNonModifiedClusters = true; if (true == m_LCMode) useNonModifiedClusters = false; - xAOD::CaloClusterContainer* tempClusterContainer = m_clusterCollectionTool->execute(theEflowCaloObjectContainer, useNonModifiedClusters); + std::unique_ptr<xAOD::CaloClusterContainer> tempClusterContainer = m_clusterCollectionTool->execute(theEflowCaloObjectContainer, useNonModifiedClusters); /* Set the layer energies */ /* This must be set before the cluster moment calculations, which use the layer energies */ @@ -46,12 +46,10 @@ void eflowMomentCalculatorTool::execute(eflowCaloObjectContainer* theEflowCaloOb /* Remake the cluster moments */ - if (m_clusterMomentsMaker->execute(tempClusterContainer).isFailure()) { + if (m_clusterMomentsMaker->execute(tempClusterContainer.get()).isFailure()) { msg(MSG::WARNING) << "Could not execute ClusterMomentsMaker " << endmsg; } - delete tempClusterContainer; - } StatusCode eflowMomentCalculatorTool::finalize(){ return StatusCode::SUCCESS; } diff --git a/Reconstruction/eflowRec/src/eflowPreparation.cxx b/Reconstruction/eflowRec/src/eflowPreparation.cxx index 01daa515e62ffb98b64a65fb509f437302fb2d23..fd4349e470b076db0bbfae13ce3e468f43d5399c 100644 --- a/Reconstruction/eflowRec/src/eflowPreparation.cxx +++ b/Reconstruction/eflowRec/src/eflowPreparation.cxx @@ -42,8 +42,6 @@ CREATED: 8th November, 2001 #include "xAODMuon/Muon.h" #include "xAODEgamma/ElectronxAODHelpers.h" -#include "CxxUtils/make_unique.h" - // INCLUDE GAUDI HEADER FILES: #include "GaudiKernel/SystemOfUnits.h" #include "GaudiKernel/Property.h" @@ -125,7 +123,7 @@ StatusCode eflowPreparation::initialize() { return StatusCode::SUCCESS; } - if (m_useLeptons) m_selectedMuons = CxxUtils::make_unique<xAOD::MuonContainer>(SG::VIEW_ELEMENTS); + if (m_useLeptons) m_selectedMuons = std::make_unique<xAOD::MuonContainer>(SG::VIEW_ELEMENTS); ATH_CHECK(m_selTool.retrieve()); @@ -149,7 +147,7 @@ StatusCode eflowPreparation::execute() { /* Create the eflowCaloObjectContainer and register it */ - sc = m_eflowCaloObjectContainerWriteHandle.record(CxxUtils::make_unique<eflowCaloObjectContainer>()); + sc = m_eflowCaloObjectContainerWriteHandle.record(std::make_unique<eflowCaloObjectContainer>()); if (sc.isFailure()) { if (msgLvl(MSG::WARNING)) { @@ -159,7 +157,7 @@ StatusCode eflowPreparation::execute() { } /* Create the eflowRecTrackContainer and register it */ - sc = m_eflowRecTrackContainerWriteHandle.record(CxxUtils::make_unique<eflowRecTrackContainer>()); + sc = m_eflowRecTrackContainerWriteHandle.record(std::make_unique<eflowRecTrackContainer>()); if (sc.isFailure()) { if (msgLvl(MSG::WARNING)) { @@ -170,7 +168,7 @@ StatusCode eflowPreparation::execute() { /* Create the eflowRecClusterContainer and register it */ - sc = m_eflowRecClusterContainerWriteHandle.record(CxxUtils::make_unique<eflowRecClusterContainer>()); + sc = m_eflowRecClusterContainerWriteHandle.record(std::make_unique<eflowRecClusterContainer>()); if (sc.isFailure()) { if (msgLvl(MSG::WARNING)) { @@ -264,7 +262,7 @@ StatusCode eflowPreparation::makeClusterContainer() { unsigned int nClusters = m_caloClusterReadHandle->size(); for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) { /* Create the eflowRecCluster and put it in the container */ - std::unique_ptr<eflowRecCluster> thisEFRecCluster = CxxUtils::make_unique<eflowRecCluster>(ElementLink<xAOD::CaloClusterContainer>(*m_caloClusterReadHandle, iCluster)); + std::unique_ptr<eflowRecCluster> thisEFRecCluster = std::make_unique<eflowRecCluster>(ElementLink<xAOD::CaloClusterContainer>(*m_caloClusterReadHandle, iCluster)); if (m_caloCalClusterReadHandle.isValid()){ std::map<IdentifierHash,double> cellsWeightMap; @@ -321,7 +319,7 @@ StatusCode eflowPreparation::makeTrackContainer() { if (!rejectTrack) { /* Create the eflowRecCluster and put it in the container */ - std::unique_ptr<eflowRecTrack> thisEFRecTrack = CxxUtils::make_unique<eflowRecTrack>(ElementLink<xAOD::TrackParticleContainer>(*m_trackReadHandle, trackIndex), m_theTrackExtrapolatorTool); + std::unique_ptr<eflowRecTrack> thisEFRecTrack = std::make_unique<eflowRecTrack>(ElementLink<xAOD::TrackParticleContainer>(*m_trackReadHandle, trackIndex), m_theTrackExtrapolatorTool); thisEFRecTrack->setTrackId(trackIndex); m_eflowRecTrackContainerWriteHandle->push_back(std::move(thisEFRecTrack)); } @@ -340,7 +338,7 @@ bool eflowPreparation::selectTrack(const xAOD::TrackParticle* track) { StatusCode eflowPreparation::recordLeptonContainers(){ - StatusCode sc = m_selectedElectronsWriteHandle.record(CxxUtils::make_unique<xAOD::ElectronContainer>(SG::VIEW_ELEMENTS)); + StatusCode sc = m_selectedElectronsWriteHandle.record(std::make_unique<xAOD::ElectronContainer>(SG::VIEW_ELEMENTS)); if (sc.isFailure()) { if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) @@ -352,7 +350,7 @@ StatusCode eflowPreparation::recordLeptonContainers(){ if (true == m_storeLeptonCells) { //record the cell container - sc = m_leptonCaloCellContainerWriteHandle.record(CxxUtils::make_unique<ConstDataVector<CaloCellContainer> >(SG::VIEW_ELEMENTS)); + sc = m_leptonCaloCellContainerWriteHandle.record(std::make_unique<ConstDataVector<CaloCellContainer> >(SG::VIEW_ELEMENTS)); if (sc.isFailure()) { if (msgLvl(MSG::WARNING)) diff --git a/Reconstruction/eflowRec/src/eflowRecCluster.cxx b/Reconstruction/eflowRec/src/eflowRecCluster.cxx index 5b125cd30eb8795e1d1d11f409eff68aa3ab7488..13bda9022831ee3354694ceeedb0ec67c023f5dd 100644 --- a/Reconstruction/eflowRec/src/eflowRecCluster.cxx +++ b/Reconstruction/eflowRec/src/eflowRecCluster.cxx @@ -16,7 +16,7 @@ eflowRecCluster::eflowRecCluster(const ElementLink<xAOD::CaloClusterContainer>& clusElementLink) : m_clusterId(-1), m_cluster(*clusElementLink), m_clusElementLink(clusElementLink), m_isTouchable(false), m_type(0), m_matchCluster(nullptr) { - m_matchCluster = new eflowMatchCluster(this); + m_matchCluster = std::make_unique<eflowMatchCluster>(this); } eflowRecCluster::eflowRecCluster(const eflowRecCluster& originalEflowRecCluster) { @@ -25,7 +25,7 @@ eflowRecCluster::eflowRecCluster(const eflowRecCluster& originalEflowRecCluster) m_clusElementLink = originalEflowRecCluster.m_clusElementLink; m_isTouchable = originalEflowRecCluster.m_isTouchable; m_type = originalEflowRecCluster.m_type; - m_matchCluster = new eflowMatchCluster(this); + m_matchCluster = std::make_unique<eflowMatchCluster>(this); } eflowRecCluster& eflowRecCluster::operator=(const eflowRecCluster& originalEflowRecCluster) { @@ -35,20 +35,21 @@ eflowRecCluster& eflowRecCluster::operator=(const eflowRecCluster& originalEflow m_cluster = originalEflowRecCluster.m_cluster; m_clusElementLink = originalEflowRecCluster.m_clusElementLink; m_isTouchable = originalEflowRecCluster.m_isTouchable; - if (m_matchCluster) delete m_matchCluster; - m_matchCluster = new eflowMatchCluster(this); + m_matchCluster = std::make_unique<eflowMatchCluster>(this); return *this; }//if not assigning to self, then we have copied the data to the new object } -eflowRecCluster::~eflowRecCluster() { delete m_matchCluster; } +eflowRecCluster::~eflowRecCluster() { } void eflowRecCluster::replaceClusterByCopyInContainer(xAOD::CaloClusterContainer* container) { - xAOD::CaloCluster* copiedCluster = new xAOD::CaloCluster(*m_cluster); - container->push_back(copiedCluster); - m_cluster = copiedCluster; + std::unique_ptr<xAOD::CaloCluster> copiedCluster = std::make_unique<xAOD::CaloCluster>(*m_cluster); + container->push_back(std::move(copiedCluster)); + //Cannot set m_cluster to copiedCluster - std::move makes copiedCluster a nullptr. Hence must access from + //back of container, we have just pushed into. + m_cluster = container->back(); m_clusElementLink = ElementLink<xAOD::CaloClusterContainer>(); - m_clusElementLink.toContainedElement(*container, copiedCluster); + m_clusElementLink.toContainedElement(*container,container->back()); } xAOD::CaloCluster* eflowRecCluster::getClusterForModification(xAOD::CaloClusterContainer* container) { diff --git a/Reconstruction/eflowRec/src/eflowRecTrack.cxx b/Reconstruction/eflowRec/src/eflowRecTrack.cxx index 8aef158c435fb49de8aa7ec5b686684a2c3926e1..b35ed08633f7db0004e34440740ab787675534e8 100644 --- a/Reconstruction/eflowRec/src/eflowRecTrack.cxx +++ b/Reconstruction/eflowRec/src/eflowRecTrack.cxx @@ -34,7 +34,7 @@ eflowRecTrack::eflowRecTrack(const eflowRecTrack& eflowRecTrack){ m_isInDenseEnvironment = eflowRecTrack.m_isInDenseEnvironment; m_isSubtracted = eflowRecTrack.m_isSubtracted; m_hasBin = eflowRecTrack.m_hasBin; - m_trackCaloPoints = new eflowTrackCaloPoints(*eflowRecTrack.m_trackCaloPoints); + m_trackCaloPoints = std::make_unique<eflowTrackCaloPoints>(*eflowRecTrack.m_trackCaloPoints); } eflowRecTrack& eflowRecTrack::operator = (const eflowRecTrack& originalEflowRecTrack){ @@ -51,13 +51,12 @@ eflowRecTrack& eflowRecTrack::operator = (const eflowRecTrack& originalEflowRecT m_isInDenseEnvironment = originalEflowRecTrack.m_isInDenseEnvironment; m_isSubtracted = originalEflowRecTrack.m_isSubtracted; m_hasBin = originalEflowRecTrack.m_hasBin; - if (m_trackCaloPoints) delete m_trackCaloPoints; - m_trackCaloPoints = new eflowTrackCaloPoints(*originalEflowRecTrack.m_trackCaloPoints); + m_trackCaloPoints = std::make_unique<eflowTrackCaloPoints>(*originalEflowRecTrack.m_trackCaloPoints); return *this; }//if not assigning to self, then we have copied the data to the new object } -eflowRecTrack::~eflowRecTrack() { delete m_trackCaloPoints; } +eflowRecTrack::~eflowRecTrack() {} void eflowRecTrack::setCaloDepthArray(const double* depthArray) { m_caloDepthArray.assign(depthArray, depthArray + eflowDepthCalculator::NDepth() + 1); diff --git a/Reconstruction/eflowRec/src/eflowRecoverSplitShowersTool.cxx b/Reconstruction/eflowRec/src/eflowRecoverSplitShowersTool.cxx index 7d00feee608e473fe259902a860f46a8d69cedd0..021c31e6a4843e5f99ca9354a5964e8822a37452 100644 --- a/Reconstruction/eflowRec/src/eflowRecoverSplitShowersTool.cxx +++ b/Reconstruction/eflowRec/src/eflowRecoverSplitShowersTool.cxx @@ -42,8 +42,8 @@ m_rCell(0.75), m_windowRms(0.032), m_theEOverPTool("eflowCellEOverPTool",this), m_matchingTool("PFTrackClusterMatchingTool/RcvrSpltMatchingTool", this), -m_binnedParameters(new eflowEEtaBinnedParameters()), -m_integrator(new eflowLayerIntegrator(m_windowRms, 1.0e-3, 3.0)), +m_binnedParameters(std::make_unique<eflowEEtaBinnedParameters>()), +m_integrator(std::make_unique<eflowLayerIntegrator>(m_windowRms, 1.0e-3, 3.0)), m_subtractionSigmaCut(1.5), m_recoverIsolatedTracks(false), m_nTrackClusterMatches(0), @@ -79,7 +79,7 @@ StatusCode eflowRecoverSplitShowersTool::initialize(){ return StatusCode::SUCCESS; } - if (m_theEOverPTool->execute(m_binnedParameters).isFailure()){ + if (m_theEOverPTool->execute(m_binnedParameters.get()).isFailure()){ msg(MSG::WARNING) << "Could not execute eflowCellEOverPTool " << endmsg; return StatusCode::SUCCESS; } @@ -107,9 +107,6 @@ StatusCode eflowRecoverSplitShowersTool::finalize(){ msg(MSG::INFO) << "Produced " << m_nTrackClusterMatches << " track-cluster matches." << endmsg; - delete m_binnedParameters; - delete m_integrator; - return StatusCode::SUCCESS; } @@ -205,9 +202,9 @@ int eflowRecoverSplitShowersTool::matchAndCreateEflowCaloObj() { eflowRecTrack* thisEfRecTrack = *itEfRecTrack; /* No point to do anything if bin does not exist */ if (!thisEfRecTrack->hasBin()) { - eflowCaloObject* thisEflowCaloObject = new eflowCaloObject(); + std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>(); thisEflowCaloObject->addTrack(thisEfRecTrack); - m_eflowCaloObjectContainer->push_back(thisEflowCaloObject); + m_eflowCaloObjectContainer->push_back(std::move(thisEflowCaloObject)); continue; } if (msgLvl(MSG::WARNING)){ @@ -240,7 +237,7 @@ int eflowRecoverSplitShowersTool::matchAndCreateEflowCaloObj() { /* integrate cells; determine FLI; eoverp */ for (unsigned int iCalo = nCaloObj; iCalo < m_eflowCaloObjectContainer->size(); ++iCalo) { eflowCaloObject* thisEflowCaloObject = m_eflowCaloObjectContainer->at(iCalo); - thisEflowCaloObject->simulateShower(m_integrator, m_binnedParameters, m_useUpdated2015ChargedShowerSubtraction); + thisEflowCaloObject->simulateShower(m_integrator.get(), m_binnedParameters.get(), m_useUpdated2015ChargedShowerSubtraction); } return nCaloObj; } diff --git a/Reconstruction/eflowRec/src/eflowTrackCaloExtensionTool.cxx b/Reconstruction/eflowRec/src/eflowTrackCaloExtensionTool.cxx index 47c6f9f24d58da28dad74f4bde2348cd54432e8d..37e4b8b02e80fe8988625f4d34e4e825c647b34b 100644 --- a/Reconstruction/eflowRec/src/eflowTrackCaloExtensionTool.cxx +++ b/Reconstruction/eflowRec/src/eflowTrackCaloExtensionTool.cxx @@ -25,25 +25,21 @@ #include "CaloDetDescr/CaloDepthTool.h" #include "GaudiKernel/ListItem.h" -//#include "GaudiKernel/ToolHandle.h" #include <map> #include <vector> #include <utility> -//using std::pair; - eflowTrackCaloExtensionTool::eflowTrackCaloExtensionTool(const std::string& type, const std::string& name, const IInterface* parent) : AthAlgTool(type, name, parent), m_theTrackExtrapolatorTool("Trk::ParticleCaloExtensionTool"), - m_trackParametersIdHelper(new Trk::TrackParametersIdHelper) + m_trackParametersIdHelper(std::make_unique<Trk::TrackParametersIdHelper>()) { declareInterface<eflowTrackExtrapolatorBaseAlgTool>(this); declareProperty("TrackCaloExtensionTool", m_theTrackExtrapolatorTool, "TrackCaloExtension Tool Handle"); } eflowTrackCaloExtensionTool::~eflowTrackCaloExtensionTool() { - delete m_trackParametersIdHelper; } StatusCode eflowTrackCaloExtensionTool::initialize() { @@ -66,7 +62,7 @@ StatusCode eflowTrackCaloExtensionTool::initialize() { return StatusCode::SUCCESS; } -eflowTrackCaloPoints* eflowTrackCaloExtensionTool::execute(const xAOD::TrackParticle* track) const { +std::unique_ptr<eflowTrackCaloPoints> eflowTrackCaloExtensionTool::execute(const xAOD::TrackParticle* track) const { //++m_tracksProcessed; msg(MSG::VERBOSE) << " Now running eflowTrackCaloExtensionTool" << endmsg; @@ -89,12 +85,12 @@ eflowTrackCaloPoints* eflowTrackCaloExtensionTool::execute(const xAOD::TrackPart parametersMap[getLayer(clParameter)] = clParameter->clone(); } } - return new eflowTrackCaloPoints(parametersMap); + return std::make_unique<eflowTrackCaloPoints>(parametersMap); } else{ msg(MSG::WARNING) << "TrackExtension failed for track with pt and eta " << track->pt() << " and " << track->eta() << endmsg; parametersMap[eflowCalo::LAYER::Unknown] = nullptr; - return new eflowTrackCaloPoints(parametersMap); + return std::make_unique<eflowTrackCaloPoints>(parametersMap); }