Adding changed from Indra to use common online/offline decoder and take care of gain...
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 14 Apr 2008 17:14:11 +0000 (17:14 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 14 Apr 2008 17:14:11 +0000 (17:14 +0000)
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h
HLT/MUON/macros/CreateBusToDetElemFile.C [deleted file]
HLT/MUON/macros/CreateHitRecoLookupTables.C
HLT/MUON/macros/RunChain.C

index ed71918..243bd5f 100644 (file)
 #include <strings.h>
 
 
-const int AliHLTMUONHitReconstructor::fgkDetectorId = 0xA00;
-const int AliHLTMUONHitReconstructor::fgkDDLOffSet = 12 ;
-const int AliHLTMUONHitReconstructor::fgkNofDDL = 8 ;
-
-const int AliHLTMUONHitReconstructor::fgkDDLHeaderSize = 8;
-
-const int AliHLTMUONHitReconstructor::fgkEvenLutSize = 1645632 + 1;
-const int AliHLTMUONHitReconstructor::fgkOddLutSize = 3363840 + 1;
-
-const int AliHLTMUONHitReconstructor::fgkLutLine[2] = {54208, 59648};
-
-const int AliHLTMUONHitReconstructor::fgkMinIdManuChannel[2] = {917696, 64};
-const int AliHLTMUONHitReconstructor::fgkMaxIdManuChannel[2] = {2563327, 3363903};
-
-const float AliHLTMUONHitReconstructor::fgkHalfPadSize[3] = {1.25, 2.50, 5.00};
-
-
-AliHLTMUONHitReconstructor::AliHLTMUONHitReconstructor():
-  fkBlockHeaderSize(8),
-  fkDspHeaderSize(8),
-  fkBuspatchHeaderSize(4),
-  fDCCut(0),
-  fPadData(NULL),
-  fLookUpTableData(NULL),
-  fRecPoints(NULL),
-  fRecPointsCount(NULL),
-  fMaxRecPointsCount(0),
-  fCentralCountB(0),
-  fCentralCountNB(0),
-  fIdOffSet(0),
-  fDDLId(0),
-  fDigitPerDDL(0),
-  fDetManuChannelIdList(NULL),
-  fCentralChargeB(NULL),
-  fCentralChargeNB(NULL),
-  fRecX(NULL),
-  fRecY(NULL),
-  fAvgChargeX(NULL),
-  fAvgChargeY(NULL),
-  fNofFiredDetElem(0),
-  fDebugLevel(0),
-  fBusToDetElem(),
-  fBusToDDL()
+const AliHLTInt32_t AliHLTMUONHitReconstructor::fgkDetectorId = 0xA00;
+const AliHLTInt32_t AliHLTMUONHitReconstructor::fgkDDLOffSet = 12;
+const AliHLTInt32_t AliHLTMUONHitReconstructor::fgkNofDDL = 8;
+const AliHLTInt32_t AliHLTMUONHitReconstructor::fgkDDLHeaderSize = 8;
+const AliHLTInt32_t AliHLTMUONHitReconstructor::fgkLutLine = 59648 + 1;
+
+
+AliHLTMUONHitReconstructor::AliHLTMUONHitReconstructor() :
+       AliHLTLogging(),
+       fHLTMUONDecoder(),
+       fkBlockHeaderSize(8),
+       fkDspHeaderSize(8),
+       fkBuspatchHeaderSize(4),
+       fDCCut(0),
+       fPadData(NULL),
+       fLookUpTableData(NULL),
+       fRecPoints(NULL),
+       fRecPointsCount(NULL),
+       fMaxRecPointsCount(0),
+       fCentralCountB(0),
+       fCentralCountNB(0),
+       fDDLId(0),
+       fDigitPerDDL(0),
+       fCentralChargeB(NULL),
+       fCentralChargeNB(NULL),
+       fRecX(NULL),
+       fRecY(NULL),
+       fAvgChargeX(NULL),
+       fAvgChargeY(NULL),
+       fNofBChannel(NULL),
+       fNofNBChannel(NULL),
+       fNofFiredDetElem(0),
+       //fDebugLevel(0),  //TODO: remove
+       fIdToEntry()
 {
-  // ctor 
-  
-  if(AliHLTMUONHitReconstructor::fgkEvenLutSize > AliHLTMUONHitReconstructor::fgkOddLutSize){
-    fPadData = new DHLTPad[AliHLTMUONHitReconstructor::fgkEvenLutSize];
-  }
-  else{
-    fPadData = new DHLTPad[AliHLTMUONHitReconstructor::fgkOddLutSize];
-  }
-
-  fkBlockHeaderSize    = 8;
-  fkDspHeaderSize      = 8;
-  fkBuspatchHeaderSize = 4;
-
-  bzero(fGetIdTotalData,336*80*2*sizeof(int));
+       /// Default constructor
+       
+       fkBlockHeaderSize    = 8;
+       fkDspHeaderSize      = 8;
+       fkBuspatchHeaderSize = 4;
+       
+       try
+       {
+               fPadData = new AliHLTMUONPad[fgkLutLine];
+       }
+       catch (const std::bad_alloc&)
+       {
+               HLTError("Dynamic memory allocation failed for AliHLTMUONHitReconstructor::fPadData in constructor.");
+               throw;
+       }
+       
+       fPadData[0].fDetElemId = 0;
+       fPadData[0].fIX = 0 ;
+       fPadData[0].fIY = 0 ;
+       fPadData[0].fRealX = 0.0 ;
+       fPadData[0].fRealY = 0.0 ;
+       fPadData[0].fRealZ = 0.0 ;
+       fPadData[0].fHalfPadSize = 0.0 ;
+       fPadData[0].fPlane = -1 ;
+       fPadData[0].fCharge = 0 ;
+       
+       bzero(fGetIdTotalData, 336*237*2*sizeof(int));
 }
 
 
 AliHLTMUONHitReconstructor::~AliHLTMUONHitReconstructor()
 {
-  // dtor
-
-  if(fPadData){
-    delete []fPadData;
-    fPadData = NULL;
-  }
-   
-  if(fLookUpTableData){
-    delete []fLookUpTableData;
-    fLookUpTableData = NULL;
-  }
-}
-
-
-int AliHLTMUONHitReconstructor::GetLutLine(int iDDL) const
-{
-       return ( iDDL<16 ) ? fgkLutLine[0] : fgkLutLine[1] ;
+       /// Default destructor
+       
+       if(fPadData)
+       {
+               delete [] fPadData;
+               fPadData = NULL;
+       }
+       
+       if(fLookUpTableData)
+       {
+               delete [] fLookUpTableData;
+               fLookUpTableData = NULL;
+       }
 }
 
 
-bool AliHLTMUONHitReconstructor::LoadLookUpTable(DHLTLut* lookUpTableData, int lookUpTableId)
+bool AliHLTMUONHitReconstructor::LoadLookUpTable(AliHLTMUONHitRecoLutRow* lookUpTableData, int lookUpTableId)
 {
   // function that loads LookUpTable (= position of each pad with electronic channel associated with it)
 
   if(lookUpTableId<fgkDDLOffSet || lookUpTableId>= fgkDDLOffSet + fgkNofDDL){
-    HLTError("DDL number is out of range (must be %d<=iDDL<%d)\n",fgkDDLOffSet,fgkDDLOffSet+fgkNofDDL);
+    HLTError("DDL number %d is out of range (must be %d<=iDDL<%d)\n",lookUpTableId,fgkDDLOffSet,fgkDDLOffSet+fgkNofDDL);
     return false;
   }
-  
-  fDDLId = lookUpTableId;
 
-  int lutSize = ((lookUpTableId%2)==0) ? fgkEvenLutSize : fgkOddLutSize ;
-  int nofLutLine = GetLutLine(lookUpTableId);
-  int idOffSet = fgkMinIdManuChannel[lookUpTableId%2];
 
-  int detManuChannelId;
+  if(fIdToEntry.size()==0){
+    HLTError("SetLineNumToIdManuChannel() is not set properly");
+    return false;
+  }else{
+    
+//     if(fLookUpTableData){
+//       delete []fLookUpTableData;
+//       fLookUpTableData = NULL;
+//     }
+
+    try{
+      fLookUpTableData = new AliHLTMUONHitRecoLutRow[fIdToEntry.size()+1];
+    }
+    catch(const std::bad_alloc&){
+      HLTError("Dynamic memory allocation failed for AliHLTMUONHitReconstructor::fLookUpTableData");
+      return false;
+    }
+
+  }
 
-  fLookUpTableData = new DHLTLut[lutSize];
+  fDDLId = lookUpTableId;
 
-  fLookUpTableData[0].fIdManuChannel = 0;
+  fLookUpTableData[0].fDetElemId = 0;
   fLookUpTableData[0].fIX = 0 ;
   fLookUpTableData[0].fIY = 0 ;
   fLookUpTableData[0].fRealX = 0.0 ;
   fLookUpTableData[0].fRealY = 0.0 ;
   fLookUpTableData[0].fRealZ = 0.0 ;
+  fLookUpTableData[0].fHalfPadSize = 0.0 ;
   fLookUpTableData[0].fPlane = -1 ;
-  fLookUpTableData[0].fPcbZone = -1 ;
-
-  for(int i=0; i<nofLutLine; i++){
-
-    detManuChannelId = lookUpTableData[i].fIdManuChannel - idOffSet + 1;
-    fLookUpTableData[detManuChannelId].fIdManuChannel = lookUpTableData[i].fIdManuChannel - idOffSet;
-    fLookUpTableData[detManuChannelId].fIX = lookUpTableData[i].fIX ;
-    fLookUpTableData[detManuChannelId].fIY = lookUpTableData[i].fIY ;
-    fLookUpTableData[detManuChannelId].fRealX = lookUpTableData[i].fRealX ;
-    fLookUpTableData[detManuChannelId].fRealY = lookUpTableData[i].fRealY ;
-    fLookUpTableData[detManuChannelId].fRealZ = lookUpTableData[i].fRealZ ;
-    fLookUpTableData[detManuChannelId].fPcbZone = lookUpTableData[i].fPcbZone ;
-    fLookUpTableData[detManuChannelId].fPlane = lookUpTableData[i].fPlane ;
+  fLookUpTableData[0].fPed = -1 ;
+  fLookUpTableData[0].fSigma = -1 ;
+  fLookUpTableData[0].fA0 = -1 ;
+  fLookUpTableData[0].fA1 = -1 ;
+  fLookUpTableData[0].fThres = -1 ;
+  fLookUpTableData[0].fSat = -1 ;
+
+  for(int i=0; i<int(fIdToEntry.size()); i++){
+
+    fLookUpTableData[i+1].fDetElemId = lookUpTableData[i].fDetElemId;
+    fLookUpTableData[i+1].fIX = lookUpTableData[i].fIX ;
+    fLookUpTableData[i+1].fIY = lookUpTableData[i].fIY ;
+    fLookUpTableData[i+1].fRealX = lookUpTableData[i].fRealX ;
+    fLookUpTableData[i+1].fRealY = lookUpTableData[i].fRealY ;
+    fLookUpTableData[i+1].fRealZ = lookUpTableData[i].fRealZ ;
+    fLookUpTableData[i+1].fHalfPadSize = lookUpTableData[i].fHalfPadSize ;
+    fLookUpTableData[i+1].fPlane = lookUpTableData[i].fPlane ;
+    fLookUpTableData[i+1].fPed = lookUpTableData[i].fPed ;
+    fLookUpTableData[i+1].fSigma = lookUpTableData[i].fSigma ;
+    fLookUpTableData[i+1].fA0 = lookUpTableData[i].fA0 ;
+    fLookUpTableData[i+1].fA1 = lookUpTableData[i].fA1 ;
+    fLookUpTableData[i+1].fThres= lookUpTableData[i].fThres ;
+    fLookUpTableData[i+1].fSat = lookUpTableData[i].fSat ;
+    
   }
-  return true;
-}
-
 
-bool AliHLTMUONHitReconstructor::SetBusToDetMap(BusToDetElem busToDetElem)
-{
-
-  // function that loads BusPatch To Detection Element (SlatId) map
-
-  if(busToDetElem.size()==0) {
-    HLTError("Empty BusToDetElem mapping");
-    return false;
-  } else {
-    fBusToDetElem = busToDetElem;
-  }
-  
   return true;
+  
 }
 
 
-bool AliHLTMUONHitReconstructor::SetBusToDDLMap(BusToDDL busToDDL)
+bool AliHLTMUONHitReconstructor::SetIdManuChannelToEntry(IdManuChannelToEntry idToEntry)
 {
 
-  // function that loads BusPatch To DDL Element (DDL) map
+  // function that loads LineNumber To IdManuChannel map
 
-  if(busToDDL.size()==0) {
-    HLTError("Empty BusToDDL mapping");
+  if(idToEntry.size()==0) {
+    HLTError("Empty idToEntry mapping");
     return false;
   } else {
-    fBusToDDL = busToDDL;
+    fIdToEntry = idToEntry;
   }
   
   return true;
 }
 
-
 bool AliHLTMUONHitReconstructor::Run(
                const AliHLTUInt32_t* rawData,
                AliHLTUInt32_t rawDataSize,
@@ -211,26 +221,14 @@ bool AliHLTMUONHitReconstructor::Run(
   fMaxRecPointsCount = nofHit;
   fRecPointsCount = &nofHit;
   *fRecPointsCount = 0;
+  fDigitPerDDL = 0;
 
-  fPadData[0].fDetElemId = 0;
-  fPadData[0].fBuspatchId = 0;
-  fPadData[0].fIdManuChannel = 0;
-  fPadData[0].fIX = 0 ;
-  fPadData[0].fIY = 0 ;
-  fPadData[0].fRealX = 0.0 ;
-  fPadData[0].fRealY = 0.0 ;
-  fPadData[0].fRealZ = 0.0 ;
-  fPadData[0].fPlane = -1 ;
-  fPadData[0].fPcbZone = -1 ;
-  fPadData[0].fCharge = 0 ;
-
-  if (not ReadDDL(rawData, rawDataSize)) {
-    // Dont need to log any message again. Already done so in ReadDDL.
-    Clear();
+  if (not DecodeDDL(rawData, rawDataSize)) {
+    // Dont need to log any message again. Already done so in DecodeDDL.
     return false;
   }
-  
-  if (fDigitPerDDL == 0)
+
+  if (fDigitPerDDL == 1)
   {
     // There are no digits to process so stop here.
     return true;
@@ -241,115 +239,32 @@ bool AliHLTMUONHitReconstructor::Run(
     Clear();
     return false;
   }
-    
+
   return true;
 }
 
 
-bool AliHLTMUONHitReconstructor::ReadDDL(
-               const AliHLTUInt32_t* rawData,
-               AliHLTUInt32_t rawDataSize
-       )
+bool AliHLTMUONHitReconstructor::DecodeDDL(const AliHLTUInt32_t* rawData,AliHLTUInt32_t rawDataSize)
 {
-  //function to read Raw Data files
-
-  //const int* buffer = reinterpret_cast<const int*>(rawData);
-  const AliHLTUInt32_t* buffer = rawData;
-
-  fIdOffSet= fgkMinIdManuChannel[(fDDLId%2)];
-  fDetManuChannelIdList = new int[rawDataSize];
-
-  int index = 0;
-  int dataCount = 0;
-  fNofFiredDetElem = 0;
-  int detElemId = 0 ;
-  int buspatchId = 0;
-  int prevDetElemId = 0 ;
-  int totalBlockSize,blockRawDataSize;
-  int totalDspSize,dspRawDataSize;
-  int totalBuspatchSize,buspatchRawDataSize;
-  int indexDsp,indexBuspatch,indexRawData;
-  unsigned int dataWord;
-  int charge;
-  int idManuChannel;
-  
-  for(int iBlock = 0; iBlock < 2 ;iBlock++){  // loop over 2 blocks
-    totalBlockSize = buffer[index + 1];
-    blockRawDataSize = buffer[index + 2];
-    indexDsp = index + fkBlockHeaderSize;
-    HLTDebug("totalBlockSize : %d, blockRawDataSize : %d",totalBlockSize,blockRawDataSize);
-    while(blockRawDataSize > 0){
-      totalDspSize = buffer[indexDsp + 1];
-      dspRawDataSize = buffer[indexDsp + 2];
-      HLTDebug("   totalDSPSize : %d, dspRawDataSize : %d",totalDspSize,dspRawDataSize);
-      //if(buffer[indexDsp+1] == 1)
-      dspRawDataSize --;                              // temporary solution to read buspatches 
-      indexBuspatch = indexDsp + fkDspHeaderSize + 2; // this extra 2 word comes from the faulty defination of Dsp header size
-      while(dspRawDataSize > 0){
-       totalBuspatchSize = buffer[indexBuspatch + 1];
-       buspatchRawDataSize = buffer[indexBuspatch + 2];
-       buspatchId = buffer[indexBuspatch + 3];
-       if((detElemId = fBusToDetElem[buspatchId])==0){
-         HLTError("No Detection element found for buspatch : %d",buspatchId);
-         return false;
-       }
-       HLTDebug("\ttotalBusPatchSize : %d, buspatchRawDataSize : %d",totalBuspatchSize,buspatchRawDataSize);
-       indexRawData = indexBuspatch + fkBuspatchHeaderSize;
-       while(buspatchRawDataSize > 0){
-         dataWord = buffer[indexRawData];
-         charge = (unsigned short)(dataWord & 0xFFF);
-         
-         idManuChannel = 0x0;
-         idManuChannel = (idManuChannel|(detElemId%100))<<17;
-         idManuChannel |= (dataWord >> 12) & 0x1FFFF;
-         idManuChannel -= fIdOffSet ;
-         
-         if(charge > fDCCut && charge > 5){  // (charge > 4) is due cut out the noise level                    
-           fPadData[idManuChannel].fBuspatchId = buspatchId;
-           fPadData[idManuChannel].fDetElemId = detElemId;
-           fPadData[idManuChannel].fIdManuChannel = idManuChannel;
-           fPadData[idManuChannel].fIX = fLookUpTableData[idManuChannel+1].fIX;
-           fPadData[idManuChannel].fIY = fLookUpTableData[idManuChannel+1].fIY;
-           fPadData[idManuChannel].fRealX = fLookUpTableData[idManuChannel+1].fRealX;
-           fPadData[idManuChannel].fRealY = fLookUpTableData[idManuChannel+1].fRealY;
-           fPadData[idManuChannel].fRealZ = fLookUpTableData[idManuChannel+1].fRealZ;
-           fPadData[idManuChannel].fPcbZone = fLookUpTableData[idManuChannel+1].fPcbZone;
-           fPadData[idManuChannel].fPlane = fLookUpTableData[idManuChannel+1].fPlane;
-           fPadData[idManuChannel].fCharge = charge;
-           
-           fDetManuChannelIdList[dataCount] = idManuChannel;
-           if(detElemId != prevDetElemId){
-             if(fNofFiredDetElem>0){
-               fMaxFiredPerDetElem[fNofFiredDetElem-1] = dataCount;
-             }
-             fNofFiredDetElem++;
-             prevDetElemId = detElemId ;
-           }
-           
-           HLTDebug("\t  buspatch : %d, detele : %d, id : %d, manu : %d, channel : %d, X : %f, Y: %f",
-                   fPadData[idManuChannel].fBuspatchId,fPadData[idManuChannel].fDetElemId,
-                   idManuChannel,((dataWord >> 12) & 0x7FF),((dataWord >> 23) & 0x3F),
-                   fPadData[idManuChannel].fRealX,fPadData[idManuChannel].fRealY);
+  //function to decode Raw Data 
+
+  AliHLTMUONRawDecoder& handler = reinterpret_cast<AliHLTMUONRawDecoder&>(fHLTMUONDecoder.GetHandler());
+  UInt_t bufferSize = UInt_t(rawDataSize*sizeof(AliHLTUInt32_t));
+
+  handler.SetDCCut(fDCCut);
+  handler.SetPadData(fPadData);
+  handler.SetLookUpTable(fLookUpTableData);
+  handler.SetIdManuChannelToEntry(fIdToEntry);
+  handler.SetNofFiredDetElemId(fNofFiredDetElem);
+  handler.SetMaxFiredPerDetElem(fMaxFiredPerDetElem);
+  if(!fHLTMUONDecoder.Decode(rawData,bufferSize))
+    return false;
 
-           dataCount ++;
-         }// if charge is more than DC Cut limit condition
-         
-         indexRawData++;
-         buspatchRawDataSize --;
-       }
-       indexBuspatch += totalBuspatchSize;
-       dspRawDataSize -= totalBuspatchSize;
-      }// buspatch loop
-      indexDsp += totalDspSize;
-      blockRawDataSize -= totalDspSize;
-    }// DSP loop
-    index = totalBlockSize;
-  }// Block loop
-  
-  fDigitPerDDL = dataCount;
-  fMaxFiredPerDetElem[fNofFiredDetElem-1] = dataCount;
+  fDigitPerDDL = handler.GetDataCount();
+  fMaxFiredPerDetElem[fNofFiredDetElem-1] = handler.GetDataCount();
     
-  if(fDigitPerDDL == 0){
+  if(fDigitPerDDL == 1){
     HLTInfo("An Empty DDL File found");
   }
     
@@ -357,7 +272,7 @@ bool AliHLTMUONHitReconstructor::ReadDDL(
 }
 
 
-bool AliHLTMUONHitReconstructor::FindRecHits() 
+bool AliHLTMUONHitReconstructor::FindRecHits()
 {
   // fuction that calls hit reconstruction detector element-wise   
 
@@ -365,26 +280,42 @@ bool AliHLTMUONHitReconstructor::FindRecHits()
     
     fCentralCountB = 0 ;
     fCentralCountNB = 0 ;
-    fCentralChargeB = new int[fMaxFiredPerDetElem[iDet]];
-    fCentralChargeNB = new int[fMaxFiredPerDetElem[iDet]];
+
     
+    try{
+      fCentralChargeB = new int[fMaxFiredPerDetElem[iDet]];
+      fCentralChargeNB = new int[fMaxFiredPerDetElem[iDet]];
+    }
+    catch(const std::bad_alloc&){
+      HLTError("Dynamic memory allocation failed for AliHLTMUONHitReconstructor::fCentralChargeNB and fCentralChargeB");
+      return false;
+    }
+
     if(iDet>0)
       FindCentralHits(fMaxFiredPerDetElem[iDet-1],fMaxFiredPerDetElem[iDet]);
     else
-      FindCentralHits(0,fMaxFiredPerDetElem[iDet]);
-    
-    RecXRecY();
+      FindCentralHits(1,fMaxFiredPerDetElem[iDet]); // minimum value is 1 because dataCount in ReadDDL starts from 1 instead of 0;
+
+    if(!RecXRecY()){
+      HLTError("Failed to find RecX and RecY hits\n");
+      return false;
+    }
+
+
     if(!MergeRecHits()){
       HLTError("Failed to merge hits\n");
       return false;
     }
-    
+
+
     if(iDet==0)
-      for(int i=0;i<fMaxFiredPerDetElem[iDet];i++)
-       fGetIdTotalData[fPadData[fDetManuChannelIdList[i]].fIX][fPadData[fDetManuChannelIdList[i]].fIY][fPadData[fDetManuChannelIdList[i]].fPlane] = 0;
+      for(int i=1;i<fMaxFiredPerDetElem[iDet];i++) // minimum value is 1 because dataCount in ReadDDL starts from 1 instead of 0;
+       fGetIdTotalData[fPadData[i].fIX][fPadData[i].fIY][fPadData[i].fPlane] = 0;
     else
       for(int i=fMaxFiredPerDetElem[iDet-1];i<fMaxFiredPerDetElem[iDet];i++)
-       fGetIdTotalData[fPadData[fDetManuChannelIdList[i]].fIX][fPadData[fDetManuChannelIdList[i]].fIY][fPadData[fDetManuChannelIdList[i]].fPlane] = 0;
+       fGetIdTotalData[fPadData[i].fIX][fPadData[i].fIY][fPadData[i].fPlane] = 0;
+
+
 
     if(fCentralChargeB){
       delete []fCentralChargeB;
@@ -396,8 +327,25 @@ bool AliHLTMUONHitReconstructor::FindRecHits()
       fCentralChargeNB = NULL;
     }
 
+
   }
-    
+
+  for(int iPad=1;iPad<fDigitPerDDL;iPad++){
+    fGetIdTotalData[fPadData[iPad].fIX][fPadData[iPad].fIY][fPadData[iPad].fPlane] = 0;
+    fPadData[iPad].fDetElemId = 0;
+    fPadData[iPad].fIX = 0 ;
+    fPadData[iPad].fIY = 0 ;
+    fPadData[iPad].fRealX = 0.0 ;
+    fPadData[iPad].fRealY = 0.0 ;
+    fPadData[iPad].fRealZ = 0.0 ;
+    fPadData[iPad].fHalfPadSize = 0.0 ;
+    fPadData[iPad].fPlane = -1 ;
+    fPadData[iPad].fCharge = 0 ;
+  }  
+  
+  for(int i=0;i<13;i++)
+    fMaxFiredPerDetElem[i] = 0;
+
   Clear();
 
   return true;
@@ -411,49 +359,46 @@ void AliHLTMUONHitReconstructor::FindCentralHits(int minPadId, int maxPadId)
   int b,nb;
   int idManuChannelCentral;
   bool hasFind;
-  int idManuChannel;
-  
+
   for(int iPad=minPadId;iPad<maxPadId;iPad++){
-    idManuChannel   = fDetManuChannelIdList[iPad];
-    
-    
-    fGetIdTotalData[fPadData[idManuChannel].fIX]
-      [fPadData[idManuChannel].fIY]
-      [fPadData[idManuChannel].fPlane] = idManuChannel;
+
+    fGetIdTotalData[fPadData[iPad].fIX]
+      [fPadData[iPad].fIY]
+      [fPadData[iPad].fPlane] = iPad ;
     
-    if(fPadData[idManuChannel].fPlane == 0 ){//&& fPadData[idManuChannel].fIY > (0+1) && fPadData[idManuChannel].fIY < (79 - 1)){
-      //if(fPadData[idManuChannel].fIY > 0){
+    if(fPadData[iPad].fPlane == 0 ){//&& fPadData[iPad].fIY > (0+1) && fPadData[iPad].fIY < (79 - 1)){
+      //if(fPadData[iPad].fIY > 0){
       if(fCentralCountB>0){
        hasFind = false;
        for(b = 0;b<fCentralCountB;b++){
          idManuChannelCentral = fCentralChargeB[b];
-         if(fPadData[idManuChannel].fIX == fPadData[idManuChannelCentral].fIX
+         if(fPadData[iPad].fIX == fPadData[idManuChannelCentral].fIX
             &&
-            (fPadData[idManuChannel].fIY 
+            (fPadData[iPad].fIY 
              == fPadData[idManuChannelCentral].fIY + 1 
              ||
-             fPadData[idManuChannel].fIY 
+             fPadData[iPad].fIY 
              == fPadData[idManuChannelCentral].fIY + 2 
              ||
-             fPadData[idManuChannel].fIY 
+             fPadData[iPad].fIY 
              == fPadData[idManuChannelCentral].fIY - 2 
              ||
-             fPadData[idManuChannel].fIY 
+             fPadData[iPad].fIY 
              == fPadData[idManuChannelCentral].fIY - 1)){
            
            hasFind = true;
-           if(fPadData[idManuChannel].fCharge > fPadData[idManuChannelCentral].fCharge){
-             fCentralChargeB[b] = idManuChannel;
+           if(fPadData[iPad].fCharge > fPadData[idManuChannelCentral].fCharge){
+             fCentralChargeB[b] = iPad;
            }// if condn on pad charge
          }// if condon on pad position
        }// for loop over b
        if(!hasFind){
-         fCentralChargeB[fCentralCountB] = idManuChannel;
+         fCentralChargeB[fCentralCountB] = iPad;
          fCentralCountB++;
        }
       }
       else{
-       fCentralChargeB[fCentralCountB] = idManuChannel;
+       fCentralChargeB[fCentralCountB] = iPad;
        fCentralCountB++;
       }// check the size of centralHitB
       for(b = 0;b<fCentralCountB;b++){
@@ -466,42 +411,43 @@ void AliHLTMUONHitReconstructor::FindCentralHits(int minPadId, int maxPadId)
        hasFind = false;
        for(nb = 0;nb<fCentralCountNB;nb++){
          idManuChannelCentral = fCentralChargeNB[nb];
-         if(fPadData[idManuChannel].fIY == fPadData[idManuChannelCentral].fIY
+         if(fPadData[iPad].fIY == fPadData[idManuChannelCentral].fIY
             &&
-            (fPadData[idManuChannel].fIX 
+            (fPadData[iPad].fIX 
              == fPadData[idManuChannelCentral].fIX + 1 
              ||
-             fPadData[idManuChannel].fIX
+             fPadData[iPad].fIX
              == fPadData[idManuChannelCentral].fIX + 2
              ||
-             fPadData[idManuChannel].fIX
+             fPadData[iPad].fIX
              == fPadData[idManuChannelCentral].fIX - 2
              ||
-             fPadData[idManuChannel].fIX
+             fPadData[iPad].fIX
              == fPadData[idManuChannelCentral].fIX - 1)){
            
            hasFind = true;       
-           if(fPadData[idManuChannel].fCharge > fPadData[idManuChannelCentral].fCharge){
-             fCentralChargeNB[nb] = idManuChannel;
+           if(fPadData[iPad].fCharge > fPadData[idManuChannelCentral].fCharge){
+             fCentralChargeNB[nb] = iPad;
            }// if condn over to find higher charge
          }// if condn over to find position
        }// for loop over presently all nb values
        if(!hasFind){
-         fCentralChargeNB[fCentralCountNB] = idManuChannel;
+         fCentralChargeNB[fCentralCountNB] = iPad;
          fCentralCountNB++;
        }
       }// centralHitNB size test
       else{
-       fCentralChargeNB[fCentralCountNB] = idManuChannel;
+       fCentralChargeNB[fCentralCountNB] = iPad;
        fCentralCountNB++;
       }// centralHitNB size test
       
     }// fill for bending and nonbending hit
   }// detElemId loop
+
 }
 
 
-void AliHLTMUONHitReconstructor::RecXRecY()
+bool AliHLTMUONHitReconstructor::RecXRecY()
 {
   // find reconstructed X and Y for each plane separately
   int b,nb;
@@ -510,36 +456,57 @@ void AliHLTMUONHitReconstructor::RecXRecY()
   int idUpper = 0;
   int idRight = 0;
   int idLeft = 0;
-  fRecY = new float[fCentralCountB];
-  fRecX = new float[fCentralCountNB];
-  
-  fAvgChargeY = new float[fCentralCountB];
-  fAvgChargeX = new float[fCentralCountNB];
 
+  try{
+    fRecY = new float[fCentralCountB];
+    fRecX = new float[fCentralCountNB];
+    
+    fAvgChargeY = new float[fCentralCountB];
+    fAvgChargeX = new float[fCentralCountNB];
+    
+    fNofBChannel = new int[fCentralCountB];
+    fNofNBChannel = new int[fCentralCountNB];
+  }
+  catch(const std::bad_alloc&){
+    HLTError("Dynamic memory allocation failed for AliHLTMUONHitReconstructor::fRecY and others at method RecXRecY()");
+    return false;
+  }
+  
   for(b=0;b<fCentralCountB;b++){
     idCentral = fCentralChargeB[b];
-    
+
     if(fPadData[idCentral].fIY==0)
       idLower = 0;
     else
       idLower = fGetIdTotalData[fPadData[idCentral].fIX][fPadData[idCentral].fIY-1][0];
-    
-    if(fPadData[idCentral].fIY==79)
+
+    if(fPadData[idCentral].fIX==236)
       idUpper = 0;
     else
       idUpper = fGetIdTotalData[fPadData[idCentral].fIX][fPadData[idCentral].fIY+1][0];
 
+
     fRecY[b] = (fPadData[idCentral].fRealY*fPadData[idCentral].fCharge
               +
-              fPadData[idUpper].fRealY*fPadData[idUpper].fCharge
+               fPadData[idUpper].fRealY*fPadData[idUpper].fCharge
               +
-              fPadData[idLower].fRealY*fPadData[idLower].fCharge
-              )/(fPadData[idCentral].fCharge + fPadData[idUpper].fCharge + fPadData[idLower].fCharge) ;
-
-    fAvgChargeY[b] = fPadData[idCentral].fCharge;
-  
-
-    fRecY[b] += 0.025*sin(12.56637*(0.25-(fRecY[b] - fPadData[idCentral].fRealY))) ;
+               fPadData[idLower].fRealY*fPadData[idLower].fCharge
+               )/(fPadData[idCentral].fCharge + fPadData[idUpper].fCharge + fPadData[idLower].fCharge) ;
+    
+    fAvgChargeY[b] = (fPadData[idCentral].fCharge + fPadData[idUpper].fCharge + fPadData[idLower].fCharge)/3.0 ;
+    
+    fNofBChannel[b] = 0;
+    if(fPadData[idLower].fCharge>0)
+      fNofBChannel[b]++ ;
+    if(fPadData[idCentral].fCharge>0)
+      fNofBChannel[b]++ ;
+    if(fPadData[idUpper].fCharge>0)
+      fNofBChannel[b]++ ;
+
+    HLTDebug("lower : %d, middle : %d, upper : %d, nofChannel : %d",fPadData[idLower].fCharge,
+           fPadData[idCentral].fCharge,fPadData[idUpper].fCharge,fNofBChannel[b]);
+
+    HLTDebug("RecY[%d] : %f",b,fRecY[b]);
   }
       
   for(nb=0;nb<fCentralCountNB;nb++){
@@ -563,9 +530,26 @@ void AliHLTMUONHitReconstructor::RecXRecY()
                 )/(fPadData[idCentral].fCharge + fPadData[idRight].fCharge + fPadData[idLeft].fCharge);
     
 
-    fAvgChargeX[nb] = fPadData[idCentral].fCharge;
+    fAvgChargeX[nb] = (fPadData[idCentral].fCharge + fPadData[idRight].fCharge + fPadData[idLeft].fCharge)/3.0 ;
     
+    
+    fNofNBChannel[nb] = 0;
+    if(fPadData[idLeft].fCharge>0)
+      fNofNBChannel[nb]++ ;
+    if(fPadData[idCentral].fCharge>0)
+      fNofNBChannel[nb]++ ;
+    if(fPadData[idRight].fCharge>0)
+      fNofNBChannel[nb]++ ;
+
+    HLTDebug("left : %d, middle : %d, right : %d, nofChannel : %d",fPadData[idLeft].fCharge,
+           fPadData[idCentral].fCharge,fPadData[idRight].fCharge,fNofNBChannel[nb]);
+
+    HLTDebug("RecX[%d] : %f",nb,fRecX[nb]);
+
   }
+
+  return true;
+  
 }
 
 
@@ -666,7 +650,7 @@ bool AliHLTMUONHitReconstructor::MergeRecHits()
       idCentralB = fCentralChargeB[b];
       padCenterXB = fPadData[idCentralB].fRealX; 
       
-      halfPadLengthX = fgkHalfPadSize[fPadData[idCentralB].fPcbZone] ;
+      halfPadLengthX = fPadData[idCentralB].fIY ;
 
       for(int nb=0;nb<fCentralCountNB;nb++){
        if(fRecX[nb]!=0.0){
@@ -674,7 +658,7 @@ bool AliHLTMUONHitReconstructor::MergeRecHits()
 
          padCenterYNB = fPadData[idCentralNB].fRealY;
 
-         halfPadLengthY = fgkHalfPadSize[fPadData[idCentralNB].fPcbZone] ;
+         halfPadLengthY = fPadData[idCentralNB].fHalfPadSize ;
 
          if(fabsf(fRecX[nb]) > fabsf(padCenterXB))
            diffX = fabsf(fRecX[nb]) -  fabsf(padCenterXB);
@@ -688,6 +672,11 @@ bool AliHLTMUONHitReconstructor::MergeRecHits()
 
          if(diffX < halfPadLengthX && diffY < halfPadLengthY ){//&& fPadData[idCentralB].fIY != 0){
 
+           if(fNofBChannel[b]==3)
+             fRecY[b] += 0.025*sin(12.0*(fRecY[b] - fPadData[idCentralB].fRealY)) ;
+           
+           fRecX[nb] += 0.075*sin(9.5*(fRecX[nb] - fPadData[idCentralNB].fRealX)) ;
+           
            // First check that we have not overflowed the buffer.
            if((*fRecPointsCount) == fMaxRecPointsCount){
              HLTError("Nof RecHit (i.e. %d) exceeds the max nof RecHit limit %d\n",(*fRecPointsCount),fMaxRecPointsCount);
@@ -698,7 +687,11 @@ bool AliHLTMUONHitReconstructor::MergeRecHits()
            fRecPoints[(*fRecPointsCount)].fX = fRecX[nb];
            fRecPoints[(*fRecPointsCount)].fY = fRecY[b];
            fRecPoints[(*fRecPointsCount)].fZ = fPadData[idCentralB].fRealZ;
-           //fRecPoints[(*fRecPointsCount)].fDetElemId = (AliHLTUInt32_t)fPadData[idCentralB].fDetElemId;
+//         fRecPoints[(*fRecPointsCount)].fXCenter = fPadData[idCentralNB].fRealX;
+//         fRecPoints[(*fRecPointsCount)].fYCenter = fPadData[idCentralB].fRealY;
+//         fRecPoints[(*fRecPointsCount)].fNofBChannel = fNofBChannel[b];
+//         fRecPoints[(*fRecPointsCount)].fNofNBChannel = fNofNBChannel[nb];
+//         fRecPoints[(*fRecPointsCount)].fDetElemId = (AliHLTUInt32_t)fPadData[idCentralB].fDetElemId;
            (*fRecPointsCount)++;
          }//if lies wihtin 5.0 mm
        }// condn over fRecX ! = 0.0
@@ -726,35 +719,40 @@ bool AliHLTMUONHitReconstructor::MergeRecHits()
     fAvgChargeY = NULL;
   }
 
+  if(fNofBChannel){
+    delete []fNofBChannel;
+    fNofBChannel = NULL;
+  }
+
+  if(fNofNBChannel){
+    delete []fNofNBChannel;
+    fNofNBChannel = NULL;
+  }
+
   return true;
 }
 
 
 void AliHLTMUONHitReconstructor::Clear()
 {
-  for(int iPad=0;iPad<fDigitPerDDL;iPad++){
-    fGetIdTotalData[fPadData[fDetManuChannelIdList[iPad]].fIX][fPadData[fDetManuChannelIdList[iPad]].fIY][fPadData[fDetManuChannelIdList[iPad]].fPlane] = 0;
-    fPadData[fDetManuChannelIdList[iPad]].fDetElemId = 0;
-    fPadData[fDetManuChannelIdList[iPad]].fBuspatchId = 0;
-    fPadData[fDetManuChannelIdList[iPad]].fIdManuChannel = 0;
-    fPadData[fDetManuChannelIdList[iPad]].fIX = 0 ;
-    fPadData[fDetManuChannelIdList[iPad]].fIY = 0 ;
-    fPadData[fDetManuChannelIdList[iPad]].fRealX = 0.0 ;
-    fPadData[fDetManuChannelIdList[iPad]].fRealY = 0.0 ;
-    fPadData[fDetManuChannelIdList[iPad]].fRealZ = 0.0 ;
-    fPadData[fDetManuChannelIdList[iPad]].fPlane = -1 ;
-    fPadData[fDetManuChannelIdList[iPad]].fPcbZone = -1 ;
-    fPadData[fDetManuChannelIdList[iPad]].fCharge = 0 ;
+  // function to clear internal arrays and release the allocated memory.
+
+  for(int iPad=1;iPad<fDigitPerDDL;iPad++){
+    fGetIdTotalData[fPadData[iPad].fIX][fPadData[iPad].fIY][fPadData[iPad].fPlane] = 0;
+    fPadData[iPad].fDetElemId = 0;
+    fPadData[iPad].fIX = 0 ;
+    fPadData[iPad].fIY = 0 ;
+    fPadData[iPad].fRealX = 0.0 ;
+    fPadData[iPad].fRealY = 0.0 ;
+    fPadData[iPad].fRealZ = 0.0 ;
+    fPadData[iPad].fHalfPadSize = -1 ;
+    fPadData[iPad].fPlane = -1 ;
+    fPadData[iPad].fCharge = 0 ;
   }  
   
   for(int i=0;i<13;i++)
     fMaxFiredPerDetElem[i] = 0;
 
-  if(fDetManuChannelIdList){
-    delete []fDetManuChannelIdList;
-    fDetManuChannelIdList = NULL;
-  }
-
   if(fCentralChargeB){
     delete []fCentralChargeB;
     fCentralChargeB = NULL;
@@ -784,4 +782,94 @@ void AliHLTMUONHitReconstructor::Clear()
     delete []fAvgChargeY;
     fAvgChargeY = NULL;
   }
+
+  if(fNofBChannel){
+    delete []fNofBChannel;
+    fNofBChannel = NULL;
+  }
+
+  if(fNofNBChannel){
+    delete []fNofNBChannel;
+    fNofNBChannel = NULL;
+  }
+
+}
+
+
+AliHLTMUONHitReconstructor::AliHLTMUONRawDecoder::AliHLTMUONRawDecoder() :
+       fBufferStart(NULL),
+  fDCCut(0),
+  fPadData(NULL),
+  fLookUpTableData(NULL),
+  fMaxFiredPerDetElem(NULL),
+  fNofFiredDetElem(NULL),
+  fBusPatchId(0),
+  fDataCount(1),
+  fPrevDetElemId(0),
+  fPadCharge(0),
+  fCharge(0.0),
+  fIdManuChannel(0x0),
+  fLutEntry(0),
+  fIdToEntry()
+{
+       // ctor
+}
+
+
+AliHLTMUONHitReconstructor::AliHLTMUONRawDecoder::~AliHLTMUONRawDecoder()
+{
+       // dtor
+}
+
+void AliHLTMUONHitReconstructor::AliHLTMUONRawDecoder::OnData(UInt_t dataWord, bool /*parityError*/)
+{
+  //function to arrange the decoded Raw Data
+
+  fIdManuChannel = 0x0;
+  fIdManuChannel = (fIdManuChannel|fBusPatchId)<<17;
+  fIdManuChannel |= (dataWord >> 12) & 0x1FFFF;
+  
+  fLutEntry = fIdToEntry[fIdManuChannel];
+  fPadCharge = int(((unsigned short)(dataWord & 0xFFF)) - fLookUpTableData[fLutEntry].fPed);
+  
+  fCharge = 0;   
+  if(fPadCharge > fDCCut && fPadCharge > 5.0*fLookUpTableData[fLutEntry].fSigma){  // (charge > 4) is due cut out the noise level                      
+      
+    fPadData[fDataCount].fDetElemId = fLookUpTableData[fLutEntry].fDetElemId;
+    fPadData[fDataCount].fIX = fLookUpTableData[fLutEntry].fIX;
+    fPadData[fDataCount].fIY = fLookUpTableData[fLutEntry].fIY;
+    fPadData[fDataCount].fRealX = fLookUpTableData[fLutEntry].fRealX;
+    fPadData[fDataCount].fRealY = fLookUpTableData[fLutEntry].fRealY;
+    fPadData[fDataCount].fRealZ = fLookUpTableData[fLutEntry].fRealZ;
+    fPadData[fDataCount].fHalfPadSize = fLookUpTableData[fLutEntry].fHalfPadSize;
+    fPadData[fDataCount].fPlane = fLookUpTableData[fLutEntry].fPlane;
+    
+    if ( fPadCharge < fLookUpTableData[fLutEntry].fThres ) {
+      fCharge = (fLookUpTableData[fLutEntry].fA0)*fPadCharge;
+    }else{
+      fCharge = (fLookUpTableData[fLutEntry].fA0)*(fLookUpTableData[fLutEntry].fThres) 
+       + (fLookUpTableData[fLutEntry].fA0)*(fPadCharge-fLookUpTableData[fLutEntry].fThres) 
+       + (fLookUpTableData[fLutEntry].fA1)*(fPadCharge-fLookUpTableData[fLutEntry].fThres)*(fPadCharge-fLookUpTableData[fLutEntry].fThres);
+    }
+    
+    fPadData[fDataCount].fCharge = fCharge;
+    
+    if(fLookUpTableData[fLutEntry].fDetElemId != fPrevDetElemId){
+      if((*fNofFiredDetElem)>0){
+       fMaxFiredPerDetElem[(*fNofFiredDetElem)-1] = fDataCount;
+      }
+      (*fNofFiredDetElem)++;
+      fPrevDetElemId =  fLookUpTableData[fLutEntry].fDetElemId ;
+    }
+    
+//     HLTDebug("buspatch : %d, detele : %d, id : %d, manu : %d, channel : %d, iX : %d, iY: %d, (X,Y) : (%f, %f), charge : %d, padsize : %f, plane : %d",
+//          fBusPatchId,fPadData[fDataCount].fDetElemId,
+//          fIdManuChannel,((dataWord >> 18) & 0x7FF),((dataWord >> 12) & 0x3F),
+//          fPadData[fDataCount].fIX,fPadData[fDataCount].fIY,
+//          fPadData[fDataCount].fRealX,fPadData[fDataCount].fRealY,
+//          fPadData[fDataCount].fCharge,fPadData[fDataCount].fHalfPadSize,fPadData[fDataCount].fPlane);
+    
+      fDataCount ++;
+  }// if charge is more than DC Cut limit condition
+  
 }
index 2393cac..83075b2 100644 (file)
@@ -1,20 +1,8 @@
 #ifndef ALIHLTMUONHITRECONSTRUCTOR_H
 #define ALIHLTMUONHITRECONSTRUCTOR_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$ */
 
 #include <cstring>
 #include <cmath>
 #include <map>
+#include <cassert>
 
-#include <TString.h>
+#include "TString.h"
+#include "AliHLTLogging.h"
+#include "AliMUONTrackerDDLDecoder.h"
+#include "AliMUONTrackerDDLDecoderEventHandler.h"
+#include "AliHLTMUONDataTypes.h"
 
-#include <AliHLTLogging.h>
-
-#include "AliRawReader.h"
-#include "AliRawReaderFile.h"
-#include "AliRawReaderRoot.h"
-#include "AliRawReaderDate.h"
+#include "AliRawDataHeader.h"
 
 #if __GNUC__ && __GNUC__ < 3
 #define std
 #endif
 
 
-typedef std::map<int,int> BusToDetElem;
-typedef std::map<int,int> BusToDDL;
-
 extern "C" struct AliHLTMUONRecHitStruct;
 
+typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
+
 
 class AliHLTMUONHitReconstructor : public AliHLTLogging
 {
 public:
+       
+       AliHLTMUONHitReconstructor();
+       virtual ~AliHLTMUONHitReconstructor(void);
+
+       bool LoadLookUpTable(AliHLTMUONHitRecoLutRow* lookUpTableData, AliHLTInt32_t lookUpTableId);
+       bool SetIdManuChannelToEntry(IdManuChannelToEntry lineToId);
+       
+       
+       bool Run(
+                       const AliHLTUInt32_t* rawData,
+                       AliHLTUInt32_t rawDataSize,
+                       AliHLTMUONRecHitStruct* recHit,
+                       AliHLTUInt32_t& nofHit
+               );
+       void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
+       //void SetDebugLevel(AliHLTInt32_t debugLevel) {fDebugLevel = debugLevel;} //TODO: remove
+       //int GetDebugLevel() const {return fDebugLevel;} //TODO: remove
+       
+       static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
+       static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
+       static AliHLTInt32_t GetkNofDDL() { return fgkNofDDL; }
+       static AliHLTInt32_t GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
+
+private:
+
+       static const AliHLTInt32_t fgkDetectorId;      // DDL Offset
+       static const AliHLTInt32_t fgkDDLOffSet;       // DDL Offset
+       static const AliHLTInt32_t fgkNofDDL;          // Number of DDL 
+       static const AliHLTInt32_t fgkDDLHeaderSize;   // DDL header size
+       static const AliHLTInt32_t fgkLutLine;         // nof Line in LookupTable
 
-  struct DHLTLut{
-    int fIdManuChannel;  // Manu channel address
-    int fIX,fIY;  // The X,Y number of the pad.
-    float fRealX,fRealY,fRealZ;  // The real coordinate of the pad.
-    int fPlane,fPcbZone;  // The plane and PCB zone ID numbers.
-  };
-
-  struct DHLTPad{
-    int fDetElemId;  // The detector element ID of the pad.
-    int fBuspatchId;  // The bus patch ID number for the pad.
-    int fIdManuChannel;  // The Manu channel address.
-    int fIX,fIY;  // The X,Y number of the pad.
-    float fRealX,fRealY,fRealZ;   // The real coordinate of the pad.
-    int fPlane,fPcbZone;   // The plane and PCB zone ID numbers.
-    int fCharge;  // The charge measured on the pad.
-  };
-
-  AliHLTMUONHitReconstructor();
-  virtual ~AliHLTMUONHitReconstructor(void);
-
-  bool LoadLookUpTable(DHLTLut* lookUpTableData, int lookUpTableId);
-  bool SetBusToDetMap(BusToDetElem busToDetElem);
-  bool SetBusToDDLMap(BusToDDL busToDDL);
-  
-  bool Run(
-               const AliHLTUInt32_t* rawData,
-               AliHLTUInt32_t rawDataSize,
-               AliHLTMUONRecHitStruct* recHit,
-               AliHLTUInt32_t& nofHit
-       );
-  void SetDCCut(int dcCut) {fDCCut = dcCut;}
-  void SetDebugLevel(int debugLevel) {fDebugLevel = debugLevel;}
-  int GetDebugLevel() const {return fDebugLevel;}
-  int GetDEId(int iBusPatch) {return fBusToDetElem[iBusPatch] ;}           
-    
-  int GetLutLine(int iDDL) const;
-
-  static int GetkDetectorId() { return fgkDetectorId; }
-  static int GetkDDLOffSet() { return fgkDDLOffSet; }
-  static int GetkNofDDL() { return fgkNofDDL; }
-  static int GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
-  
-private: 
-  static const int fgkDetectorId ;            // DDL Offset
-  static const int fgkDDLOffSet ;             // DDL Offset
-  static const int fgkNofDDL ;                // Number of DDL 
-  static const int fgkDDLHeaderSize  ;        // DDL header size
 protected:
-  AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
-  AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
-  
+
+       AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
+       AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
+
 private:
 
-  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[2];            // nof Line in LookupTable    
-
-  static const int fgkMinIdManuChannel[2];   // Minimum value of idManuChannel in LookupTable  
-  static const int fgkMaxIdManuChannel[2];   // Maximum value of idManuChannel in LookupTable  
-  static const float fgkHalfPadSize[3];      // pad halflength for the pcb zones  
-  
-  int fkBlockHeaderSize;                     // Block header size
-  int fkDspHeaderSize;                       // DSP header size
-  int fkBuspatchHeaderSize;                  // buspatch header size
-  
-  int fDCCut;                                // DC Cut value
-
-  DHLTPad* fPadData;                         // pointer to the array containing the information of each padhits
-  DHLTLut* fLookUpTableData;                 // pointer to the array of Lookuptable data
-  
-  AliHLTMUONRecHitStruct* fRecPoints;       // Reconstructed hits
-  AliHLTUInt32_t *fRecPointsCount;                      // nof reconstructed hit  
-  AliHLTUInt32_t fMaxRecPointsCount;                    // max nof reconstructed hit  
-   
-  int fCentralCountB, fCentralCountNB;        // centeral hits 
-  int fIdOffSet,fDDLId;                       // DDLId and DDL id offset
-  int fDigitPerDDL;                           // Total nof Digits perDDL 
-  
-  int *fDetManuChannelIdList;                          // pointer to an array of idManuChannel
-  int *fCentralChargeB,*fCentralChargeNB;              // pointer to an array of central hit
-  float *fRecX,*fRecY;                                 // pointer to an array of reconstructed hit
-  float *fAvgChargeX,*fAvgChargeY;                     // average charge on central pad found using CG method
-  int fGetIdTotalData[336][80][2] ;                    // an array of idManuChannel with argumrnt of centralX,centralY and  planeType
-  int fNofFiredDetElem,fMaxFiredPerDetElem[13];        // counter for detector elements that are fired 
-  int fDebugLevel;
-  BusToDetElem fBusToDetElem;             // Mapping between bus address and detector element ID.
-  BusToDetElem fBusToDDL;                 // Mapping between bus address and DDL.
-
-
-  bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
-  void FindCentralHits(int minPadId, int maxPadId);
-  bool FindRecHits() ;
-  void RecXRecY();
-  bool MergeRecHits();
-  void Clear();
+       struct AliHLTMUONPad
+       {
+               AliHLTInt32_t fDetElemId;  // The detector element ID of the pad.
+               AliHLTInt32_t fIX, fIY;  // The X,Y number of the pad.
+               AliHLTFloat32_t fRealX, fRealY, fRealZ;   // The real coordinate of the pad.
+               AliHLTFloat32_t fHalfPadSize; // half padsize in X and Y
+               AliHLTInt32_t fPlane;   // The plane and PCB zone ID numbers.
+               AliHLTFloat32_t fCharge;  // The charge measured on the pad.
+       };
+       
+
+       class AliHLTMUONRawDecoder : public AliMUONTrackerDDLDecoderEventHandler, public AliHLTLogging
+       {
+       public:
+       
+               AliHLTMUONRawDecoder();
+               virtual ~AliHLTMUONRawDecoder();
+               
+               void OnData(UInt_t dataWord, bool /*parityError*/);
+               void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* /*data*/) 
+               {
+                       fBusPatchId = int(header->fBusPatchId);
+               };
+               
+               void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/) 
+               {
+                       assert( buffer != NULL );
+                       fBufferStart = buffer;
+                       fDataCount = 1;  // dataCount starts from 1 because the 0-th element of fPadData is used as null value.
+                       *fNofFiredDetElem = 0;
+                       fPrevDetElemId = 0 ;
+               };
+               
+               void OnError(ErrorCode code, const void* location)
+               {
+                       long bytepos = long(location) - long(fBufferStart) + sizeof(AliRawDataHeader);
+                       HLTError("There is a problem with decoding the raw data. %s (Error code: %d, at byte %d)",
+                               ErrorCodeToMessage(code), code, bytepos
+                       );
+               };
+               
+               void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
+               void SetPadData(AliHLTMUONPad* padData) {fPadData = padData;}
+               void SetLookUpTable(AliHLTMUONHitRecoLutRow* lookUpTableData) {fLookUpTableData = lookUpTableData;}
+               void SetNofFiredDetElemId(AliHLTInt32_t& nofFiredDetElem) {fNofFiredDetElem = &nofFiredDetElem;}
+               void SetIdManuChannelToEntry(IdManuChannelToEntry idToEntry) {fIdToEntry = idToEntry;}
+               void SetMaxFiredPerDetElem(AliHLTInt32_t* maxFiredPerDetElem) {fMaxFiredPerDetElem = maxFiredPerDetElem;}
+               
+               AliHLTInt32_t GetDataCount() {return fDataCount;}
+       
+       private:
+               // Do not allow copying of this class.
+                /// Not implemented
+               AliHLTMUONRawDecoder(const AliHLTMUONRawDecoder& rhs); // copy constructor
+                /// Not implemented
+               AliHLTMUONRawDecoder& operator=(const AliHLTMUONRawDecoder& rhs); // assignment operator
+       
+               const void* fBufferStart;   // Pointer to the start of the current DDL payload buffer.
+               AliHLTInt32_t fBusPatchId;                                                // buspatchId
+               AliHLTInt32_t fDCCut;                                                     // DC Cut value
+               AliHLTMUONPad* fPadData;                  // pointer to the array containing the information of each padhits
+               AliHLTMUONHitRecoLutRow* fLookUpTableData;          // pointer to the array of Lookuptable data
+               AliHLTInt32_t* fNofFiredDetElem;                                          // counter for detector elements that are fired 
+               AliHLTInt32_t* fMaxFiredPerDetElem;                                       // array for detector elements that are fired 
+               IdManuChannelToEntry fIdToEntry;                                // Mapping between Linenumber to IdManuChannel;
+               
+               AliHLTInt32_t fDataCount;                                                 // Data Counter
+               AliHLTInt32_t fPrevDetElemId;                                             // previous detection elementId
+               AliHLTInt32_t fPadCharge;                                                 // pedestal subtracted pad charge
+               AliHLTFloat32_t fCharge;                                                  //calibrated pad charge 
+               AliHLTInt32_t fIdManuChannel;                                             // id manu channel
+               AliHLTInt32_t fLutEntry;                                                  // i-th entry in lookuptable
+       };
+
+       AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
+       
+       AliHLTInt32_t fkBlockHeaderSize;                     // Block header size
+       AliHLTInt32_t fkDspHeaderSize;                       // DSP header size
+       AliHLTInt32_t fkBuspatchHeaderSize;                  // buspatch header size
+       
+       AliHLTInt32_t fDCCut;                                // DC Cut value
+       
+       AliHLTMUONPad* fPadData;                         // pointer to the array containing the information of each padhits
+       AliHLTMUONHitRecoLutRow* fLookUpTableData;                 // pointer to the array of Lookuptable data
+       
+       AliHLTMUONRecHitStruct* fRecPoints;       // Reconstructed hits
+       AliHLTUInt32_t *fRecPointsCount;                      // nof reconstructed hit  
+       AliHLTUInt32_t fMaxRecPointsCount;                    // max nof reconstructed hit  
+       
+       AliHLTInt32_t fCentralCountB, fCentralCountNB;        // centeral hits 
+       AliHLTInt32_t fDDLId;                                 // DDLId
+       AliHLTInt32_t fDigitPerDDL;                           // Total nof Digits perDDL 
+       
+       AliHLTInt32_t *fCentralChargeB, *fCentralChargeNB;           // pointer to an array of central hit
+       AliHLTFloat32_t *fRecX, *fRecY;                              // pointer to an array of reconstructed hit
+       AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY;                  // average charge on central pad found using CG method
+       AliHLTInt32_t *fNofBChannel, *fNofNBChannel;                 // number of channels bending and non-bending.
+       AliHLTInt32_t fGetIdTotalData[336][237][2];                  // an array of idManuChannel with argument of centralX, centralY and planeType.
+       AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[13];      // counter for detector elements that are fired 
+       AliHLTInt32_t fDebugLevel;
+       IdManuChannelToEntry fIdToEntry;       // Mapping between Linenumber to IdManuChannel;
+       
+       //bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
+       bool DecodeDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
+       void FindCentralHits(AliHLTInt32_t minPadId, AliHLTInt32_t maxPadId);
+       bool FindRecHits();
+       bool RecXRecY();
+       bool MergeRecHits();
+       void Clear();
+
 };
 
 #endif // ALIHLTMUONHITRECONSTRUCTOR_H
index 893316c..282db30 100644 (file)
 #include <cerrno>
 #include <cassert>
 
+//STEER 
+#include "AliCDBManager.h"
+#include "AliGeomManager.h"
+
+//MUON
+#include "AliMUONGeometryTransformer.h"
+#include "AliMUONCalibrationData.h"
+#include "AliMUONVCalibParam.h"
+
+//MUON/mapping 
+#include "AliMpCDB.h"
+#include "AliMpPad.h"
+#include "AliMpSegmentation.h"
+#include "AliMpDDLStore.h"
+#include "AliMpDEIterator.h"
+#include "AliMpVSegmentation.h"
+#include "AliMpDEManager.h"
+#include "AliMpDetElement.h"
+
 ClassImp(AliHLTMUONHitReconstructorComponent)
 
 
 AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() :
        AliHLTProcessor(),
        fHitRec(NULL),
-       fDDLDir(""),
        fDDL(0),
-       fReaderType(false),
+       fIdToEntry(),
        fWarnForUnexpecedBlock(false)
 {
        ///
@@ -60,6 +78,11 @@ AliHLTMUONHitReconstructorComponent::~AliHLTMUONHitReconstructorComponent()
        ///
        /// Default destructor.
        ///
+       
+       if (fHitRec != NULL)
+       {
+               delete fHitRec;
+       }
 }
 
 const char* AliHLTMUONHitReconstructorComponent::GetComponentID()
@@ -120,131 +143,212 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
        /// Inherited from AliHLTComponent.
        /// Parses the command line parameters and initialises the component.
        ///
-       
-  // perform initialization. We check whether our relative output size is specified in the arguments.
-     
-  HLTInfo("Initialising DHLT HitReconstruction Component");
-
-  fHitRec = new AliHLTMUONHitReconstructor();
-  fWarnForUnexpecedBlock = false;
 
-  // this is to get rid of the warning "unused parameter"
-  if (argc==0 && argv==NULL) {
-    HLTError("Arguments missing", " no arguments" );
-  }
-
-  char lutFileName[500],buspatchFileName[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 */ 
-       }
-           
-       sprintf(lutFileName,"%s",argv[i+1]);
+       HLTInfo("Initialising dHLT hit reconstruction component.");
        
-       i += 2;
-       continue;
-      }// lut argument
-         
-         
-      if ( !strcmp( argv[i], "-ddl" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("DDL number not specified" );
-         return EINVAL;  /* Invalid argument */
+       try
+       {
+               fHitRec = new AliHLTMUONHitReconstructor();
        }
-           
-       unsigned long num = strtoul( argv[i+1], &cpErr, 0 );
-       if (cpErr == NULL or *cpErr != '\0')
-         {
-           HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
-           return EINVAL;
-         }
-       if (num < 13 or 20 < num)
+       catch (const std::bad_alloc&)
        {
-               HLTError("The DDL number must be in the range [13..20].");
-               return EINVAL;
+               HLTError("Could not allocate more memory for the hit reconstructor component.");
+               return -ENOMEM;
        }
-       fDDL = num - 1;
        
-       i += 2;
-       continue;
-      }// ddl argument
-      
+       fWarnForUnexpecedBlock = false;
 
-      if ( !strcmp( argv[i], "-rawdir" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("DDL directory not specified" );
-         return EINVAL;  /* Invalid argument */
+       const char* lutFileName = NULL;
+       const char* cdbPath = NULL;
+       Int_t run = -1;
+       bool useCDB = false;
+       
+       for (int i = 0; i < argc; i++)
+       {
+               HLTDebug("argv[%d] == %s", i, argv[i]);
+               
+               if (strcmp( argv[i], "-ddl" ) == 0)
+               {
+                       if (argc <= i+1)
+                       {
+                               HLTError("The DDL number was not specified. Must be in the range [13..20].");
+                               return EINVAL;
+                       }
+                       
+                       char* cpErr = NULL;
+                       unsigned long num = strtoul( argv[i+1], &cpErr, 0 );
+                       if (cpErr == NULL or *cpErr != '\0')
+                       {
+                               HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
+                               return EINVAL;
+                       }
+                       if (num < 13 or 20 < num)
+                       {
+                               HLTError("The DDL number must be in the range [13..20].");
+                               return EINVAL;
+                       }
+                       fDDL = num - 1;
+                       
+                       i++;
+                       continue;
+               } // -ddl argument
+               
+               if (strcmp( argv[i], "-lut" ) == 0)
+               {
+                       if (argc <= i+1)
+                       {
+                               HLTError("The lookup table filename was not specified.");
+                               return EINVAL;
+                       }
+                       lutFileName = argv[i+1];
+                       i++;
+                       continue;
+               } // -lut argument
+               
+               if (strcmp( argv[i], "-cdb" ) == 0)
+               {
+                       useCDB = true;
+                       continue;
+               } // -cdb argument
+               
+               if (strcmp( argv[i], "-cdbpath" ) == 0)
+               {
+                       if ( argc <= i+1 )
+                       {
+                               HLTError("The CDB path was not specified." );
+                               return EINVAL;
+                       }
+                       cdbPath = argv[i+1];
+                       useCDB = true;
+                       i++;
+                       continue;
+               } // -cdb argument
+       
+               if (strcmp( argv[i], "-run" ) == 0)
+               {
+                       if ( argc <= i+1 )
+                       {
+                               HLTError("The RUN number was not specified." );
+                               return EINVAL;
+                       }
+                       
+                       char* cpErr = NULL;
+                       run = Int_t( strtoul(argv[i+1], &cpErr, 0) );
+                       if (cpErr == NULL or *cpErr != '\0')
+                       {
+                               HLTError("Cannot convert '%s' to a valid run number."
+                                       " Expected an integer value.", argv[i+1]
+                               );
+                               return EINVAL;
+                       }
+                       
+                       i++;
+                       continue;
+               } // -run argument
+               
+               if (strcmp( argv[i], "-warn_on_unexpected_block" ) == 0)
+               {
+                       fWarnForUnexpecedBlock = true;
+                       continue;
+               }
+       
+               HLTError("Unknown option '%s'", argv[i]);
+               return EINVAL;
+       
+       } // for loop
+       
+       if (lutFileName == NULL) useCDB = true;
+       
+       AliHLTMUONHitRecoLutRow* lookupTable;
+       
+       if (useCDB)
+       {
+               if(!ReadCDB(lookupTable,cdbPath,run))
+               {
+                       HLTError("Failed to read cdb, cdb cannot be read, DoInit");
+                       
+                       if (fHitRec)
+                       {
+                               delete fHitRec;
+                               fHitRec = NULL;
+                       }
+                       if(lookupTable)
+                               delete []lookupTable;
+                       
+                       return ENOENT ; /* No such file or directory */
+               }
        }
-           
-       fDDLDir = argv[i+1] ;
-           
-       i += 2;
-       continue;
-      }// ddl directory argument
-         
-         
-      if ( !strcmp( argv[i], "-buspatchmap" ) ) {
-       if ( argc <= i+1 ) {
-         HLTError("Buspatch filename not specified" );
-         return EINVAL; /* Invalid argument */
+       else
+       {
+               AliHLTUInt32_t lutLine;
+               if(!GetLutLine(lutFileName,fDDL,lutLine))
+               {
+                       HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
+                       
+                       if(fHitRec)
+                               delete fHitRec;
+                       return EIO;
+               }
+       
+               try
+               {
+                       lookupTable = new AliHLTMUONHitRecoLutRow[lutLine];
+               }
+               catch(const std::bad_alloc&)
+               {
+                       HLTError("Dynamic memory allocation failed for lookuptable, DoInit");
+                       
+                       if(fHitRec)
+                               delete fHitRec;
+                       
+                       return ENOMEM;
+               }
+       
+       
+               if(!ReadLookUpTable(lookupTable,lutFileName))
+               {
+                       HLTError("Failed to read lut, lut cannot be read, DoInit");
+                       
+                       if(fHitRec)
+                               delete fHitRec;
+                       if(lookupTable)
+                               delete []lookupTable;
+                       
+                       return ENOENT ; /* No such file or directory */
+               }
        }
-           
-       sprintf(buspatchFileName,"%s",argv[i+1]);
        
-       i += 2;
-       continue;
-      }// buspatch argument
-
-      if ( !strcmp( argv[i], "-rawreader" ) ) {
-       fReaderType = true; // true when using rawreader for standalone it is set to false.
-       i += 1;
-       continue;
-      }
-         
-      if ( !strcmp( argv[i], "-warn_on_unexpected_block" ) ) {
-        fWarnForUnexpecedBlock = true;
-       i++;
-       continue;
-      }
-
-      HLTError("Unknown option '%s'", argv[i] );
-      return EINVAL;
-      
-    }//while loop
-
-  int lutline = fHitRec->GetLutLine(fDDL);
-  AliHLTMUONHitReconstructor::DHLTLut* lookupTable = new AliHLTMUONHitReconstructor::DHLTLut[lutline];
-  if(!ReadLookUpTable(lookupTable,lutFileName)){
-    HLTError("Failed to read lut, lut cannot be read, DoInit");
-    return ENOENT ; /* No such file or directory */
-  }else{
-    
-    BusToDetElem busToDetElem;
-    BusToDDL busToDDL;
-    if(!ReadBusPatchToDetElemFile(busToDetElem,busToDDL,buspatchFileName)){
-      HLTError("Failed to read buspatchmap, buspatchmap cannot be read, DoInit");
-      return ENOENT ; /* No such file or directory */
-    }
-    
-    fHitRec->SetBusToDetMap(busToDetElem);
-    fHitRec->SetBusToDDLMap(busToDDL);
-    fHitRec->LoadLookUpTable(lookupTable,fDDL);
-    
-  }// reading lut
-
-  delete []lookupTable;
-  
-  HLTInfo("Initialisation of DHLT HitReconstruction Component is done");
-  
-  return 0;
+       if(!fHitRec->SetIdManuChannelToEntry(fIdToEntry))
+       {
+               HLTError("Failed to set fIdToEntry mapping, DoInit");
+               
+               if(fHitRec)
+               delete fHitRec;
+               if(lookupTable)
+               delete []lookupTable;
+               
+               fIdToEntry.clear();
+               
+               return ENOENT ; /* No such file or directory */
+       }
+       
+       if(!fHitRec->LoadLookUpTable(lookupTable,fDDL))
+       {
+               HLTError("Cannot Laod hitrec lookuptable , DoInit");
+               
+               if(fHitRec)
+               delete fHitRec;
+               if(lookupTable)
+               delete []lookupTable;
+               
+               fIdToEntry.clear();
+               
+               return ENOENT;
+       }
+       
+       delete [] lookupTable;
+       
+       return 0;
 }
 
 
@@ -254,12 +358,17 @@ int AliHLTMUONHitReconstructorComponent::DoDeinit()
        /// Inherited from AliHLTComponent. Performs a cleanup of the component.
        ///
        
-  if(fHitRec)
-    delete fHitRec;
-  
-  HLTInfo(" Deinitialising DHLT HitReconstruction Component");
-  
-  return 0;
+       HLTInfo("Deinitialising dHLT hit reconstruction component.");
+       
+       if (fHitRec != NULL)
+       {
+               delete fHitRec;
+               fHitRec = NULL;
+       }
+       
+       fIdToEntry.clear();
+       
+       return 0;
 }
 
 
@@ -329,6 +438,13 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
                        continue;
                }
                
+               bool ddl[22];
+               AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
+               if (not ddl[fDDL])
+               {
+                       HLTWarning("Received raw data from an unexpected DDL.");
+               }
+               
                // Create a new output data block and initialise the header.
                AliHLTMUONRecHitsBlockWriter block(outputPtr+totalSize, size-totalSize);
                if (not block.InitCommonHeader())
@@ -347,10 +463,12 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
                        + fHitRec->GetkDDLHeaderSize();
                AliHLTUInt32_t nofHit = block.MaxNumberOfEntries();
 
+#ifdef DEBUG
                HLTDebug("=========== Dumping DDL payload buffer ==========");
                for (AliHLTUInt32_t j = 0; j < totalDDLSize; j++)
                        HLTDebug("buffer[%d] : %x",j,buffer[j]);
                HLTDebug("================== End of dump =================");
+#endif // DEBUG
 
                if (not fHitRec->Run(buffer, ddlRawDataSize, block.GetArray(), nofHit))
                {
@@ -387,74 +505,247 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
 }
 
 
-bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath)
+bool AliHLTMUONHitReconstructorComponent::GetLutLine(
+               const char* lutFileName, AliHLTInt32_t /*iDDL*/, AliHLTUInt32_t& iLine
+       )
+{
+  // Reads LUT from CDB.
+  // TODO: combine this with ReadLookUpTable().
+  
+  ifstream fin(lutFileName);
+
+  if(!fin){
+    HLTError("Failed to open file '%s' ",lutFileName);
+    return false;
+  }
+
+  string s;
+  iLine = 0;
+  while(getline(fin,s)){
+    iLine++;
+  }
+
+  fin.close();
+
+  return true;
+}
+
+
+bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(
+               AliHLTMUONHitRecoLutRow* lookupTable, const char* lutFileName
+       )
 {
        ///
        /// Read in the lookup table from a text file.
        ///
-       
+  
   if (fDDL < AliHLTMUONHitReconstructor::GetkDDLOffSet() ||
-      fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL()){
+      fDDL >= AliHLTMUONHitReconstructor::GetkDDLOffSet() + AliHLTMUONHitReconstructor::GetkNofDDL())
+  {
     HLTError("DDL number is out of range");
     return false;
   }
   
-  int lutLine = fHitRec->GetLutLine(fDDL);
-  
-  FILE* fin = fopen(lutpath, "r");
-  if (fin == NULL){
-    HLTError("Failed to open file: %s",lutpath);
+  AliHLTUInt32_t lutLine;
+  if(!GetLutLine(lutFileName,fDDL,lutLine)){
+    HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
+    
     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
-          );
-  }
+  int idManuChannel;
+  fIdToEntry.clear();
   
+  FILE *fin = fopen(lutFileName,"r");
+  if(fin == NULL){
+    printf("Failed to open file %s\n",lutFileName);
+    return false;
+  }else{
+    for(AliHLTUInt32_t i=0;i<lutLine;i++){
+      fscanf(fin,"%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%d\t%f\t%f\t%f\t%f\t%d\t%d\n",
+            &idManuChannel,&lookupTable[i].fDetElemId,&lookupTable[i].fIX,
+            &lookupTable[i].fIY,&lookupTable[i].fRealX,
+            &lookupTable[i].fRealY,&lookupTable[i].fRealZ,
+            &lookupTable[i].fHalfPadSize,&lookupTable[i].fPlane,
+            &lookupTable[i].fPed,&lookupTable[i].fSigma,&lookupTable[i].fA0,
+            &lookupTable[i].fA1,&lookupTable[i].fThres,&lookupTable[i].fSat);
+      
+      fIdToEntry[idManuChannel] = i+1;
+
+      
+    }
+  }
+
   fclose(fin);
+
   return true;
 }
 
 
-bool AliHLTMUONHitReconstructorComponent::ReadBusPatchToDetElemFile(BusToDetElem& busToDetElem, BusToDDL& busToDDL, const char* buspatchmappath)
+bool AliHLTMUONHitReconstructorComponent::ReadCDB(
+               AliHLTMUONHitRecoLutRow*& lookupTable,
+               const char* cdbPath, Int_t run
+       )
 {
-       ///
-       /// Read in the lookup table for bus patch to detector element IDs from a text file.
-       ///
-       
-  char getLine[80];
-  char temp;
-  int detElem, minBusPatch, maxBusPatch, ddl;
+  // Reads LUT from CDB.
+  // TODO: merge this with CreateHitRecoLookupTables.C, make this static and use in the macro for example.
+
+  vector<AliHLTMUONHitRecoLutRow> lutList;
+  lutList.clear();
+  AliHLTMUONHitRecoLutRow lut;
+  int iEntry = 0;
+
+  Bool_t warn = kTRUE;
+
+  AliCDBManager* cdbManager = AliCDBManager::Instance();
+  if (cdbPath != NULL) cdbManager->SetDefaultStorage(cdbPath);
+  if (run != -1) cdbManager->SetRun(run);
+
+  if (! AliMpCDB::LoadDDLStore(warn)){
+    HLTError("Failed to Load DDLStore specified for CDBPath '%s', and Run : '%d'",cdbPath,run);
+    return false;
+  }
+
+  AliMpSegmentation *mpSegFactory = AliMpSegmentation::Instance();
+  AliGeomManager::LoadGeometry();
+  AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer();
+  if(! chamberGeometryTransformer->LoadGeometryData()){
+    HLTError("Failed to Load Geomerty Data ");
+    return false;
+  }
   
-  FILE* fin = fopen(buspatchmappath, "r");
-  if (fin == NULL){
-    HLTError("Failed to open file: %s",buspatchmappath);
+  AliMUONCalibrationData calibData(run);
+
+  int totMaxIX = -1;
+  int totMaxIY = -1;
+  Int_t chamberId;
+
+  for(Int_t iCh = 6; iCh < 10; iCh++){ // max 4
+
+    chamberId = iCh ;
+
+    AliMpDEIterator it;
+    for ( it.First(chamberId); ! it.IsDone(); it.Next() ) {
+    
+      Int_t detElemId = it.CurrentDEId();
+      int iDDL = AliMpDDLStore::Instance()->GetDetElement(detElemId)->GetDdlId() + 1;
+      if(iDDL == fDDL){
+
+       for(Int_t iCath = 0 ; iCath <= 1 ; iCath++){
+       
+         AliMp::CathodType cath;
+         
+         if(iCath == 0)
+           cath = AliMp::kCath0 ;
+         else
+         cath = AliMp::kCath1 ;
+         
+         const AliMpVSegmentation* seg = mpSegFactory->GetMpSegmentation(detElemId, cath);
+         AliMp::PlaneType plane = seg->PlaneType(); 
+         Int_t maxIX = seg->MaxPadIndexX();  
+         Int_t maxIY = seg->MaxPadIndexY(); 
+         if(maxIX > totMaxIX)
+           totMaxIX = maxIX;
+         if(maxIY > totMaxIY)
+           totMaxIY = maxIY;
+         
+         Int_t idManuChannel, manuId, channelId, buspatchId;
+         float padSizeX, padSizeY;
+         float halfPadSize ;
+         Double_t realX, realY, realZ;
+         Double_t localX, localY, localZ;
+         Float_t calibA0Coeff,calibA1Coeff,pedestal,sigma;
+         Int_t thresold,saturation;
+         
+         //    cout<<"Running for detElemId :"<<detElemId<<", and plane : "<<plane<<endl;
+         //Pad Info of a segment to print in lookuptable
+         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);
+               
+               // Getting Manu id
+               manuId = pad.GetLocation().GetFirst();
+               manuId &= 0x7FF; // 11 bits 
+
+               buspatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
+               
+               // Getting channel id
+               channelId =  pad.GetLocation().GetSecond();
+               channelId &= 0x3F; // 6 bits
+               
+               idManuChannel &= 0x0;
+               idManuChannel = (idManuChannel|buspatchId)<<11;  
+               idManuChannel = (idManuChannel|manuId)<<6 ;
+               idManuChannel |= channelId ;
+               
+               localX = pad.Position().X();
+               localY = pad.Position().Y();
+               localZ = 0.0;
+               
+               chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ,
+                                                      realX,realY,realZ);
+               
+               padSizeX = pad.Dimensions().X();
+               padSizeY = pad.Dimensions().Y();
+               
+               calibA0Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,0) ;
+               calibA1Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,1) ;
+               thresold = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,2) ;
+               saturation = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,4) ;
+               
+               pedestal = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,0);
+               sigma = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,1);
+               
+               if(plane==0)
+                 halfPadSize = padSizeX;
+               else
+                 halfPadSize = padSizeY;
+               
+               fIdToEntry[idManuChannel] = iEntry+1;
+
+               lut.fDetElemId = detElemId;
+               lut.fIX = iX;
+               lut.fIY = iY;
+               lut.fRealX = realX;
+               lut.fRealY = realY;
+               lut.fRealZ = realZ;
+               lut.fHalfPadSize = halfPadSize;
+               lut.fPlane = plane;
+               lut.fPed = pedestal;
+               lut.fSigma = sigma;
+               lut.fA0 = calibA0Coeff;
+               lut.fA1 = calibA1Coeff;
+               lut.fThres = thresold;
+               lut.fSat = saturation;
+               
+               lutList.push_back(lut);
+               iEntry++;
+             }// HasPad Condn
+           }// iY loop
+         }// iX loop
+       
+       }// iPlane
+      }// iDDL
+    } // detElemId loop
+
+  }// ichamber loop
+
+  AliHLTMUONHitRecoLutRow *temp;
+
+  try{
+    temp = new AliHLTMUONHitRecoLutRow[iEntry];
+  }
+  catch(const std::bad_alloc&){
+    HLTError("Dynamic memory allocation failed for temp");
+
     return false;
   }
   
