]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPreClusterFinder.cxx
Coverity fix for uninitialized variables and check for returned null value
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinder.cxx
index b21d6a792553d0c1d87f739d4ee96ce31c84f1af..cbbadf62bb901259bc1f006a37d5be161141b49e 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "AliMUONPreClusterFinder.h"
 
+#include "AliCodeTimer.h"
+
 #include "AliMUONCluster.h"
 #include "AliMUONPad.h"
 #include "AliMUONVDigit.h"
@@ -29,7 +31,7 @@
 #include "AliLog.h"
 
 #include <Riostream.h>
-#include <TClonesArray.h>
+#include <TObjArray.h>
 #include <TVector2.h>
 
 //-----------------------------------------------------------------------------
@@ -74,7 +76,7 @@ AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
     return kFALSE;
   }
   
-  new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad); 
+  fPads[pad.Cathode()]->Add(new AliMUONPad(pad)); 
   // FIXME: should set the ClusterId of that new pad to be -1
   return kTRUE;
 }
@@ -82,12 +84,12 @@ AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
 //_____________________________________________________________________________
 Bool_t
 AliMUONPreClusterFinder::Prepare(Int_t detElemId,
-                                 TClonesArray* pads[2],
+                                 TObjArray* pads[2],
                                  const AliMpArea& area)
 {
   /// Prepare for clustering, by giving access to segmentations and digit lists
 
-  fClusters.Clear("C");
+  fClusters.Delete();
   
   fPads = pads;
   fDetElemId = detElemId;
@@ -104,33 +106,38 @@ AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
 {
   /// Add a pad to a cluster
   
-  if ( cluster.Multiplicity() > 500 ) 
+  if ( cluster.IsMonoCathode() && cluster.Multiplicity() > 199 ) 
   {
+    /// FIXME : we should at that point really find a better way to remove "bad" preclusters,
+    /// like e.g. computing the charge dispersion (the lower, the most probably we have noise cluster)
+    /// and/or mean charge per pad (if too close to LowestPadCharge, again that's a noise cluster...
+    /// *BUT* this needs carefull testing !
     fShouldAbort = kTRUE;
     return;
   }
   
-  cluster.AddPad(*pad);
+  AliMUONPad* addedPad = cluster.AddPad(*pad);
   
   Int_t cathode = pad->Cathode();
-  TClonesArray& padArray = *fPads[cathode];
+  TObjArray& padArray = *fPads[cathode];
   // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
   // present (otherwise just compares pointers) : so that one must be correct
   // if implemented !
-  padArray.Remove(pad);
- // TObject* o = padArray.Remove(pad); 
+  TObject* o = padArray.Remove(pad);
 //  if (!o)
 //  {
 //    AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
 //             " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
 //             " as the first suspect for failed remove");
 //  }  
+  delete o;
+  
   TIter next(&padArray);
   AliMUONPad* testPad;
 
   while ( ( testPad = static_cast<AliMUONPad*>(next())))
   {
-    if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
+    if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
     {
       AddPad(cluster,testPad);
     }
@@ -203,6 +210,7 @@ void
 AliMUONPreClusterFinder::RemoveCluster(AliMUONCluster* cluster)
 {
   /// Remove a cluster
+  /// Note that we are *not* releasing the pads, so they won't be used further on
   fClusters.Remove(cluster);
   fClusters.Compress();
 }
@@ -212,7 +220,6 @@ AliMUONCluster*
 AliMUONPreClusterFinder::NextCluster()
 {
   /// Builds the next cluster, and returns it.
-//  AliCodeTimerAuto("pre-clustering",0)
   
   // Start a new cluster
   
@@ -245,7 +252,7 @@ AliMUONPreClusterFinder::NextCluster()
     if ( !ShouldAbort() ) 
     {
       // On the 2nd cathode, only add pads overlapping with the current cluster
-      TClonesArray& padArray = *fPads[1];
+      TObjArray& padArray = *fPads[1];
       TIter next(&padArray);
       AliMUONPad* testPad;
       
@@ -261,9 +268,9 @@ AliMUONPreClusterFinder::NextCluster()
   
   if ( ShouldAbort() ) 
   {
-    AliError(Form("Aborting clustering of DE %d because we've got too many pads",fDetElemId));
+    AliCodeTimerAuto(Form("Skipping a precluster in DE %d because it got too many pads",fDetElemId),0);
     RemoveCluster(cluster);
-    return 0x0;
+    return NextCluster();
   }
   
   if ( cluster->Multiplicity() <= 1 )