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< nChannels; i ++)
66 hw2geomapPtr[i].col = 0;
67 hw2geomapPtr[i].row = 0;
68 hw2geomapPtr[i].gain = 0;
73 for(int i=0; i<nChannels; i ++)
75 fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
76 // printf("tmpHwaddr = %d\t tmpXCol = %d\t tmpZRow = %d\t tmpGain = %d\n", tmpHwaddr, tmpXCol, tmpZRow, tmpGain);
78 hw2geomapPtr[tmpHwaddr].col = tmpXCol;
79 hw2geomapPtr[tmpHwaddr].row = tmpZRow;
80 hw2geomapPtr[tmpHwaddr].gain = tmpGain;
85 // for(int i=0; i< nChannels; i ++)
89 for(int i=120; i< 500; i ++)
91 printf( "%d\t%d\t%d\t%d\n", i, hw2geomapPtr[i].col, hw2geomapPtr[i].row, hw2geomapPtr[i].gain);
102 cout << "ERROR could not find mapping file" << endl;
108 printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
119 AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
121 // Find row & col by CSP
124 //In 2004 beam test was also: if(row>7)row=23-row;
125 // Check if arguments Ok
126 assert((col>=0)&&(col<2));
127 assert((row>=0)&&(row<16));
128 assert((csp>=0)&&(csp<32));
129 assert((numHi>=0)&&(numHi<64));
130 assert((numLo>=0)&&(numLo<64));
131 assert((chHi>=0)&&(chHi< N_ALTROCHANNELS));
132 assert((chLo>=0)&&(chLo< N_ALTROCHANNELS));
133 assert((chip>=0)&&(chip<N_ALTROS));
135 CSP_MAP[chip][chHi].row=row; CSP_MAP[chip][chLo].row=row;
136 CSP_MAP[chip][chHi].col=col; CSP_MAP[chip][chLo].col=col;
137 CSP_MAP[chip][chHi].gain=1; CSP_MAP[chip][chLo].gain=0;
138 CSP_MAP[chip][chHi].csp=csp; CSP_MAP[chip][chLo].csp=csp;
139 CSP_MAP[chip][chHi].num=numHi; CSP_MAP[chip][chLo].num=numLo;
144 /////////////////////////////////////////////////////////////////
145 // Initialize CSP mapping table.
146 // Note we use (0,1,2,3) instead of (0,2,3,4) ALTRO chip numbers.
147 // So strange numbers we have due to well known RCU firmware bug.
148 /////////////////////////////////////////////////////////////////
152 AliHLTPHOSMapper::InitAltroCspMapping()
154 // T1 csp chip chHi chLo numHi numLo
155 AddCsp( 0, 1, 10, 11, 26, 27);
156 AddCsp( 1, 1, 14, 15, 30, 31);
157 AddCsp( 2, 1, 5, 4, 21, 20);
158 AddCsp( 3, 1, 1, 0, 17, 16);
159 AddCsp( 4, 2, 1, 0, 33, 32);
160 AddCsp( 5, 2, 5, 4, 37, 36);
161 AddCsp( 6, 2, 14, 15, 46, 47);
162 AddCsp( 7, 2, 10, 11, 42, 43);
163 // T2 csp chip chHi chLo numHi numLo
164 AddCsp( 8, 0, 10, 11, 10, 11);
165 AddCsp( 9, 0, 14, 15, 14, 15);
166 AddCsp( 10, 0, 5, 4, 5, 4);
167 AddCsp( 11, 0, 1, 0, 1, 0);
168 AddCsp( 12, 3, 1, 0, 49, 48);
169 AddCsp( 13, 3, 5, 4, 53, 52);
170 AddCsp( 14, 3, 14, 15, 62, 63);
171 AddCsp( 15, 3, 10, 11, 58, 59);
172 // T3 csp chip chHi chLo numHi numLo
173 AddCsp( 16, 1, 8, 9, 24, 25);
174 AddCsp( 17, 1, 12, 13, 28, 29);
175 AddCsp( 18, 1, 7, 6, 23, 22);
176 AddCsp( 19, 1, 3, 2, 19, 18);
177 AddCsp( 20, 2, 3, 2, 35, 34);
178 AddCsp( 21, 2, 7, 6, 39, 38);
179 AddCsp( 22, 2, 12, 13, 44, 45);
180 AddCsp( 23, 2, 8, 9, 40, 41);
181 // T4 csp chip chHi chLo numHi numLo
182 AddCsp( 24, 0, 8, 9, 8, 9);
183 AddCsp( 25, 0, 12, 13, 12, 13);
184 AddCsp( 26, 0, 7, 6, 7, 6);
185 AddCsp( 27, 0, 3, 2, 3, 2);
186 AddCsp( 28, 3, 3, 2, 51, 50);
187 AddCsp( 29, 3, 7, 6, 55, 54);
188 AddCsp( 30, 3, 12, 13, 60, 61);
189 AddCsp( 31, 3, 8, 9, 56, 57);
194 //AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
204 AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
206 return mod*100000+gain*10000+row*100+col;
211 AliHLTPHOSMapper::Hid2mod(int hid)
219 AliHLTPHOSMapper::Hid2gain(int hid)
221 return (hid/10000)%10;
226 AliHLTPHOSMapper::Hid2row(int hid)
228 return (hid/100)%100;
233 AliHLTPHOSMapper::Hid2col(int hid)
238 ////////////////////////////////////////////////////////////////////////
239 // ALTRO mapping first time initialization (do it once in startup time).
240 ////////////////////////////////////////////////////////////////////////
245 //AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
246 // initAltroMapping(int)'
248 AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
251 // Init CSP mapping first.
253 InitAltroCspMapping();
256 // Clear index arrays
258 for(int m=0; m<N_MODULES; m++)
259 for(int g=0; g<N_GAINS;g++)
260 for(int r=0; r< N_XCOLUMNS_MOD; r++)
261 for(int c=0; c<N_ZROWS_MOD; c++)
263 geo2hdw[m][g][r][c]=-1;
266 for(int m=0; m<N_MODULES; m++)
267 for(int r=0; r<N_RCUS; r++)
268 for(int b=0; b<N_BRANCHES; b++)
269 for(int f=0; f<N_FEECS; f++)
270 for(int a=0; a<N_ALTROS; a++)
271 for(int c=0; c<N_ALTROCHANNELS; c++)
273 hdw2geo[m][r][b][f][a][c]=-1;
276 // Fill all FEE cards via formula
279 for(int m=0; m<N_MODULES; m++)
280 for(int r=0; r<N_RCUS; r++)
281 for(int b=0; b<N_BRANCHES; b++)
282 for(int f=0; f<N_FEECS; f++)
283 for(int a=0; a<N_ALTROS; a++)
284 for(int c=0; c<N_ALTROCHANNELS; c++)
286 int row = (r/2)*32 + b*16 + CSP_MAP[a][c].row;
287 int col = (r%2)*28 + f*2 + CSP_MAP[a][c].col;
288 int gain = CSP_MAP[a][c].gain;
289 int csp = CSP_MAP[a][c].csp;
290 int num = CSP_MAP[a][c].num;
291 ALTRO_MAP[index].mod=m;
292 ALTRO_MAP[index].row=row;
293 ALTRO_MAP[index].col=col;
294 ALTRO_MAP[index].gain=gain;
295 ALTRO_MAP[index].rcu=r;
296 ALTRO_MAP[index].branch=b;
297 ALTRO_MAP[index].card=f;
298 ALTRO_MAP[index].chip=a;
299 ALTRO_MAP[index].chan=c;
300 ALTRO_MAP[index].csp=csp;
301 ALTRO_MAP[index].num=num;
302 ALTRO_MAP[index].hid=Geo2hid(m,gain,row,col);
303 hdw2geo[m][r][b][f][a][c]=index;
304 if((row>=0)&&(row< N_XCOLUMNS_MOD))
305 if((col>=0)&&(col<N_ZROWS_MOD))
306 if((gain>=0)&&(gain<N_GAINS)) geo2hdw[m][gain][row][col]=index;
311 // Check if geo2hdw map table is filled
313 for(int m=0; m<N_MODULES; m++)
314 for(int g=0; g<N_GAINS;g++)
315 for(int r=0; r< N_XCOLUMNS_MOD; r++)
316 for(int c=0; c< N_ZROWS_MOD; c++)
318 assert(geo2hdw[m][g][r][c] >= 0);
321 // Check if hdw2geo map table is filled
323 for(int m=0; m<N_MODULES; m++)
324 for(int r=0; r<N_RCUS; r++)
325 for(int b=0; b<N_BRANCHES; b++)
326 for(int f=0; f<N_FEECS; f++)
327 for(int a=0; a<N_ALTROS; a++)
328 for(int c=0; c<N_ALTROCHANNELS; c++)
330 assert(hdw2geo[m][r][b][f][a][c] >= 0);
339 ////////////////////////////////////////////////////////////////////////
340 // Return histogramm id from histogramm name or -1 on error.
341 // extractHid("hMax011426")=11426;
342 ////////////////////////////////////////////////////////////////////////
345 AliHLTPHOSMapper::ExtractHid(char *objName){
348 if(strlen(objName)<7) return -1;
349 int hid=strtol(&objName[strlen(objName)-6],&perr,10);
350 if(strlen(perr))return -1;
354 ////////////////////////////////////////////////////////////////////////
355 // Print geometry and hardware information for given histogramm
356 // printHistMapInfo("hMax011426");
357 // hid mod gain row col rcu bran fee chip chan csp num
358 // 011426 0 1 14 26 0 0 13 3 14 14 62
359 ////////////////////////////////////////////////////////////////////////
362 AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
363 int hid=ExtractHid(objName);
365 int mod=Hid2mod(hid);
366 int gain=Hid2gain(hid);
367 int row=Hid2row(hid);
368 int col=Hid2col(hid);
369 int index=geo2hdw[mod][gain][row][col]; assert(index>=0);
370 int rcu = ALTRO_MAP[index].rcu;
371 int bran = ALTRO_MAP[index].branch;
372 int fec = ALTRO_MAP[index].card;
373 int chip = ALTRO_MAP[index].chip;
374 int chan = ALTRO_MAP[index].chan;
375 int csp = ALTRO_MAP[index].csp;
376 int num = ALTRO_MAP[index].num;
377 printf("%s attributes:\nhid\tmod\tgain\trow\tcol\trcu\tbran\tfee\tchip\tchan\tcsp\tnum\n",objName);
378 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);