-  while (feof(fin)==0){
-    fgets(getLine,80,fin);
-    sscanf(getLine, "%d\t%d %c %d\t%d", &detElem, &minBusPatch, &temp, &maxBusPatch,&ddl);
-    if (detElem >= 700 && detElem <= 1025){
-      
-      for(int i = minBusPatch; i <= maxBusPatch; i++){
-       busToDetElem[i] = detElem;
-       busToDDL[i] = ddl;
-      }//for loop
-    } // detElem condn
-  } // while loop for file
+  for(int iterm = 0; iterm < iEntry ;iterm++)
+    temp[iterm] = lutList.at(iterm);
   
-  fclose(fin);
+  lookupTable = temp;
+
   return true;
 }
index 1f286b4..a51dc0a 100644 (file)
@@ -1,20 +1,8 @@
 #ifndef ALIHLTMUONHITRECONSTRUCTORCOMPONENT_H
 #define ALIHLTMUONHITRECONSTRUCTORCOMPONENT_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$ */
 
 #endif
 
 
+extern "C" struct AliHLTMUONHitRecoLutRow;
+
+
 class AliHLTMUONHitReconstructorComponent : public AliHLTProcessor
 {
-    public:
+public:
        AliHLTMUONHitReconstructorComponent();
        virtual ~AliHLTMUONHitReconstructorComponent();
 
@@ -49,7 +40,7 @@ class AliHLTMUONHitReconstructorComponent : public AliHLTProcessor
        virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
        virtual AliHLTComponent* Spawn();
        
-    protected:
+protected:
        
        // Protected functions to implement AliHLTComponent's interface.
        // These functions provide initialization as well as the actual processing
@@ -61,28 +52,28 @@ class AliHLTMUONHitReconstructorComponent : public AliHLTProcessor
                        const AliHLTComponentEventData& evtData,
                        const AliHLTComponentBlockData* blocks,
                        AliHLTComponentTriggerData& trigData,
-                       AliHLTUInt8_t* outputPtr, 
+                       AliHLTUInt8_t* outputPtr,
                        AliHLTUInt32_t& size,
                        std::vector<AliHLTComponentBlockData>& outputBlocks
                );
        
        using AliHLTProcessor::DoEvent;
        
