]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/AliPMDDDLRawData.cxx
Using raw-data error log class in order to store data decoding errors.
[u/mrichter/AliRoot.git] / PMD / AliPMDDDLRawData.cxx
index 7b611bf1719b6921736db110c8e61360d4a957d4..bdad7821105e52eb8620e171d66e010393eb2911 100644 (file)
@@ -25,6 +25,9 @@
 #include "AliRawDataHeader.h"
 #include "AliBitPacking.h"
 #include "AliPMDdigit.h"
+#include "AliPMDBlockHeader.h"
+#include "AliPMDDspHeader.h"
+#include "AliPMDPatchBusHeader.h"
 #include "AliPMDRawStream.h"
 #include "AliPMDDDLRawData.h"
 #include "AliDAQ.h"
@@ -39,6 +42,23 @@ AliPMDDDLRawData::AliPMDDDLRawData():
 
 }
 //____________________________________________________________________________
+AliPMDDDLRawData::AliPMDDDLRawData(const AliPMDDDLRawData& ddlraw):
+  TObject(ddlraw),
+  fDigits(ddlraw.fDigits)
+{
+  //Copy Constructor 
+}
+//____________________________________________________________________________
+AliPMDDDLRawData & AliPMDDDLRawData::operator=(const AliPMDDDLRawData& ddlraw)
+{
+  //Assignment operator 
+  if(this != &ddlraw)
+    {
+      fDigits = ddlraw.fDigits;
+    }
+  return *this;
+}
+//____________________________________________________________________________
 
 AliPMDDDLRawData::~AliPMDDDLRawData()
 {
@@ -157,9 +177,9 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
          dsp[i] += 4*dspBus[i];
        }
 
-      Int_t dspBlockARDL = 0;
-      Int_t dspBlockBRDL = 0;
-      
+      Int_t dspBlockARDL    = 0;
+      Int_t dspBlockBRDL    = 0;
+
       for (Int_t i = 0; i < 5; i++)
        {
          Int_t ieven = 2*i;
@@ -167,43 +187,60 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
          if (dsp[ieven] > 0)
            {
              dspBlockARDL += dsp[ieven];
-             dspBlockARDL += 8;
+             Int_t remainder = dsp[ieven]%2;
+             if (remainder == 1)
+               {
+                 dspBlockARDL++;
+               }
            }
          if (dsp[iodd] > 0)
            {
              dspBlockBRDL += dsp[iodd];
-             dspBlockBRDL += 8;
+             Int_t remainder = dsp[ieven]%2;
+             if (remainder == 1)
+               {
+                 dspBlockARDL++;
+               }
            }
        }
       
       // Start writing the DDL file
+
+      AliPMDBlockHeader blHeader;
+      AliPMDDspHeader   dspHeader;
+      AliPMDPatchBusHeader pbusHeader;
+
+      const Int_t kblHLen   = blHeader.GetHeaderLength();
+      const Int_t kdspHLen  = dspHeader.GetHeaderLength();
+      const Int_t kpbusHLen = pbusHeader.GetHeaderLength();
+
       UInt_t dspRDL = 0;
-      UInt_t dspBlockHeader[8];
-      UInt_t dspHeader[8];
-      UInt_t patchBusHeader[4];
+      UInt_t dspBlockHeaderWord[8];
+      UInt_t dspHeaderWord[10];
+      UInt_t patchBusHeaderWord[4];
       Int_t iskip[5];
 
