]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/AliPMDDDLRawData.cxx
bug fixed
[u/mrichter/AliRoot.git] / PMD / AliPMDDDLRawData.cxx
index 5dcce4d616c8ef659d73edf721b96580d8bf6870..faca049fd0debbf11ca96ceed6b59c381c5121fe 100644 (file)
 #include "AliPMDDspHeader.h"
 #include "AliPMDPatchBusHeader.h"
 #include "AliPMDRawStream.h"
+#include "AliPMDddlinfoData.h"
+#include "AliPMDMappingData.h"
 #include "AliPMDDDLRawData.h"
 #include "AliDAQ.h"
 #include "AliFstream.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
 
 ClassImp(AliPMDDDLRawData)
 
 AliPMDDDLRawData::AliPMDDDLRawData():
+  fDdlinfo(GetDdlinfoData()),
+  fMapData(GetMappingData()),
   fDigits(new TClonesArray("AliPMDdigit", 1000))
 {
   // Default Constructor
@@ -45,6 +52,8 @@ AliPMDDDLRawData::AliPMDDDLRawData():
 //____________________________________________________________________________
 AliPMDDDLRawData::AliPMDDDLRawData(const AliPMDDDLRawData& ddlraw):
   TObject(ddlraw),
+  fDdlinfo(ddlraw.fDdlinfo),
+  fMapData(ddlraw.fMapData),
   fDigits(ddlraw.fDigits)
 {
   //Copy Constructor 
@@ -55,7 +64,9 @@ AliPMDDDLRawData & AliPMDDDLRawData::operator=(const AliPMDDDLRawData& ddlraw)
   //Assignment operator 
   if(this != &ddlraw)
     {
-      fDigits = ddlraw.fDigits;
+      fDdlinfo = ddlraw.fDdlinfo;
+      fMapData = ddlraw.fMapData;
+      fDigits  = ddlraw.fDigits;
     }
   return *this;
 }
@@ -87,7 +98,6 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
   AliDebug(1,Form("Number of modules inside treeD = %d",nmodules));
 
   const Int_t kDDL          = AliDAQ::NumberOfDdls("PMD");
-  Int_t modulePerDDL        = 0;
 
 
   AliRawDataHeaderSim header;
@@ -103,32 +113,25 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
 
   Char_t filename[80];
 
-
+  Int_t modulePerDDL        = 0;
   Int_t mmodule = 0;
+  Int_t ddlno;
+  Int_t modulenoddl[12] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
+
   for(Int_t iddl = 0; iddl < kDDL; iddl++)
     {
-      strcpy(filename,AliDAQ::DdlFileName("PMD",iddl));
-      
-      outfile = new AliFstream(filename);
-      
-      if (iddl < 4)
-       {
-         modulePerDDL = 6;
-         mmodule = 6*iddl;
-       }
-      else if (iddl == 4)
-       {
-         modulePerDDL = 12;
-         mmodule = 24;
-       }
-      else if (iddl == 5)
+      ddlno = iddl;
+      modulePerDDL = fDdlinfo->GetNoOfModulePerDdl(iddl);
+      if (modulePerDDL == 0) continue;
+      for (Int_t im = 0; im < 12; im++)
        {
-         modulePerDDL = 12;
-         mmodule = 30;
+         modulenoddl[im] = fDdlinfo->GetModulesPerDdl(iddl,im);;
        }
 
-
-
+      strncpy(filename,AliDAQ::DdlFileName("PMD",iddl),79);
+      
+      outfile = new AliFstream(filename);
+      
       // Write the Dummy Data Header into the file
       Int_t bHPosition = outfile->Tellp();
       outfile->WriteBuffer((char*)(&header),sizeof(header));
@@ -142,20 +145,17 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
            }
        }
 
-      for(Int_t ium = 0; ium < modulePerDDL; ium++)
+      for(Int_t ium = 0; ium < 12; ium++)
        {
-         if (iddl == 4 && ium == 6) mmodule = 42;
-
          // Extract energy deposition per cell and pack it
          // in a 32-bit word and returns all the total words
          // per one unit-module
          
+         mmodule = modulenoddl[ium];
+         if(mmodule == -1) continue;
          GetUMDigitsData(treeD, mmodule, iddl, contentsBus, busPatch);
-         mmodule++;
        }
 
-      
-
       Int_t ij = 0;
       Int_t dsp[10];
       Int_t dspBus[10];
