]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Reimplemented the lookup table. It is now much simpler, smaller and faster to use.
authorszostak <szostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Oct 2007 23:57:26 +0000 (23:57 +0000)
committerszostak <szostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 5 Oct 2007 23:57:26 +0000 (23:57 +0000)
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.h
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.h
HLT/MUON/macros/CreateRegionalToLocalCardMapping.C [deleted file]
HLT/MUON/macros/CreateTriggerRecoLookupTables.C

index 14a4c7693f89e70c517fd5e56bf1221782a280ce..2e0f646b009f7705ca07cc26b5121fd18a100394 100644 (file)
@@ -1,16 +1,17 @@
 /**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
+ * This file is property of and copyright by the ALICE HLT Project        *
  * All rights reserved.                                                   *
  *                                                                        *
  * Primary Authors:                                                       *
  *   Indranil Das <indra.das@saha.ac.in>                                  *
+ *   Artur Szostak <artursz@iafrica.com>                                  *
  *                                                                        *
  * Permission to use, copy, modify and distribute this software and its   *
  * documentation strictly for non-commercial purposes is hereby granted   *
  * without fee, provided that the above copyright notice appears in all   *
  * copies and that both the copyright notice and this permission notice   *
  * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
+ * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
 
 /**********************************************************************
  Created on : 16/05/2007
- Purpose    : This class is supposed to read the tracker DDL files and 
-              give the output AliMUONCoreTriggerRecord
+ Purpose    : This class reads the tracker DDL files and gives the output
+              as AliMUONTriggerRecordStruct structures.
  Author     : Indranil Das, HEP Division, SINP
  Email      : indra.das@saha.ac.in | indra.ehep@gmail.com
+
+ Artur Szostak <artursz@iafrica.com>:
+  Completely reimplemented the lookup table to a simplified format.
 **********************************************************************/
 
 ///*
 #include <vector>
 #include <cassert>
 
-const int AliHLTMUONTriggerReconstructor::fgkDetectorId = 0xB00;
-const int AliHLTMUONTriggerReconstructor::fgkDDLOffSet = 20 ;
-const int AliHLTMUONTriggerReconstructor::fgkNofDDL = 2 ;
-
-const int AliHLTMUONTriggerReconstructor::fgkDDLHeaderSize = 8;
-const int AliHLTMUONTriggerReconstructor::fgkEvenLutSize = 2602351 + 1; 
-const int AliHLTMUONTriggerReconstructor::fgkOddLutSize = 2528735 + 1;
-
-const int AliHLTMUONTriggerReconstructor::fgkLutLine = 10496;
-
-const int AliHLTMUONTriggerReconstructor::fgkMinIdUnique[2] = {819616, 862288};
-const int AliHLTMUONTriggerReconstructor::fgkMaxIdUnique[2] = {3421966, 3391022};
-
-const float AliHLTMUONTriggerReconstructor::fgkHalfPadSizeXB[3] = {8.5, 17.0, 25.5};
-const float AliHLTMUONTriggerReconstructor::fgkHalfPadSizeYNB[2] = {25.5, 34.0};
-
-const int AliHLTMUONTriggerReconstructor::fgkDetElem = 9*4 ; // 9 detele per half chamber
-
 
 AliHLTMUONTriggerReconstructor::AliHLTMUONTriggerReconstructor() :
-       fLookUpTableData(NULL),
        fMaxRecPointsCount(0),
-       fDDLId(0),
-       fIdOffSet(0),
        fTrigRecId(0)
 {
        // ctor
+       
+       for (Int_t i = 0; i < 8; i++)
+       for (Int_t j = 0; j < 16; j++)
+       for (Int_t k = 0; k < 4; k++)
+       for (Int_t n = 0; n < 2; n++)
+       for (Int_t m = 0; m < 16; m++)
+       {
+               fLookupTable[i][j][k][n][m].fX = 0;
+               fLookupTable[i][j][k][n][m].fY = 0;
+               fLookupTable[i][j][k][n][m].fZ = 0;
+       }
 }
 
 
 AliHLTMUONTriggerReconstructor::~AliHLTMUONTriggerReconstructor()
 {
        // dtor
-       if (fLookUpTableData != NULL)
-               delete [] fLookUpTableData;
-}
-
-bool AliHLTMUONTriggerReconstructor::SetRegToLocCardMap(RegToLoc* regToLoc)
-{
-  if(!memcpy(fRegToLocCard,regToLoc,128*sizeof(RegToLoc)))
-    return false;
-
-  for(int i=0;i<128;i++){
-    HLTDebug("DDL : %d, reg : %d, loc : %d",fRegToLocCard[i].fTrigDDL,
-           fRegToLocCard[i].fRegId,fRegToLocCard[i].fLocId);
-  }
-
-  return true;
 }
 
