* provided "as is" without express or implied warranty. *
**************************************************************************/
-#include "AliHLTPHOSMapper.h"
-
+//
+// Mapping class fro mapping
+// from hardware address to geometrical address
+//
+//
-AliHLTPHOSMapper::AliHLTPHOSMapper() : AliHLTPHOSBase(), hw2geomapPtr(0)
+#include "AliHLTPHOSMapper.h"
+#include "AliHLTPHOSConstants.h"
+#include "AliHLTLogging.h"
+#include "Rtypes.h"
+#include "unistd.h"
+#include <iostream>
+
+using namespace PhosHLTConst;
+AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(),
+ fHw2geomapPtr(0),
+ fIsInitializedMapping(false),
+ fSpecificationMapPtr(0)
{
- // printf("\nCreating new mapper\n");
InitAltroMapping();
+ InitDDLSpecificationMapping();
}
AliHLTPHOSMapper::~AliHLTPHOSMapper()
{
-
+ delete [] fHw2geomapPtr;
+ fHw2geomapPtr = 0;
}
-
void
AliHLTPHOSMapper::InitAltroMapping()
{
- char filename[256];
- char *base = getenv("ALICE_ROOT");
+ // Loads mapping between Altro addresses and geometrical addresses from file
+ // char filename[256];
+ char *base = getenv("ALICE_ROOT");
int nChannels = 0;
int maxaddr = 0;
-
int tmpHwaddr = 0;
int tmpZRow = 0;
int tmpXCol = 0;
if(base !=0)
{
- sprintf(filename,"%s/PHOS/mapping/RCU0.data", base);
- // printf("AliHLTPHOSMapper::InitAltroMapping()")
- FILE *fp = fopen(filename, "r");
+ sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
+
+ FILE *fp = fopen(fFilepath, "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);
- hw2geomapPtr = new altromap[maxaddr +1];
-
+ fHw2geomapPtr = new fAltromap[maxaddr +1];
for(int i=0; i< maxaddr + 1 ; i ++)
{
- hw2geomapPtr[i].col = 0;
- hw2geomapPtr[i].row = 0;
- hw2geomapPtr[i].gain = 0;
+ fHw2geomapPtr[i].fXCol = 0;
+ fHw2geomapPtr[i].fZRow = 0;
+ fHw2geomapPtr[i].fGain = 0;
}
-
- printf("\n");
-
for(int i=0; i<nChannels; i ++)
{
fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
- // printf("tmpHwaddr = %d\t tmpXCol = %d\t tmpZRow = %d\t tmpGain = %d\n", tmpHwaddr, tmpXCol, tmpZRow, tmpGain);
-
- hw2geomapPtr[tmpHwaddr].col = tmpXCol;
- hw2geomapPtr[tmpHwaddr].row = tmpZRow;
- hw2geomapPtr[tmpHwaddr].gain = tmpGain;
-
+ fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
+ fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
+ fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
}
-
- printf("\n");
- // for(int i=0; i< nChannels; i ++)
-
-
- /*Æ
- for(int i=120; i< 500; i ++)
- {
- printf( "%d\t%d\t%d\t%d\n", i, hw2geomapPtr[i].col, hw2geomapPtr[i].row, hw2geomapPtr[i].gain);
- }
-
- printf("\n");
- */
-
-
-
+ fIsInitializedMapping = true;
+ fclose(fp);
}
else
{
- cout << "ERROR could not find mapping file" << endl;
+ fIsInitializedMapping = false;
}
-
}
else
{
- printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
+ fIsInitializedMapping = false;
}
-
}
-
-
-
-
-/*
-void
-AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
+void
+AliHLTPHOSMapper::InitDDLSpecificationMapping()
{
- // Find row & col by CSP
- int col = csp / 16;
- int row = csp % 16;
- //In 2004 beam test was also: if(row>7)row=23-row;
- // Check if arguments Ok
- assert((col>=0)&&(col<2));
- assert((row>=0)&&(row<16));
- assert((csp>=0)&&(csp<32));
- assert((numHi>=0)&&(numHi<64));
- assert((numLo>=0)&&(numLo<64));
- assert((chHi>=0)&&(chHi< N_ALTROCHANNELS));
- assert((chLo>=0)&&(chLo< N_ALTROCHANNELS));
- assert((chip>=0)&&(chip<N_ALTROS));
- // Fill CSP array
- CSP_MAP[chip][chHi].row=row; CSP_MAP[chip][chLo].row=row;
- CSP_MAP[chip][chHi].col=col; CSP_MAP[chip][chLo].col=col;
- CSP_MAP[chip][chHi].gain=1; CSP_MAP[chip][chLo].gain=0;
- CSP_MAP[chip][chHi].csp=csp; CSP_MAP[chip][chLo].csp=csp;
- CSP_MAP[chip][chHi].num=numHi; CSP_MAP[chip][chLo].num=numLo;
+ fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::N_MODULES*PhosHLTConst::N_RCUS_PER_MODULE];
+ for(Int_t ddl = 0; ddl < PhosHLTConst::N_MODULES*PhosHLTConst::N_RCUS_PER_MODULE; ddl++)
+ {
+
+ fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::N_RCUS_PER_MODULE;
+
+ if(ddl%4 == 0)
+ {
+ fSpecificationMapPtr[ddl].fRcuX = 0;
+ fSpecificationMapPtr[ddl].fRcuZ = 0;
+ }
+
+ else if(ddl%4 == 1)
+ {
+ fSpecificationMapPtr[ddl].fRcuX = 0;
+ fSpecificationMapPtr[ddl].fRcuZ = 1;
+ }
+
+ else if( ddl%4 == 2)
+ {
+ fSpecificationMapPtr[ddl].fRcuX = 1;
+ fSpecificationMapPtr[ddl].fRcuZ = 0;
+ }
+ else
+ {
+ fSpecificationMapPtr[ddl].fRcuX = 1;
+ fSpecificationMapPtr[ddl].fRcuZ = 1;
+ }
+
+ fSpecificationMapPtr[ddl].fRcuZOffset = N_ZROWS_RCU*(fSpecificationMapPtr[ddl].fRcuZ);
+ fSpecificationMapPtr[ddl].fRcuXOffset = N_XCOLUMNS_RCU*(fSpecificationMapPtr[ddl].fRcuX);
+ }
}
-*/
- /////////////////////////////////////////////////////////////////
- // Initialize CSP mapping table.
- // Note we use (0,1,2,3) instead of (0,2,3,4) ALTRO chip numbers.
- // So strange numbers we have due to well known RCU firmware bug.
- /////////////////////////////////////////////////////////////////
-
- /*
-void
-AliHLTPHOSMapper::InitAltroCspMapping()
+bool
+AliHLTPHOSMapper::GetIsInitializedMapping()
{
- // T1 csp chip chHi chLo numHi numLo
- AddCsp( 0, 1, 10, 11, 26, 27);
- AddCsp( 1, 1, 14, 15, 30, 31);
- AddCsp( 2, 1, 5, 4, 21, 20);
- AddCsp( 3, 1, 1, 0, 17, 16);
- AddCsp( 4, 2, 1, 0, 33, 32);
- AddCsp( 5, 2, 5, 4, 37, 36);
- AddCsp( 6, 2, 14, 15, 46, 47);
- AddCsp( 7, 2, 10, 11, 42, 43);
- // T2 csp chip chHi chLo numHi numLo
- AddCsp( 8, 0, 10, 11, 10, 11);
- AddCsp( 9, 0, 14, 15, 14, 15);
- AddCsp( 10, 0, 5, 4, 5, 4);
- AddCsp( 11, 0, 1, 0, 1, 0);
- AddCsp( 12, 3, 1, 0, 49, 48);
- AddCsp( 13, 3, 5, 4, 53, 52);
- AddCsp( 14, 3, 14, 15, 62, 63);
- AddCsp( 15, 3, 10, 11, 58, 59);
- // T3 csp chip chHi chLo numHi numLo
- AddCsp( 16, 1, 8, 9, 24, 25);
- AddCsp( 17, 1, 12, 13, 28, 29);
- AddCsp( 18, 1, 7, 6, 23, 22);
- AddCsp( 19, 1, 3, 2, 19, 18);
- AddCsp( 20, 2, 3, 2, 35, 34);
- AddCsp( 21, 2, 7, 6, 39, 38);
- AddCsp( 22, 2, 12, 13, 44, 45);
- AddCsp( 23, 2, 8, 9, 40, 41);
- // T4 csp chip chHi chLo numHi numLo
- AddCsp( 24, 0, 8, 9, 8, 9);
- AddCsp( 25, 0, 12, 13, 12, 13);
- AddCsp( 26, 0, 7, 6, 7, 6);
- AddCsp( 27, 0, 3, 2, 3, 2);
- AddCsp( 28, 3, 3, 2, 51, 50);
- AddCsp( 29, 3, 7, 6, 55, 54);
- AddCsp( 30, 3, 12, 13, 60, 61);
- AddCsp( 31, 3, 8, 9, 56, 57);
-}
-
-*/
-//void
-//AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
-//{
-//
-//
-//}
-
-//inline int
-
-/*
-int
-AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
-{
- return mod*100000+gain*10000+row*100+col;
-}
-
-//inline int
-int
-AliHLTPHOSMapper::Hid2mod(int hid)
-{
- return hid/100000;
-}
-
-
-//inline int
-int
-AliHLTPHOSMapper::Hid2gain(int hid)
-{
- return (hid/10000)%10;
+ return fIsInitializedMapping;
}
-//inline int
-int
-AliHLTPHOSMapper::Hid2row(int hid)
-{
- return (hid/100)%100;
-}
-//inline int
-int
-AliHLTPHOSMapper::Hid2col(int hid)
-{
- return hid%100;
+char*
+AliHLTPHOSMapper::GetFilePath()
+{
+ return fFilepath;
}
-////////////////////////////////////////////////////////////////////////
-// ALTRO mapping first time initialization (do it once in startup time).
-////////////////////////////////////////////////////////////////////////
-
-
-
-//inline void
-//AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
-// initAltroMapping(int)'
-void
-AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
+UShort_t
+AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
{
- //
- // Init CSP mapping first.
- //
- InitAltroCspMapping();
- //
-
- // Clear index arrays
- //
- for(int m=0; m<N_MODULES; m++)
- for(int g=0; g<N_GAINS;g++)
- for(int r=0; r< N_XCOLUMNS_MOD; r++)
- for(int c=0; c<N_ZROWS_MOD; c++)
- {
- geo2hdw[m][g][r][c]=-1;
- }
- for(int m=0; m<N_MODULES; m++)
- for(int r=0; r<N_RCUS; r++)
- for(int b=0; b<N_BRANCHES; b++)
- for(int f=0; f<N_FEECS; f++)
- for(int a=0; a<N_ALTROS; a++)
- for(int c=0; c<N_ALTROCHANNELS; c++)
- {
- hdw2geo[m][r][b][f][a][c]=-1;
- }
- //
- // Fill all FEE cards via formula
- //
- int index=0;
- for(int m=0; m<N_MODULES; m++)
- for(int r=0; r<N_RCUS; r++)
- for(int b=0; b<N_BRANCHES; b++)
- for(int f=0; f<N_FEECS; f++)
- for(int a=0; a<N_ALTROS; a++)
- for(int c=0; c<N_ALTROCHANNELS; c++)
- {
- int row = (r/2)*32 + b*16 + CSP_MAP[a][c].row;
- int col = (r%2)*28 + f*2 + CSP_MAP[a][c].col;
- int gain = CSP_MAP[a][c].gain;
- int csp = CSP_MAP[a][c].csp;
- int num = CSP_MAP[a][c].num;
- ALTRO_MAP[index].mod=m;
- ALTRO_MAP[index].row=row;
- ALTRO_MAP[index].col=col;
- ALTRO_MAP[index].gain=gain;
- ALTRO_MAP[index].rcu=r;
- ALTRO_MAP[index].branch=b;
- ALTRO_MAP[index].card=f;
- ALTRO_MAP[index].chip=a;
- ALTRO_MAP[index].chan=c;
- ALTRO_MAP[index].csp=csp;
- ALTRO_MAP[index].num=num;
- ALTRO_MAP[index].hid=Geo2hid(m,gain,row,col);
- hdw2geo[m][r][b][f][a][c]=index;
- if((row>=0)&&(row< N_XCOLUMNS_MOD))
- if((col>=0)&&(col<N_ZROWS_MOD))
- if((gain>=0)&&(gain<N_GAINS)) geo2hdw[m][gain][row][col]=index;
- index++;
- }
-
- //
- // Check if geo2hdw map table is filled
- //
- for(int m=0; m<N_MODULES; m++)
- for(int g=0; g<N_GAINS;g++)
- for(int r=0; r< N_XCOLUMNS_MOD; r++)
- for(int c=0; c< N_ZROWS_MOD; c++)
- {
- assert(geo2hdw[m][g][r][c] >= 0);
- }
- //
- // Check if hdw2geo map table is filled
- //
- for(int m=0; m<N_MODULES; m++)
- for(int r=0; r<N_RCUS; r++)
- for(int b=0; b<N_BRANCHES; b++)
- for(int f=0; f<N_FEECS; f++)
- for(int a=0; a<N_ALTROS; a++)
- for(int c=0; c<N_ALTROCHANNELS; c++)
- {
- assert(hdw2geo[m][r][b][f][a][c] >= 0);
- }
-}
-
-
-*/
-
-/*
-
-////////////////////////////////////////////////////////////////////////
-// Return histogramm id from histogramm name or -1 on error.
-// extractHid("hMax011426")=11426;
-////////////////////////////////////////////////////////////////////////
-//inline int
-int
-AliHLTPHOSMapper::ExtractHid(char *objName){
- // char *perr= NULL;
- char *perr= 0;
- if(strlen(objName)<7) return -1;
- int hid=strtol(&objName[strlen(objName)-6],&perr,10);
- if(strlen(perr))return -1;
- return hid;
+ 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);
+
+ return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
+ ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
+ (fHw2geomapPtr[hwAddress].fGain << 12) |
+ fSpecificationMapPtr[index].fModId << 13);
}
-////////////////////////////////////////////////////////////////////////
-// Print geometry and hardware information for given histogramm
-// printHistMapInfo("hMax011426");
-// hid mod gain row col rcu bran fee chip chan csp num
-// 011426 0 1 14 26 0 0 13 3 14 14 62
-////////////////////////////////////////////////////////////////////////
-//inline void
-void
-AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
- int hid=ExtractHid(objName);
- if(hid>=0){
- int mod=Hid2mod(hid);
- int gain=Hid2gain(hid);
- int row=Hid2row(hid);
- int col=Hid2col(hid);
- int index=geo2hdw[mod][gain][row][col]; assert(index>=0);
- int rcu = ALTRO_MAP[index].rcu;
- int bran = ALTRO_MAP[index].branch;
- int fec = ALTRO_MAP[index].card;
- int chip = ALTRO_MAP[index].chip;
- int chan = ALTRO_MAP[index].chan;
- int csp = ALTRO_MAP[index].csp;
- int num = ALTRO_MAP[index].num;
- printf("%s attributes:\nhid\tmod\tgain\trow\tcol\trcu\tbran\tfee\tchip\tchan\tcsp\tnum\n",objName);
- printf("%06d\t%d\t%d\t%02d\t%02d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",hid,mod,gain,row,col,rcu,bran,fec,chip,chan,csp,num);
- }
+void
+AliHLTPHOSMapper::GetChannelCoord(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;
}
-
-
-*/