]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Coverity (Chiara)
authordainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Feb 2011 21:56:21 +0000 (21:56 +0000)
committerdainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Feb 2011 21:56:21 +0000 (21:56 +0000)
PWG3/vertexingHF/AliCFTaskVertexingHF.cxx
PWG3/vertexingHF/AliCFVertexingHF.cxx

index a3846d4514937f7b41c890ee82ebf9e4cdae6c4d..2fc7d512cc90953a763b1c3892c093c2fae26796 100644 (file)
@@ -215,7 +215,11 @@ void AliCFTaskVertexingHF::Init()
        
        if (fDebug>1) printf("AliCFTaskVertexingHF::Init()");
        AliRDHFCuts *copyfCuts = 0x0;
-       
+       if (!fCuts){
+               AliFatal("No cuts defined - Exiting...");
+               return;
+       }
+
        switch (fDecayChannel){
        case 2:{
                copyfCuts = new AliRDHFCutsD0toKpi(*(dynamic_cast<AliRDHFCutsD0toKpi*>(fCuts)));
@@ -265,10 +269,15 @@ void AliCFTaskVertexingHF::Init()
        }  
        
        const char* nameoutput=GetOutputSlot(4)->GetContainer()->GetName();
-       copyfCuts->SetName(nameoutput);
-       
-       //Post the data
-       PostData(4, copyfCuts);
+       if (copyfCuts){
+               copyfCuts->SetName(nameoutput);
+               
+               //Post the data
+               PostData(4, copyfCuts);
+       }
+       else{
+               AliFatal("Failing initializing AliRDHFCuts object - Exiting...");
+       }       
        
        return;
 }
@@ -426,6 +435,10 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
        default:
                break;
        }
+       if (!cfVtxHF){
+               AliError("No AliCFVertexingHF initialized");
+               return;
+       }
        
        Double_t zPrimVertex = aodVtx ->GetZ();
        Double_t zMCVertex = mcHeader->GetVtxZ();
@@ -438,7 +451,10 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
        for (Int_t iPart=0; iPart<mcArray->GetEntriesFast(); iPart++) { 
                
                AliAODMCParticle* mcPart = dynamic_cast<AliAODMCParticle*>(mcArray->At(iPart));
-               
+               if (!mcPart){
+                       AliError("Failed casting particle from MC array!, Skipping particle");
+                       continue;
+               }
                // check the MC-level cuts, must be the desidered particle
                if (!fCFManager->CheckParticleCuts(0, mcPart)) continue;  // 0 stands for MC level
                
index e25992a10b24e7b66d7cc774ede67b15dc43b5a6..3c88fae77b7994e562c407ae3f16871c70c5b02b 100644 (file)
@@ -196,8 +196,13 @@ void AliCFVertexingHF::SetMCCandidateParam(Int_t label)
        // setting the parameters (candidate and n. daughters)
        //      
        
-       fmcPartCandidate = dynamic_cast <AliAODMCParticle*> (fmcArray->At(label));
-       fNDaughters = fmcPartCandidate->GetNDaughters();
+        fmcPartCandidate = dynamic_cast <AliAODMCParticle*> (fmcArray->At(label));
+       if (fmcPartCandidate){
+         fNDaughters = fmcPartCandidate->GetNDaughters();
+       }
+       else {
+         AliError(Form("Dynamic cast failed, fNdaughters will remain set to %d",fNDaughters));
+       }
        return;
 }
 
@@ -209,9 +214,11 @@ Int_t AliCFVertexingHF::MCcquarkCounting(AliAODMCParticle* mcPart) const
        // 
 
        Int_t cquarks = 0;
