]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGeoUtils.cxx
Fixes for Coverity defects
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGeoUtils.cxx
index 8ac47fc129c9f063bb3f14c9cd0fedbd58298d8f..2f10ee868c91d513496a99d27bde58d83faf5e25 100644 (file)
@@ -56,6 +56,19 @@ AliPHOSGeoUtils::AliPHOSGeoUtils():
 {
     // default ctor 
     // must be kept public for root persistency purposes, but should never be called by the outside world
+  
+  fXtlArrSize[0]=0.;   
+  fXtlArrSize[1]=0.;                                                                           
+  fXtlArrSize[2]=0.; 
+  
+  for(Int_t mod=0; mod<5; mod++){
+    fEMCMatrix[mod]=0 ;
+    for(Int_t istrip=0; istrip<224; istrip++)
+      fStripMatrix[mod][istrip]=0 ;
+    fCPVMatrix[mod]=0;
+    fPHOSMatrix[mod]=0 ;
+  }
+
 }  
 
 //____________________________________________________________________________
@@ -149,6 +162,14 @@ AliPHOSGeoUtils::~AliPHOSGeoUtils(void)
   if(fMisalArray){
     delete fMisalArray; fMisalArray=0 ;
   }
+
+  for(Int_t mod=0; mod<5; mod++){
+    delete fEMCMatrix[mod] ;
+    for(Int_t istrip=0; istrip<224; istrip++)
+      delete fStripMatrix[mod][istrip];
+    delete fCPVMatrix[mod];
+    delete fPHOSMatrix[mod];
+  }
 }
 //____________________________________________________________________________
 Bool_t AliPHOSGeoUtils::AbsToRelNumbering(Int_t absId, Int_t * relid) const
@@ -572,7 +593,8 @@ const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForCPV(Int_t mod)const {
   if(gGeoManager){ 
     char path[255] ;
     //now apply possible shifts and rotations
-    sprintf(path,"/ALIC_1/PHOS_%d/PCPV_1",mod) ;
+    TString spath = "/ALIC_1/PHOS_%d/PCPV_1";
+    snprintf(path,spath.Length(),spath.Data(),mod) ;
     if (!gGeoManager->cd(path)){
       AliWarning(Form("Geo manager can not find path %s \n",path));
       return 0 ;
@@ -597,8 +619,11 @@ const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForPHOS(Int_t mod)const {
 
   //If GeoManager exists, take matrixes from it
   if(gGeoManager){
+
     char path[255] ;
-    sprintf(path,"/ALIC_1/PHOS_%d",mod) ;
+    TString spath = "/ALIC_1/PHOS_%d";
+    snprintf(path,spath.Length(),spath.Data(),mod) ;
+
     if (!gGeoManager->cd(path)){
       AliWarning(Form("Geo manager can not find path %s \n",path));
       return 0 ;
@@ -621,9 +646,14 @@ const TGeoHMatrix * AliPHOSGeoUtils::GetMatrixForPHOS(Int_t mod)const {
 void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
   //Fills pointers to geo matrixes
  
-  fPHOSMatrix[mod]=m ;
+  if(fPHOSMatrix[mod]){ //have been set already. Can not be changed any more
+    return ;
+  }
+  if(m==NULL) //Matrix for non-existing modules? Remain zero, no need to re-set
+    return ;
+  fPHOSMatrix[mod]= new TGeoHMatrix(*m) ;
 
-  //If modules does not exist, make sure all its matrixes are zero
+  //If module does not exist, make sure all its matrices are zero
   if(m==NULL){
     fEMCMatrix[mod]=NULL ;
     Int_t istrip=0 ;
@@ -636,7 +666,7 @@ void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
     return ;
   }
 
-  //Calculate maxtrixes for PTII
+  //Calculate maxtrices for PTII
   if(!fMisalArray)
     fMisalArray = new TClonesArray("TGeoHMatrix",1120+10) ;
   Int_t nr = fMisalArray->GetEntriesFast() ;
@@ -649,13 +679,13 @@ void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
   Double_t locTII[3]={0.,0.,z} ; 
   Double_t globTII[3] ;
 
-  TGeoHMatrix * mTII = new((*fMisalArray)[nr])TGeoHMatrix() ;
+  if (fEMCMatrix[mod] == NULL)
+    fEMCMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
   nr++ ;
-  mTII->SetRotation(rotEMC) ;
-  mTII->MultiplyLeft(fPHOSMatrix[mod]) ;
+  fEMCMatrix[mod]->SetRotation(rotEMC) ;
+  fEMCMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
   fPHOSMatrix[mod]->LocalToMaster(locTII,globTII) ;
-  mTII->SetTranslation(globTII) ;
-  fEMCMatrix[mod]=mTII ;
+  fEMCMatrix[mod]->SetTranslation(globTII) ;
  
   //Now calculate ideal matrixes for strip misalignment.
   //For the moment we can not store them in ESDHeader
@@ -669,10 +699,10 @@ void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
     for(Int_t icol = 0; icol < fGeometryEMCA->GetNStripZ(); icol ++){
       loc[2] = (2*icol + 1 - fGeometryEMCA->GetNStripZ()) * strip[2] ;
       fEMCMatrix[mod]->LocalToMaster(loc,glob) ;
-      TGeoHMatrix * mSTR = new((*fMisalArray)[nr])TGeoHMatrix(*(fEMCMatrix[mod])) ; //Use same rotation as PHOS module
+      if (fStripMatrix[mod][istrip] == NULL)
+       fStripMatrix[mod][istrip] = new((*fMisalArray)[nr])TGeoHMatrix(*(fEMCMatrix[mod])) ; //Use same rotation as PHOS module
       nr++ ;
-      mSTR->SetTranslation(glob) ;
-      fStripMatrix[mod][istrip]=mSTR ;
+      fStripMatrix[mod][istrip]->SetTranslation(glob) ;
       istrip++;
     }
   }
@@ -683,14 +713,14 @@ void AliPHOSGeoUtils::SetMisalMatrix(const TGeoHMatrix * m, Int_t mod){
   Double_t locCPV[3]={0.,0.,- emcParams[3]} ;
   Double_t rot[9]={1.,0.,0.,0.,0.,1.,0.,-1.,0.} ;
 
-  TGeoHMatrix * mCPV = new((*fMisalArray)[nr])TGeoHMatrix() ;
+  if (fCPVMatrix[mod] == NULL)
+    fCPVMatrix[mod] = new((*fMisalArray)[nr])TGeoHMatrix() ;
   nr++ ;
-  mCPV->SetRotation(rot) ;
-  mCPV->MultiplyLeft(fPHOSMatrix[mod]) ;
-  mCPV->ReflectY(kFALSE) ;
+  fCPVMatrix[mod]->SetRotation(rot) ;
+  fCPVMatrix[mod]->MultiplyLeft(fPHOSMatrix[mod]) ;
+  fCPVMatrix[mod]->ReflectY(kFALSE) ;
   fPHOSMatrix[mod]->LocalToMaster(locCPV,globCPV) ;
-  mCPV->SetTranslation(globCPV) ;
-  fCPVMatrix[mod]=mCPV ;
+  fCPVMatrix[mod]->SetTranslation(globCPV) ;
 
 }