1 /**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2006 *
6 * Author: Per Thomas Hille perthi@fys.uio.no for the ALICE DCS Project. *
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to perthi@fys.uio.no *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 #include "AliHLTPHOSMapper.h"
22 AliHLTPHOSMapper::AliHLTPHOSMapper() : AliHLTPHOSBase(), hw2geomapPtr(0)
24 // printf("\nCreating new mapper\n");
29 AliHLTPHOSMapper::~AliHLTPHOSMapper()
36 AliHLTPHOSMapper::InitAltroMapping()
39 char *base = getenv("ALICE_ROOT");
51 sprintf(filename,"%s/PHOS/mapping/RCU0.data", base);
52 // printf("AliHLTPHOSMapper::InitAltroMapping()")
53 FILE *fp = fopen(filename, "r");
56 cout << "mapping file found" << endl;
57 fscanf(fp, "%d", &nChannels);
58 fscanf(fp, "%d", &maxaddr);
59 printf("nChannels = %d", nChannels);
60 printf("maxaddr = %d", maxaddr);
61 hw2geomapPtr = new altromap[maxaddr +1];
64 for(int i=0; i< maxaddr + 1 ; i ++)
66 hw2geomapPtr[i].col = 0;
67 hw2geomapPtr[i].row = 0;
68 hw2geomapPtr[i].gain = 0;
74 for(int i=0; i<nChannels; i ++)
76 fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
77 // printf("tmpHwaddr = %d\t tmpXCol = %d\t tmpZRow = %d\t tmpGain = %d\n", tmpHwaddr, tmpXCol, tmpZRow, tmpGain);
79 hw2geomapPtr[tmpHwaddr].col = tmpXCol;
80 hw2geomapPtr[tmpHwaddr].row = tmpZRow;
81 hw2geomapPtr[tmpHwaddr].gain = tmpGain;
86 // for(int i=0; i< nChannels; i ++)
90 for(int i=120; i< 500; i ++)
92 printf( "%d\t%d\t%d\t%d\n", i, hw2geomapPtr[i].col, hw2geomapPtr[i].row, hw2geomapPtr[i].gain);
103 cout << "ERROR could not find mapping file" << endl;
109 printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
120 AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
122 // Find row & col by CSP
125 //In 2004 beam test was also: if(row>7)row=23-row;
126 // Check if arguments Ok
127 assert((col>=0)&&(col<2));
128 assert((row>=0)&&(row<16));
129 assert((csp>=0)&&(csp<32));
130 assert((numHi>=0)&&(numHi<64));
131 assert((numLo>=0)&&(numLo<64));
132 assert((chHi>=0)&&(chHi< N_ALTROCHANNELS));
133 assert((chLo>=0)&&(chLo< N_ALTROCHANNELS));
134 assert((chip>=0)&&(chip<N_ALTROS));
136 CSP_MAP[chip][chHi].row=row; CSP_MAP[chip][chLo].row=row;
137 CSP_MAP[chip][chHi].col=col; CSP_MAP[chip][chLo].col=col;
138 CSP_MAP[chip][chHi].gain=1; CSP_MAP[chip][chLo].gain=0;
139 CSP_MAP[chip][chHi].csp=csp; CSP_MAP[chip][chLo].csp=csp;
140 CSP_MAP[chip][chHi].num=numHi; CSP_MAP[chip][chLo].num=numLo;
145 /////////////////////////////////////////////////////////////////
146 // Initialize CSP mapping table.
147 // Note we use (0,1,2,3) instead of (0,2,3,4) ALTRO chip numbers.
148 // So strange numbers we have due to well known RCU firmware bug.
149 /////////////////////////////////////////////////////////////////
153 AliHLTPHOSMapper::InitAltroCspMapping()
155 // T1 csp chip chHi chLo numHi numLo
156 AddCsp( 0, 1, 10, 11, 26, 27);
157 AddCsp( 1, 1, 14, 15, 30, 31);
158 AddCsp( 2, 1, 5, 4, 21, 20);
159 AddCsp( 3, 1, 1, 0, 17, 16);
160 AddCsp( 4, 2, 1, 0, 33, 32);
161 AddCsp( 5, 2, 5, 4, 37, 36);
162 AddCsp( 6, 2, 14, 15, 46, 47);
163 AddCsp( 7, 2, 10, 11, 42, 43);
164 // T2 csp chip chHi chLo numHi numLo
165 AddCsp( 8, 0, 10, 11, 10, 11);
166 AddCsp( 9, 0, 14, 15, 14, 15);
167 AddCsp( 10, 0, 5, 4, 5, 4);
168 AddCsp( 11, 0, 1, 0, 1, 0);
169 AddCsp( 12, 3, 1, 0, 49, 48);
170 AddCsp( 13, 3, 5, 4, 53, 52);
171 AddCsp( 14, 3, 14, 15, 62, 63);
172 AddCsp( 15, 3, 10, 11, 58, 59);
173 // T3 csp chip chHi chLo numHi numLo
174 AddCsp( 16, 1, 8, 9, 24, 25);
175 AddCsp( 17, 1, 12, 13, 28, 29);
176 AddCsp( 18, 1, 7, 6, 23, 22);
177 AddCsp( 19, 1, 3, 2, 19, 18);
178 AddCsp( 20, 2, 3, 2, 35, 34);
179 AddCsp( 21, 2, 7, 6, 39, 38);
180 AddCsp( 22, 2, 12, 13, 44, 45);
181 AddCsp( 23, 2, 8, 9, 40, 41);
182 // T4 csp chip chHi chLo numHi numLo
183 AddCsp( 24, 0, 8, 9, 8, 9);
184 AddCsp( 25, 0, 12, 13, 12, 13);
185 AddCsp( 26, 0, 7, 6, 7, 6);
186 AddCsp( 27, 0, 3, 2, 3, 2);
187 AddCsp( 28, 3, 3, 2, 51, 50);
188 AddCsp( 29, 3, 7, 6, 55, 54);
189 AddCsp( 30, 3, 12, 13, 60, 61);
190 AddCsp( 31, 3, 8, 9, 56, 57);
195 //AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
205 AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
207 return mod*100000+gain*10000+row*100+col;
212 AliHLTPHOSMapper::Hid2mod(int hid)
220 AliHLTPHOSMapper::Hid2gain(int hid)
222 return (hid/10000)%10;
227 AliHLTPHOSMapper::Hid2row(int hid)
229 return (hid/100)%100;
234 AliHLTPHOSMapper::Hid2col(int hid)
239 ////////////////////////////////////////////////////////////////////////
240 // ALTRO mapping first time initialization (do it once in startup time).
241 ////////////////////////////////////////////////////////////////////////
246 //AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
247 // initAltroMapping(int)'
249 AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
252 // Init CSP mapping first.
254 InitAltroCspMapping();
257 // Clear index arrays
259 for(int m=0; m<N_MODULES; m++)
260 for(int g=0; g<N_GAINS;g++)
261 for(int r=0; r< N_XCOLUMNS_MOD; r++)
262 for(int c=0; c<N_ZROWS_MOD; c++)
264 geo2hdw[m][g][r][c]=-1;
267 for(int m=0; m<N_MODULES; m++)
268 for(int r=0; r<N_RCUS; r++)
269 for(int b=0; b<N_BRANCHES; b++)
270 for(int f=0; f<N_FEECS; f++)
271 for(int a=0; a<N_ALTROS; a++)
272 for(int c=0; c<N_ALTROCHANNELS; c++)
274 hdw2geo[m][r][b][f][a][c]=-1;
277 // Fill all FEE cards via formula
280 for(int m=0; m<N_MODULES; m++)
281 for(int r=0; r<N_RCUS; r++)
282 for(int b=0; b<N_BRANCHES; b++)
283 for(int f=0; f<N_FEECS; f++)
284 for(int a=0; a<N_ALTROS; a++)
285 for(int c=0; c<N_ALTROCHANNELS; c++)
287 int row = (r/2)*32 + b*16 + CSP_MAP[a][c].row;
288 int col = (r%2)*28 + f*2 + CSP_MAP[a][c].col;
289 int gain = CSP_MAP[a][c].gain;
290 int csp = CSP_MAP[a][c].csp;
291 int num = CSP_MAP[a][c].num;
292 ALTRO_MAP[index].mod=m;
293 ALTRO_MAP[index].row=row;
294 ALTRO_MAP[index].col=col;
295 ALTRO_MAP[index].gain=gain;
296 ALTRO_MAP[index].rcu=r;
297 ALTRO_MAP[index].branch=b;
298 ALTRO_MAP[index].card=f;
299 ALTRO_MAP[index].chip=a;
300 ALTRO_MAP[index].chan=c;
301 ALTRO_MAP[index].csp=csp;
302 ALTRO_MAP[index].num=num;
303 ALTRO_MAP[index].hid=Geo2hid(m,gain,row,col);
304 hdw2geo[m][r][b][f][a][c]=index;
305 if((row>=0)&&(row< N_XCOLUMNS_MOD))
306 if((col>=0)&&(col<N_ZROWS_MOD))
307 if((gain>=0)&&(gain<N_GAINS)) geo2hdw[m][gain][row][col]=index;
312 // Check if geo2hdw map table is filled
314 for(int m=0; m<N_MODULES; m++)
315 for(int g=0; g<N_GAINS;g++)
316 for(int r=0; r< N_XCOLUMNS_MOD; r++)
317 for(int c=0; c< N_ZROWS_MOD; c++)
319 assert(geo2hdw[m][g][r][c] >= 0);
322 // Check if hdw2geo map table is filled
324 for(int m=0; m<N_MODULES; m++)
325 for(int r=0; r<N_RCUS; r++)
326 for(int b=0; b<N_BRANCHES; b++)
327 for(int f=0; f<N_FEECS; f++)
328 for(int a=0; a<N_ALTROS; a++)
329 for(int c=0; c<N_ALTROCHANNELS; c++)
331 assert(hdw2geo[m][r][b][f][a][c] >= 0);
340 ////////////////////////////////////////////////////////////////////////
341 // Return histogramm id from histogramm name or -1 on error.
342 // extractHid("hMax011426")=11426;
343 ////////////////////////////////////////////////////////////////////////
346 AliHLTPHOSMapper::ExtractHid(char *objName){
349 if(strlen(objName)<7) return -1;
350 int hid=strtol(&objName[strlen(objName)-6],&perr,10);
351 if(strlen(perr))return -1;
355 ////////////////////////////////////////////////////////////////////////
356 // Print geometry and hardware information for given histogramm
357 // printHistMapInfo("hMax011426");
358 // hid mod gain row col rcu bran fee chip chan csp num
359 // 011426 0 1 14 26 0 0 13 3 14 14 62
360 ////////////////////////////////////////////////////////////////////////
363 AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
364 int hid=ExtractHid(objName);
366 int mod=Hid2mod(hid);
367 int gain=Hid2gain(hid);
368 int row=Hid2row(hid);
369 int col=Hid2col(hid);
370 int index=geo2hdw[mod][gain][row][col]; assert(index>=0);
371 int rcu = ALTRO_MAP[index].rcu;
372 int bran = ALTRO_MAP[index].branch;
373 int fec = ALTRO_MAP[index].card;
374 int chip = ALTRO_MAP[index].chip;
375 int chan = ALTRO_MAP[index].chan;
376 int csp = ALTRO_MAP[index].csp;
377 int num = ALTRO_MAP[index].num;
378 printf("%s attributes:\nhid\tmod\tgain\trow\tcol\trcu\tbran\tfee\tchip\tchan\tcsp\tnum\n",objName);
379 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);