Fixing small memory leaks (Hans)
[u/mrichter/AliRoot.git] / TOF / AliTOFCal.cxx
index 2ea4612..445f366 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*$Log$
+/*
+$Log$
+Revision 1.6  2006/04/20 22:30:49  hristov
+Coding conventions (Annalisa)
+
+Revision 1.5  2006/04/16 22:29:05  hristov
+Coding conventions (Annalisa)
+
+Revision 1.4  2006/04/05 08:35:38  hristov
+Coding conventions (S.Arcelli, C.Zampolli)
+
+Revision 1.3  2006/03/28 14:56:48  arcelli
+updates to handle new V5 geometry & some re-arrangements
+
+Revision 1.2  2006/02/13 17:22:26  arcelli
+just Fixing Log info
+
+Revision 1.1  2006/02/13 16:10:48  arcelli
+Add classes for TOF Calibration (C.Zampolli)
+
 author: Chiara Zampolli, zampolli@bo.infn.it
- */  
+*/  
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -23,40 +42,79 @@ author: Chiara Zampolli, zampolli@bo.infn.it
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include "TObject.h"
-#include "TROOT.h"
 #include "TBrowser.h"
-#include "TClass.h"
-#include "AliTOFGeometryV4.h"
+#include "TROOT.h"
+
+#include "AliLog.h"
+
 #include "AliTOFCalSector.h"
 #include "AliTOFCal.h"
-#include "AliTOFChannel.h"
+#include "AliTOFGeometryV5.h"
 
-extern TROOT *gROOT;
+//extern TROOT *gROOT;
 
 ClassImp(AliTOFCal)
 
 //________________________________________________________________
 
-AliTOFCal::AliTOFCal():TObject(){
-  // fCalp = 0;
-  fNSector = AliTOFGeometryV4::NSectors();
-  fNPlate = AliTOFGeometryV4::NPlates();
-  fNStripA = AliTOFGeometryV4::NStripA();
-  fNStripB = AliTOFGeometryV4::NStripB();
-  //  fNStripC = AliTOFGeometryV4::NStripC();
-  fNStripC = 20;
-  fNpadZ = AliTOFGeometryV4::NpadZ();
-  fNpadX = AliTOFGeometryV4::NpadX();
-  fnpad = 0;
-  fPads = 0x0;
+AliTOFCal::AliTOFCal():
+  TObject(),
+  fNSector(0),
+  fNPlate(0),
+  fNStripA(0),
+  fNStripB(0),
+  fNStripC(0),
+  fNpadZ(0),
+  fNpadX(0),
+  fnpad(0),
+  fGeom(0x0),
+  fPads(0x0)
+{
+  //main ctor
+  gROOT->GetListOfBrowsables()->Add(this);
+ }
+//________________________________________________________________
+
+AliTOFCal::AliTOFCal(AliTOFGeometry *geom):
+  TObject(),
+  fNSector(0),
+  fNPlate(0),
+  fNStripA(0),
+  fNStripB(0),
+  fNStripC(0),
+  fNpadZ(0),
+  fNpadX(0),
+  fnpad(0),
+  fGeom(geom),
+  fPads(0x0)
+{
+  //ctor with geom
+  fNSector = fGeom->NSectors();
+  fNPlate  = fGeom->NPlates();
+  fNStripA = fGeom->NStripA();
+  fNStripB = fGeom->NStripB();
+  fNStripC = fGeom->NStripC();
+  fNpadZ = fGeom->NpadZ();
+  fNpadX = fGeom->NpadX();
+  fnpad = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX;
   gROOT->GetListOfBrowsables()->Add(this);
 }
 //________________________________________________________________
 
 AliTOFCal::AliTOFCal(const AliTOFCal& cal):
-  TObject(cal)
-  {
+  TObject(cal),
+  fNSector(0),
+  fNPlate(0),
+  fNStripA(0),
+  fNStripB(0),
+  fNStripC(0),
+  fNpadZ(0),
+  fNpadX(0),
+  fnpad(0),
+  fGeom(0x0),
+  fPads(0x0)  
+{
+    //copy ctor 
     fNSector = cal.fNSector;
     fNPlate = cal.fNPlate;
     fNStripA = cal.fNStripA;
@@ -71,14 +129,35 @@ AliTOFCal::AliTOFCal(const AliTOFCal& cal):
     gROOT->GetListOfBrowsables()->Add(this);
   }
 //____________________________________________________________________________ 
+AliTOFCal& AliTOFCal::operator=(const AliTOFCal& cal)
+  {
+    //assignment operator
+    this->fNSector = cal.fNSector;
+    this->fNPlate = cal.fNPlate;
+    this->fNStripA = cal.fNStripA;
+    this->fNStripB = cal.fNStripB;
+    this->fNStripC = cal.fNStripC;
+    this->fNpadZ = cal.fNpadZ;
+    this->fNpadX = cal.fNpadX;
+    this->fnpad = cal.fnpad;
+    for (Int_t i = 0; i<fnpad; i++){
+      this->fPads[i]=cal.fPads[i];
+    }
+    return *this;
+
+  }
+//____________________________________________________________________________ 
 AliTOFCal::~AliTOFCal()
 {
+  //dtor
+  gROOT->GetListOfBrowsables()->Remove(this);
   delete [] fPads;
 }
 //________________________________________________________________
 
 void AliTOFCal::Browse(TBrowser *b)
 {
+  //add cal obj to list of browsables
   char name[10];
   for(Int_t i=0; i<fNSector; ++i) {
     snprintf(name,sizeof(name),"Sector %2.2d",i);
@@ -88,6 +167,19 @@ void AliTOFCal::Browse(TBrowser *b)
 //________________________________________________________________
 
 void AliTOFCal::CreateArray(){
-  fnpad = AliTOFGeometryV4::NSectors()*(2*(20+AliTOFGeometryV4::NStripB())+AliTOFGeometryV4::NStripA())*AliTOFGeometryV4::NpadZ()*AliTOFGeometryV4::NpadX();
+  //create cal channel array
+  if(fGeom==0x0){
+    AliInfo("V5 TOF Geometry is taken as a default");
+    AliTOFGeometry *geom= new AliTOFGeometryV5();
+    fNSector = geom->NSectors();
+    fNPlate  = geom->NPlates();
+    fNStripA = geom->NStripA();
+    fNStripB = geom->NStripB();
+    fNStripC = geom->NStripC();
+    fNpadZ = geom->NpadZ();
+    fNpadX = geom->NpadX();
+    fnpad = fNSector*(2*(fNStripC+fNStripB)+fNStripA)*fNpadZ*fNpadX;
+    delete geom;
+  }
   fPads= new AliTOFChannel[fnpad];
 }