+
       for (Int_t iblock = 0; iblock < 2; iblock++)
        {
          // DSP Block Header
          
-         for (Int_t i=0; i<8; i++)
+         for (Int_t i=0; i<kblHLen; i++)
            {
-             dspBlockHeader[i] = 0;
-             if (i == 1)
-               {
-                 if (iblock == 0)
-                   {
-                     dspBlockHeader[1] = (UInt_t) dspBlockARDL;
-                   }
-                 else if (iblock == 1)
-                   {
-                     dspBlockHeader[1] = (UInt_t) dspBlockBRDL;
-                   }
-               }
+             dspBlockHeaderWord[i] = 0;
+           }
+         if (iblock == 0)
+           {
+             dspBlockHeaderWord[1] = (UInt_t) (dspBlockARDL + kblHLen);
+             dspBlockHeaderWord[2] = (UInt_t) dspBlockARDL;
+           }
+         else if (iblock == 1)
+           {
+             dspBlockHeaderWord[1] = (UInt_t) (dspBlockBRDL + kblHLen);
+             dspBlockHeaderWord[2] = (UInt_t) dspBlockBRDL;
            }
 
-         outfile.write((char*)(&dspBlockHeader),8*sizeof(UInt_t));
+         outfile.write((char*)dspBlockHeaderWord,kblHLen*sizeof(UInt_t));
 
          if (iblock == 0)
            {
@@ -237,28 +274,43 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
                  dspRDL = (UInt_t) dsp[dspno];
                }
 
-             for (Int_t i=0; i<8; i++)
+             for (Int_t i=0; i<kdspHLen; i++)
                {
-                 dspHeader[i] = 0;
+                 dspHeaderWord[i] = 0;
                }
-             dspHeader[1] = dspRDL;
-             dspHeader[6] = dspno;
-             outfile.write((char*)(&dspHeader),8*sizeof(UInt_t));
-             
+             Int_t remainder = dspRDL%2;
+             if (remainder == 1) dspRDL++;
+
+             dspHeaderWord[1] = dspRDL + kdspHLen;
+             dspHeaderWord[2] = dspRDL;
+             dspHeaderWord[3] = dspno;
+             if (remainder == 1) dspHeaderWord[8] = 1; // setting the padding word
+             outfile.write((char*)dspHeaderWord,kdspHLen*sizeof(UInt_t));
+
              for (Int_t ibus = 0; ibus < 5; ibus++)
                {
                  // Patch Bus Header
                  Int_t busno = iskip[idsp] + ibus;
                  Int_t patchbusRDL = contentsBus[busno];
-                 
-                 for (Int_t i=0; i<4; i++)
+
+                 if (patchbusRDL > 0)
+                   {
+                     patchBusHeaderWord[0] = 0;
+                     patchBusHeaderWord[1] = (UInt_t) (patchbusRDL + kpbusHLen);
+                     patchBusHeaderWord[2] = (UInt_t) patchbusRDL;
+                     patchBusHeaderWord[3] = (UInt_t) busno;
+                   }
+                 else if (patchbusRDL == 0)
                    {
-                     patchBusHeader[i] = 0;
+                     patchBusHeaderWord[0] = 0;
+                     patchBusHeaderWord[1] = (UInt_t) kpbusHLen;
+                     patchBusHeaderWord[2] = (UInt_t) 0;
+                     patchBusHeaderWord[3] = (UInt_t) busno;
                    }
-                 patchBusHeader[1] = (UInt_t) patchbusRDL;
-                 patchBusHeader[2] = (UInt_t) busno;
 
-                 outfile.write((char*)(&patchBusHeader),4*sizeof(UInt_t));
+
+                 outfile.write((char*)patchBusHeaderWord,4*sizeof(UInt_t));
+
 
                  for (Int_t iword = 0; iword < patchbusRDL; iword++)
                    {
@@ -266,12 +318,19 @@ void AliPMDDDLRawData::WritePMDRawData(TTree *treeD)
                    }
                  
                  outfile.write((char*)buffer,patchbusRDL*sizeof(UInt_t));
-                 
+
+               } // End of patch bus loop
+
+
+             // Adding a padding word if the total words odd
+             if (remainder == 1)
+               {
+                 UInt_t paddingWord = dspHeader.GetDefaultPaddingWord();
+                 outfile.write((char*)(&paddingWord),sizeof(UInt_t));
                }
            }
        }
-      
-      
+
       // Write real data header
       // take the pointer to the beginning of the data header
       // write the total number of words per ddl and bring the
@@ -296,11 +355,13 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
                                       UInt_t busPatch[][1536])
 {
   // Retrives digits data UnitModule by UnitModule
+
   UInt_t baseword;
   UInt_t mcmno, chno;
   UInt_t adc;
   Int_t  det, smn, irow, icol;
-
+  Int_t  parity;
+  
   const Int_t kMaxBus = 50;
   Int_t totPatchBus, bPatchBus, ePatchBus;
   Int_t ibus, totmcm, rows, cols, rowe, cole;
@@ -331,10 +392,6 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
       modulePerDDL = 12;
     }
 
-
-
-
-
   TString fileName(gSystem->Getenv("ALICE_ROOT"));
 
   if(ddlno == 0)
@@ -401,15 +458,17 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
   Int_t nentries = fDigits->GetLast();
   Int_t totword = nentries+1;
 