-    private:
+private:
 
        // Do not allow copying of this class.
        AliHLTMUONHitReconstructorComponent(const AliHLTMUONHitReconstructorComponent& /*obj*/);
        AliHLTMUONHitReconstructorComponent& operator = (const AliHLTMUONHitReconstructorComponent& /*obj*/);
        
+       bool ReadLookUpTable(AliHLTMUONHitRecoLutRow* lookupTable, const char* lutpath);
+       bool ReadCDB(AliHLTMUONHitRecoLutRow*& lookupTable, const char* cdbpath, Int_t run);
+       bool GetLutLine(const char* lutPath, AliHLTInt32_t iDDL, AliHLTUInt32_t& iLine); //To count the nof lines in lookuptable
        AliHLTMUONHitReconstructor* fHitRec;   // Internal class instance implementing the hit reconstruction algorithm.
-       bool ReadLookUpTable(AliHLTMUONHitReconstructor::DHLTLut* lookupTable, const char* lutpath);
-       bool ReadBusPatchToDetElemFile(BusToDetElem& busToDetElem, BusToDDL& busToDDL, const char* buspatchmappath);
-
-       TString fDDLDir;   //TODO: Deprecated, should be removed.
-       Int_t fDDL;        // DDL number in the range [12..19].
-       bool fReaderType;  //TODO: Deprecated, should be removed.
+       AliHLTInt32_t fDDL;        // DDL number in the range [13..20].
+       IdManuChannelToEntry fIdToEntry; // id to line mapping.
        bool fWarnForUnexpecedBlock;  // Flag indicating if we should log a warning if we got a block of an unexpected type.
