Merge branch 'master' into LocalDev
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.cxx
index bd4ada5..2dc7037 100644 (file)
@@ -149,7 +149,7 @@ AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
   fNTrackSegments(0),
   fRcpv(0.f),
   fRtpc(0.f),
-  fVtx(0.f), 
+  fVtx(0.f,0.f,0.f), 
   fLinkUpArray(0),
   fEmcFirst(0),
   fEmcLast(0),
@@ -170,7 +170,7 @@ AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(AliPHOSGeometry *geom) :
   fNTrackSegments(0),
   fRcpv(0.f),
   fRtpc(0.f),
-  fVtx(0.f), 
+  fVtx(0.f,0.f,0.f), 
   fLinkUpArray(0),
   fEmcFirst(0),
   fEmcLast(0),
@@ -193,7 +193,7 @@ AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegment
   fNTrackSegments(0),
   fRcpv(0.f),
   fRtpc(0.f),
-  fVtx(0.f), 
+  fVtx(0.f,0.f,0.f), 
   fLinkUpArray(0),
   fEmcFirst(0),
   fEmcLast(0),
@@ -548,20 +548,23 @@ void  AliPHOSTrackSegmentMakerv1::MakePairs()
   // remove them from the list of "unassigned". 
 
   //Make arrays to mark clusters already chosen
+  Int_t index;
+
   Int_t * emcExist = 0;
-  if(fEmcLast > fEmcFirst)
+  if(fEmcLast > fEmcFirst) {
     emcExist = new Int_t[fEmcLast-fEmcFirst] ;
-  
-  Int_t index;
-  for(index = 0; index <fEmcLast-fEmcFirst; index ++)
-    emcExist[index] = 1 ;
-  
+    for(index = 0; index <fEmcLast-fEmcFirst; index ++)
+      emcExist[index] = 1 ;
+  }
+  else 
+    return;
+
   Bool_t * cpvExist = 0;
-  if(fCpvLast > fCpvFirst)
+  if(fCpvLast > fCpvFirst) {
     cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
-  for(index = 0; index <fCpvLast-fCpvFirst; index ++)
-    cpvExist[index] = kTRUE ;
-  
+    for(index = 0; index <fCpvLast-fCpvFirst; index ++)
+      cpvExist[index] = kTRUE ;
+  }
   
   // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance 
   TIter nextUp(fLinkUpArray) ;
@@ -574,7 +577,9 @@ void  AliPHOSTrackSegmentMakerv1::MakePairs()
 
     if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
 
-      if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
+      //array cpvExist[] should be non-zero as far as linkUp exists
+      //But Coverity requires to check it
+      if(cpvExist && cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
          Float_t dx,dz ;
          linkUp->GetXZ(dx,dz) ;
         new ((* fTrackSegments)[fNTrackSegments]) 
@@ -582,14 +587,14 @@ void  AliPHOSTrackSegmentMakerv1::MakePairs()
                               static_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(linkUp->GetCpv())) , 
                               linkUp->GetTrack(),dx,dz) ;
         
-       (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
+       (static_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
        fNTrackSegments++ ;
        emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc  that Cpv was found 
        //mark CPV recpoint as already used 
        cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
       } //if CpvUp still exist
-    } 
-  }        
+    }
+  }
 
   //look through emc recPoints left without CPV
   if(emcExist){ //if there is emc rec point
@@ -604,13 +609,14 @@ void  AliPHOSTrackSegmentMakerv1::MakePairs()
          new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment(emcclu,nullpointer) ;
         else
           new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment(emcclu,0,track,dx,dz);
-       (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
+       (static_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
        fNTrackSegments++;    
       } 
     }
   }
   delete [] emcExist ; 
-  delete [] cpvExist ; 
+  if(cpvExist)
+    delete [] cpvExist ; 
 }
 
 //____________________________________________________________________________