]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/PHOS/AliHLTPHOSMapper.cxx
Changes for #64259 Request for including the new class AliTRDresponse in STEER and...
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
index 37e81e747f30c41d12487011cfd6964ba8c90bdc..8681e5b416b9e002cf7ce2ef7477eca9dc636f72 100644 (file)
@@ -1,3 +1,5 @@
+// $Id$
+
 /**************************************************************************
  * This file is property of and copyright by the Experimental Nuclear     *
  * Physics Group, Dep. of Physics                                         *
 //
 
 #include "AliHLTPHOSMapper.h"
+#include "unistd.h"
+#include <iostream>
+#include "AliHLTPHOSCoordinate.h"
 
-
-AliHLTPHOSMapper::AliHLTPHOSMapper() : AliHLTPHOSBase(), fHw2geomapPtr(0)
+AliHLTPHOSMapper::AliHLTPHOSMapper():  
+   AliHLTCaloMapper(0,"PHOS") 
+   ,fIsInitializedMapping(false)
+   ,fModuleId(-1)
+   ,fDDLId(-1)
 {
-  //  printf("\nCreating new mapper\n");
-  InitAltroMapping(); 
+  InitDDLSpecificationMapping();
+  sprintf(fFilepath, "./");
 }
 
 
 AliHLTPHOSMapper::~AliHLTPHOSMapper()
 {
-  
+  delete []  fHw2geomapPtr;
+  fHw2geomapPtr = 0;
 }
 
-void
-AliHLTPHOSMapper::InitAltroMapping()
+
+Bool_t
+AliHLTPHOSMapper::InitAltroMapping(const unsigned long specification)
 {
   // Loads mapping between Altro addresses and geometrical addresses from file
 
-  char filename[256];
+  //  HLTError("Initialising ALTRO map");
+
+  fDDLId = GetDDLFromSpec(specification);
+  Int_t modId = GetModuleFromSpec(specification);
+
   char *base =  getenv("ALICE_ROOT");
-  int nChannels = 0;
-  int maxaddr = 0;
-  int tmpHwaddr = 0;
-  int tmpZRow = 0;
-  int tmpXCol = 0;
-  int tmpGain = 0;
-
-  if(base !=0)
+
+  if ( base )
     {
-      sprintf(filename,"%s/PHOS/mapping/RCU0.data", base);
+      if ( modId != fModuleId )
+        {
+          fModuleId = modId;
+          if ( base )
+            {
+              sprintf ( fFilepath,"%s/PHOS/mapping/Mod%dRCU0.data", base, GetModuleFromSpec ( specification ) );
+              int nChannels = 0;
+              int maxaddr = 0;
+              int tmpHwaddr = 0;
+              int tmpZRow = 0;
+              int tmpXCol = 0;
+              int tmpGain = 0;
+              int res = 0;
 
-      FILE *fp = fopen(filename, "r");
-      if(fp != 0)
-       {
-         cout << "mapping file found" << endl;
-         fscanf(fp, "%d", &nChannels);
-         fscanf(fp, "%d", &maxaddr);
-         printf("nChannels = %d", nChannels);
-         printf("maxaddr = %d", maxaddr);
-         fHw2geomapPtr = new fAltromap[maxaddr +1]; 
-
-         for(int i=0; i< maxaddr + 1 ; i ++)
-           {
-             fHw2geomapPtr[i].fXCol = 0;
-             fHw2geomapPtr[i].fZRow = 0;
-             fHw2geomapPtr[i].fGain = 0;
-           }
+              FILE *fp = fopen ( fFilepath, "r" );
+              if ( fp != 0 )
+                {
+                  res = fscanf ( fp, "%d", &nChannels );
+                  res = fscanf ( fp, "%d", &maxaddr );
+                  if (fHw2geomapPtr)
+                    {
+                      delete fHw2geomapPtr;
+                    }
+                  fHw2geomapPtr = new fAltromap[maxaddr +1];
 
-         for(int i=0; i<nChannels; i ++)
-           {
-             fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain);
-             fHw2geomapPtr[tmpHwaddr].fXCol   = tmpXCol;
-             fHw2geomapPtr[tmpHwaddr].fZRow   = tmpZRow;
-             fHw2geomapPtr[tmpHwaddr].fGain  = tmpGain;
+                  for ( int i=0; i< maxaddr + 1 ; i ++ )
+                    {
+                      fHw2geomapPtr[i].fXCol = 0;
+                      fHw2geomapPtr[i].fZRow = 0;
+                      fHw2geomapPtr[i].fGain = 0;
+                    }
+
+                  for ( int i=0; i<nChannels; i ++ )
+                    {
+                      res = fscanf ( fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain );
+                      if ( tmpGain < 2 )
+                        {
+                          fHw2geomapPtr[tmpHwaddr].fXCol   = tmpXCol;
+                          fHw2geomapPtr[tmpHwaddr].fZRow   = tmpZRow;
+                          fHw2geomapPtr[tmpHwaddr].fGain  = tmpGain;
+                        }
+                    }
+                  fIsInitializedMapping = true;
+                  fclose ( fp );
+                }
+              else
+                {
+                  fIsInitializedMapping = false;
+                }
            }
-         
+       }
+    }
+   else 
+   {
+      fIsInitializedMapping = false;
+   }
+   
+   return fIsInitializedMapping;
+}
+   
+
+void
+AliHLTPHOSMapper::InitDDLSpecificationMapping()
+{
+  fSpecificationMapPtr = new fDDLSpecificationMap[fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE()];
+  //  HLTError("NUMBER OF DDLs: %d, map ptr: %d", fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(), fSpecificationMapPtr);
+  for(Int_t ddl = 0; ddl < fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(); ddl++)
+    {
+      
+      fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE();
+      
+      if(ddl%4 == 0)
+       {
+         fSpecificationMapPtr[ddl].fRcuX = 0; 
+         fSpecificationMapPtr[ddl].fRcuZ = 0;
+       }
+      
+      else if(ddl%4 == 1)
+       {
+         fSpecificationMapPtr[ddl].fRcuX = 1; 
+         fSpecificationMapPtr[ddl].fRcuZ = 0;
+       }
+      
+      else if( ddl%4 == 2)
+       {
+         fSpecificationMapPtr[ddl].fRcuX = 2; 
+         fSpecificationMapPtr[ddl].fRcuZ = 0;
        }
       else
        {
-         cout << "ERROR could not find mapping file" << endl;
+         fSpecificationMapPtr[ddl].fRcuX = 3; 
+         fSpecificationMapPtr[ddl].fRcuZ = 0;
        }
+      
+      fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ);
+      fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX);
 
     }
-  else
-    {
-      printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
-    }
+}
 
-} 
 
+bool 
+AliHLTPHOSMapper::GetIsInitializedMapping()
+{
+  return  fIsInitializedMapping;
+}
+
+Int_t
+AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
+{
+
+  //  HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset,
+  //      fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset,
+  //      fHw2geomapPtr[hwAddress].fGain);
+  return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) |
+
+         ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
+         (fHw2geomapPtr[hwAddress].fGain << 12) |
+         fSpecificationMapPtr[fDDLId].fModId << 13);
+}
+
+Int_t
+AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
+{
+  
+  Short_t index = 0;
+
+  if(specification == 0x00001) index = 0;
+  else if(specification == 0x00002) index = 1;
+  else if(specification == 0x00004) index = 2;
+  else if(specification == 0x00008) index = 3;
+
+  else if(specification == 0x00010) index = 4;
+  else if(specification == 0x00020) index = 5;
+  else if(specification == 0x00040) index = 6;
+  else if(specification == 0x00080) index = 7;
+
+  else if(specification == 0x00100) index = 8;
+  else if(specification == 0x00200) index = 9;
+  else if(specification == 0x00400) index = 10;
+  else if(specification == 0x00800) index = 11;
+
+  else if(specification == 0x01000) index = 12;
+  else if(specification == 0x02000) index = 13;
+  else if(specification == 0x04000) index = 14;
+  else if(specification == 0x08000) index = 15;
+
+  else if(specification == 0x10000) index = 16;
+  else if(specification == 0x20000) index = 17;
+  else if(specification == 0x40000) index = 18;
+  else if(specification == 0x80000) index = 19;
+
+  else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
+
+  //  HLTError("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d", ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | (fHw2geomapPtr[hwAddress].fGain << 12) | fSpecificationMapPtr[index].fModId << 13),
+  //      fHw2geomapPtr[hwAddress].fXCol,
+  //     fHw2geomapPtr[hwAddress].fZRow, 
+  //      fHw2geomapPtr[hwAddress].fGain);
+
+  //  HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset,
+  //      fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset,
+  //      fHw2geomapPtr[hwAddress].fGain);
+  //  HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset);
+  //  HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset);
+  return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
+         ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
+         (fHw2geomapPtr[hwAddress].fGain << 12) |
+         fSpecificationMapPtr[index].fModId << 13);
+}
+
+
+
+// void
+// AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
+// {
+//   channelCoord[0] = channelId&0x3f;
+//   channelCoord[1] = (channelId >> 6)&0x3f;
+//   channelCoord[2] = (channelId >> 12)&0x1;
+//   channelCoord[3] = (channelId >> 13)&0x1f;
+//   //  printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
+// }
+// 
+// 
+// 
+// void
+// AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId,    AliHLTPHOSCoordinate &channelCoord)
+// {
+//   channelCoord.fX = channelId&0x3f;
+//   channelCoord.fZ = (channelId >> 6)&0x3f;
+//   channelCoord.fGain = (channelId >> 12)&0x1;
+//   channelCoord.fModuleId  = (channelId >> 13)&0x1f;
+//   //  printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
+// }
+// 
+// 
+// 
+// void
+// AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
+// {
+//   channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
+//   channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
+//   //  printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
+// }
+
+Int_t 
+AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification)
+{
+  Int_t index = -1;
+  if(specification == 0x00001) index = 0;
+  else if(specification == 0x00002) index = 1;
+  else if(specification == 0x00004) index = 2;
+  else if(specification == 0x00008) index = 3;
+
+  else if(specification == 0x00010) index = 4;
+  else if(specification == 0x00020) index = 5;
+  else if(specification == 0x00040) index = 6;
+  else if(specification == 0x00080) index = 7;
+
+  else if(specification == 0x00100) index = 8;
+  else if(specification == 0x00200) index = 9;
+  else if(specification == 0x00400) index = 10;
+  else if(specification == 0x00800) index = 11;
+
+  else if(specification == 0x01000) index = 12;
+  else if(specification == 0x02000) index = 13;
+  else if(specification == 0x04000) index = 14;
+  else if(specification == 0x08000) index = 15;
+
+  else if(specification == 0x10000) index = 16;
+  else if(specification == 0x20000) index = 17;
+  else if(specification == 0x40000) index = 18;
+  else if(specification == 0x80000) index = 19;
+
+  else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
+
+  return index;
+}
+
+Int_t 
+AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
+{
+  Int_t module = -1;
+      
+  if(specification & 0xf) module = 0;
+  else if((specification >> 4) & 0xf) module = 1;
+  else if((specification >> 8) & 0xf) module = 2;
+  else if((specification >> 12) & 0xf) module = 3;
+  else if((specification >> 16) & 0xf) module = 4;
+  else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);
+
+  return module;
+}