]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
08-jan-2003 NvE Delete statements for fMatrix[i] and fPositions[i] added in the dtor of
authornick <nick@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 9 Jan 2003 16:06:35 +0000 (16:06 +0000)
committernick <nick@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 9 Jan 2003 16:06:35 +0000 (16:06 +0000)
                AliCalorimeter to fix a memory leak.
09-jan-2003 NvE Different modes introduced for AliCalorimeter::Reset() to prevent memory
                leaks in reading back AliCalorimeter objects from a data file.
                Also unnecessary "LoadMatrix()" statement removed in AliCalorimeter::Reset().
                Irrelevant cout statement removed from AliEvent constructor.

RALICE/AliCalorimeter.cxx
RALICE/AliCalorimeter.h
RALICE/AliEvent.cxx
RALICE/history.txt

index 964e9d3f83055a8cd111cdc64fc3c0cfda87c37c..47917b8521c03a57e9229d1540e8d9ade27a4298 100644 (file)
@@ -80,7 +80,7 @@ AliCalorimeter::AliCalorimeter()
 ///////////////////////////////////////////////////////////////////////////
 AliCalorimeter::~AliCalorimeter()
 {
 ///////////////////////////////////////////////////////////////////////////
 AliCalorimeter::~AliCalorimeter()
 {
-// Destructor to delete memory allocated to the various arrays and matrix
+// Destructor to delete memory allocated to the various arrays and matrices
  if (fModules)
  {
   delete fModules;
  if (fModules)
  {
   delete fModules;
@@ -106,15 +106,20 @@ AliCalorimeter::~AliCalorimeter()
   delete fHclusters;
   fHclusters=0;
  }
   delete fHclusters;
   fHclusters=0;
  }
+
+ // Free memory allocated for (internal) module and position matrices.
+ // The modules have already been deleted via the fModules I/O array,
+ // so they shouldn't be deleted here anymore.
  if (fMatrix || fPositions)
  {
   for (Int_t i=0; i<fNrows; i++)
   {
    for (Int_t j=0; j<fNcolumns; j++)
    {
  if (fMatrix || fPositions)
  {
   for (Int_t i=0; i<fNrows; i++)
   {
    for (Int_t j=0; j<fNcolumns; j++)
    {
-    fMatrix[i][j]=0;
     if (fPositions[i][j]) delete fPositions[i][j];
    }
     if (fPositions[i][j]) delete fPositions[i][j];
    }
+   if (fPositions[i]) delete [] fPositions[i];
+   if (fMatrix[i]) delete [] fMatrix[i];
   }
   if (fMatrix)
   {
   }
   if (fMatrix)
   {
@@ -323,13 +328,26 @@ void AliCalorimeter::Reset(Int_t row,Int_t col)
  }
 }
 ///////////////////////////////////////////////////////////////////////////
  }
 }
 ///////////////////////////////////////////////////////////////////////////
-void AliCalorimeter::Reset()
+void AliCalorimeter::Reset(Int_t mode)
 {
 {
-// Reset the signals for the complete calorimeter
-// Normally this is done to prepare for the data of the next event
-// Note : Module gains, edge and dead flags remain unchanged
- if (!fMatrix) LoadMatrix(); // Restore matrix data in case of reading input
+// Reset the signals for the complete calorimeter.
+// Normally this is done to prepare for the data of the next event.
+//
+// mode = 0 : Module positions, gains, edge and dead flags remain unchanged.
+//        1 : Module positions, gains, edge and dead flags are cleared.
+//
+// The default is mode=0.
+//
+// Note : In the case of reading AliCalorimeter objects from a data file,
+//        one has to reset the AliCalorimeter object with mode=1
+//        (or explicitly delete it) before reading-in the next object
+//        in order to prevent memory leaks.
+
+ if (mode<0 || mode>1)
+ {
+  cout << " *AliCalorimeter::Reset* Wrong argument. mode = " << mode << endl;
+  return;
+ }
 
  fNsignals=0;
  if (fModules)
 
  fNsignals=0;
  if (fModules)
@@ -337,13 +355,6 @@ void AliCalorimeter::Reset()
   delete fModules;
   fModules=0;
  }
   delete fModules;
   fModules=0;
  }
- for (Int_t i=0; i<fNrows; i++)
- {
-  for (Int_t j=0; j<fNcolumns; j++)
-  {
-   fMatrix[i][j]=0;
-  }
- }
 
  fNclusters=0;
  if (fClusters)
 
  fNclusters=0;
  if (fClusters)
@@ -358,6 +369,64 @@ void AliCalorimeter::Reset()
   delete fVetos;
   fVetos=0;
  }
   delete fVetos;
   fVetos=0;
  }
