From 57f3728ebb345213bd49f626737e5d1346c5b70f Mon Sep 17 00:00:00 2001 From: laphecet Date: Tue, 1 Dec 2009 05:35:38 +0000 Subject: [PATCH] Fixing clustering(s) memory leaks --- MUON/AliMUONCluster.cxx | 14 ++++++++-- MUON/AliMUONClusterFinderMLEM.cxx | 6 ++-- MUON/AliMUONClusterFinderPeakCOG.cxx | 12 ++++---- MUON/AliMUONClusterFinderPeakFit.cxx | 12 ++++---- MUON/AliMUONPreClusterFinder.cxx | 42 +++++++++++++++++++++------- MUON/AliMUONPreClusterFinder.h | 3 ++ 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/MUON/AliMUONCluster.cxx b/MUON/AliMUONCluster.cxx index 2ab947e661b..1afaab414db 100644 --- a/MUON/AliMUONCluster.cxx +++ b/MUON/AliMUONCluster.cxx @@ -144,6 +144,7 @@ AliMUONCluster::operator=(const AliMUONCluster& src) AliMUONCluster::~AliMUONCluster() { /// dtor : note that we're owner of our pads +// fPads.Delete(); } //_____________________________________________________________________________ @@ -152,6 +153,7 @@ AliMUONCluster::Clear(Option_t*) { /// Clear our pad array fPads.Clear(); +// fPads.Delete(); } //_____________________________________________________________________________ @@ -345,8 +347,15 @@ AliMUONCluster::Copy(TObject& obj) const /// TObject::Copy(obj); AliMUONCluster& dest = static_cast(obj); - dest.fPads.Delete(); - dest.fPads = fPads; + +// dest.fPads.Delete(); + dest.fPads.Clear(); + + for ( Int_t i = 0; i <= fPads.GetLast(); ++i ) + { + AliMUONPad* p = static_cast(fPads.UncheckedAt(i)); + dest.fPads.AddLast(new AliMUONPad(*p)); + } dest.fHasPosition = fHasPosition; dest.fPosition = fPosition; dest.fPositionError = fPositionError; @@ -744,6 +753,7 @@ AliMUONCluster::RemovePad(AliMUONPad* pad) fPads.Remove(pad); fPads.Compress(); + delete pad; // update cluster's data fIsSaturated[0]=fIsSaturated[1]=kFALSE; fMultiplicity[0]=fMultiplicity[1]=0; diff --git a/MUON/AliMUONClusterFinderMLEM.cxx b/MUON/AliMUONClusterFinderMLEM.cxx index d8631828732..060a13ab56f 100644 --- a/MUON/AliMUONClusterFinderMLEM.cxx +++ b/MUON/AliMUONClusterFinderMLEM.cxx @@ -84,7 +84,7 @@ fNClusters(0), fNAddVirtualPads(0) { /// Constructor - + fkSegmentation[1] = fkSegmentation[0] = 0x0; if (fPlot) fDebug = 1; @@ -129,7 +129,8 @@ AliMUONClusterFinderMLEM::Prepare(Int_t detElemId, fEventNumber = runLoader ? runLoader->GetEventNumber() : 0; fClusterNumber = -1; fClusterList.Delete(); - + fPixArray->Delete(); + AliDebug(3,Form("EVT %d DE %d",fEventNumber,fDetElemId)); if ( fPreClusterFinder->NeedSegmentation() ) @@ -162,6 +163,7 @@ AliMUONClusterFinderMLEM::NextCluster() fPreCluster = fPreClusterFinder->NextCluster(); + fPixArray->Delete(); fClusterList.Delete(); // reset the list of clusters for this pre-cluster fClusterNumber = -1; //AZ diff --git a/MUON/AliMUONClusterFinderPeakCOG.cxx b/MUON/AliMUONClusterFinderPeakCOG.cxx index 6b7d1543aad..c6b80f25fb8 100644 --- a/MUON/AliMUONClusterFinderPeakCOG.cxx +++ b/MUON/AliMUONClusterFinderPeakCOG.cxx @@ -148,6 +148,9 @@ AliMUONClusterFinderPeakCOG::NextCluster() // if the cluster list is exhausted, we need to go to the next // pre-cluster and treat it + fClusterList.Delete(); // reset the list of clusters for this pre-cluster + fClusterNumber = -1; + fPreCluster = fPreClusterFinder->NextCluster(); if (!fPreCluster) @@ -156,9 +159,6 @@ AliMUONClusterFinderPeakCOG::NextCluster() return 0x0; } - fClusterList.Delete(); // reset the list of clusters for this pre-cluster - fClusterNumber = -1; - WorkOnPreCluster(); // WorkOnPreCluster may have used only part of the pads, so we check that @@ -821,8 +821,8 @@ void AliMUONClusterFinderPeakCOG::FindCluster(AliMUONCluster& cluster, Double_t yc = fHistAnode->GetYaxis()->GetBinCenter(ic); Double_t xc = fHistAnode->GetXaxis()->GetBinCenter(jc); Double_t cont = fHistAnode->GetCellContent(jc,ic); - AliMUONPad* pixPtr = new AliMUONPad (xc, yc, wx, wy, cont); - if (fDebug) pixPtr->Print("full"); + AliMUONPad pixel(xc, yc, wx, wy, cont); + if (fDebug) pixel.Print("full"); Int_t npad = cluster.Multiplicity(); @@ -832,7 +832,7 @@ void AliMUONClusterFinderPeakCOG::FindCluster(AliMUONCluster& cluster, for (Int_t j = 0; j < npad; ++j) { AliMUONPad* pad = cluster.Pad(j); - if ( Overlap(*pad,*pixPtr) ) + if ( Overlap(*pad,pixel) ) { if (fDebug) { cout << j << " "; pad->Print("full"); } if (pad->Charge() > qMax[pad->Cathode()]) { diff --git a/MUON/AliMUONClusterFinderPeakFit.cxx b/MUON/AliMUONClusterFinderPeakFit.cxx index 4ab7ccb3f07..24a488104ee 100644 --- a/MUON/AliMUONClusterFinderPeakFit.cxx +++ b/MUON/AliMUONClusterFinderPeakFit.cxx @@ -240,6 +240,9 @@ AliMUONClusterFinderPeakFit::NextCluster() // if the cluster list is exhausted, we need to go to the next // pre-cluster and treat it + fClusterList.Delete(); // reset the list of clusters for this pre-cluster + fClusterNumber = -1; + fPreCluster = fPreClusterFinder->NextCluster(); if (!fPreCluster) @@ -248,9 +251,6 @@ AliMUONClusterFinderPeakFit::NextCluster() return 0x0; } - fClusterList.Delete(); // reset the list of clusters for this pre-cluster - fClusterNumber = -1; - WorkOnPreCluster(); // WorkOnPreCluster may have used only part of the pads, so we check that @@ -1029,8 +1029,8 @@ void AliMUONClusterFinderPeakFit::FindClusterCOG(AliMUONCluster& cluster, Double_t yc = fHistAnode->GetYaxis()->GetBinCenter(ic); Double_t xc = fHistAnode->GetXaxis()->GetBinCenter(jc); Double_t cont = fHistAnode->GetCellContent(jc,ic); - AliMUONPad* pixPtr = new AliMUONPad (xc, yc, wx, wy, cont); - if (fDebug) pixPtr->Print("full"); + AliMUONPad pixel(xc, yc, wx, wy, cont); + if (fDebug) pixel.Print("full"); Int_t npad = cluster.Multiplicity(); @@ -1040,7 +1040,7 @@ void AliMUONClusterFinderPeakFit::FindClusterCOG(AliMUONCluster& cluster, for (Int_t j = 0; j < npad; ++j) { AliMUONPad* pad = cluster.Pad(j); - if ( Overlap(*pad,*pixPtr) ) + if ( Overlap(*pad,pixel) ) { if (fDebug) { cout << j << " "; pad->Print("full"); } if (pad->Charge() > qMax[pad->Cathode()]) { diff --git a/MUON/AliMUONPreClusterFinder.cxx b/MUON/AliMUONPreClusterFinder.cxx index f803f29d85c..b21d6a79255 100644 --- a/MUON/AliMUONPreClusterFinder.cxx +++ b/MUON/AliMUONPreClusterFinder.cxx @@ -187,6 +187,26 @@ AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const } } +//_____________________________________________________________________________ +AliMUONCluster* +AliMUONPreClusterFinder::NewCluster() +{ + /// Create a new (empty) cluster + Int_t id = fClusters.GetLast()+1; + AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster; + cluster->SetUniqueID(id); + return cluster; +} + +//_____________________________________________________________________________ +void +AliMUONPreClusterFinder::RemoveCluster(AliMUONCluster* cluster) +{ + /// Remove a cluster + fClusters.Remove(cluster); + fClusters.Compress(); +} + //_____________________________________________________________________________ AliMUONCluster* AliMUONPreClusterFinder::NextCluster() @@ -195,27 +215,31 @@ AliMUONPreClusterFinder::NextCluster() // AliCodeTimerAuto("pre-clustering",0) // Start a new cluster - Int_t id = fClusters.GetLast()+1; - AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster; - cluster->SetUniqueID(id); AliMUONPad* pad = GetNextPad(0); + AliMUONCluster* cluster(0x0); + if (!pad) // protection against no pad in first cathode, which might happen { // try other cathode pad = GetNextPad(1); if (!pad) { - // we are done. return 0x0; } - // Builds (recursively) a cluster on second cathode only - AddPad(*cluster,pad); + else + { + cluster = NewCluster(); + // Builds (recursively) a cluster on second cathode only + AddPad(*cluster,pad); + } } else { // Builds (recursively) a cluster on first cathode only + + cluster = NewCluster(); AddPad(*cluster,pad); if ( !ShouldAbort() ) @@ -238,8 +262,7 @@ AliMUONPreClusterFinder::NextCluster() if ( ShouldAbort() ) { AliError(Form("Aborting clustering of DE %d because we've got too many pads",fDetElemId)); - fClusters.Remove(cluster); - fClusters.Compress(); + RemoveCluster(cluster); return 0x0; } @@ -252,8 +275,7 @@ AliMUONPreClusterFinder::NextCluster() } // else only 1 pad (not suspicious, but kind of useless, probably noise) // so we remove it from our list - fClusters.Remove(cluster); - fClusters.Compress(); + RemoveCluster(cluster); // then proceed further return NextCluster(); } diff --git a/MUON/AliMUONPreClusterFinder.h b/MUON/AliMUONPreClusterFinder.h index 06823bc465d..3d5254e4290 100644 --- a/MUON/AliMUONPreClusterFinder.h +++ b/MUON/AliMUONPreClusterFinder.h @@ -54,6 +54,9 @@ private: /// Whether we should stop working... virtual Bool_t ShouldAbort() const { return fShouldAbort; } + AliMUONCluster* NewCluster(); + void RemoveCluster(AliMUONCluster* cluster); + private: TClonesArray fClusters; //!< the clusters we've found (owner) TClonesArray** fPads; //!< the pads corresponding to the digits (not owner) -- 2.43.0