]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONTriggerIO.cxx
Add Config/HighVoltage directory and entry
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerIO.cxx
index 7cfcab08271170dbdcdc2870cb9d3ad27cb03cab..549b15c74b20229db982728c0486076909901516 100644 (file)
@@ -72,7 +72,7 @@ AliMUONTriggerIO::~AliMUONTriggerIO()
 }
 
 //_____________________________________________________________________________
-void 
+Bool_t 
 AliMUONTriggerIO::DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UChar_t &xpos, 
                                 UShort_t address) const
 {  
@@ -92,6 +92,49 @@ AliMUONTriggerIO::DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UCh
   ytri = (address >>  bitsYpos)                    & maskYtri;
   xdev = (address >> (bitsYpos+bitsYtri))          & maskXdev;
   xpos = (address >> (bitsYpos+bitsYtri+bitsXdev)) & maskXpos;
+
+  // convert deviation format
+  // online: sign 1bit , dev 4bit
+  // sign    dev    trigger
+  // 0       1-15   mu-
+  // 1       1-15   mu+
+  // 0       0      mu+, mu- infinite momentum (unde)
+  // 1       0      no x-trigger
+  // offline: dev 5bit
+  // sign    dev    trigger
+  // -        0-14  mu-
+  // -       16-31  mu+
+  // -       15     mu+, mu- infinite momentum (unde)
+
+  Int_t iXdevOff, iXdevOn, iXdev, sign;
+  Bool_t trigx;
+
+  iXdev = xdev;
+
+  iXdevOn = sign = 0;
+  iXdevOn +=  iXdev & 0x0F;
+  sign    += (iXdev >> 4) & 0x01;
+  if (iXdevOn == 0) {
+    if (sign == 0) {
+      iXdevOff = 15;
+      trigx = kTRUE;
+    } else {
+      iXdevOff = 15;
+      trigx = kFALSE;
+    }
+  } else {
+    trigx = kTRUE;
+    if (sign == 0) {
+      iXdevOff = - iXdevOn + 15;  // gives range  0-14
+    } else {
+      iXdevOff = + iXdevOn + 15;  // gives range 16-30 !
+    }
+  }
+
+  xdev = iXdevOff;
+
+  return trigx;
+
 }
 
 //_____________________________________________________________________________
@@ -136,9 +179,9 @@ AliMUONTriggerIO::FillLut(AliMUONTriggerLut& lut,
   lut.SetContent("LptUnde",icirc,istripX,idev,iLptUnde);
   lut.SetContent("LptPlus",icirc,istripX,idev,iLptPlus);
 
-  lut.SetContent("HptMinu",icirc,istripX,idev,iLptMinu);
-  lut.SetContent("HptUnde",icirc,istripX,idev,iLptUnde);
-  lut.SetContent("HptPlus",icirc,istripX,idev,iLptPlus);
+  lut.SetContent("HptMinu",icirc,istripX,idev,iHptMinu);
+  lut.SetContent("HptUnde",icirc,istripX,idev,iHptUnde);
+  lut.SetContent("HptPlus",icirc,istripX,idev,iHptPlus);
 }
 
 //_____________________________________________________________________________
@@ -213,11 +256,11 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
 
   UShort_t address;
   
-  UChar_t buffer;
+  UChar_t buffer[16384];   // 32768 hpt/lpt addresses divided by two
   UChar_t mask1 = 0xF0;
   UChar_t mask2 = 0x0F;
-  UChar_t maskLpt = 0x0C;
-  UChar_t maskHpt = 0x03;
+  UChar_t maskHpt = 0x0C;
+  UChar_t maskLpt = 0x03;
   UChar_t lh, lpt, hpt;
   
   UChar_t xpos, xdev, ypos, ytri;
@@ -229,26 +272,28 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
   AliDebug(1,Form("Reading LUT values for local board %d",boardnr));
   
   Int_t ny = 0;
+  Bool_t trigx = kFALSE;
   
+  // read two lut addresses at once, 32768/2=16384 times
+  fread(buffer,16384,1,flut);
+
   // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