+
+ if (fMatrix || fPositions)
+ {
+  for (Int_t i=0; i<fNrows; i++)
+  {
+   for (Int_t j=0; j<fNcolumns; j++)
+   {
+    if (mode==0)
+    {
+     fMatrix[i][j]=0;
+    }
+    else
+    {
+     if (fPositions[i][j]) delete fPositions[i][j];
+    }
+   }
+   if (mode==1)
+   {
+    if (fPositions[i]) delete [] fPositions[i];
+    if (fMatrix[i]) delete [] fMatrix[i];
+   }
+  }
+ }
+
+ // Free memory allocated for various arrays and matrices.
+ if (mode==1)
+ {
+  if (fMatrix)
+  {
+   delete [] fMatrix;
+   fMatrix=0;
+  }
+  if (fPositions)
+  {
+   delete [] fPositions;
+   fPositions=0;
+  }
+  if (fGains)
+  {
+   delete fGains;
+   fGains=0;
+  }
+  if (fAttributes)
+  {
+   delete fAttributes;
+   fAttributes=0;
+  }
+  if (fHmodules)
+  {
+   delete fHmodules;
+   fHmodules=0;
+  }
+  if (fHclusters)
+  {
+   delete fHclusters;
+   fHclusters=0;
+  }
+ }
 }
 ///////////////////////////////////////////////////////////////////////////
 Float_t AliCalorimeter::GetSignal(Int_t row,Int_t col)
 }
 ///////////////////////////////////////////////////////////////////////////
 Float_t AliCalorimeter::GetSignal(Int_t row,Int_t col)
index f8d284a74f76eb3a0dc8bd9144debb8127716056..762d0538c10f6e637fd66ca6bd9af8a5b7b0d21e 100644 (file)
@@ -30,7 +30,7 @@ class AliCalorimeter : public TObject
   void AddSignal(Int_t row,Int_t col,Float_t s);   // Add signal to a certain module
   void AddSignal(AliCalmodule* m);                 // Add module signal to current calorimeter
   void Reset(Int_t row,Int_t col);                 // Reset signal for a certain module
   void AddSignal(Int_t row,Int_t col,Float_t s);   // Add signal to a certain module
   void AddSignal(AliCalmodule* m);                 // Add module signal to current calorimeter
   void Reset(Int_t row,Int_t col);                 // Reset signal for a certain module
-  void Reset();                                    // Reset the complete calorimeter
+  void Reset(Int_t mode=0);                        // Reset the complete calorimeter
   Float_t GetSignal(Int_t row,Int_t col);          // Provide signal of a certain module
   Int_t GetNsignals();                             // Return number of modules with a signal
   void Group(Int_t n);                             // Group modules into clusters (n rings)
   Float_t GetSignal(Int_t row,Int_t col);          // Provide signal of a certain module
   Int_t GetNsignals();                             // Return number of modules with a signal
   void Group(Int_t n);                             // Group modules into clusters (n rings)
@@ -81,6 +81,6 @@ class AliCalorimeter : public TObject
   AliPosition ***fPositions;                 //! Matrix of module position pointers for internal use
   TString fName;                             // Name of the calorimeter system
  
   AliPosition ***fPositions;                 //! Matrix of module position pointers for internal use
   TString fName;                             // Name of the calorimeter system
  
- ClassDef(AliCalorimeter,2) // Description of a modular calorimeter system.
+ ClassDef(AliCalorimeter,3) // Description of a modular calorimeter system.
 };
 #endif
 };
 #endif
index 2190570c24348d9ce14053666a10720717c74449..10e11feb796a86ea42dbe455b7986e3768bccf9c 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-// $Id: AliEvent.cxx,v 1.7 2002/06/25 09:38:28 nick Exp $
+// $Id: AliEvent.cxx,v 1.8 2002/12/02 15:10:37 nick Exp $
 
 ///////////////////////////////////////////////////////////////////////////
 // Class AliEvent
 
 ///////////////////////////////////////////////////////////////////////////
 // Class AliEvent
 // Note : All quantities are in GeV, GeV/c or GeV/c**2
 //
 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
 // Note : All quantities are in GeV, GeV/c or GeV/c**2
 //
 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
-//- Modified: NvE $Date: 2002/06/25 09:38:28 $ UU-SAP Utrecht
+//- Modified: NvE $Date: 2002/12/02 15:10:37 $ UU-SAP Utrecht
 ///////////////////////////////////////////////////////////////////////////
 
 #include "AliEvent.h"
 ///////////////////////////////////////////////////////////////////////////
 
 #include "AliEvent.h"
@@ -220,7 +220,6 @@ AliEvent::AliEvent(Int_t n): AliVertex(n)
 {
 // Create an event to hold initially a maximum of n tracks
 // All variables initialised to default values
 {
 // Create an event to hold initially a maximum of n tracks
 // All variables initialised to default values
- cout << "AliEvent init with n = " << n << endl;
  fDaytime.Set();
  fRun=0;
  fEvent=0;
  fDaytime.Set();
  fRun=0;
  fEvent=0;
index dd05f6f0698dd05aedbf0c06a1487bdb238fb5a5..24a49ac1d312db5fc7d40c3d537f586c38797910 100644 (file)
 11-dec-2002 NvE Copyright notice added into AliCollider.h and AliCollider.cxx.
                 Also small (integer division) modification made in AliCollider.cxx
                 to prevent an innocent warning of the g++ compiler under Linux.
 11-dec-2002 NvE Copyright notice added into AliCollider.h and AliCollider.cxx.
                 Also small (integer division) modification made in AliCollider.cxx
                 to prevent an innocent warning of the g++ compiler under Linux.
+08-jan-2003 NvE Delete statements for fMatrix[i] and fPositions[i] added in the dtor of
+                AliCalorimeter to fix a memory leak.
+09-jan-2003 NvE Different modes introduced for AliCalorimeter::Reset() to prevent memory
+                leaks in reading back AliCalorimeter objects from a data file.
+                Also unnecessary "LoadMatrix()" statement removed in AliCalorimeter::Reset().
+                Irrelevant cout statement removed from AliEvent constructor.