attempt to address new coverity reports for AliCalo stuff and QA checker
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerRawDigitMaker.cxx
index 964be5d..916632b 100644 (file)
@@ -43,6 +43,10 @@ Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
 #include "AliRawVEquipment.h"
 #include "AliRawEquipmentHeader.h"
 
+#include "Riostream.h"
+
+#include "AliCaloRawAnalyzerFactory.h"
+
 namespace
 {
        const Int_t kSTUEqId = 4652;
@@ -75,8 +79,10 @@ fTriggerData(0x0)
       fGeometry =  AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
     }
   
-  fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO();
+  //  fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO ();
   
+  fRawAnalyzer =  (AliCaloRawAnalyzerFakeALTRO*)AliCaloRawAnalyzerFactory::CreateAnalyzer(kFakeAltro);
+
   fDCSConfig = AliEMCALTriggerDCSConfigDB::Instance();
   
   for (Int_t i=0; i<3072; i++) fRawDigitIndex[i] = -1;
@@ -198,7 +204,6 @@ void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunc
                                                        dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                                }
                                                
-                                               dig->SetL0Trigger(1);
                                                dig->SetL0Time(iBin);
                                        }
                                }
@@ -273,6 +278,7 @@ void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunc
 void AliEMCALTriggerRawDigitMaker::PostProcess()
 {      
        //
+        AliDebug(2,"Start post processing the raw digit maker");
        Int_t idx;
        
        AliEMCALTriggerRawDigit* dig = 0x0;
@@ -305,9 +311,29 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
        
        if (STUin && fSTURawStream && fSTURawStream->ReadPayLoad())
        {
+               fTriggerData->SetL1DataDecoded(1);
+               
                fTriggerData->SetL1GammaThreshold(fSTURawStream->GetL1GammaThreshold());
                fTriggerData->SetL1JetThreshold(  fSTURawStream->GetL1JetThreshold()  );
                
+               Int_t v0[2] = {fSTURawStream->GetV0A(), fSTURawStream->GetV0C()};
+               
+               Int_t type[8] = 
+               {
+                       fSTURawStream->GetGA(),
+                       fSTURawStream->GetGB(),
+                       fSTURawStream->GetGC(),
+                       fSTURawStream->GetJA(),
+                       fSTURawStream->GetJB(),
+                       fSTURawStream->GetJC(),
+                       fSTURawStream->GetRegionEnable(), 
+                       fSTURawStream->GetFwVersion()
+               };              
+               
+               fTriggerData->SetL1FrameMask(fSTURawStream->GetFrameReceived());
+               fTriggerData->SetL1V0(v0);
+               fTriggerData->SetL1TriggerType(type);
+               
                Int_t iTRU, x, y;
 
                if (fSTURawStream->GetRawData())
@@ -321,10 +347,19 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                UInt_t adc[96]; for (Int_t j = 0; j < 96; j++) adc[j] = 0;
                                
                                fSTURawStream->GetADC(i, adc);
+                               /*
+                               ofstream outfile(Form("data_TRU%d.txt",i),ios_base::trunc);
                                
+                               for (Int_t j = 0; j < 96; j++) 
+                               {
+                                       outfile << adc[j] << endl;
+                               }
+                               
+                               outfile.close();
+                               */
                                for (Int_t j = 0; j < 96; j++)
                                {
-                                       if (adc[j] < 5) continue;
+                                       //if (adc[j] < 5) continue;
                                        
                                        if (AliDebugLevel()) printf("| STU => TRU# %2d raw data: ADC# %2d: %d\n", iTRU, j, adc[j]);
                                        
@@ -334,10 +369,7 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                        {
                                                dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                                
-                                               if (!dig->GetNSamples())
-                                                       AliDebug(10,Form("TRG digit of id: %4d found in STU but has 0 sample in F-ALTRO!",idx));
-                                                       
-                                               dig->SetL1TimeSum(adc[j]);
+                                               if (!dig->GetNSamples()) AliDebug(10,Form("TRG digit of id: %4d found in STU but has no time sample in F-ALTRO!",idx));
                                        }
                                        else
                                        {
@@ -347,14 +379,14 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                                new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
                                                
                                                dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
-                                               dig->SetL1TimeSum(adc[j]);
                                        }
+                                       
+                                       dig->SetL1TimeSum(adc[j]);
                                }
                        }
                }
                
                // List of patches in EMCal coordinate system