+  AliPMDdigit *pmddigit;
+
   for (Int_t ient = 0; ient < totword; ient++)
     {
-      fPMDdigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
+      pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
       
-      det    = fPMDdigit->GetDetector();
-      smn    = fPMDdigit->GetSMNumber();
-      irow   = fPMDdigit->GetRow();
-      icol   = fPMDdigit->GetColumn();
-      adc    = (UInt_t) fPMDdigit->GetADC();
+      det    = pmddigit->GetDetector();
+      smn    = pmddigit->GetSMNumber();
+      irow   = pmddigit->GetRow();
+      icol   = pmddigit->GetColumn();
+      adc    = (UInt_t) pmddigit->GetADC();
 
       TransformS2H(smn,irow,icol);
 
@@ -422,7 +481,8 @@ void AliPMDDDLRawData::GetUMDigitsData(TTree *treeD, Int_t imodule,
       AliBitPacking::PackWord(chno,baseword,12,17);
       AliBitPacking::PackWord(mcmno,baseword,18,28);
       AliBitPacking::PackWord(0,baseword,29,30);
-      AliBitPacking::PackWord(1,baseword,31,31);
+      parity = ComputeParity(baseword);      // generate the parity bit
+      AliBitPacking::PackWord(parity,baseword,31,31);
 
       Int_t jj = contentsBus[busno];
       busPatch[busno][jj] = baseword;
@@ -456,9 +516,6 @@ void AliPMDDDLRawData::TransformS2H(Int_t smn, Int_t &irow, Int_t &icol)
       icolnew = icol;
     }
 
-  // In the new geometry always Geant (0,0) and Hardware (0,0) start
-  // from the top left corner
-
   irow = irownew;
   icol = icolnew;
 
@@ -474,32 +531,32 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t row, Int_t col,
                                Int_t *endRowBus, Int_t *endColBus,
                                Int_t & busno, UInt_t &mcmno, UInt_t &chno)
 {
-  // This part will be modified once the final track layout on the PCB is
-  // designed. This will only change the coordinate of the individual cell
-
-  static const UInt_t kCh[16][4] = { {12, 13, 18, 19},
-                                    {11, 15, 17, 21},
-                                    {10, 14, 16, 22},
-                                    {8, 9, 20, 23},
-                                    {7, 4, 25, 24},
-                                    {6, 0, 30, 26},
-                                    {5, 1, 31, 27},
-                                    {3, 2, 29, 28},
-                                    {44, 45, 50, 51},
-                                    {43, 47, 49, 53},
-                                    {42, 46, 48, 54},
-                                    {40, 41, 52, 55},
-                                    {39, 36, 57, 56},
-                                    {38, 32, 62, 58},
-                                    {37, 33, 63, 59},
-                                    {35, 34, 61, 60} };
+  // This converts row col to hardware channel number
+  // This is the final version of mapping supplied by Mriganka
+
+  static const UInt_t kCh[16][4] = { {56, 58, 59, 57},
+                                    {54, 62, 61, 53},
+                                    {52, 60, 63, 51},
+                                    {48, 50, 55, 49},
+                                    {46, 40, 45, 47},
+                                    {44, 32, 35, 43},
+                                    {42, 34, 33, 41},
+                                    {38, 36, 37, 39},
+                                    {24, 26, 27, 25},
+                                    {22, 30, 29, 21},
+                                    {20, 28, 31, 19},
+                                    {16, 18, 23, 17},
+                                    {14, 8, 13, 15},
+                                    {12, 0, 3, 11},
+                                    {10, 2, 1, 9},
+                                    {6, 4, 5, 7} };
   
   Int_t irownew = row%16;
   Int_t icolnew = col%4;
   
   chno  = kCh[irownew][icolnew];
-
-
+  
+  
   for (Int_t ibus = beginPatchBus; ibus <= endPatchBus; ibus++)
     {
       Int_t srow = startRowBus[ibus];
@@ -510,108 +567,117 @@ void AliPMDDDLRawData::GetMCMCh(Int_t ddlno, Int_t row, Int_t col,
       if ((row >= srow && row <= erow) && (col >= scol && col <= ecol))
        {
          busno = ibus;
-
+         
          // Find out the MCM Number
          //
-
+         
          if (ddlno == 0 || ddlno == 1)
            {
              // PRE plane, SU Mod = 0, 1
-             Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
-             if(rowdiff > 16)
+             mcmno = (col-scol)/4;
+             
+           }
+         else if (ddlno == 2 || ddlno == 3)
+           {
+             // PRE plane,  SU Mod = 2, 3
+             Int_t icolnew = (col - scol)/4;
+             mcmno = tmcm - 1 - icolnew;
+           }
+         else if (ddlno == 4 )
+           {
+             // CPV plane,  SU Mod = 0, 3 : ddl = 4
+             
+             if(ibus <= 17)
                {
                  Int_t midrow = srow + 16;
                  if(row >= srow && row < midrow)
                    {
                      mcmno = 12 + (col-scol)/4;
                    }
-                 else if(row >= midrow && row < erow)
+                 else if(row >= midrow && row <= erow)
+                 
                    {
                      mcmno = (col-scol)/4;
                    }
                }
-             else
-               {
-                 mcmno = (col-scol)/4;
-               }
-           } // end of ddl 0 and 1
-         else if (ddlno == 2)
-           {
-             // PRE plane,  SU Mod = 2
-             
-             Int_t icolnew = (col - scol)/4;
-             mcmno = tmcm - 1 - icolnew;
-           }
-         else if (ddlno == 3)
-           {
-             // PRE plane,  SU Mod = 3
              
-             Int_t icolnew = (col - scol)/4;
-             mcmno = tmcm - 1 - icolnew;
-           }
-         else if (ddlno == 4)
-           {
-             // CPV plane,  SU Mod = 0, 3 : ddl = 4
-             
-             if(ibus <= 20)
+             else if (ibus > 17)
                {
                  Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
                  if(rowdiff > 16)
                    {
                      Int_t midrow = srow + 16;
-                     if(row >= srow && row < midrow)
+                     if (row >= midrow && row <= erow)
                        {
-                         mcmno = 12 + (col-scol)/4;
+                         mcmno = 12 + (ecol -col)/4;
                        }
-                     else if(row >= midrow && row < erow)
+                     else if (row >= srow && row < midrow)
                        {
-                         mcmno = (col-scol)/4;
+                         mcmno = (ecol - col)/4;
                        }
                    }
-                 else
+                 else if (rowdiff < 16) 
                    {
-                     mcmno = (col-scol)/4;
-                   }
-               }
-             else if (ibus > 20)
-               {
-                 Int_t icolnew = (col - scol)/4;
-                 mcmno = tmcm - 1 - icolnew;
+                     mcmno = (ecol - col)/4;
+                   } 
                }
            }
-         else if (ddlno == 5)
+         else if ( ddlno == 5)
            {
-             // CPV plane,  SU Mod = 2, 1 : ddl = 5
+             // CPV plane,  SU Mod = 0, 3 : ddl = 4
              
-             if(ibus <= 20)
+             if(ibus <= 17)
+               {
+                 Int_t midrow = srow + 16;
+                 if(row >= srow && row < midrow)
+                   {
+                     mcmno = 12 + (col-scol)/4;
+                   }
+                 else if(row >= midrow && row <= erow)
+                   {
+                     mcmno = (col-scol)/4;
+                   }
+               }
+             
+             else if (ibus > 17)
                {
                  Int_t rowdiff = endRowBus[ibus] - startRowBus[ibus];
                  if(rowdiff > 16)
                    {
                      Int_t midrow = srow + 16;
-                     if(row >= srow && row < midrow)
+                     if (row >= midrow && row <= erow)
                        {
-                         mcmno = 12 + (col-scol)/4;
+                         mcmno = 12 + (ecol -col)/4;
                        }
-                     else if(row >= midrow && row < erow)
+                     else if (row >= srow && row < midrow)
                        {
-                         mcmno = (col-scol)/4;
+                         mcmno = (ecol - col)/4;
                        }
                    }
-                 else
+                 else if (rowdiff < 16) 
                    {
-                     mcmno = (col-scol)/4;
-                   }
-               }
-             else if (ibus > 20)
-               {
-                 Int_t icolnew = (col - scol)/4;
-                 mcmno = tmcm - 1 - icolnew;
+                     mcmno = (ecol - col)/4;
+                   } 
                }
            }
-       }  
+       }
     }
-  
-}
+} 
+
 //____________________________________________________________________________
 
+Int_t AliPMDDDLRawData::ComputeParity(UInt_t baseword)
+{
+  // Generate the parity bit
+
+  Int_t count = 0;
+  for(Int_t j=0; j<29; j++)
+    {
+      if (baseword & 0x01 ) count++;
+      baseword >>= 1;
+    }
+  Int_t parity = count%2;
+  return parity;
+}
+
+//____________________________________________________________________________