]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/AliPMDRawStream.cxx
Fixes, new methods (Markus)
[u/mrichter/AliRoot.git] / PMD / AliPMDRawStream.cxx
index 2f2e180a2fd809e6d86394dad1bfd32e8beff378..e53298b1bc1ea032c5d5b5af6eb8dd262a4445d0 100644 (file)
@@ -81,20 +81,25 @@ AliPMDRawStream::~AliPMDRawStream()
 
 //_____________________________________________________________________________
 
-void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
+Bool_t AliPMDRawStream::DdlData(Int_t indexDDL, TObjArray *pmdddlcont)
 {
 // read the next raw digit
 // returns kFALSE if there is no digit left
 
   AliPMDddldata *pmdddldata;
 
-  //  Int_t indexDDL = 0;
-  //  fRawReader->Select(12, indexDDL, indexDDL);
-  fRawReader->ReadHeader();
+  if (!fRawReader->ReadHeader()) return kFALSE;
   Int_t  iddl  = fRawReader->GetDDLID();
   Int_t dataSize = fRawReader->GetDataSize();
   Int_t totaldataword = dataSize/4;
 
+  if (dataSize <= 0) return kFALSE;
+  if (indexDDL != iddl)
+    {
+      AliError("Mismatch in the DDL index");
+      return kFALSE;
+    }
+
   UInt_t *buffer;
   buffer = new UInt_t[totaldataword];
   UInt_t data;
@@ -106,7 +111,6 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
 
   // --- Open the mapping file
 
-
   TString fileName(gSystem->Getenv("ALICE_ROOT"));
   if(iddl == 0)
     {
@@ -171,7 +175,7 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
     {
       infile >> modno;
       infile >> totPatchBus >> bPatchBus >> ePatchBus;
-
+      
       for(Int_t i=0; i<totPatchBus; i++)
        {
          infile >> ibus >> totmcm >> rows >> rowe >> cols >> cole;
@@ -185,6 +189,8 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
        }
     }
 
+
+
   infile.close();
 
 
@@ -192,47 +198,65 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
   AliPMDDspHeader      dspHeader;
   AliPMDPatchBusHeader pbusHeader;
 
+  const Int_t kblHLen   = blockHeader.GetHeaderLength();
+  const Int_t kdspHLen  = dspHeader.GetHeaderLength();
+  const Int_t kpbusHLen = pbusHeader.GetHeaderLength();
+  
+  Int_t parity;
   Int_t idet, ismn;
   Int_t irow = -1;
   Int_t icol = -1;
 
-  Int_t block[8];
-  Int_t pbus[4];
+  Int_t blHeaderWord[8];
+  Int_t dspHeaderWord[10];
+  Int_t pbusHeaderWord[4];
 
   Int_t ilowLimit = 0;
   Int_t iuppLimit = 0;
+
+  Int_t blRawDataLength = 0;
+  Int_t iwordcount = 0;
+
+
   for (Int_t iblock = 0; iblock < 2; iblock++)
     {
       ilowLimit = iuppLimit;
-      iuppLimit = ilowLimit + 8;
+      iuppLimit = ilowLimit + kblHLen;
+
 
       for (Int_t i = ilowLimit; i < iuppLimit; i++)
        {
-         block[i-ilowLimit] = (Int_t) buffer[i];
+         blHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
        }
-      blockHeader.SetHeader(block);
+
+      blockHeader.SetHeader(blHeaderWord);
+
+      blRawDataLength = blockHeader.GetRawDataLength();
+
       for (Int_t idsp = 0; idsp < 5; idsp++)
        {
          ilowLimit = iuppLimit;
-         iuppLimit = ilowLimit + 8;
+         iuppLimit = ilowLimit + kdspHLen;
 
          for (Int_t i = ilowLimit; i < iuppLimit; i++)
            {
-             block[i-ilowLimit] = (Int_t) buffer[i];
+             iwordcount++;
+             dspHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
            }
-         dspHeader.SetHeader(block);
+         dspHeader.SetHeader(dspHeaderWord);
 
          for (Int_t ibus = 0; ibus < 5; ibus++)
            {
 
              ilowLimit = iuppLimit;
-             iuppLimit = ilowLimit + 4;
+             iuppLimit = ilowLimit + kpbusHLen;
 
              for (Int_t i = ilowLimit; i < iuppLimit; i++)
                {
-                 pbus[i-ilowLimit] = (Int_t) buffer[i];
+                 iwordcount++;
+                 pbusHeaderWord[i-ilowLimit] = (Int_t) buffer[i];
                }
-             pbusHeader.SetHeader(pbus);
+             pbusHeader.SetHeader(pbusHeaderWord);
              Int_t rawdatalength = pbusHeader.GetRawDataLength();
              Int_t pbusid = pbusHeader.GetPatchBusId();
 
@@ -244,6 +268,7 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
 
              for (Int_t iword = ilowLimit; iword < iuppLimit; iword++)
                {
+                 iwordcount++;
                  data = buffer[iword];
 
                  Int_t isig =  data & 0x0FFF;
@@ -251,6 +276,11 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
                  Int_t imcm = (data >> 18) & 0x07FF;
                  Int_t ibit = (data >> 31) & 0x0001;
 
+                 parity = ComputeParity(data);
+                 if (ibit != parity)
+                   {
+                     AliWarning("ComputeParity:: Parity Error");
+                   }
                  GetRowCol(iddl, pbusid, imcm, ich, 
                            startRowBus, endRowBus,
                            startColBus, endColBus,
@@ -274,17 +304,24 @@ void AliPMDRawStream::DdlData(TObjArray *pmdddlcont)
                  
                  pmdddlcont->Add(pmdddldata);
                  
-               }
+               } // data word loop
 
-           }
-       } // end of DSP
+             if (iwordcount == blRawDataLength) break;
+
+           } // patch bus loop
 
+         if (dspHeader.GetPaddingWord() == 1) iuppLimit++;
+         if (iwordcount == blRawDataLength) break;
+
+       } // end of DSP
+      if (iwordcount == blRawDataLength) break;
 
     } // end of BLOCK
 
   
   delete [] buffer;
 