-               TClonesArray* patches = new TClonesArray("AliEMCALTriggerPatch", 96);
                
                for (Int_t i = 0; i < fSTURawStream->GetNL0GammaPatch(); i++)
                {
@@ -366,28 +398,35 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                        
                        const Int_t sizePatchL0 = fDCSConfig->GetTRUSegmentation(iTRU) * fDCSConfig->GetTRUSegmentation(iTRU);
                        
-                       Int_t* idFastOR = new Int_t[sizePatchL0]; 
-                       
-                       for (Int_t j = 0; j < sizePatchL0; j++) idFastOR[j] = -1;
+                       Int_t idFastOR[4];
+                       for (Int_t j = 0; j < 4; j++) idFastOR[j] = -1;
                        
                        if (fGeometry->GetFastORIndexFromL0Index(iTRU, x, idFastOR, sizePatchL0))
                        {
+                               idx = idFastOR[1];
+                               
                                Int_t px, py;
-                               if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idFastOR[1], px, py))
+                               if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idx, px, py))
                                {
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(px, py);
-                                       
                                        if (AliDebugLevel()) printf("| STU => Add L0 patch at (%2d , %2d)\n", px, py);
+                                                                               
+                                       if (fRawDigitIndex[idx] >= 0)
+                                       {
+                                               dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                       }
+                                       else
+                                       {
+                                               fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                               new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
+                       
+                                               dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                       }
+               
+                                       dig->SetTriggerBit(kL0,1);
                                }
                        }
-                       
-                       delete [] idFastOR;
                }
                
-               fTriggerData->SetPatches(kL0, 1, *patches);                     
-               
-               patches->Delete();
-               
                for (Int_t i = 0; i < fSTURawStream->GetNL1GammaPatch(); i++)
                {
                        if (fSTURawStream->GetL1GammaPatch(i, iTRU, x, y)) // col (0..23), row (0..3)
@@ -404,16 +443,27 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                                
                                if (vx >= 0) 
                                {
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(vx, vy);
-                                       
+                                       if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(vx, vy, idx))
+                                       {
                                        if (AliDebugLevel()) printf("| STU => Add L1 gamma patch at (%2d , %2d)\n", vx, vy);
+                                               
+                                               if (fRawDigitIndex[idx] >= 0)
+                                               {
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
                                }
-                       }
-               }
+                                               else
+                                               {
+                                                       fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                                       new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
 
-               fTriggerData->SetPatches(kL1Gamma, 1, *patches);                        
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
                
-               patches->Delete();
+                                               dig->SetTriggerBit(kL1Gamma,1);
+                                       }
+                               }
+                       }
+               }
                
                for (Int_t i = 0; i < fSTURawStream->GetNL1JetPatch(); i++)
                {
@@ -421,26 +471,35 @@ void AliEMCALTriggerRawDigitMaker::PostProcess()
                        {
                                if (AliDebugLevel()) printf("| STU => Found L1 jet patch at (%2d , %2d)\n", x, y);
                                
-                               Int_t ix = sizeL1jsubr[0] * (11 - y - sizeL1jpatch[0] + 1);
+                               Int_t ix = sizeL1jsubr[0] * (11 - y - 4 + 1);
 
-                               Int_t iy = sizeL1jsubr[1] * (15 - x - sizeL1jpatch[1] + 1);
+                               Int_t iy = sizeL1jsubr[1] * (15 - x - 4 + 1);
                                
                                // FIXME: x = 0 || y = 0 (Olivier's CS) patches a lost?
                                
                                if (ix >= 0 && iy >= 0)
                                {       
-                                       new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(ix, iy);
-                                       
+                                       if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(ix, iy, idx))
+                                       {
                                        if (AliDebugLevel()) printf("| STU => Add L1 jet patch at (%2d , %2d)\n", ix, iy);
-                               }
-                       }
-               }
                
-               fTriggerData->SetPatches(kL1Jet, 1, *patches);                  
+                                               if (fRawDigitIndex[idx] >= 0)
+                                               {
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
+                                               else
+                                               {
+                                                       fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
+                                                       new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
                
-               patches->Delete();
+                                                       dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
+                                               }
                
-               delete patches;
+                                               dig->SetTriggerBit(kL1Jet,1);
+                                       }
+                               }
+                       }
+               }               
        }
 }