@@ -205,6 +205,9 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
            }
        }
 
+      dspBlockARDL += 50;
+      dspBlockBRDL += 50;
+
       // Start writing the DDL file
 
       AliPMDBlockHeader blHeader;
@@ -222,9 +225,6 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
       Int_t  iskip[5];
       UInt_t ddlEndWord[2] = {0xDEADFACE, 0xDEADFACE};
 
-      Int_t bknJunk = 0;
-
-
       for (Int_t iblock = 0; iblock < 2; iblock++)
        {
          // DSP Block Header
@@ -318,8 +318,6 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
 
                  outfile->WriteBuffer((char*)patchBusHeaderWord,4*sizeof(UInt_t));
 
-                 bknJunk += patchbusRDL;
-
                  for (Int_t iword = 0; iword < patchbusRDL; iword++)
                    {
                      buffer[iword] = busPatch[busno][iword];
@@ -358,25 +356,23 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
       delete outfile;
     } // DDL Loop over
 
-
 }
 //____________________________________________________________________________
+
 void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
-                                      Int_t ddlno, Int_t *contentsBus,
+                                      Int_t ddlno,  Int_t *contentsBus,
                                       UInt_t busPatch[][1536])
 {
-  // Retrives digits data UnitModule by UnitModule
+  // Retrieves digits data UnitModule by UnitModule
+
+  const Int_t kMaxBus = 51;
 
-  UInt_t baseword;
-  UInt_t mcmno, chno;
-  UInt_t adc;
-  Int_t  det, smn, irow, icol;
-  Int_t  parity;
+  UInt_t baseword = 0;
+  UInt_t mcmno = 0, chno = 0;
+  UInt_t adc = 0;
+  Int_t  det = 0, smn = 0, irow = 0, icol = 0;
+  UInt_t  parity = 0;
   
-  const Int_t kMaxBus = 51;   // BKN
-  Int_t totPatchBus, bPatchBus, ePatchBus;
-  Int_t ibus, totmcm, rows, cols, rowe, cole;
-  Int_t moduleno;
   Int_t busno = 0;
   Int_t patchBusNo[kMaxBus], mcmperBus[kMaxBus];
   Int_t startRowBus[kMaxBus], startColBus[kMaxBus];
@@ -393,83 +389,40 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
       endRowBus[i]   = -1;
       endColBus[i]   = -1;
     }
-  Int_t modulePerDDL = 0;
-  if (ddlno < 4)
-    {
-      modulePerDDL = 6;
-    }
-  else if (ddlno == 4 || ddlno == 5)
-    {
-      modulePerDDL = 12;
-    }
 
-  TString fileName(gSystem->Getenv("ALICE_ROOT"));
+  // Fetch the DDL mapping info from the mapping database
 
-  if(ddlno == 0)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl0.dat";
-    }
-  else if(ddlno == 1)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl1.dat";
-    }
-  else if(ddlno == 2)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl2.dat";
-    }
-  else if(ddlno == 3)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl3.dat";
-    }
-  else if(ddlno == 4)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl4.dat";
-    }
-  else if(ddlno == 5)
-    {
-      fileName += "/PMD/PMD_Mapping_ddl5.dat";
-    }
+  DdlMapping(ddlno, imodule, beginPatchBus, endPatchBus,
+            patchBusNo, mcmperBus, startRowBus, endRowBus,
+            startColBus, endColBus);
 
-  ifstream infile;
-  infile.open(fileName.Data(), ios::in); // ascii file
-  if(!infile)
-    AliError(Form("Could not read the mapping file for DDL No = %d",ddlno));
+  // Read if some chains are off from the ddlinfo database
 