-       if (mcPart->GetPdgCode() == 4) cquarks++; 
-       if (mcPart->GetPdgCode() == -4) cquarks++; 
-       if (!mcPart) {
+       if (mcPart) {
+         if (mcPart->GetPdgCode() == 4) cquarks++; 
+         if (mcPart->GetPdgCode() == -4) cquarks++; 
+       }
+       else {
                AliWarning("Particle not found in tree, skipping\n"); 
                return cquarks;
        } 
@@ -264,17 +271,23 @@ Int_t AliCFVertexingHF::CheckOrigin() const
                istep++;
                AliDebug(2,Form("mother at step %d = %d", istep, mother));
                AliAODMCParticle* mcGranma = dynamic_cast<AliAODMCParticle*>(fmcArray->At(mother));
-               pdgGranma = mcGranma->GetPdgCode();
-               AliDebug(2,Form("Pdg mother at step %d = %d", istep, pdgGranma));
-               abspdgGranma = TMath::Abs(pdgGranma);
-               if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)) {
-                       if (!fKeepDfromB) return -9999; //skip particle if come from a B meson.
-                       
-                       else{
-                               break;
+               if (mcGranma){
+                       pdgGranma = mcGranma->GetPdgCode();
+                       AliDebug(2,Form("Pdg mother at step %d = %d", istep, pdgGranma));
+                       abspdgGranma = TMath::Abs(pdgGranma);
+                       if ((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000)) {
+                               if (!fKeepDfromB) return -9999; //skip particle if come from a B meson.
+                               
+                               else{
+                                       break;
+                               }
                        }
+                       mother = mcGranma->GetMother();
+               }
+               else {
+                       AliError("Failed casting the mother particle!");
+                       break;
                }
-               mother = mcGranma->GetMother();
        }
        if (!((abspdgGranma > 500 && abspdgGranma < 600) || (abspdgGranma > 5000 && abspdgGranma < 6000))){
                if (fKeepDfromBOnly) return -999;
@@ -683,7 +696,15 @@ Bool_t AliCFVertexingHF::SetLabelArray()
        if (label1 - label0 == fProngs-1){
                for (Int_t iProng = 0; iProng<fProngs; iProng++){
                        mcPartDaughter = dynamic_cast<AliAODMCParticle*>(fmcArray->At(label0+iProng));    
-                       fLabelArray[iProng] =  mcPartDaughter->GetLabel();
+                       if (mcPartDaughter){
+                               fLabelArray[iProng] =  mcPartDaughter->GetLabel();
+                       }
+                       else{
+                               AliError("Failed casting the daughter particle, returning a NULL label array");
+                               delete [] fLabelArray; 
+                               fLabelArray = 0x0;  
+                               return bLabelArray;
+                       }
                }
 
        }
@@ -696,8 +717,16 @@ Bool_t AliCFVertexingHF::SetLabelArray()
                        AliAODMCParticle* part = dynamic_cast<AliAODMCParticle*>(fmcArray->At(iLabelDau));
                        Int_t pdgCode=TMath::Abs(part->GetPdgCode());
                        if(pdgCode==211 || pdgCode==321 || pdgCode==2212){
-                               fLabelArray[foundDaughters] = part->GetLabel();
-                               foundDaughters++;
+                               if (part) {
+                                       fLabelArray[foundDaughters] = part->GetLabel();
+                                       foundDaughters++;
+                               }
+                               else{
+                                       AliError("Error while casting particle! returning a NULL array");
+                                       delete [] fLabelArray; 
+                                       fLabelArray = 0x0;  
+                                       return bLabelArray;
+                               }
                        }
                        else{
                                Int_t nDauRes=part->GetNDaughters();
@@ -710,8 +739,16 @@ Bool_t AliCFVertexingHF::SetLabelArray()
                                for(Int_t iDauRes=0; iDauRes<nDauRes; iDauRes++){
                                        Int_t iLabelDauRes = labelFirstDauRes+iDauRes;
                                        AliAODMCParticle* dauRes = dynamic_cast<AliAODMCParticle*>(fmcArray->At(iLabelDauRes));
-                                       fLabelArray[foundDaughters] = dauRes->GetLabel();
-                                       foundDaughters++;
+                                       if (dauRes){
+                                               fLabelArray[foundDaughters] = dauRes->GetLabel();
+                                               foundDaughters++;
+                                       }
+                                       else{
+                                               AliError("Error while casting resonant daughter! returning a NULL array");
+                                               delete [] fLabelArray; 
+                                               fLabelArray = 0x0;  
+                                               return bLabelArray;
+                                       }
                                }
                        }
                }