-bool AliHLTMUONTriggerReconstructor::LoadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookUpTableData, int lookUpTableId)
-{
-  if(lookUpTableId<fgkDDLOffSet || lookUpTableId>= fgkDDLOffSet + fgkNofDDL){
-    HLTError("DDL number is out of range (must be %d<=iDDL<%d)",fgkDDLOffSet,fgkDDLOffSet+fgkNofDDL);
-    return false;
-  }
-  
-  fDDLId = lookUpTableId;
-
-  int lutSize = ((lookUpTableId%2)==0) ? fgkEvenLutSize : fgkOddLutSize ;
-  int nofLutLine = fgkLutLine ;
-  fIdOffSet = fgkMinIdUnique[lookUpTableId%2];
-
-  int detUniqueId;
-
-  fLookUpTableData = new AliHLTMUONHitReconstructor::DHLTLut[lutSize];
-
-  memset(fLookUpTableData,-1,lutSize*sizeof(AliHLTMUONHitReconstructor::DHLTLut));
-
-  for(int i=0; i<nofLutLine; i++){
-
-    detUniqueId = lookUpTableData[i].fIdManuChannel - fIdOffSet + 1;
-    fLookUpTableData[detUniqueId].fIdManuChannel = lookUpTableData[i].fIdManuChannel - fIdOffSet;
-    fLookUpTableData[detUniqueId].fIX = lookUpTableData[i].fIX ;
-    fLookUpTableData[detUniqueId].fIY = lookUpTableData[i].fIY ;
-    fLookUpTableData[detUniqueId].fRealX = lookUpTableData[i].fRealX ;
-    fLookUpTableData[detUniqueId].fRealY = lookUpTableData[i].fRealY ;
-    fLookUpTableData[detUniqueId].fRealZ = lookUpTableData[i].fRealZ ;
-    fLookUpTableData[detUniqueId].fPcbZone = lookUpTableData[i].fPcbZone ;
-    fLookUpTableData[detUniqueId].fPlane = lookUpTableData[i].fPlane ;
-  }
-  
-  return true;
-}
 
 bool AliHLTMUONTriggerReconstructor::Run(
                const AliHLTUInt32_t* rawData,
@@ -137,291 +82,200 @@ bool AliHLTMUONTriggerReconstructor::Run(
                bool suppressPartialTrigs
        )
 {
-  fMaxRecPointsCount = nofTrigRec;
-  
-  // nofTrigRec now becomes the output of how many trigger records were found.
-  nofTrigRec = 0;
-  
-  int lutAddress;
-  
-  int index = 0;
-  int dataCount = 0;
-  int detElemId = 0 ;
-  int reg_output,reg_phys_trig_occur ;
-  int iLocIndex,loc,locDec,triggY,sign,loDev,triggX;
-  int iRegLoc = 0, locId = 0;
-  short pattern[2][4]; // 2 stands for two cathode planes and 4 stands for 4 chambers
-
-  Int_t offset,ithSwitch,secondLocation,idetElemId;
-
-  int shiftIndex = 10 - 6 - 1; // the one comes due to indexing from zero
-
-#ifdef __DEBUG
-  int globalcard_data_occurance = (rawData[index]>>10)&0x1; //Set to 1 if global info present in DDL else set to 0 
-  int version = (rawData[index]>>12)&0xFF; // software version
-  int serial_number =  (rawData[index]>>20)&0xF; // serial number set to 0xF 
-#endif
-  int phys_trig_occur = (rawData[index]>>30)&0x1; // 1 for physics trigger, 0 for software trigger
-  
-  HLTDebug("globalcard_data_occurance  %d, version  %d, serial_number  %d, phys_trig_occur  %d",
-        globalcard_data_occurance,version,serial_number,phys_trig_occur
-  );
-
-  if(!phys_trig_occur) // for software trigger
-    index += 8 ;// corresponding to scalar words
-  
-  index += 1 ; // To skip the separator 0xDEADFACE
-  
-  index += 4 ; // corresponding to global input
-  
-  index += 1 ; // reaches to global output
-  
-  if((fDDLId - AliHLTMUONTriggerReconstructor::fgkDDLOffSet) == 0){ //if globalData is present in DDL 0 (presummed may be changed)
-#ifdef __DEBUG
-    int singleLpt = rawData[index] & 0x1;
-    int singleHpt = (rawData[index] >> 1) & 0x1;
-    
-    int pairUnlikeLpt = (rawData[index] >> 4)  & 0x1;
-    int pairUnlikeHpt = (rawData[index] >> 5)  & 0x1;
-    
-    int pairLikeLpt = (rawData[index] >> 2)  & 0x1;
-    int pairLikeHpt = (rawData[index] >> 3)  & 0x1;
-#endif
-    HLTDebug("singleLpt : %x, singleHpt : %x, pairUnlikeLpt : %x, pairUnlikeHpt : %x, pairLikeLpt : %x, pairLikeHpt : %x",
-            singleLpt,singleHpt,pairUnlikeLpt,pairUnlikeHpt,pairLikeLpt,pairLikeHpt
-    );
-  }
-
-  if(!phys_trig_occur)
-    index += 10; // corresponds to scalar words
-
-  index += 1; // separator 0xDEADBEEF 
-
-  for (int iReg = 0; iReg < 8; iReg++) {
-    index += 1; // DARC Status Word
-    index += 1; // Regeional Word
-    reg_output = rawData[index] & 0xFF;
-    reg_phys_trig_occur = ( rawData[index] >> 31) & 0x1;
-    
-    index += 2; // 2 words for regional input
-    
-    index += 1; // L0 counter
-    
-    if(!reg_phys_trig_occur)
-      index += 10;
-    
-    index += 1; // end of Regeonal header 0xBEEFFACE
-
-    for(int iLoc = 0; iLoc < 16 ; iLoc++){
-
-      iLocIndex = index;      
-
-      loc = (rawData[index+5] >> 19) &  0xF ;
-      
-      locDec = (rawData[index+5] >> 15) & 0xF;
-      triggY = (rawData[index+5] >> 14) & 0x1;
-      sign = (rawData[index+5] >> 9) & 0x1;
-      loDev = (rawData[index+5] >> 5) & 0xF ;
-      triggX = (loDev >> 4 & 0x1 ) && !(loDev & 0xF);
-
-      if( locDec != 0x9 ){ // check for Dec
+       fMaxRecPointsCount = nofTrigRec;
        
-       iRegLoc = iReg*16 + iLoc;
-       locId = fRegToLocCard[iRegLoc].fLocId; 
+       // nofTrigRec now becomes the output of how many trigger records were found.
+       nofTrigRec = 0;
        
-       if(locId<=234){ // to avoid the copy locCards
-         
-         index += 1;
-         pattern[0][0] = rawData[index] & 0xFFFF; // x-strip pattern for chamber 0 
-         pattern[0][1] = (rawData[index] >> 16) & 0xFFFF; // x-strip pattern for chamber 1
-         index += 1; 
-         pattern[0][2] = rawData[index] & 0xFFFF; 
-         pattern[0][3] = (rawData[index] >> 16) & 0xFFFF; 
-         
-         index += 1;
-         pattern[1][0] = rawData[index] & 0xFFFF; // y-strip pattern for chamber 0
-         pattern[1][1] = (rawData[index] >> 16) & 0xFFFF; // y-strip pattern for chamber 0 
-         index += 1; 
-         pattern[1][2] = rawData[index] & 0xFFFF; 
-         pattern[1][3] = (rawData[index] >> 16) & 0xFFFF; 
-
-         if (pattern[0][0] || pattern[0][1] || pattern[0][2] || pattern[0][3]
-             || pattern[1][0] || pattern[1][1] || pattern[1][2] || pattern[1][3]
-            )
-         {
-           if (nofTrigRec == fMaxRecPointsCount) {
-             HLTError("Output buffer is overflowed maximum assiged arraysize : %d, present array index : %d",
-                      fMaxRecPointsCount, nofTrigRec
-             );
-             return false;
-           }
-
-           HLTDebug("iReg: %d, iLoc :%d, locId : %d,X : %x, %x, %x, %x ...Y : %x, %x, %x, %x",
-                   iReg,iLoc,locId,pattern[0][0],pattern[0][1],pattern[0][2],pattern[0][3],
-                   pattern[1][0],pattern[1][1],pattern[1][2],pattern[1][3]
-           );
-
-           // hitset indicates which hits on chambers 7 to 10 have been found and filled.
-           bool hitset[4] = {false, false, false, false};
-           bool Xset[4] = {false, false, false, false};
-           bool Yset[4] = {false, false, false, false};
-
-           for(int iChamber = 0; iChamber < 4 ; iChamber++){ //4 chambers per DDL 
-             for(int iPlane = 0; iPlane < 2 ; iPlane++){// 2 cathode plane
-               if(pattern[iPlane][iChamber]){
-                 detElemId = fRegToLocCard[iRegLoc].fDetElemId[iChamber];
-                 
-                 HLTDebug("\tdetElemId : %d\n",detElemId);
-                 
-                 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
-                   if ((pattern[iPlane][iChamber] >> ibitxy) & 0x1) {
-         
-                     // not quite sure about this
-                     offset = 0;
-                     ithSwitch = (fRegToLocCard[iRegLoc].fSwitch >> shiftIndex) & 0x1;
-                     if (iPlane && ithSwitch) offset = -8;
-                     
-                     secondLocation = ibitxy + offset;
-                     
-                     idetElemId = detElemId%1000;
-
-                     idetElemId &= 0x1FF;
-                     iPlane &= 0x1;
-                     locId &= 0xFF;
-                     secondLocation &= 0xF;
-                     
-                     lutAddress &= 0x0;
-                     lutAddress = (lutAddress|idetElemId)<<1;  
-                     lutAddress = (lutAddress|iPlane)<<8;  
-                     lutAddress = (lutAddress|locId)<<4;
-                     lutAddress |= secondLocation;
-
-                     lutAddress -= fIdOffSet;
-                     
-                     if(fLookUpTableData[lutAddress+1].fIdManuChannel == -1) //skip uninitialized values
-                       continue;
-                       
-                     if (iPlane == 1)
-                     {      
-                       trigRecord[nofTrigRec].fHit[iChamber].fX = fLookUpTableData[lutAddress+1].fRealX;
-                       Xset[iChamber] = true;
-                     }
-                     else
-                     {
-                       trigRecord[nofTrigRec].fHit[iChamber].fY = fLookUpTableData[lutAddress+1].fRealY;
-                       trigRecord[nofTrigRec].fHit[iChamber].fZ = fLookUpTableData[lutAddress+1].fRealZ;
-                       Yset[iChamber] = true;
-                     } 
-                       
-                     HLTDebug("\t Hit Found fo ich : %d, iPlane : %d, detelem %d, id : %d, at (%lf, %lf, %lf) cm",
-                              iChamber,fLookUpTableData[lutAddress+1].fPlane,detElemId,fLookUpTableData[lutAddress+1].fIdManuChannel,
-                              fLookUpTableData[lutAddress+1].fRealX,
-                              fLookUpTableData[lutAddress+1].fRealY,
-                              fLookUpTableData[lutAddress+1].fRealZ
-                     );
-                     
-                     dataCount++;
-                     
-                   }//pattern maching is found 
-                 }// loop of ibitxy
-               }// if pattern
-             }// iplane
-           }// ichamber
-           
-             {
-             
-               // Fill the hitset flags and make sure the hit structures that were not
-               // filled (set) get set to a nil value.
-               for (int i = 0; i < 4; i++)
-               {
-                       if (Xset[i] and Yset[i]) hitset[i] = true;
-                       
-                       if (not hitset[i])
-                       {
-                               trigRecord[nofTrigRec].fHit[i]
-                                       = AliHLTMUONConstants::NilRecHitStruct();
-                       }
-               }
-
-               trigRecord[nofTrigRec].fId = fTrigRecId;
-           
-               // Increment trigger record Id and keep it positive.
-               //TODO: handle the wrapparound better.
-               if (fTrigRecId < 0x7FFFFFFF)
-                       fTrigRecId++;
-               else
-                       fTrigRecId = 0;
+       int index = 0;
+       int reg_output, reg_phys_trig_occur;
+       int iLocIndex,loc,locDec,triggY,sign,loDev,triggX;
+       short pattern[2][4]; // 2 stands for two cathode planes and 4 stands for 4 chambers
+       
+       int phys_trig_occur = (rawData[index]>>30)&0x1; // 1 for physics trigger, 0 for software trigger
+       
+       if (not phys_trig_occur) // for software trigger
+               index += 8 ;// corresponding to scalar words
+       
+       index += 1 ; // To skip the separator 0xDEADFACE
+       
+       index += 4 ; // corresponding to global input
+       
+       index += 1 ; // reaches to global output
+       
+       if (not phys_trig_occur) index += 10; // corresponds to scalar words
+       
+       index += 1; // separator 0xDEADBEEF 
+       
+       for (int iReg = 0; iReg < 8; iReg++)
+       {
+               index += 1; // DARC Status Word
+               index += 1; // Regeional Word
+               reg_output = rawData[index] & 0xFF;
+               reg_phys_trig_occur = ( rawData[index] >> 31) & 0x1;
+               
+               index += 2; // 2 words for regional input
+               
+               index += 1; // L0 counter
+               
+               if (not reg_phys_trig_occur) index += 10;
                
-               AliHLTMUONRecHitStruct* hit1 = NULL;
-               if (hitset[0])
-                       hit1 = &trigRecord[nofTrigRec].fHit[0];
-               else if (hitset[1])
-                       hit1 = &trigRecord[nofTrigRec].fHit[1];
-               AliHLTMUONRecHitStruct* hit2 = NULL;
-               if (hitset[2])
-                       hit2 = &trigRecord[nofTrigRec].fHit[2];
-               else if (hitset[3])
-                       hit2 = &trigRecord[nofTrigRec].fHit[3];
+               index += 1; // end of Regeonal header 0xBEEFFACE
                
-               if (hit1 != NULL and hit2 != NULL)
+               for(int iLoc = 0; iLoc < 16 ; iLoc++)
                {
-                       // Calculate the momentum and fill in the flags and momentum fields.
-                       AliHLTMUONCalculations::ComputeMomentum(
-                                       hit1->fX,
-                                       hit1->fY, hit2->fY,
-                                       hit1->fZ, hit2->fZ
-                               );
-                       trigRecord[nofTrigRec].fPx = AliHLTMUONCalculations::Px();
-                       trigRecord[nofTrigRec].fPy = AliHLTMUONCalculations::Py();
-                       trigRecord[nofTrigRec].fPz = AliHLTMUONCalculations::Pz();
-
-                       trigRecord[nofTrigRec].fFlags =
-                               AliHLTMUONUtils::PackTriggerRecordFlags(
-                                       AliHLTMUONCalculations::Sign(),
-                                       hitset
-                               );
+                       iLocIndex = index;
                        
-                       nofTrigRec++;
-               }
-               else if ((hit1 != NULL or hit2 != NULL) and not suppressPartialTrigs)
-               {
-                       trigRecord[nofTrigRec].fPx = 0;
-                       trigRecord[nofTrigRec].fPy = 0;
-                       trigRecord[nofTrigRec].fPz = 0;
-
-                       trigRecord[nofTrigRec].fFlags =
-                               AliHLTMUONUtils::PackTriggerRecordFlags(
-                                       kSignUnknown,
-                                       hitset
-                               );
+                       loc = (rawData[index+5] >> 19) &  0xF ;
                        
-                       nofTrigRec++;
-               }
-           
-               //int xPos = rawData[index] & 0x1F;
-               //int dev = (rawData[index]>>5) & 0x1F;
-               //int yPos = (rawData[index]>>10) & 0xF;
-           }
-         
-         }// if any non zero pattern found
-
-         index += 1 ; // the last word, important one
-       }// if locId <=234
-      }// Dec Condn
-
-      if(!reg_phys_trig_occur)
-        index += 45;
+                       locDec = (rawData[index+5] >> 15) & 0xF;
+                       triggY = (rawData[index+5] >> 14) & 0x1;
+                       sign = (rawData[index+5] >> 9) & 0x1;
+                       loDev = (rawData[index+5] >> 5) & 0xF ;
+                       triggX = (loDev >> 4 & 0x1 ) && !(loDev & 0xF);
+                       
+                       if( locDec != 0x9 )
+                       { // check for Dec
+                       
+                               index += 1;
+                               pattern[0][0] = rawData[index] & 0xFFFF; // x-strip pattern for chamber 0 
+                               pattern[0][1] = (rawData[index] >> 16) & 0xFFFF; // x-strip pattern for chamber 1
+                               index += 1; 
+                               pattern[0][2] = rawData[index] & 0xFFFF; 
+                               pattern[0][3] = (rawData[index] >> 16) & 0xFFFF; 
+                               
+                               index += 1;
+                               pattern[1][0] = rawData[index] & 0xFFFF; // y-strip pattern for chamber 0
+                               pattern[1][1] = (rawData[index] >> 16) & 0xFFFF; // y-strip pattern for chamber 0 
+                               index += 1; 
+                               pattern[1][2] = rawData[index] & 0xFFFF; 
+                               pattern[1][3] = (rawData[index] >> 16) & 0xFFFF; 
+                       
+                               if (pattern[0][0] || pattern[0][1] || pattern[0][2] || pattern[0][3]
+                                  || pattern[1][0] || pattern[1][1] || pattern[1][2] || pattern[1][3]
+                               )
+                               {
+                                       if (nofTrigRec == fMaxRecPointsCount)
+                                       {
+                                               HLTError("Output buffer is overflowed maximum assiged arraysize : %d, present array index : %d",
+                                                       fMaxRecPointsCount, nofTrigRec
+                                               );
+                                               return false;
+                                       }
+                               
+                                       bool Xset[4] = {false, false, false, false};
+                                       bool Yset[4] = {false, false, false, false};
+                               
+                                       for (int iChamber = 0; iChamber < 4 ; iChamber++) //4 chambers per DDL 
+                                       for (int iPlane = 0; iPlane < 2 ; iPlane++) // 2 cathode plane
+                                       {
+                                               for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy)
+                                               {
+                                                       if (((pattern[iPlane][iChamber] >> ibitxy) & 0x1) != 0x1)
+                                                               continue;
+                                                       
+                                                       if (iPlane == 1)
+                                                       {
+                                                               trigRecord[nofTrigRec].fHit[iChamber].fX =
+                                                                       fLookupTable[iReg][iLoc][iChamber][iPlane][ibitxy].fX;
+                                                               Xset[iChamber] = true;
+                                                       }
+                                                       else
+                                                       {
+                                                               trigRecord[nofTrigRec].fHit[iChamber].fY =
+                                                                       fLookupTable[iReg][iLoc][iChamber][iPlane][ibitxy].fY;
+                                                               trigRecord[nofTrigRec].fHit[iChamber].fZ =
+                                                                       fLookupTable[iReg][iLoc][iChamber][iPlane][ibitxy].fZ;
+                                                               Yset[iChamber] = true;
+                                                       }
+                                                       
+                                               }// loop of ibitxy
+                                       }// ichamber, iplane
+                               
+                                       // hitset indicates which hits on chambers 7 to 10 have been found and filled.
+                                       bool hitset[4] = {false, false, false, false};
+                                       
+                                       // Fill the hitset flags and make sure the hit structures that were not
+                                       // filled (set) get set to a nil value.
+                                       for (int i = 0; i < 4; i++)
+                                       {
+                                               hitset[i] = Xset[i] and Yset[i];
+                                               
+                                               if (not hitset[i])
+                                               {
+                                                       trigRecord[nofTrigRec].fHit[i]
+                                                               = AliHLTMUONConstants::NilRecHitStruct();
+                                               }
+                                       }
+                       
+                                       trigRecord[nofTrigRec].fId = fTrigRecId;
+                               
+                                       // Increment trigger record Id and keep it positive.
+                                       //TODO: handle the wrapparound better.
+                                       if (fTrigRecId < 0x7FFFFFFF)
+                                               fTrigRecId++;
+                                       else
+                                               fTrigRecId = 0;
+                                       
+                                       AliHLTMUONRecHitStruct* hit1 = NULL;
+                                       if (hitset[0])
+                                               hit1 = &trigRecord[nofTrigRec].fHit[0];
+                                       else if (hitset[1])
+                                               hit1 = &trigRecord[nofTrigRec].fHit[1];
+                                       AliHLTMUONRecHitStruct* hit2 = NULL;
+                                       if (hitset[2])
+                                               hit2 = &trigRecord[nofTrigRec].fHit[2];
+                                       else if (hitset[3])
+                                               hit2 = &trigRecord[nofTrigRec].fHit[3];
+                                       
+                                       if (hit1 != NULL and hit2 != NULL)
+                                       {
+                                               // Calculate the momentum and fill in the flags and momentum fields.
+                                               AliHLTMUONCalculations::ComputeMomentum(
+                                                               hit1->fX,
+                                                               hit1->fY, hit2->fY,
+                                                               hit1->fZ, hit2->fZ
+                                                       );
+                                               trigRecord[nofTrigRec].fPx = AliHLTMUONCalculations::Px();
+                                               trigRecord[nofTrigRec].fPy = AliHLTMUONCalculations::Py();
+                                               trigRecord[nofTrigRec].fPz = AliHLTMUONCalculations::Pz();
+                       
+                                               trigRecord[nofTrigRec].fFlags =
+                                                       AliHLTMUONUtils::PackTriggerRecordFlags(
+                                                               AliHLTMUONCalculations::Sign(),
+                                                               hitset
+                                                       );
+                                               
+                                               nofTrigRec++;
+                                       }
+                                       else if ((hit1 != NULL or hit2 != NULL) and not suppressPartialTrigs)
+                                       {
+                                               trigRecord[nofTrigRec].fPx = 0;
+                                               trigRecord[nofTrigRec].fPy = 0;
+                                               trigRecord[nofTrigRec].fPz = 0;
+                       
+                                               trigRecord[nofTrigRec].fFlags =
+                                                       AliHLTMUONUtils::PackTriggerRecordFlags(
+                                                               kSignUnknown,
+                                                               hitset
+                                                       );
+                                               
+                                               nofTrigRec++;
+                                       }
+                               
+                               }// if any non zero pattern found
+                       
+                               index += 1 ; // the last word, important one
+                       }// Dec Condn
+                       
+                       if (not reg_phys_trig_occur)
+                               index += 45;
+                               
+                       index += 1; // end of local Data 0xCAFEFADE
+                       
+                       index = iLocIndex + 6; //important to reset the index counter for fake locids like 235 
+               }// iLoc loop
+       }// iReg Loop
        
-      index += 1; // end of local Data 0xCAFEFADE
-
-      HLTDebug("iReg %d, iLoc %d, locId : %d, trigY %x, triggX %x, loDev %x, dec %x, sign %x,rawData : %x",
-              iReg,iLoc,locId,triggY,triggX,loDev,dec,sign, rawData[index]);
-
-      index = iLocIndex + 6; //important to reset the index counter for fake locids like 235 
-      
-     }// iLoc loop
-     
-  }// iReg Loop
-
-  return true;
+       return true;
 }