-  for (UShort_t ilut = 0; ilut < 0x7FFF; ilut += 2) 
+  for (UShort_t ilut = 0; ilut < 32768; ilut += 2) 
   {
-    // read two lut addresses at once
-    fread(&buffer,1,1,flut);
     
     // 1st 4-bits half-byte
     address = ilut;   
-    lh = (buffer & mask1) >> 4;
+    lh = (buffer[ilut/2] & mask1) >> 4;
     
     // Lpt and Hpt response
-    lpt = (lh & maskLpt) >> 2;
-    hpt =  lh & maskHpt;
+    hpt = (lh & maskHpt) >> 2;
+    lpt =  lh & maskLpt;
     
     // decompose the 15-bits address
-    DeCompAddress(ypos,ytri,xdev,xpos,address);
+    trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
     
     // calculate group of y-strips
-    if (ny < 16
+    if (trigx && (ny < 16)
     {
       lutLpt[ny][0] =  lpt & 1;
       lutLpt[ny][1] = (lpt & 2) >> 1;
@@ -268,17 +313,17 @@ AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
     
     // 2nd 4-bits half-byte
     address = ilut+1; 
-    lh = (buffer & mask2);
+    lh = (buffer[ilut/2] & mask2);
     
     // Lpt and Hpt response
-    lpt = (lh & maskLpt) >> 2;
-    hpt =  lh & maskHpt;
+    hpt = (lh & maskHpt) >> 2;
+    lpt =  lh & maskLpt;
     
     // decompose the 15-bits address
-    DeCompAddress(ypos,ytri,xdev,xpos,address);
+    trigx = DeCompAddress(ypos,ytri,xdev,xpos,address);
     
     // calculate group of y-strips
-    if (ny < 16
+    if (trigx && (ny < 16)
     {
       lutLpt[ny][0] =  lpt & 1;
       lutLpt[ny][1] = (lpt & 2) >> 1;
@@ -686,6 +731,9 @@ AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
   const Int_t kMaskYtri = 0x01;
   const Int_t kMaskXdev = 0x1F;
   const Int_t kMaskXpos = 0x1F;
+
+  UChar_t buffer[16384];  // 32768 hpt/lpt addresses divided by two
+  Int_t bc = 0;
   
   for (Int_t i = 0; i < 32768; ++i) 
   {
@@ -698,32 +746,67 @@ AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
     Int_t iXdev = ( i >> ( 4 + 1 )     ) & kMaskXdev;
     Int_t iXpos = ( i >> ( 4 + 1 + 5 ) ) & kMaskXpos;
     
+    // convert deviation format
+    // online: sign 1bit , dev 4bit
+    // sign    dev    trigger
+    // 0       1-15   mu-
+    // 1       1-15   mu+
+    // 0       0      mu+, mu- infinite momentum (unde)
+    // 1       0      no x-trigger
+    // offline: dev 5bit
+    // sign    dev    trigger
+    // -        0-14  mu-
+    // -       16-31  mu+
+    // -       15     mu+, mu- infinite momentum (unde)
+    Int_t iXdevOn  = 0;
+    Int_t iXdevOff = 0;
+    Int_t sign     = 0;
+    Bool_t trigx = kFALSE;
+    iXdevOn +=  iXdev & 0x0F;
+    sign    += (iXdev >> 4) & 0x01;
+    if (iXdevOn == 0) {
+      if (sign == 0) {
+       iXdevOff = 15;
+       trigx = kTRUE;
+      } else {
+       iXdevOff = 15;
+       trigx = kFALSE;
+      }
+    } else {
+      trigx = kTRUE;
+      if (sign == 0) {
+       iXdevOff = - iXdevOn + 15;  // gives range  0-14
+      } else {
+       iXdevOff = + iXdevOn + 15;  // gives range 16-30 !
+      }
+    }
+    iXdev = iXdevOff;
+
     // iYtri == 1 means no trigger in y-direction
-    if (iYtri == 0) 
+    if (iYtri == 0 && trigx
     {
       lut.GetLutOutput(localBoardId,iXpos,iXdev,iYpos,lutLpt,lutHpt);
     }
     
-    UChar_t buffer;
-    
     // fill byte
     if (i%2 == 0) 
     {
       // upper half-byte
-      buffer = 0;          
-      buffer += lutLpt[1] << 7;
-      buffer += lutLpt[0] << 6;
-      buffer += lutHpt[1] << 5;
-      buffer += lutHpt[0] << 4;
+      buffer[bc] = 0;      
+      buffer[bc] += lutHpt[1] << 7;
+      buffer[bc] += lutHpt[0] << 6;
+      buffer[bc] += lutLpt[1] << 5;
+      buffer[bc] += lutLpt[0] << 4;
     } else {
       // lower half-byte
-      buffer += lutLpt[1] << 3;
-      buffer += lutLpt[0] << 2;
-      buffer += lutHpt[1] << 1;
-      buffer += lutHpt[0] << 0;
-      fwrite(&buffer,1,1,flut);
+      buffer[bc] += lutHpt[1] << 3;
+      buffer[bc] += lutHpt[0] << 2;
+      buffer[bc] += lutLpt[1] << 1;
+      buffer[bc] += lutLpt[0] << 0;
+      bc++;
     }
   }
+  fwrite(&buffer,bc,1,flut);
 }  
 
 //_____________________________________________________________________________