diff --git a/Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx b/Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx index f8265012137791c30e6ff08a2a26fab87a81c796..4f704e4a5e00d08f8940b95964c99477b43f08f5 100644 --- a/Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx +++ b/Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx @@ -39,6 +39,7 @@ #include <algorithm> #include <iterator> #include <sstream> +#include <memory> #include "xAODCaloEvent/CaloClusterKineHelper.h" @@ -581,7 +582,7 @@ CaloTopoClusterMaker::execute(const EventContext& ctx, //Create temporary list of proto-clusters //Clusters below Et cut will be dropped. //The remaining clusters will be sorted in E_t before storing - std::vector<CaloProtoCluster*> sortClusters; + std::vector<std::unique_ptr<CaloProtoCluster> > sortClusters; sortClusters.reserve (myHashClusters.size()); for (HashCluster* tmpCluster : myHashClusters) { @@ -595,25 +596,24 @@ CaloTopoClusterMaker::execute(const EventContext& ctx, addCluster = true; } if ( addCluster) { - CaloProtoCluster* myCluster = new CaloProtoCluster(cellCollLink); + std::unique_ptr<CaloProtoCluster> myCluster = std::make_unique<CaloProtoCluster>(cellCollLink); + //CaloProtoCluster* myCluster = new CaloProtoCluster(cellCollLink); myCluster->getCellLinks()->reserve(tmpCluster->size()); for (CaloTopoTmpClusterCell* cell : *tmpCluster) { - size_t iCell = cell->getCaloCell(); + const size_t iCell = cell->getCaloCell(); myCluster->addCell(iCell,1.); } - float cl_et = myCluster->et(); + const float cl_et = myCluster->et(); if ( (m_seedCutsInAbsE ? std::abs(cl_et) : cl_et) > m_clusterEtorAbsEtCut ) { - sortClusters.push_back(myCluster); + sortClusters.push_back(std::move(myCluster)); } - else { - delete myCluster; - } } } // Sort the clusters according to Et - std::sort(sortClusters.begin(),sortClusters.end(),[](CaloProtoCluster* pc1, CaloProtoCluster* pc2) { + std::sort(sortClusters.begin(),sortClusters.end(),[](const std::unique_ptr<CaloProtoCluster>& pc1, + const std::unique_ptr<CaloProtoCluster>& pc2) { //As in CaloUtils/CaloClusterEtSort. //assign to volatile to avoid excess precison on in FP unit on x386 machines volatile double et1(pc1->et()); @@ -625,11 +625,10 @@ CaloTopoClusterMaker::execute(const EventContext& ctx, // add to cluster container clusColl->reserve(sortClusters.size()); - for (CaloProtoCluster* protoCluster: sortClusters) { + for (const auto& protoCluster: sortClusters) { xAOD::CaloCluster* xAODCluster=new xAOD::CaloCluster(); clusColl->push_back(xAODCluster); xAODCluster->addCellLink(protoCluster->releaseCellLinks());//Hand over ownership to xAOD::CaloCluster - delete protoCluster; xAODCluster->setClusterSize(m_clusterSize); CaloClusterKineHelper::calculateKine(xAODCluster,false,true); //No weight at this point! } diff --git a/Calorimeter/CaloRec/src/CaloTopoClusterSplitter.cxx b/Calorimeter/CaloRec/src/CaloTopoClusterSplitter.cxx index 25d7f92f76b69e9d83a5170ba8a1083c46219e87..4d7ef0a5716fd9dd83636692dd60d7a597b81c55 100644 --- a/Calorimeter/CaloRec/src/CaloTopoClusterSplitter.cxx +++ b/Calorimeter/CaloRec/src/CaloTopoClusterSplitter.cxx @@ -37,6 +37,7 @@ #include <algorithm> #include <iterator> #include <sstream> +#include <memory> using HepGeom::Vector3D; @@ -1051,21 +1052,18 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, // create cluster list for the purpose of sorting in E_t before storing // in the cluster collection - std::vector<CaloProtoCluster*> myCaloClusters; + std::vector<std::unique_ptr<CaloProtoCluster> > myCaloClusters; myCaloClusters.reserve (500); - std::vector<CaloProtoCluster*> myRestClusters; - myRestClusters.resize(clusColl->size(),0); // this has a 0 pointer as default! + std::vector<std::unique_ptr<CaloProtoCluster> > myRestClusters; + myRestClusters.resize(clusColl->size()); // this has a 0 pointer as default! std::vector<HashCluster *>::iterator hashClusIter = myHashClusters.begin(); std::vector<HashCluster *>::iterator hashClusIterEnd=myHashClusters.end(); for (;hashClusIter!=hashClusIterEnd;++hashClusIter) { HashCluster * tmpCluster = (*hashClusIter); if ( tmpCluster->size() > 1 ) { // local maximum implies at least 2 cells are in the cluster ... - // CaloCluster *myCluster = new CaloCluster(); - //xAOD::CaloCluster *myCluster = CaloClusterStoreHelper::makeCluster(myCellColl); - CaloProtoCluster* myCluster=new CaloProtoCluster(myCellCollLink); - - ATH_MSG_DEBUG("[CaloCluster@" << myCluster << "] created in <myCaloClusters>."); + std::unique_ptr<CaloProtoCluster> myCluster = std::make_unique<CaloProtoCluster>(myCellCollLink); + ATH_MSG_DEBUG("[CaloCluster@" << myCluster.get() << "] created in <myCaloClusters>."); HashCluster::iterator clusCellIter=tmpCluster->begin(); HashCluster::iterator clusCellIterEnd=tmpCluster->end(); myCluster->getCellLinks()->reserve(tmpCluster->size()); @@ -1082,9 +1080,9 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, myCluster->addCell(itrCell.index(),myWeight); } //CaloClusterKineHelper::calculateKine(myCluster); - ATH_MSG_DEBUG("[CaloCluster@" << myCluster << "] size: " << myCluster->size()); + ATH_MSG_DEBUG("[CaloCluster@" << myCluster.get() << "] size: " << myCluster->size()); //myCluster->setClusterSize(clusterSize); - myCaloClusters.push_back(myCluster); + myCaloClusters.push_back(std::move(myCluster)); } else if ( tmpCluster->size() == 1 ) { // either cells belonging to a cluster with no local maximum @@ -1096,9 +1094,9 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, // any local max are copied anyways if (!myRestClusters[tmpCluster->getParentClusterIndex()]) { - myRestClusters[tmpCluster->getParentClusterIndex()] = new CaloProtoCluster(myCellColl); + myRestClusters[tmpCluster->getParentClusterIndex()] = std::make_unique<CaloProtoCluster>(myCellColl); } - ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[tmpCluster->getParentClusterIndex()] + ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[tmpCluster->getParentClusterIndex()].get() << "] created in <myRestClusters>"); myRestClusters[tmpCluster->getParentClusterIndex()]->getCellLinks()->reserve(tmpCluster->size()); HashCluster::iterator clusCellIter=tmpCluster->begin(); @@ -1110,7 +1108,7 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, myRestClusters[tmpCluster->getParentClusterIndex()]->addCell(itrCell.index(),myWeight); } //CaloClusterKineHelper::calculateKine(myRestClusters[tmpCluster->getParentClusterIndex()]); - ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[tmpCluster->getParentClusterIndex()] + ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[tmpCluster->getParentClusterIndex()].get() << "] size: " << myRestClusters[tmpCluster->getParentClusterIndex()]->size()); //myRestClusters[tmpCluster->getParentClusterIndex()]->setClusterSize(clusterSize); } @@ -1125,22 +1123,22 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, const xAOD::CaloCluster* parentCluster = (*clusCollIter); if ( !hasLocalMaxVector[iClusterNumber] ) { //xAOD::CaloCluster *myClone = new xAOD::CaloCluster(*parentCluster); - myCaloClusters.push_back(new CaloProtoCluster(parentCluster->getCellLinks())); - ATH_MSG_DEBUG("[CaloProtoCluster@" << myCaloClusters.back() << "] with " << myCaloClusters.back()->size() - << "cells cloned from " << parentCluster << " with " << parentCluster->size() - <<" cells"); + myCaloClusters.push_back(std::make_unique<CaloProtoCluster>(parentCluster->getCellLinks())); + ATH_MSG_DEBUG("[CaloProtoCluster@" << myCaloClusters.back().get() << "] with " + << myCaloClusters.back()->size() << "cells cloned from " + << parentCluster << " with " << parentCluster->size() <<" cells"); } else if (myRestClusters[iClusterNumber]) { - myCaloClusters.push_back(myRestClusters[iClusterNumber]); - ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[iClusterNumber] + ATH_MSG_DEBUG("[CaloCluster@" << myRestClusters[iClusterNumber].get() << "] pushed into <myCaloClusters> with " << myRestClusters[iClusterNumber]->size() << " cells"); + myCaloClusters.push_back(std::move(myRestClusters[iClusterNumber])); } } - // Sort the clusters according to Et //CaloClusterEtSort::compare compareEt; - std::sort(myCaloClusters.begin(),myCaloClusters.end(),[](CaloProtoCluster* pc1, CaloProtoCluster* pc2) { + std::sort(myCaloClusters.begin(),myCaloClusters.end(),[](const std::unique_ptr<CaloProtoCluster>& pc1, + const std::unique_ptr<CaloProtoCluster>& pc2) { //As in CaloUtils/CaloClusterEtSort. //assign to volatile to avoid excess precison on in FP unit on x386 machines volatile double et1(pc1->et()); @@ -1158,11 +1156,10 @@ StatusCode CaloTopoClusterSplitter::execute(const EventContext& ctx, int nTot(0); float eMax(0.); // add to cluster container. - for(CaloProtoCluster* protoCluster : myCaloClusters) { + for(const auto& protoCluster : myCaloClusters) { xAOD::CaloCluster* xAODCluster=new xAOD::CaloCluster(); clusColl->push_back(xAODCluster); xAODCluster->addCellLink(protoCluster->releaseCellLinks());//Hand over ownership to xAOD::CaloCluster - delete protoCluster; xAODCluster->setClusterSize(clusterSize); CaloClusterKineHelper::calculateKine(xAODCluster); ATH_MSG_DEBUG("CaloCluster@" << xAODCluster << " pushed into "