index b71d355e5ce7a93a643e655daaed030123abd885..140c658749700ed28b113bedd2d4877e00db4cc5 100644 (file)
@@ -1,20 +1,8 @@
 #ifndef AliHLTMUONTRIGGERRECONSTRUCTOR_H
 #define AliHLTMUONTRIGGERRECONSTRUCTOR_H
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * All rights reserved.                                                   *
- *                                                                        *
- * Primary Authors:                                                       *
- *   Indranil Das <indra.das@saha.ac.in>                                  *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+/* This file is property of and copyright by the ALICE HLT Project        *
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ * See cxx source for full Copyright notice                               */
 
 /* $Id$ */
 
@@ -24,6 +12,9 @@
               give the output AliHLTMUONTriggerRecordStruct
  Author     : Indranil Das, HEP Division, SINP
  Email      : indra.das@saha.ac.in | indra.ehep@gmail.com
+
+ Artur Szostak <artursz@iafrica.com>:
+  Completely reimplemented the lookup table to a simplified format.
 **********************************************************************/
 
 #include "AliHLTLogging.h"
@@ -35,24 +26,9 @@ class AliHLTMUONTriggerReconstructor : public AliHLTLogging
 {
 public:
 
-       struct RegToLoc
-       {
-               int fTrigDDL;  // trigger id (0 or 1)
-               int fRegId,fLoc,fLocId;  // regeonal and local id.
-               int fSwitch;  // packed switch word of 10 bits.
-               int fDetElemId[4];  // Four detection element correspond to four detection element for each local card.
-       };
-
        AliHLTMUONTriggerReconstructor();
        virtual ~AliHLTMUONTriggerReconstructor();
 
-       bool LoadLookUpTable(
-                       AliHLTMUONHitReconstructor::DHLTLut* lookUpTableData,
-                       int lookUpTableId
-               );
-
-       bool SetRegToLocCardMap(RegToLoc* regToLoc);
-
        bool Run(
                        const AliHLTUInt32_t* rawData,
                        AliHLTUInt32_t rawDataSize,
@@ -61,48 +37,24 @@ public:
                        bool suppressPartialTrigs = false
                );
 
-       int GetLutLine() { return fgkLutLine; }
-
-       static int GetkDetectorId() { return AliHLTMUONTriggerReconstructor::fgkDetectorId; }
-       static int GetkDDLOffSet() { return AliHLTMUONTriggerReconstructor::fgkDDLOffSet; }
-       static int GetkNofDDL() { return AliHLTMUONTriggerReconstructor::fgkNofDDL; }
-       static int GetkDDLHeaderSize() { return AliHLTMUONTriggerReconstructor::fgkDDLHeaderSize; } 
+       void* LookupTableBuffer() { return &fLookupTable; }
+       size_t LookupTableSize() const { return sizeof(fLookupTable); }
 
-protected:
+private:
 
        AliHLTMUONTriggerReconstructor(const AliHLTMUONTriggerReconstructor& rhs); // copy constructor
        AliHLTMUONTriggerReconstructor& operator=(const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
 
-private:
-
-       static const int fgkDetectorId;            // Detector ID
-       static const int fgkDDLOffSet;             // DDL Offset
-       static const int fgkNofDDL;                // Number of DDL 
-       static const int fgkDDLHeaderSize;         // DDL header size  
-
-       static const int fgkEvenLutSize;           // Size of the LookupTable with event DDLID
-       static const int fgkOddLutSize;            // Size of the LookupTable with odd DDLID
-       static const int fgkLutLine;               // nof Line in LookupTable    
-
-       static const int fgkMinIdUnique[2];   // Minimum value of idUnique in LookupTable, 2 corresponds to two types of DDL (even/odd)  
-       static const int fgkMaxIdUnique[2];   // Maximum value of idUnique in LookupTable  
-       static const float fgkHalfPadSizeXB[3];    // pad halflength for the pcb zones, 3 corresponds to 3 types of pad in bending side  
-       static const float fgkHalfPadSizeYNB[2];   // pad halflength for the pcb zones, 2 corresponds to 2 types on nonbneding pad  
-
-       static const int fgkDetElem;               // nof Detection element per DDL    
-
-       AliHLTMUONHitReconstructor::DHLTLut* fLookUpTableData; // pointer to the array of Lookuptable data
-       AliHLTUInt32_t fMaxRecPointsCount;            // max nof reconstructed hit  
-
-       //104 correspond to maximum nuber of x indices a nonbending side of detelem may have (i.e. 1101) 
-       //and 64 corresponds to the maximum number of y indices occurs in bending side of detelem (i.e 1100)
-       int fGetIdTotalData[104][64][2];  // an array of idUnique with argumrnt of centralX,centralY and  planeType
-       RegToLoc fRegToLocCard[128];      // 8 regional card per ddl and 16 slots per regional crate together made 16*8 = 128.
-
-       int fDDLId;
-       int fIdOffSet;
+       struct LookupTableRow
+       {
+               float fX, fY, fZ;
+       };
 
+       AliHLTUInt32_t fMaxRecPointsCount;   // max nof reconstructed hit
        AliHLTInt32_t fTrigRecId;  // A running counter for the trigger record ID.
+       
+       // [regional header index][local board ID][chamber][cathode - X/Y][bit set in bit pattern]
+       LookupTableRow fLookupTable[8][16][4][2][16];  // pointer to the array of Lookuptable data
 };
 
 #endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H
index 29309e03c34a8c58e6ef113a594f9b93f6b52fd5..c718ac12f1770458f06774800b68bf224bf3f21e 100644 (file)
@@ -1,34 +1,39 @@
 /**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
+ * This file is property of and copyright by the ALICE HLT Project        *
  * All rights reserved.                                                   *
  *                                                                        *
  * Primary Authors:                                                       *
  *   Indranil Das <indra.das@saha.ac.in>                                  *
+ *   Artur Szostak <artursz@iafrica.com>                                  *
  *                                                                        *
  * Permission to use, copy, modify and distribute this software and its   *
  * documentation strictly for non-commercial purposes is hereby granted   *
  * without fee, provided that the above copyright notice appears in all   *
  * copies and that both the copyright notice and this permission notice   *
  * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
+ * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
 /* $Id$ */
 
-/** @file   AliHLTMUONTriggerReconstructorComponent.cxx
-    @author Indranil Das
-    @date   
-    @brief  Implementation of the trigger DDL reconstructor component. */
+/**
+ * @file   AliHLTMUONTriggerReconstructorComponent.cxx
+ * @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
+ * @date
+ * @brief  Implementation of the trigger DDL reconstructor component.
+ */
 
 #include "AliHLTMUONTriggerReconstructorComponent.h"
 #include "AliHLTMUONTriggerReconstructor.h"
 #include "AliHLTMUONHitReconstructor.h"
 #include "AliHLTMUONConstants.h"
+#include "AliHLTMUONUtils.h"
 #include "AliHLTMUONDataBlockWriter.h"
 #include <cstdlib>
 #include <cerrno>
 #include <cassert>
+#include <fstream>
 
 namespace
 {
@@ -40,12 +45,11 @@ namespace
 
 
 ClassImp(AliHLTMUONTriggerReconstructorComponent)
-    
-    
+
+
 AliHLTMUONTriggerReconstructorComponent::AliHLTMUONTriggerReconstructorComponent() :
        fTrigRec(NULL),
-       fDDLDir(""),
-       fDDL(0),
+       fDDL(-1),
        fWarnForUnexpecedBlock(false),
        fSuppressPartialTrigs(false)
 {
@@ -93,133 +97,103 @@ AliHLTComponent* AliHLTMUONTriggerReconstructorComponent::Spawn()
 
 int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
 {
-  // perform initialization. We check whether our relative output size is
-  // specified in the arguments.
-  
-  HLTInfo("Initialising DHLT Trigger Record Component");
-
-  fWarnForUnexpecedBlock = false;
-  fSuppressPartialTrigs = false;
-  fTrigRec = new AliHLTMUONTriggerReconstructor();
-      
-  // this is just to get rid of the warning "unused parameter"
-  if (argc==0 && argv==NULL) {
-    HLTError("Arguments missing, no arguments" );
-  }
-
-  char lutFileName[500],reglocFileName[500];
-
-  int i = 0;
-  char* cpErr;
-  while ( i < argc )
-    {
-      HLTDebug("argv[%d] == %s", i, argv[i] );
-      
-      if ( !strcmp( argv[i], "lut" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("LookupTable filename not specified" );
-         return EINVAL; /* Invalid argument */ 
-       }
+       // perform initialization.
+       
+       HLTInfo("Initialising dHLT trigger reconstructor component.");
        
-       sprintf(lutFileName,"%s",argv[i+1]);
+       fWarnForUnexpecedBlock = false;
+       fSuppressPartialTrigs = false;
+       assert(fTrigRec == NULL);
+       fTrigRec = new AliHLTMUONTriggerReconstructor();
        
-       i += 2;
-       continue;
-      }// lut argument
-      
-      if ( !strcmp( argv[i], "ddl" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("DDL number not specified" );
-         return EINVAL;  /* Invalid argument */
+       const char* lutFileName = NULL;
+       
+       for (int i = 0; i < argc; i++)
+       {
+               if ( !strcmp( argv[i], "-lut" ) )
+               {
+                       if ( argc <= i+1 )
+                       {
+                               HLTError("LookupTable filename not specified." );
+                               return EINVAL; /* Invalid argument */ 
+                       }
+                       
+                       lutFileName = argv[i+1];
+                       
+                       i++;
+                       continue;
+               }
+               
+               if ( !strcmp( argv[i], "-ddl" ) )
+               {
+                       if ( argc <= i+1 )
+                       {
+                               HLTError("DDL number not specified." );
+                               return EINVAL;  /* Invalid argument */
+                       }
+               
+                       char* cpErr = NULL;
+                       unsigned long num = strtoul(argv[i+1], &cpErr, 0);
+                       if (cpErr == NULL or *cpErr != '\0')
+                       {
+                               HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );
+                               return EINVAL;
+                       }
+                       if (num < 21 or 22 < num)
+                       {
+                               HLTError("The DDL number must be in the range [21..22].");
+                               return EINVAL;
+                       }
+                       fDDL = num - 1; // Convert to DDL number in the range 0..21
+                       
+                       i++;
+                       continue;
+               }
+                       
+               if (not strcmp( argv[i], "-warn_on_unexpected_block" ))
+               {
+                       fWarnForUnexpecedBlock = true;
+                       continue;
+               }
+                       
+               if (not strcmp( argv[i], "-suppress_partial_triggers" ))
+               {
+                       fSuppressPartialTrigs = true;
+                       continue;
+               }
+               
+               HLTError("Unknown option '%s'.", argv[i] );
+               return EINVAL;
+                       
+       }//while loop
+       
+       if (fDDL == -1)
+       {
+               HLTWarning("DDL number not specified. Cannot check if incomming data is valid.");
        }
-
-       fDDL = strtoul( argv[i+1], &cpErr, 0 );
-       if ( *cpErr )
-         {
-           HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
-           return EINVAL;
-         }
-       //fDDL = atoi(argv[i+1]);
        
-       i += 2;
-       continue;
-      }// ddl argument
-         
-      if ( !strcmp( argv[i], "rawdir" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("DDL directory not specified" );
-         return EINVAL;  /* Invalid argument */
+       if (lutFileName != NULL)
+       {
+               if (not ReadLookUpTable(lutFileName))
+               {
+                       HLTError("Failed to read lut, lut cannot be read");
+                       return ENOENT ; /* No such file or directory */
+               }
        }
-
-       fDDLDir = argv[i+1] ;
-       i += 2;
-       continue;
-      }// ddl directory argument
-
-      if ( !strcmp( argv[i], "reglocmap" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("Regional to Local Card mapping  filename not specified" );
-         return EINVAL; /* Invalid argument */
+       else
+       {
+               HLTWarning("The lookup table has not been specified. Output results will be invalid.");
        }
-
-       sprintf(reglocFileName,"%s",argv[i+1]);
-
-       i += 2;
-       continue;
-      }// regtolocalmap argument
-         
-      if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) {
-        fWarnForUnexpecedBlock = true;
-       i++;
-       continue;
-      }
-         
-      if ( !strcmp( argv[i], "-suppress_partial_triggers" ) ) {
-        fSuppressPartialTrigs = true;
-       i++;
-       continue;
-      }
-
-      HLTError("Unknown option '%s'", argv[i] );
-      return EINVAL;
-         
-    }//while loop
-
-    int lutline = fTrigRec->GetLutLine();
-    AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
-    if(!ReadLookUpTable(lookupTable,lutFileName)){
-      HLTError("Failed to read lut, lut cannot be read");
-      return ENOENT ; /* No such file or directory */
-    }else{
-      
-      fTrigRec->LoadLookUpTable(lookupTable,fDDL+AliHLTMUONTriggerReconstructor::GetkDDLOffSet());
-
-      AliHLTMUONTriggerReconstructor::RegToLoc regToLocMap[128]; // 16(locCard)*8(regCard)
-      if(!ReadRegToLocMap(regToLocMap,reglocFileName)){
-       HLTError("Failed to read RegToLocMap file");
-       return ENOENT ; /* No such file or directory */
-      }
-
-      if(!(fTrigRec->SetRegToLocCardMap(regToLocMap))){
-       HLTError("Failed to assign RegToLocMap to TrigRec Class due to memory problem");
-       return ENOMEM ; /*cannot allocate memory*/
-      }
-      
-    }// reading lut
-
-    delete []lookupTable;
-
-    HLTInfo("Initialisation of DHLT Trigger Record Component is done");
-
-    return 0;
+       
+       return 0;
 }
 
 
 int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
 {
-       HLTInfo("Deinitialising DHLT Trigger Record Component");
+       HLTInfo("Deinitialising dHLT trigger reconstructor component.");
 
-       if(fTrigRec)
+       if (fTrigRec != NULL)
        {
                delete fTrigRec;
                fTrigRec = NULL;
@@ -230,9 +204,9 @@ int AliHLTMUONTriggerReconstructorComponent::DoDeinit()
 
 int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                const AliHLTComponentEventData& evtData,
-               const AliHLTComponentBlockData* blocks, 
-               AliHLTComponentTriggerData& trigData,
-               AliHLTUInt8_t* outputPtr, 
+               const AliHLTComponentBlockData* blocks,
+               AliHLTComponentTriggerData& /*trigData*/,
+               AliHLTUInt8_t* outputPtr,
                AliHLTUInt32_t& size,
                std::vector<AliHLTComponentBlockData>& outputBlocks
        )
@@ -289,12 +263,19 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                        continue;
                }
                
+               bool ddl[22];
+               AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
+               if (not ddl[fDDL])
+               {
+                       HLTWarning("Received trigger DDL raw data from a DDL which we did not expect.");
+               }
+               
                // Create a new output data block and initialise the header.
                AliHLTMUONTriggerRecordsBlockWriter block(outputPtr+totalSize, size-totalSize);
                if (not block.InitCommonHeader())
                {
                        HLTError("There is not enough space in the output buffer for the new data block.",
-                                " We require at least %u bytes, but have %u bytes left.",
+                                " We require at least %ufTrigRec->GetkDDLHeaderSize() bytes, but have %u bytes left.",
                                sizeof(AliHLTMUONTriggerRecordsBlockWriter::HeaderType),
                                block.BufferSize()
                        );
@@ -302,9 +283,8 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                }
 
                AliHLTUInt32_t totalDDLSize = blocks[n].fSize / sizeof(AliHLTUInt32_t);
-               AliHLTUInt32_t ddlRawDataSize = totalDDLSize - fTrigRec->GetkDDLHeaderSize();
-               AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr)
-                       + fTrigRec->GetkDDLHeaderSize();
+               AliHLTUInt32_t ddlRawDataSize = totalDDLSize - 8;
+               AliHLTUInt32_t* buffer = reinterpret_cast<AliHLTUInt32_t*>(blocks[n].fPtr) + 8;
                AliHLTUInt32_t nofTrigRec = block.MaxNumberOfEntries();
 
                bool runOk = fTrigRec->Run(
@@ -352,71 +332,32 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
 }
 
 
-bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
+bool AliHLTMUONTriggerReconstructorComponent::ReadLookUpTable(const char* lutpath)
 {
-  if (fDDL < 0 || fDDL >= 2){
-    HLTError("DDL number is out of range");
-    return false;
-  }
-  
-  int lutLine = fTrigRec->GetLutLine();
-  
-  FILE* fin = fopen(lutpath, "r");
-  if (fin == NULL){
-    HLTError("Failed to open file: %s",lutpath);
-    return false;
-  }
-  
-  for(int i=0;i<lutLine;i++){
-    fscanf(
-          fin,
-          "%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",
-          &lookupTable[i].fIdManuChannel,
-          &lookupTable[i].fIX,
-          &lookupTable[i].fIY,
-          &lookupTable[i].fRealX,
-          &lookupTable[i].fRealY,
-          &lookupTable[i].fRealZ,
-          &lookupTable[i].fPcbZone,
-          &lookupTable[i].fPlane
-          );
-  }
-  
-  fclose(fin);
-  return true;
-}
-
+       assert(fTrigRec != NULL);
 
-bool AliHLTMUONTriggerReconstructorComponent::ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLocMap,const char* reglocFileName)
-{
-  int iTrigDDL,iReg,iLoc,locId,switchWord,detElemId[4];
-  int index;
-
-  memset(regToLocMap,-1,128*sizeof(AliHLTMUONTriggerReconstructor::RegToLoc));
-
-  char s[100];
-  ifstream fin(reglocFileName);
-  
-  if(!fin){
-    HLTError("Failed to open file %s",reglocFileName);
-    return false;
-  }
-
-  while(fin.getline(s,100)){
-    sscanf(s,"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",
-          &iTrigDDL,&iReg,&iLoc,&locId,&switchWord,&detElemId[0],&detElemId[1],&detElemId[2],&detElemId[3]);
-    if(iTrigDDL==fDDL){
-      index = iReg*16 + iLoc;
-      regToLocMap[index].fTrigDDL = iTrigDDL ; 
-      regToLocMap[index].fRegId = iReg ;
-      regToLocMap[index].fLoc = iLoc ;
-      regToLocMap[index].fLocId = locId ;  
-      regToLocMap[index].fSwitch = switchWord ;
-      for(int idet = 0; idet<4; idet++)
-       regToLocMap[index].fDetElemId[idet] = detElemId[idet] ;
-    }// if matches with fDDL
-  }//file loop
-  
-  fin.close();
-  return true;
+       fstream file;
+       file.open(lutpath, fstream::binary | fstream::in);
+       if (not file)
+       {
+               HLTError("Could not open file: %s", lutpath);
+               return false;
+       }
+       
+       file.read(reinterpret_cast<char*>(fTrigRec->LookupTableBuffer()), fTrigRec->LookupTableSize());
+       if (file.eof())
+       {
+               HLTError("The file %s was too short to contain a valid lookup table for this component.", lutpath);
+               file.close();
+               return false;
+       }
+       if (file.bad())
+       {
+               HLTError("Could not read from file: %s", lutpath);
+               file.close();
+               return false;
+       }
+       
+       file.close();
+       return true;
 }
index 1c69800a812646894d8852055410adc29c042c34..6580a43be6ae6a48ea60925e543ba6adf20fc9eb 100644 (file)
@@ -1,44 +1,30 @@
 #ifndef AliHLTMUONTRIGGERRECONSTRUCTORCOMPONENT_H
 #define AliHLTMUONTRIGGERRECONSTRUCTORCOMPONENT_H
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * All rights reserved.                                                   *
- *                                                                        *
- * Primary Authors:                                                       *
- *   Indranil Das <indra.das@saha.ac.in>                                  *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+/* This file is property of and copyright by the ALICE HLT Project        *
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ * See cxx source for full Copyright notice                               */
 
 /* $Id$ */
 
-/** @file   AliHLTMUONTriggerReconstructorComponent.h
-    @author Timm Steinbeck, Matthias Richter
-    @date   
-    @brief  A processing component for the dHLT trigger DDL reconstruction. */
-
+/**
+ * @file   AliHLTMUONTriggerReconstructorComponent.h
+ * @author Indranil Das <indra.das@saha.ac.in>, Artur Szostak <artursz@iafrica.com>
+ * @date
+ * @brief  A processing component for the dHLT trigger DDL reconstruction.
+ */
 
 #include "AliHLTProcessor.h"
-#include "AliHLTMUONTriggerReconstructor.h"
-#include "AliHLTMUONHitReconstructor.h"
+#include "AliHLTMUONDataTypes.h"
 
 #if __GNUC__ < 3
 #define std
 #endif
 
+class AliHLTMUONTriggerReconstructor;
+
 /**
  * @class AliHLTMUONTriggerReconstructorComponent
- * @brief A dummy HLT processing component. 
- *
- * An implementiation of a dummy component that just copies its input data
- * as a test, demonstration, and example of the HLT component scheme.
- * @ingroup alihlt_tutorial
+ * @brief A processing component for the dHLT trigger DDL reconstruction.
  */
 class AliHLTMUONTriggerReconstructorComponent : public AliHLTProcessor
 {
@@ -59,34 +45,31 @@ protected:
 
        // Protected functions to implement AliHLTComponent's interface.
        // These functions provide initialization as well as the actual processing
-       // capabilities of the component. 
+       // capabilities of the component.
+       
+       virtual int DoInit(int argc, const char** argv);
+       virtual int DoDeinit();
 
-       int DoInit(int argc, const char** argv);
-       int DoDeinit();
-
-       int DoEvent(
+       virtual int DoEvent(
                        const AliHLTComponentEventData& evtData,
-                       const AliHLTComponentBlockData* blocks, 
+                       const AliHLTComponentBlockData* blocks,
                        AliHLTComponentTriggerData& trigData,
-                       AliHLTUInt8_t* outputPtr, 
+                       AliHLTUInt8_t* outputPtr,
                        AliHLTUInt32_t& size,
                        std::vector<AliHLTComponentBlockData>& outputBlocks
                );
 
 private:
 
-       AliHLTMUONTriggerReconstructor* fTrigRec;
-
-       bool ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath);
-       bool ReadRegToLocMap(AliHLTMUONTriggerReconstructor::RegToLoc* regToLoc,const char* reglocFileName);
-
-       TString fDDLDir;
-       Int_t fDDL;
+       bool ReadLookUpTable(const char* lutpath);
+       
+       AliHLTMUONTriggerReconstructor* fTrigRec; // The trigger reconstructor class implementing the algorithm.
+       AliHLTInt32_t fDDL;   // The DDL number in the range 20..21 from which to expect input.
        bool fWarnForUnexpecedBlock;  // Flag indicating if we should log a warning if we got a block of an unexpected type.
        bool fSuppressPartialTrigs;   // Flag indicating if we should suppress triggers that did not trigger the L0
 
        ClassDef(AliHLTMUONTriggerReconstructorComponent, 0)
 
 };
-    
+
 #endif // AliHLTMUONTRIGGERRECONSTRUCTORCOMPONENT_H
diff --git a/HLT/MUON/macros/CreateRegionalToLocalCardMapping.C b/HLT/MUON/macros/CreateRegionalToLocalCardMapping.C
deleted file mode 100644 (file)
index aeecf19..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * All rights reserved.                                                   *
- *                                                                        *
- * Primary Authors:                                                       *
- *   Indranil Das <indra.das@saha.ac.in>                                  *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-/**********************************************************************
- Created on : 08/09/2007
- Purpose    : TriggerDDL Regional to LocalBoard Mapping.
- Author     : Indranil Das, HEP Division, SINP
- Email      : indra.das@saha.ac.in | indra.ehep@gmail.com
-**********************************************************************/
-
-#include <iostream>
-
-#include "AliMpDDLStore.h"
-#include "AliMpSegmentation.h"
-#include "AliMpTriggerCrate.h"
-#include "AliMpLocalBoard.h"
-
-using namespace std;
-
-bool CreateRegionalToLocalCardMapping()
-{
-  AliMpSegmentation::ReadData(); 
-  AliMpDDLStore::ReadData();
-
-  FILE *fout = fopen("RegionalToLocalCard.dat","w");
-
-  for(int iTrigDDL = 0; iTrigDDL<2 ; iTrigDDL++){
-
-    for(int iReg = 0; iReg < 8 ; iReg++){
-    
-      AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(iTrigDDL,iReg);
-      cout<<"Nof Local Board : "<<crate->GetNofLocalBoards()<<endl;
-      AliMpLocalBoard* locBoard ;
-      
-      for(int i = 0 ; i < crate->GetNofLocalBoards() ; i++){
-      locBoard = AliMpDDLStore::Instance()->GetLocalBoard(crate->GetLocalBoardId(i));
-
-      cout<<"iTrigDDL : "<<iTrigDDL<<", iReg : "<<iReg<<", iLoc : "<<i
-         <<", locID : "<<locBoard->GetId()<<", Switch : (" ;
-      fprintf(fout,"%1d\t%1d\t%-2d\t%-3d\t",iTrigDDL,iReg,i,locBoard->GetId());
-
-      int switch_packed ;
-      switch_packed &= 0x0 ;
-      for(int j = 0 ; j < locBoard->GetNofSwitches() ; j++){
-       cout<<locBoard->GetSwitch(j);
-       
-       if(j<(locBoard->GetNofSwitches()-1))
-         switch_packed = (switch_packed | locBoard->GetSwitch(j))<<1 ;
-       else
-         switch_packed |= locBoard->GetSwitch(j) ;
-      }
-
-      cout<<"), packed switched : "<<switch_packed<<", DDL : ";
-      fprintf(fout,"%-4d\t",switch_packed);
-
-      for(int j = 0 ; j < 4 ; j++){ 
-       // intensionally made 4 instead of locBoard->GetNofDEs() to give identical structure for the fake local IDs
-       if(locBoard->GetNofDEs()<4){
-         cout<<locBoard->GetDEId(0)<<", ";
-         fprintf(fout,"%-4d\t",locBoard->GetDEId(0));
-       }else{
-         cout<<locBoard->GetDEId(j)<<", ";
-         fprintf(fout,"%-4d\t",locBoard->GetDEId(j));
-       }//if detelem condn
-      }// detelem loop
-
-      cout<<endl;
-      fprintf(fout,"\n");
-
-      }// loc board loop
-      delete crate;
-      //delete locBoard;
-
-    }//iReg loop
-  }//iTrigDDL loop
-
-  fclose(fout);
-  return true;
-}
index 4937f9c289498a8761679104244f1e15565b5ece..95c91b9842865167df77a706b25138416028019d 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.                                                   *
  *                                                                        *
  * Primary Authors:                                                       *
- *   Indranil Das <indra.das@saha.ac.in>                                  *
+ *   Artur Szostak <artursz@iafrica.com>                                  *
  *                                                                        *
  * Permission to use, copy, modify and distribute this software and its   *
  * documentation strictly for non-commercial purposes is hereby granted   *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/**********************************************
-Purpose:  A modified macro to generate MappingTable
-          in the following form
+/**
+ * This macro is used to generate the lookup tables for the trigger reconstructor
+ * component. All alignment and geometry data is taken from the CDB.
+ */
 
-detElemId+iPlane+iX+iY  Ix  IY  X  Y  B/NB pcbtype
+#include <iostream>
+#include <fstream>
 
-          for the trigger stations.
-
-Created:  13/05/2007
-Modified: 31/08/2007 (Adopted to AliRoot v4-06-Release)
-Modified: 08/09/2007 (To produce mapping on the basis of uniqueID as detElemId+iPlane+localCard+ibitXY )
-Author:   Indranil Das, HEP, SINP, Kolkata
-Email:    indra.das@saha.ac.in | indra.ehep@gmail.com
-***********************************************/
-
-#include <iostream> 
-
-//STEER 
 #include "AliCDBManager.h"
-
-//MUON
+#include "AliGeomManager.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryDetElement.h"
-#include "AliMUONCalibrationData.h"
-#include "AliMUONVCalibParam.h"
-
-//MUON/mapping 
+#include "AliMpCDB.h"
+#include "AliMpDDLStore.h"
 #include "AliMpPad.h"
 #include "AliMpSegmentation.h"
 #include "AliMpDEIterator.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpDEManager.h"
-
+#include "AliMpLocalBoard.h"
+#include "AliMpTriggerCrate.h"
 
 using namespace std;
 
 
-Bool_t CreateTriggerRecoLookupTables(TString transformFileName = "geometry.root")
+struct TriggerRecoLookupTableRow
 {
+       float fX, fY, fZ;
+};
 
-  Char_t filename1[20], filename2[20];
-  Int_t chamberId;
-
-  Int_t runNumber = 0;
-  
-  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
-  AliMUONCalibrationData cd(runNumber);
-
-  AliMpSegmentation *mpSegFactory = AliMpSegmentation::ReadData(); 
-
-  AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer();
-  chamberGeometryTransformer->LoadGeometryData(transformFileName);
-  
-    sprintf(filename1,"Lut%d.dat",2*(10+0));
-    //ofstream fout1(filename1);
-    FILE *fout1 = fopen(filename1,"w");
-
-    sprintf(filename2,"Lut%d.dat",2*(10+0)+1);
-    //ofstream fout2(filename2);
-    FILE *fout2 = fopen(filename2,"w");
-
-  for(Int_t iCh = 0; iCh < 4; iCh++){ // max 4
-
-    chamberId = iCh + 10;
-    
-    cout<<"Running for Chamber : "<<chamberId<<endl;
+struct TriggerRecoLookupTable
+{
+       // [regional header index][local board ID][chamber][cathode - X/Y][bit set in bit pattern]
+       TriggerRecoLookupTableRow fRow[8][16][4][2][16];
+};
 
-    AliMpDEIterator it;
-    for ( it.First(chamberId); ! it.IsDone(); it.Next() ) {
-    
-      Int_t detElemId = it.CurrentDEId();
-      
-      Double_t globPos[3] = {0.0, 0.0, 0.0};
-      Double_t locPos[3] = {0.0, 0.0, 0.0};
 
-      chamberGeometryTransformer->GetDetElement(detElemId)->Local2Global(locPos[0],locPos[1],locPos[2],globPos[0],globPos[1],globPos[2]);
-       
-      for(Int_t iPlane = 0 ; iPlane <= 1 ; iPlane++){
+void CreateTriggerRecoLookupTables(const char* CDBpath = "local://$ALICE_ROOT")
+{
+       AliCDBManager* cdbManager = AliCDBManager::Instance();
+       cdbManager->SetDefaultStorage(CDBpath);
+       cdbManager->SetRun(0);
+       AliGeomManager::LoadGeometry();
        
-       AliMp::CathodType cath;
-
-       if(iPlane == 0)
-         cath = AliMp::kCath0 ;
+       AliMUONGeometryTransformer transformer;
+       if (! transformer.LoadGeometryData())
+       {
+               cerr << "ERROR: Could not load geometry into transformer." << endl;
+               return;
+       }
+       
+       if (! AliMpCDB::LoadMpSegmentation())
+       {
+               cerr << "ERROR: Could not load segmentation mapping." << endl;
+               return;
+       }
+       AliMpSegmentation* segmentation = AliMpSegmentation::Instance();
+       if (segmentation == NULL)
+       {
+               cerr << "ERROR: AliMpSegmentation::Instance() was NULL." << endl;
+               return;
+       }
+       if (! AliMpCDB::LoadDDLStore())
+       {
+               cerr << "ERROR: Could not load DDL mapping." << endl;
+               return;
+       }
+       AliMpDDLStore* ddlStore = AliMpDDLStore::Instance();
+       if (ddlStore == NULL)
+       {
+               cerr << "ERROR: AliMpDDLStore::Instance() was NULL." << endl;
+               return;
+       }
+       
+       cout << "Building LUTs..." << endl;
+       
+       TriggerRecoLookupTable* lookupTable21 = new TriggerRecoLookupTable;
+       TriggerRecoLookupTable* lookupTable22 = new TriggerRecoLookupTable;
+       
+       for (Int_t i = 0; i < 8; i++)
+       for (Int_t j = 0; j < 16; j++)
+       for (Int_t k = 0; k < 4; k++)
+       for (Int_t n = 0; n < 2; n++)
+       for (Int_t m = 0; m < 16; m++)
+       {
+               lookupTable21->fRow[i][j][k][n][m].fX = 0;
+               lookupTable21->fRow[i][j][k][n][m].fY = 0;
+               lookupTable21->fRow[i][j][k][n][m].fZ = 0;
+               lookupTable22->fRow[i][j][k][n][m].fX = 0;
+               lookupTable22->fRow[i][j][k][n][m].fY = 0;
+               lookupTable22->fRow[i][j][k][n][m].fZ = 0;
+       }
+       
+       AliMpDEIterator detElemIter;
+       for (Int_t iDDL = 20; iDDL <= 21; iDDL++)
+       {
+               for (Int_t iReg = 0; iReg < 8; iReg++)
+               {
+                       AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(iDDL, iReg);
+                       if (crate == NULL)
+                       {
+                               cerr << "ERROR: Could not get crate for regional header = " << iReg
+                                       << ", and DDL ID = " << iDDL << endl;
+                               continue;
+                       }
+                       
+                       for (Int_t iLocBoard = 0; iLocBoard < 16; iLocBoard++)
+                       {
+                               Int_t boardId = crate->GetLocalBoardId(iLocBoard);
+                               if (boardId == 0) continue;
+                               
+                               AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(boardId);
+                               if (localBoard == NULL)
+                               {
+                                       cerr << "ERROR: Could not get loacl board: " << boardId << endl;
+                                       continue;
+                               }
+
+                               // skip copy cards
+                               if (! localBoard->IsNotified()) continue;
+                       
+                               for (Int_t iChamber = 0; iChamber < 4; iChamber++)
+                               {
+                                       Int_t detElemId = ddlStore->GetDEfromLocalBoard(boardId, iChamber);
+                                       
+                                       const AliMUONGeometryDetElement* detElemTransform = transformer.GetDetElement(detElemId);
+                                       if (detElemTransform == NULL)
+                                       {
+                                               cerr << "ERROR: Got NULL pointer for geometry transformer for detection element ID = "
+                                                       << detElemId << endl;
+                                               continue;
+                                       }
+                                       
+                                       for (Int_t iCathode = 0; iCathode <= 1; iCathode++)
+                                       {
+                                               const AliMpVSegmentation* seg = segmentation->GetMpSegmentation(
+                                                               detElemId, AliMp::GetCathodType(iCathode)
+                                                       );
+                                               
+                                               for (Int_t bitxy = 0; bitxy < 16; bitxy++)
+                                               {
+                                                       Int_t offset = 0;
+                                                       if (iCathode && localBoard->GetSwitch(6)) offset = -8;
+                                                       
+                                                       AliMpPad pad = seg->PadByLocation(AliMpIntPair(boardId, bitxy+offset), kFALSE);
+                                               
+                                                       if (! pad.IsValid())
+                                                       {
+                                                               // There is no pad associated with the given local board and bit pattern.
+                                                               continue;
+                                                       }
+                                                       
+                                                       // Get the global coodinates of the pad.
+                                                       Float_t lx = pad.Position().X();
+                                                       Float_t ly = pad.Position().Y();
+                                                       Float_t gx, gy, gz;
+                                                       detElemTransform->Local2Global(lx, ly, 0, gx, gy, gz);
+                                                       
+                                                       // Fill the LUT
+                                                       if (crate->GetDdlId() == 20)
+                                                       {
+                                                               lookupTable21->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
+                                                               lookupTable21->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
+                                                               lookupTable21->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
+                                                       }
+                                                       else
+                                                       {
+                                                               lookupTable22->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fX = gx;
+                                                               lookupTable22->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fY = gy;
+                                                               lookupTable22->fRow[iReg][iLocBoard][iChamber][iCathode][bitxy].fZ = gz;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       fstream file;
+       file.open("Lut21.dat", fstream::out | fstream::binary | fstream::trunc);
+       if (file)
+       {
+               file.write((char*)lookupTable21, sizeof(TriggerRecoLookupTable));
+               if (! file)
+               {
+                       cerr << "ERROR: There was a problem writing to file Lut21.dat" << endl;
+               }
+               file.close();
+       }
        else
-         cath = AliMp::kCath1 ;
-
-       AliMpVSegmentation* seg = mpSegFactory->CreateMpSegmentation(detElemId, cath);
-
-       Int_t maxIX = seg->MaxPadIndexX();  
-       Int_t maxIY = seg->MaxPadIndexY(); 
-       Int_t idManuChannel,idetElemId;
-
-       Double_t realX, realY, realZ;
-       Double_t localX, localY, localZ;
-       Double_t padSizeX, padSizeY;
-       Int_t pcbType;
-       Int_t locCard, ibitxy;
-
-       //Pad Info of a segment
-       for(Int_t iX = 0; iX<= maxIX ; iX++){
-         for(Int_t iY = 0; iY<= maxIY ; iY++){
-           if(seg->HasPad(AliMpIntPair(iX,iY))){
-             AliMpPad pad = seg->PadByIndices(AliMpIntPair(iX,iY),kFALSE);
-             
-             locCard = pad.GetLocation(0).GetFirst();
-             ibitxy = pad.GetLocation(0).GetSecond();
-
-             idetElemId = detElemId%1000;
-             idetElemId &= 0x1FF ;
-             iPlane &= 0x1 ;
-             locCard &= 0xFF ;
-             ibitxy &= 0xF ;
-             
-             idManuChannel &= 0x0;
-             idManuChannel = (idManuChannel|idetElemId)<<1;  
-             idManuChannel = (idManuChannel|iPlane)<<8;  
-             idManuChannel = (idManuChannel|locCard)<<4 ;
-             idManuChannel |= ibitxy;
-             
-             localX = pad.Position().X();
-             localY = pad.Position().Y();
-             localZ = 0.0;
-
-             chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ,
-                                                      realX,realY,realZ);
-             padSizeX = 2.0*pad.Dimensions().X();
-             padSizeY = 2.0*pad.Dimensions().Y();
-
-             if(iPlane == 0 ){
-               if(padSizeX==17.0)
-                 pcbType = 0;
-               else if(padSizeX==34.0)
-                 pcbType = 1;
-               else
-                 pcbType = 2;
-             }
-             else{
-               if(padSizeY==51.0)
-                 pcbType = 0;
-               else
-                 pcbType = 1;
-             }
-             
-             idetElemId %= 100;
-
-             if(idetElemId<5 || idetElemId > 13){
-               fprintf(fout1,"%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",idManuChannel,iX,iY,realX,realY,realZ,pcbType,iPlane);
-             }
-             else{
-               fprintf(fout2,"%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\n",idManuChannel,iX,iY,realX,realY,realZ,pcbType,iPlane);
-             }// HasPad Condn
-             
-           }
-         }// iY loop
-       }// iX loop
+       {
+               cerr << "ERROR: Could not open file Lut21.dat for writing." << endl;
+       }
        
-      }// iPlane
-    } // detElemId loop
-
-  }// ichamber loop
-
-  fclose(fout1);
-  fclose(fout2);
-  
-  return kTRUE;
+       file.open("Lut22.dat", fstream::out | fstream::binary | fstream::trunc);
+       if (file)
+       {
+               file.write((char*)lookupTable22, sizeof(TriggerRecoLookupTable));
+               if (! file)
+               {
+                       cerr << "ERROR: There was a problem writing to file Lut22.dat" << endl;
+               }
+               file.close();
+       }
+       else
+       {
+               cerr << "ERROR: Could not open file Lut22.dat for writing." << endl;
+       }
+       
+       delete lookupTable21;
+       delete lookupTable22;
 }