-  for (Int_t im = 0; im < modulePerDDL; im++)
-    {
-      infile >> moduleno;
-      infile >> totPatchBus >> bPatchBus >> ePatchBus;
+  Int_t srowoff1[2][24], erowoff1[2][24];
+  Int_t scoloff1[2][24], ecoloff1[2][24];
+  Int_t srowoff2[2][24], erowoff2[2][24];
+  Int_t scoloff2[2][24], ecoloff2[2][24];
 
-      if (moduleno == imodule)
-       {
-         beginPatchBus = bPatchBus;
-         endPatchBus   = ePatchBus;
-       }
-      
-      for(Int_t i=0; i<totPatchBus; i++)
+  for (Int_t idet = 0; idet < 2; idet++)
+    {
+      for (Int_t im = 0; im < 24; im++)
        {
-         infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
-
-         if (moduleno == imodule)
-           {
-             patchBusNo[ibus]   = ibus;
-             mcmperBus[ibus]    = totmcm;
-             startRowBus[ibus]  = rows;
-             startColBus[ibus]  = cols;
-             endRowBus[ibus]    = rowe;
-             endColBus[ibus]    = cole;
-           }
+         srowoff1[idet][im] = fDdlinfo->GetStartRowA(idet,im);
+         erowoff1[idet][im] = fDdlinfo->GetEndRowA(idet,im);
+         scoloff1[idet][im] = fDdlinfo->GetStartColA(idet,im);
+         ecoloff1[idet][im] = fDdlinfo->GetEndColA(idet,im);
+         srowoff2[idet][im] = fDdlinfo->GetStartRowB(idet,im);
+         erowoff2[idet][im] = fDdlinfo->GetEndRowB(idet,im);
+         scoloff2[idet][im] = fDdlinfo->GetStartColB(idet,im);
+         ecoloff2[idet][im] = fDdlinfo->GetEndColB(idet,im);
        }
-
     }
 
-  infile.close();
-
   treeD->GetEntry(imodule); 
   Int_t nentries = fDigits->GetLast();
   Int_t totword = nentries+1;
 
-  AliPMDdigit *pmddigit;
+  AliPMDdigit *pmddigit = 0x0;
 
   for (Int_t ient = 0; ient < totword; ient++)
     {
@@ -479,11 +432,35 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
       smn    = pmddigit->GetSMNumber();
       irow   = pmddigit->GetRow();
       icol   = pmddigit->GetColumn();
-      adc    = (UInt_t) pmddigit->GetADC();
+      Float_t aadc = pmddigit->GetADC();
+      if (aadc < 0.) aadc = 0.;
+      adc    = (UInt_t) aadc;
 
       TransformS2H(smn,irow,icol);
+      
+      // remove the non-existence channels
+
+      //printf("%d %d %d %d\n",det,smn,irow,icol);
+      //printf("--- %d   %d   %d   %d\n",srowoff[det][smn],erowoff[det][smn],
+      //     scoloff[det][smn],ecoloff[det][smn]);
+
+      if (irow >= srowoff1[det][smn] && irow <= erowoff1[det][smn])
+       {
+         if (icol >= scoloff1[det][smn] && icol <= ecoloff1[det][smn])
+           {
+             continue;
+           }
+       }
+      if (irow >= srowoff2[det][smn] && irow <= erowoff2[det][smn])
+       {
+         if (icol >= scoloff2[det][smn] && icol <= ecoloff2[det][smn])
+           {
+             continue;
+           }
+       }
 
-      GetMCMCh(ddlno, smn, irow, icol, beginPatchBus, endPatchBus,
+
+      GetMCMCh(imodule, irow, icol, beginPatchBus, endPatchBus,
               mcmperBus, startRowBus, startColBus,
               endRowBus, endColBus, busno, mcmno, chno);
 
@@ -535,7 +512,7 @@ void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
 
 //____________________________________________________________________________
 
-void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t smn, Int_t row, Int_t col,
+void AliPMDDDLRawData::GetMCMCh(Int_t imodule, Int_t row, Int_t col,
                                Int_t beginPatchBus, Int_t endPatchBus,
                                Int_t *mcmperBus,
                                Int_t *startRowBus, Int_t *startColBus,
@@ -657,18 +634,22 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t smn, Int_t row, Int_t col,
     
     
     for (Int_t i = 0; i < 16; i++)
-    {
+      {
        for (Int_t j = 0; j < 4; j++)
-       {
-           if (ddlno == 0 || ddlno == 1) iCh[i][j] = kChDdl01[i][j];
-           if (ddlno == 2 || ddlno == 3) iCh[i][j] = kChDdl23[i][j];
+         {
            
-           if (ddlno == 4 && smn < 6)                iCh[i][j] = kChDdl41[i][j];
-           if (ddlno == 4 && (smn >= 18 && smn < 24))iCh[i][j] = kChDdl42[i][j];
-           if (ddlno == 5 && (smn >= 12 && smn < 18))iCh[i][j] = kChDdl51[i][j];
-           if (ddlno == 5 && (smn >=  6 && smn < 12))iCh[i][j] = kChDdl52[i][j];
-       }
-    }
+           if(imodule < 6)                    iCh[i][j] = kChDdl01[i][j];
+           if(imodule >= 6 && imodule <= 11)  iCh[i][j] = kChDdl01[i][j];
+           if(imodule >= 12 && imodule <= 17) iCh[i][j] = kChDdl23[i][j];
+           if(imodule >= 18 && imodule <= 23) iCh[i][j] = kChDdl23[i][j];
+
+           if(imodule >= 24 && imodule <= 29) iCh[i][j] = kChDdl41[i][j];
+           if(imodule >= 42 && imodule <= 47) iCh[i][j] = kChDdl42[i][j];
+           if(imodule >= 36 && imodule <= 41) iCh[i][j] = kChDdl51[i][j];
+           if(imodule >= 30 && imodule <= 35) iCh[i][j] = kChDdl52[i][j];
+           
+         }
+      }
 
 
   Int_t irownew = row%16;
@@ -684,30 +665,35 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t smn, Int_t row, Int_t col,
       Int_t scol = startColBus[ibus];
       Int_t ecol = endColBus[ibus];
       Int_t tmcm = mcmperBus[ibus];
+
       if ((row >= srow && row <= erow) && (col >= scol && col <= ecol))
        {
          busno = ibus;
          
          // Find out the MCM Number
          //
-         
-         if (ddlno == 0 || ddlno == 1)
+
+         if (imodule < 6)                  mcmno = (col-scol)/4 + 1;
+         if (imodule >= 6 && imodule < 12) mcmno = (col-scol)/4 + 1;
+
+         if (imodule >= 12 && imodule < 18)
            {
-             // PRE plane, SU Mod = 0, 1
-             mcmno = (col-scol)/4 + 1;
-             
-           }
-         else if (ddlno == 2 || ddlno == 3)
+             icolnew = (col - scol)/4;
+             mcmno = tmcm - icolnew;
+           }         
+         if (imodule >= 18 && imodule < 24)
            {
-             // PRE plane,  SU Mod = 2, 3
              icolnew = (col - scol)/4;
              mcmno = tmcm - icolnew;
-           }
-         else if (ddlno == 4 )
+           }         
+
+         // DDL = 4
+         if (imodule >= 24 && imodule < 30)
            {
-             // CPV plane,  SU Mod = 0, 3 : ddl = 4
-             
-             if(ibus <= 18)
+
+             //if (tmcm == 24)
+             Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
+             if(rowdiff > 16)
                {
                  Int_t midrow = srow + 16;
                  if(row >= srow && row < midrow)
@@ -715,38 +701,46 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t smn, Int_t row, Int_t col,
                      mcmno = 12 + (col-scol)/4 + 1;
                    }
                  else if(row >= midrow && row <= erow)
-                 
+                   
                    {
                      mcmno = (col-scol)/4 + 1;
                    }
                }
-             
-             else if (ibus > 18)
+             else if (rowdiff < 16)
                {
-                 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
-                 if(rowdiff > 16)
+                 mcmno = (col-scol)/4 + 1;
+               }
+           
+           }         
+         if (imodule >= 42 && imodule < 48)
+           {
+             Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
+             if(rowdiff > 16)
+               {
+                 Int_t midrow = srow + 16;
+                 if (row >= midrow && row <= erow)
                    {
-                     Int_t midrow = srow + 16;
-                     if (row >= midrow && row <= erow)
-                       {
-                         mcmno = 12 + (ecol -col)/4 + 1;
-                       }
-                     else if (row >= srow && row < midrow)
-                       {
-                         mcmno = (ecol - col)/4 + 1;
-                       }
+                     mcmno = 12 + (ecol -col)/4 + 1;
                    }
-                 else if (rowdiff < 16)
+                 else if (row >= srow && row < midrow)
                    {
                      mcmno = (ecol - col)/4 + 1;
                    }
                }
-           }
-         else if ( ddlno == 5)
+             else if (rowdiff < 16)
+               {
+                 mcmno = (ecol - col)/4 + 1;
+               }
+           }         
+
+         // DDL = 5
+         if (imodule >= 30 && imodule < 36)
            {
              // CPV plane,  SU Mod = 1, 2 : ddl = 5
              
-             if(ibus <= 18)
+             //if(tmcm == 24)
+             Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
+             if(rowdiff > 16)
                {
                  Int_t midrow = srow + 16;
                  if(row >= srow && row < midrow)
@@ -758,46 +752,106 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t smn, Int_t row, Int_t col,
                      mcmno = (col-scol)/4 + 1;
                    }
                }
+             else if(rowdiff < 16)
+               {
+                 mcmno = (col-scol)/4 + 1;
+               }
              
-             else if (ibus > 18)
+           }
+         if (imodule >= 36 && imodule < 42)
+           {
+             Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
+             if(rowdiff > 16)
                {
-                 Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
-                 if(rowdiff > 16)
+                 Int_t midrow = srow + 16;
+                 if (row >= midrow && row <= erow)
                    {
-                     Int_t midrow = srow + 16;
-                     if (row >= midrow && row <= erow)
-                       {
-                         mcmno = 12 + (ecol - col)/4 + 1;
-                       }
-                     else if (row >= srow && row < midrow)
-                       {
-                         mcmno = (ecol - col)/4 + 1;
-                       }
+                     mcmno = 12 + (ecol - col)/4 + 1;
                    }
-                 else if (rowdiff < 16)
+                 else if (row >= srow && row < midrow)
                    {
                      mcmno = (ecol - col)/4 + 1;
                    }
                }
+             else if (rowdiff < 16)
+               {
+                 mcmno = (ecol - col)/4 + 1;
+               }
            }
