]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added protection, reset pointers to 0
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 25 Oct 2008 08:19:37 +0000 (08:19 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 25 Oct 2008 08:19:37 +0000 (08:19 +0000)
STEER/AliESDCaloCluster.cxx
STEER/AliESDCaloCluster.h

index 15b55e0111a6277d11953f4b60264e31cedf0f3d..4c411ae4947a966844e701aaa118c195f622d97c 100644 (file)
@@ -115,12 +115,10 @@ AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
 
   if(&source == this) return *this;
   TObject::operator=(source);
-
   fGlobalPos[0] = source.fGlobalPos[0];
   fGlobalPos[1] = source.fGlobalPos[1];
   fGlobalPos[2] = source.fGlobalPos[2];
 
-
   fEnergy = source.fEnergy;
   fDispersion = source.fDispersion;
   fChi2 = source.fChi2;
@@ -135,17 +133,18 @@ AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
 
   if (source.fNCells > 0) {
     if(source.fCellsAbsId){
-      if(fNCells != source.fNCells){
-       delete [] fCellsAbsId;
+      if(fNCells != source.fNCells||!fCellsAbsId){
+       if(fCellsAbsId)delete [] fCellsAbsId;
        fCellsAbsId = new UShort_t[source.fNCells];
       }
-      for (Int_t i=0; i<source.fNCells; i++)
+      for (Int_t i=0; i<source.fNCells; i++){
        fCellsAbsId[i]=source.fCellsAbsId[i];
+      }
     }
     
     if(source.fCellsAmpFraction){
-      if(fNCells != source.fNCells){
-       delete [] fCellsAmpFraction;
+      if(fNCells != source.fNCells||!fCellsAmpFraction){
+       if(fCellsAmpFraction) delete [] fCellsAmpFraction;
        fCellsAmpFraction = new Double32_t[source.fNCells];
       }
       for (Int_t i=0; i<source.fNCells; i++)
@@ -160,21 +159,25 @@ AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
   //not in use
   if(source.fTracksMatched){
     // assign or copy construct
-    if(fTracksMatched) *fTracksMatched = *source.fTracksMatched;
+    if(fTracksMatched){
+      *fTracksMatched = *source.fTracksMatched;
+    }
     else fTracksMatched = new TArrayI(*source.fTracksMatched);
   }
   else{
-    delete fTracksMatched;
+    if(fTracksMatched)delete fTracksMatched;
     fTracksMatched = 0;
   }
 
   if(source.fLabels){
     // assign or copy construct
-    if(fLabels) *fLabels = *source.fLabels;
+    if(fLabels){ 
+      *fLabels = *source.fLabels;
+    }
     else fLabels = new TArrayI(*source.fLabels);
   }
   else{
-    delete fLabels;
+    if(fLabels)delete fLabels;
     fLabels = 0;
   }
 
@@ -183,7 +186,7 @@ AliESDCaloCluster &AliESDCaloCluster::operator=(const AliESDCaloCluster& source)
     // assign or copy construct
     if(fDigitAmplitude) *fDigitAmplitude = *source.fDigitAmplitude;
     else fDigitAmplitude = new TArrayS(*source.fDigitAmplitude);
-  }
+   }
   else{
     delete fDigitAmplitude;
     fDigitAmplitude = 0;
@@ -235,13 +238,13 @@ AliESDCaloCluster::~AliESDCaloCluster(){
   //
   // This is destructor according Coding Conventions 
   //
-  delete fTracksMatched;
-  delete fLabels;
+  if(fTracksMatched)delete fTracksMatched;fTracksMatched = 0;
+  if(fLabels) delete fLabels; fLabels = 0;
   delete fDigitAmplitude;  //not in use
   delete fDigitTime;  //not in use
   delete fDigitIndex;  //not in use
-  if(fCellsAmpFraction) delete[] fCellsAmpFraction; fCellsAmpFraction=0;
-  if(fCellsAbsId) delete[] fCellsAbsId;  fCellsAbsId = 0;
+  if(fCellsAmpFraction){ delete[] fCellsAmpFraction; fCellsAmpFraction=0;}
+  if(fCellsAbsId){ delete[] fCellsAbsId;  fCellsAbsId = 0;}
 }
 
 //_______________________________________________________________________
index 2c6bb7be6040a8acdd4d36d131ab8e51c556f2fc..3fd4e5d75c8089567649143f4f6ebaf6ff816811 100644 (file)
@@ -87,8 +87,14 @@ public:
   void SetTOF(Double_t tof) { fTOF = tof; }
   Double_t GetTOF() const { return fTOF; }
   
-  void AddTracksMatched(TArrayI & array)  { fTracksMatched   = new TArrayI(array) ; }
-  void AddLabels(TArrayI & array)         { fLabels = new TArrayI(array) ; }
+  void AddTracksMatched(TArrayI & array)  { 
+    if(!fTracksMatched)fTracksMatched   = new TArrayI(array);
+    else *fTracksMatched = array;
+  }
+  void AddLabels(TArrayI & array)         { 
+    if(!fLabels)fLabels = new TArrayI(array) ; 
+    else *fLabels = array;
+}
   
   TArrayI * GetTracksMatched() const  {return  fTracksMatched;}
   TArrayI * GetLabels() const         {return  fLabels;}