+  return kTRUE;
 }
 //_____________________________________________________________________________
 void AliPMDRawStream::GetRowCol(Int_t ddlno, Int_t pbusid,
@@ -296,14 +333,15 @@ void AliPMDRawStream::GetRowCol(Int_t ddlno, Int_t pbusid,
 // decode: ddlno, patchbusid, mcmno, chno -> um, row, col
 
 
-  static const UInt_t kCh[64] = { 21, 25, 29, 28, 17, 24, 20, 16,
-                                 12, 13, 8, 4, 0, 1, 9, 5,
-                                 10, 6, 2, 3, 14, 7, 11, 15,
-                                 19, 18, 23, 27, 31, 30, 22, 26,
-                                 53, 57, 61, 60, 49, 56, 52, 48,
-                                 44, 45, 40, 36, 32, 33, 41, 37,
-                                 42, 38, 34, 35, 46, 39, 43, 47,
-                                 51, 50, 55, 59, 63, 62, 54, 58 };
+  static const UInt_t kCh[64] = { 53, 58, 57, 54, 61, 62, 60, 63,
+                                 49, 59, 56, 55, 52, 50, 48, 51,
+                                 44, 47, 45, 43, 40, 39, 36, 46,
+                                 32, 35, 33, 34, 41, 38, 37, 42,
+                                 21, 26, 25, 22, 29, 30, 28, 31,
+                                 17, 27, 24, 23, 20, 18, 16, 19,
+                                 12, 15, 13, 11,  8,  7,  4, 14,
+                                 0,   3,  1,  2,  9,  6,  5, 10 };
+
 
   Int_t rowcol  = kCh[chno];
   Int_t irownew = rowcol/4;
@@ -464,4 +502,23 @@ void AliPMDRawStream::TransformH2S(Int_t smn, Int_t &row, Int_t &col) const
   row = irownew;
   col = icolnew;
 }
+
+//_____________________________________________________________________________
+
+int AliPMDRawStream::ComputeParity(Int_t data)
+{
+// Calculate the parity bit
+
+  Int_t count = 0;
+  for(Int_t j = 0; j<29; j++)
+    {
+      if (data & 0x01 ) count++;
+      data >>= 1;
+    }
+  
+  Int_t parity = count%2;
+
+  return parity;
+}
+
 //_____________________________________________________________________________