+
        }
     }
 } 
 
 //____________________________________________________________________________
 
-Int_t AliPMDDDLRawData::ComputeParity(UInt_t baseword)
+UInt_t AliPMDDDLRawData::ComputeParity(UInt_t baseword)
 {
   // Generate the parity bit
 
-  Int_t count = 0;
+  UInt_t count = 0;
   for(Int_t j=0; j<29; j++)
     {
       if (baseword & 0x01 ) count++;
       baseword >>= 1;
     }
-  Int_t parity = count%2;
+  UInt_t parity = count%2;
   return parity;
 }
+//____________________________________________________________________________
+void AliPMDDDLRawData::DdlMapping(Int_t iddl, Int_t imodule,
+                                 Int_t &beginPatchBus, Int_t &endPatchBus,
+                                 Int_t patchBusNo[], Int_t mcmperBus[],
+                                 Int_t startRowBus[], Int_t endRowBus[],
+                                 Int_t startColBus[], Int_t endColBus[])
+{
+  // DDL Mapping fetching from mapping database
+
+  beginPatchBus = fMapData->GetBeginPatchBus(iddl,imodule);
+  endPatchBus   = fMapData->GetEndPatchBus(iddl,imodule);
+
+  for(Int_t ibus = beginPatchBus; ibus < endPatchBus+1; ibus++)
+    {
+      patchBusNo[ibus]   = ibus;
+      mcmperBus[ibus]    = fMapData->GetMcmperBus(iddl,ibus);
+      startRowBus[ibus]  = fMapData->GetStartRowBus(iddl,ibus);
+      startColBus[ibus]  = fMapData->GetStartColBus(iddl,ibus);
+      endRowBus[ibus]    = fMapData->GetEndRowBus(iddl,ibus);
+      endColBus[ibus]    = fMapData->GetEndColBus(iddl,ibus);
+    }
+
+}
+//____________________________________________________________________________
 
+AliPMDddlinfoData* AliPMDDDLRawData::GetDdlinfoData() const
+{
+  // The run number will be centralized in AliCDBManager,
+  // you don't need to set it here!
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ddlinfo");
+  
+  if(!entry) AliFatal("ddlinfo object retrieval failed!");
+  
+  AliPMDddlinfoData *ddlinfo = 0;
+  if (entry) ddlinfo = (AliPMDddlinfoData*) entry->GetObject();
+  
+  if (!ddlinfo)  AliFatal("No ddl info data from  database !");
+  
+  return ddlinfo;
+}
+//____________________________________________________________________________
+AliPMDMappingData* AliPMDDDLRawData::GetMappingData() const
+{
+  // The run number will be centralized in AliCDBManager,
+  // you don't need to set it here!
+  AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Mapping");
+  
+  if(!entry) AliFatal("Mapping object retrieval failed!");
+  
+  AliPMDMappingData *mapda = 0;
+  if (entry) mapda = (AliPMDMappingData*) entry->GetObject();
+  
+  if (!mapda)  AliFatal("No mapping data from  database !");
+  
+  return mapda;
+}
 //____________________________________________________________________________