-
+       
        ClassDef(AliHLTMUONHitReconstructorComponent, 0)
 };
 
diff --git a/HLT/MUON/macros/CreateBusToDetElemFile.C b/HLT/MUON/macros/CreateBusToDetElemFile.C
deleted file mode 100644 (file)
index c284ba0..0000000
+++ /dev/null
@@ -1,70 +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.                  *
- **************************************************************************/
-/*********************************************
-Purpose:  A macro to generate buspatch to ddl mapping file 
-
-Created:  7/10/2005
-Modified: 22/12/2005
-Modified: 09/02/2006
-Modified: 09/04/2007
-Modified: 24/08/2007 (To adopt to AliRoot v4-06-Release)
-
-Author:   Indranil Das, HEP, SINP, Kolkata
-Email:    indra.das@saha.ac.in
-***********************************************/
-
-#include <iostream>
-
-#include <TString.h>
-
-#include <AliCDBManager.h>
-
-#include <AliMpCDB.h>
-#include <AliMpDDLStore.h>
-#include <AliMpDetElement.h>
-
-int CreateBusToDetElemFile(TString CDBPath = "local://$ALICE_ROOT", Int_t run = 0)
-{
-  FILE *fp = fopen("BusToDetElem.dat","w");
-
-  AliMpDetElement* fDetElement;
-  
-  AliCDBManager* cdbManager = AliCDBManager::Instance();
-  cdbManager->SetDefaultStorage(CDBPath.Data());
-  cdbManager->SetRun(run);
-
-  if (! AliMpCDB::LoadDDLStore(true)){
-    cerr<<__FILE__<<": Failed to Load DDLStore specified for CDBPath "<<CDBPath<<", and Run : "<<run<<endl;
-    return kFALSE;
-  }
-
-  fprintf(fp,"#DE\tBusPatch\tDDL\n");
-  for(int ch=7;ch<=10;ch++){
-    fprintf(fp,"# Chamber %d\n",ch);
-    for(int i=0; i<26 ; i++){
-      fDetElement = AliMpDDLStore::Instance()->GetDetElement(ch*100 + i);
-      fprintf(fp,"%d\t%d - %d\t%d\n",ch*100 + i,fDetElement->GetBusPatchId(0),
-             fDetElement->GetBusPatchId(fDetElement->GetNofBusPatches()-1),fDetElement->GetDdlId());
-    }
-  }
-
-
-  delete fDetElement;
-  fclose(fp);
-
-  return 0;
-}
index 14371fa..a78b4b0 100644 (file)
@@ -17,7 +17,7 @@
 /*********************************************
 Purpose:  A macro to generate LookupTable
           in the following form
-detElemId+manuid+channelId  buspatchId Ix  IY  X  Y  B/NB
+buspatchId+manuid+channelId  buspatchId Ix  IY  X  Y  B/NB
 
 Created:  7/10/2005
 Modified: 22/12/2005
@@ -27,10 +27,8 @@ Modified: 24/08/2007 (To adopt to AliRoot v4-06-Release)
 
 Run Info: To run this code copy "rootlogon.C" 
           in the current directory from $ALICE_ROOT/MUON 
-          and specify the 
-          transformFileName as "geometry.root" of the 
-          simulation directory.Then compile and run using
-          .L generateLookupTable.C++
+           then compile and run using
+          .L CreateHitRecoLookupTables.C+
 
 Author:   Indranil Das, HEP, SINP, Kolkata
 Email:    indra.das@saha.ac.in
@@ -41,8 +39,11 @@ Email:    indra.das@saha.ac.in
 //STEER 
 #include "AliCDBManager.h"
 #include "AliGeomManager.h"
+
 //MUON
 #include "AliMUONGeometryTransformer.h"
+#include "AliMUONCalibrationData.h"
+#include "AliMUONVCalibParam.h"
 
 //MUON/mapping 
 #include "AliMpCDB.h"
@@ -52,14 +53,13 @@ Email:    indra.das@saha.ac.in
 #include "AliMpDEIterator.h"
 #include "AliMpVSegmentation.h"
 #include "AliMpDEManager.h"
-
-class AliMpDDLStore ;
+#include <AliMpDetElement.h>
 
 using namespace std;
 
 Bool_t CreateHitRecoLookupTables(TString CDBPath = "local://$ALICE_ROOT", Int_t run = 0, Bool_t warn = kTRUE)
 {
-  Char_t filename1[20], filename2[20];
+  Char_t filename1[50];
   Int_t chamberId;
   
   AliCDBManager* cdbManager = AliCDBManager::Instance();
@@ -79,30 +79,27 @@ Bool_t CreateHitRecoLookupTables(TString CDBPath = "local://$ALICE_ROOT", Int_t
     return kFALSE;
   }
   
-//   AliMpSegmentation *mpSegFactory = AliMpSegmentation::ReadData(); 
-
-//   AliMpDDLStore* fDDLStore = AliMpDDLStore::ReadData();
-  
-//   AliMUONGeometryTransformer* chamberGeometryTransformer = new AliMUONGeometryTransformer();
-//   chamberGeometryTransformer->LoadGeometryData(transformFileName);
+  int maxDDL = 8;
+  FILE *fout[maxDDL];
+  for(int iDDL = 0;iDDL<maxDDL; iDDL++){
+    sprintf(filename1,"Lut%d.dat",iDDL+13);
+    fout[iDDL] = fopen(filename1,"w");
+  }
   
-  for(Int_t iCh = 0; iCh < 4; iCh++){ // max 4
-    
-    sprintf(filename1,"Lut%d.dat",2*(6+iCh)+1);
-    FILE *fout1 = fopen(filename1,"w");
+  AliMUONCalibrationData calibData(run);
 
-    sprintf(filename2,"Lut%d.dat",2*(6+iCh)+2);
-    FILE *fout2 = fopen(filename2,"w");
+  int totMaxIX = -1;
+  int totMaxIY = -1;
 
-    chamberId = iCh + 6;
+  for(Int_t iCh = 6; iCh < 10; iCh++){ // max 4
+
+    chamberId = iCh ;
 
     AliMpDEIterator it;
     for ( it.First(chamberId); ! it.IsDone(); it.Next() ) {
     
       Int_t detElemId = it.CurrentDEId();
-      
-      cout<<"Running for detElemId :"<<detElemId<<endl;
-      
+      int iDDL = AliMpDDLStore::Instance()->GetDetElement(detElemId)->GetDdlId() - 12 ;
       for(Int_t iCath = 0 ; iCath <= 1 ; iCath++){
        
        AliMp::CathodType cath;
@@ -111,35 +108,43 @@ Bool_t CreateHitRecoLookupTables(TString CDBPath = "local://$ALICE_ROOT", Int_t
          cath = AliMp::kCath0 ;
        else
          cath = AliMp::kCath1 ;
-       
-       const AliMpVSegmentation* seg = mpSegFactory->CreateMpSegmentation(detElemId, cath);
+
+       const AliMpVSegmentation* seg = mpSegFactory->GetMpSegmentation(detElemId, cath);
        AliMp::PlaneType plane = seg->PlaneType(); 
        Int_t maxIX = seg->MaxPadIndexX();  
        Int_t maxIY = seg->MaxPadIndexY(); 
-       Int_t idManuChannel, manuId, channelId,idetElemId;
+       if(maxIX > totMaxIX)
+         totMaxIX = maxIX;
+       if(maxIY > totMaxIY)
+         totMaxIY = maxIY;
+
+       Int_t idManuChannel, manuId, channelId, buspatchId;
+       float padSizeX, padSizeY;
+       float halfPadSize ;
        Double_t realX, realY, realZ;
        Double_t localX, localY, localZ;
-       Double_t padSizeX, padSizeY;
-       Int_t pcbType;
+       Float_t calibA0Coeff,calibA1Coeff,pedestal,sigma;
+       Int_t thresold,saturation;
 
-       //Pad Info of a segment
+//     cout<<"Running for detElemId :"<<detElemId<<", and plane : "<<plane<<endl;
+       //Pad Info of a segment to print in lookuptable
        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);
-             
+
              // Getting Manu id
              manuId = pad.GetLocation().GetFirst();
              manuId &= 0x7FF; // 11 bits 
+
+             buspatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
              
              // Getting channel id
              channelId =  pad.GetLocation().GetSecond();
              channelId &= 0x3F; // 6 bits
              
-             idetElemId = detElemId%100;
-             
              idManuChannel &= 0x0;
-             idManuChannel = (idManuChannel|idetElemId)<<11;  
+             idManuChannel = (idManuChannel|buspatchId)<<11;  
              idManuChannel = (idManuChannel|manuId)<<6 ;
              idManuChannel |= channelId ;
              
@@ -150,34 +155,27 @@ Bool_t CreateHitRecoLookupTables(TString CDBPath = "local://$ALICE_ROOT", Int_t
              chamberGeometryTransformer->Local2Global(detElemId,localX,localY,localZ,
                                                       realX,realY,realZ);
 
-             padSizeX = 2.0*pad.Dimensions().X();
-             padSizeY = 2.0*pad.Dimensions().Y();
-
-             if(plane == 0 ){
-               if(padSizeX==2.5)
-                 pcbType = 0;
-               else if(padSizeX==5.0)
-                 pcbType = 1;
-               else
-                 pcbType = 2;
-             }
-             else{
-               if(padSizeY==2.5)
-                 pcbType = 0;
-               else if(padSizeY==5.0)
-                 pcbType = 1;
-               else
-                 pcbType = 2;
-             }
-               
-             if(idetElemId<7 || idetElemId > 19){
-               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,plane);
-             }
-             else{
-               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,plane);
-             }// HasPad Condn
-             
-           }
+             padSizeX = pad.Dimensions().X();
+             padSizeY = pad.Dimensions().Y();
+
+             calibA0Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,0) ;
+             calibA1Coeff = (calibData.Gains(detElemId,manuId))->ValueAsFloat(channelId,1) ;
+             thresold = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,2) ;
+             saturation = (calibData.Gains(detElemId,manuId))->ValueAsInt(channelId,4) ;
+
+             pedestal = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,0);
+             sigma = (calibData.Pedestals(detElemId,manuId))->ValueAsFloat(channelId,1);
+
+             if(plane==0)
+               halfPadSize = padSizeX;
+             else
+               halfPadSize = padSizeY;
+
+             fprintf(fout[iDDL],"%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%d\t%f\t%f\t%f\t%f\t%d\t%d\n",
+                     idManuChannel,detElemId,iX,iY,realX,realY,realZ,
+                     halfPadSize,plane,pedestal,sigma,calibA0Coeff,calibA1Coeff,thresold,saturation);
+
+           }// HasPad Condn
          }// iY loop
        }// iX loop
        
@@ -185,9 +183,15 @@ Bool_t CreateHitRecoLookupTables(TString CDBPath = "local://$ALICE_ROOT", Int_t
 
     } // detElemId loop
 
-    fclose(fout1);
-    fclose(fout2);
+//     fclose(fout1);
+
   }// ichamber loop
+
+  for(int iDDL = 0;iDDL<maxDDL; iDDL++){
+    fclose(fout[iDDL]);
+  }
+
+//   cout<<"TotMaxIX : "<<totMaxIX<<", and totMaxIY : "<<totMaxIY<<endl;
   
   return kTRUE;
 }
index 9d74c0f..18179e7 100644 (file)
@@ -67,6 +67,8 @@ using std::endl;
  *       "max" - Shows everything including debug messages if they were compiled in.
  *       "min" - Shows only error messages.
  * @param lutDir  This is the directory in which the LUTs can be found.
+///TODO *      If it is set to "CDB" (case sensitive) then the LUTs will be loaded from
+///TODO *      CDB instead.
  */
 void RunChain(
                const char* chainType = "full",
@@ -260,21 +262,21 @@ void RunChain(
        // these components if we are are building the ddlreco or full chains.
        if (buildDDLRecoComps)
        {
-               AliHLTConfiguration recDDL13("recDDL13", "MUONHitReconstructor", "pubDDL13", TString("-ddl 13 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut13.dat"));
-               AliHLTConfiguration recDDL14("recDDL14", "MUONHitReconstructor", "pubDDL14", TString("-ddl 14 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut14.dat"));
-               AliHLTConfiguration recDDL15("recDDL15", "MUONHitReconstructor", "pubDDL15", TString("-ddl 15 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut15.dat"));
-               AliHLTConfiguration recDDL16("recDDL16", "MUONHitReconstructor", "pubDDL16", TString("-ddl 16 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut16.dat"));
-               AliHLTConfiguration recDDL17("recDDL17", "MUONHitReconstructor", "pubDDL17", TString("-ddl 17 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut17.dat"));
-               AliHLTConfiguration recDDL18("recDDL18", "MUONHitReconstructor", "pubDDL18", TString("-ddl 18 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut18.dat"));
-               AliHLTConfiguration recDDL19("recDDL19", "MUONHitReconstructor", "pubDDL19", TString("-ddl 19 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut19.dat"));
-               AliHLTConfiguration recDDL20("recDDL20", "MUONHitReconstructor", "pubDDL20", TString("-ddl 20 -buspatchmap ") + lutDir + TString("/BusToDetElem.dat -lut ") + lutDir + TString("/Lut20.dat"));  
+               AliHLTConfiguration recDDL13("recDDL13", "MUONHitReconstructor", "pubDDL13", TString("-ddl 13 -lut ") + lutDir + TString("/Lut13.dat"));
+               AliHLTConfiguration recDDL14("recDDL14", "MUONHitReconstructor", "pubDDL14", TString("-ddl 14 -lut ") + lutDir + TString("/Lut14.dat"));
+               AliHLTConfiguration recDDL15("recDDL15", "MUONHitReconstructor", "pubDDL15", TString("-ddl 15 -lut ") + lutDir + TString("/Lut15.dat"));
+               AliHLTConfiguration recDDL16("recDDL16", "MUONHitReconstructor", "pubDDL16", TString("-ddl 16 -lut ") + lutDir + TString("/Lut16.dat"));
+               AliHLTConfiguration recDDL17("recDDL17", "MUONHitReconstructor", "pubDDL17", TString("-ddl 17 -lut ") + lutDir + TString("/Lut17.dat"));
+               AliHLTConfiguration recDDL18("recDDL18", "MUONHitReconstructor", "pubDDL18", TString("-ddl 18 -lut ") + lutDir + TString("/Lut18.dat"));
+               AliHLTConfiguration recDDL19("recDDL19", "MUONHitReconstructor", "pubDDL19", TString("-ddl 19 -lut ") + lutDir + TString("/Lut19.dat"));
+               AliHLTConfiguration recDDL20("recDDL20", "MUONHitReconstructor", "pubDDL20", TString("-ddl 20 -lut ") + lutDir + TString("/Lut20.dat"));        
                AliHLTConfiguration recDDL21("recDDL21", "MUONTriggerReconstructor", "pubDDL21", TString("-ddl 21 -lut ") + lutDir + TString("/Lut21.dat -suppress_partial_triggers"));
                AliHLTConfiguration recDDL22("recDDL22", "MUONTriggerReconstructor", "pubDDL22", TString("-ddl 22 -lut ") + lutDir + TString("/Lut22.dat -suppress_partial_triggers"));
        }
 
        TString startEventStr = "-firstevent ";
        startEventStr += firstEvent;
-        
+       
        // Build the data source components to take data from simulated hits if
        // we are building the tracker only chain with the 'sim' data source.
        if (buildSimDataPubs)