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"
21 AliHLTPHOSMapper::AliHLTPHOSMapper()
23 // printf("\nCreating new mapper\n");
29 AliHLTPHOSMapper::GenerateACL(int startZ, int endZ, int startX, int endX, int modID, int acl[RCUS_PER_MODULE][256], unsigned long int afl[RCUS_PER_MODULE])
32 for(int i=0; i<RCUS_PER_MODULE; i++)
34 for(int j=0; j<256; j++)
50 for(int i = startZ; i <= endZ; i++)
52 for(int j = startX; j <= endX; j++)
54 for(int k = 0; k < PHOS_GAINS; k++)
56 index = geo2hdw[modID][k][j][i];
57 rcu = ALTRO_MAP[index].rcu;
58 branch = ALTRO_MAP[index].branch;
59 card = ALTRO_MAP[index].card;
60 altro = ALTRO_MAP[index].chip;
61 channel = ALTRO_MAP[index].chan;
62 csp = ALTRO_MAP[index].csp;
66 altro = altro + 1; //to fix bug in mp
69 aclIndex = branch*128+(card +1)*8+altro;
70 acl[rcu][aclIndex] = acl[rcu][aclIndex] | 1<<channel;
71 afl[rcu] = (long int)afl[rcu] | (1<< ((long int)(card+1) +(long int)branch*16));
79 AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
81 // Find row & col by CSP
84 //In 2004 beam test was also: if(row>7)row=23-row;
85 // Check if arguments Ok
86 assert((col>=0)&&(col<2));
87 assert((row>=0)&&(row<16));
88 assert((csp>=0)&&(csp<32));
89 assert((numHi>=0)&&(numHi<64));
90 assert((numLo>=0)&&(numLo<64));
91 assert((chHi>=0)&&(chHi< N_ALTROCHANNELS));
92 assert((chLo>=0)&&(chLo< N_ALTROCHANNELS));
93 assert((chip>=0)&&(chip<N_ALTROS));
95 CSP_MAP[chip][chHi].row=row; CSP_MAP[chip][chLo].row=row;
96 CSP_MAP[chip][chHi].col=col; CSP_MAP[chip][chLo].col=col;
97 CSP_MAP[chip][chHi].gain=1; CSP_MAP[chip][chLo].gain=0;
98 CSP_MAP[chip][chHi].csp=csp; CSP_MAP[chip][chLo].csp=csp;
99 CSP_MAP[chip][chHi].num=numHi; CSP_MAP[chip][chLo].num=numLo;
102 /////////////////////////////////////////////////////////////////
103 // Initialize CSP mapping table.
104 // Note we use (0,1,2,3) instead of (0,2,3,4) ALTRO chip numbers.
105 // So strange numbers we have due to well known RCU firmware bug.
106 /////////////////////////////////////////////////////////////////
108 AliHLTPHOSMapper::InitAltroCspMapping()
110 // T1 csp chip chHi chLo numHi numLo
111 AddCsp( 0, 1, 10, 11, 26, 27);
112 AddCsp( 1, 1, 14, 15, 30, 31);
113 AddCsp( 2, 1, 5, 4, 21, 20);
114 AddCsp( 3, 1, 1, 0, 17, 16);
115 AddCsp( 4, 2, 1, 0, 33, 32);
116 AddCsp( 5, 2, 5, 4, 37, 36);
117 AddCsp( 6, 2, 14, 15, 46, 47);
118 AddCsp( 7, 2, 10, 11, 42, 43);
119 // T2 csp chip chHi chLo numHi numLo
120 AddCsp( 8, 0, 10, 11, 10, 11);
121 AddCsp( 9, 0, 14, 15, 14, 15);
122 AddCsp( 10, 0, 5, 4, 5, 4);
123 AddCsp( 11, 0, 1, 0, 1, 0);
124 AddCsp( 12, 3, 1, 0, 49, 48);
125 AddCsp( 13, 3, 5, 4, 53, 52);
126 AddCsp( 14, 3, 14, 15, 62, 63);
127 AddCsp( 15, 3, 10, 11, 58, 59);
128 // T3 csp chip chHi chLo numHi numLo
129 AddCsp( 16, 1, 8, 9, 24, 25);
130 AddCsp( 17, 1, 12, 13, 28, 29);
131 AddCsp( 18, 1, 7, 6, 23, 22);
132 AddCsp( 19, 1, 3, 2, 19, 18);
133 AddCsp( 20, 2, 3, 2, 35, 34);
134 AddCsp( 21, 2, 7, 6, 39, 38);
135 AddCsp( 22, 2, 12, 13, 44, 45);
136 AddCsp( 23, 2, 8, 9, 40, 41);
137 // T4 csp chip chHi chLo numHi numLo
138 AddCsp( 24, 0, 8, 9, 8, 9);
139 AddCsp( 25, 0, 12, 13, 12, 13);
140 AddCsp( 26, 0, 7, 6, 7, 6);
141 AddCsp( 27, 0, 3, 2, 3, 2);
142 AddCsp( 28, 3, 3, 2, 51, 50);
143 AddCsp( 29, 3, 7, 6, 55, 54);
144 AddCsp( 30, 3, 12, 13, 60, 61);
145 AddCsp( 31, 3, 8, 9, 56, 57);
149 //AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
157 AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
159 return mod*100000+gain*10000+row*100+col;
164 AliHLTPHOSMapper::Hid2mod(int hid)
172 AliHLTPHOSMapper::Hid2gain(int hid)
174 return (hid/10000)%10;
179 AliHLTPHOSMapper::Hid2row(int hid)
181 return (hid/100)%100;
186 AliHLTPHOSMapper::Hid2col(int hid)
191 ////////////////////////////////////////////////////////////////////////
192 // ALTRO mapping first time initialization (do it once in startup time).
193 ////////////////////////////////////////////////////////////////////////
198 //AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
199 // initAltroMapping(int)'
201 AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
204 // Init CSP mapping first.
206 InitAltroCspMapping();
209 // Clear index arrays
211 for(int m=0; m<N_MODULES; m++)
212 for(int g=0; g<N_GAINS;g++)
213 for(int r=0; r< N_XCOLUMNS_MOD; r++)
214 for(int c=0; c<N_ZROWS_MOD; c++)
216 geo2hdw[m][g][r][c]=-1;
219 for(int m=0; m<N_MODULES; m++)
220 for(int r=0; r<N_RCUS; r++)
221 for(int b=0; b<N_BRANCHES; b++)
222 for(int f=0; f<N_FEECS; f++)
223 for(int a=0; a<N_ALTROS; a++)
224 for(int c=0; c<N_ALTROCHANNELS; c++)
226 hdw2geo[m][r][b][f][a][c]=-1;
229 // Fill all FEE cards via formula
232 for(int m=0; m<N_MODULES; m++)
233 for(int r=0; r<N_RCUS; r++)
234 for(int b=0; b<N_BRANCHES; b++)
235 for(int f=0; f<N_FEECS; f++)
236 for(int a=0; a<N_ALTROS; a++)
237 for(int c=0; c<N_ALTROCHANNELS; c++)
239 int row = (r/2)*32 + b*16 + CSP_MAP[a][c].row;
240 int col = (r%2)*28 + f*2 + CSP_MAP[a][c].col;
241 int gain = CSP_MAP[a][c].gain;
242 int csp = CSP_MAP[a][c].csp;
243 int num = CSP_MAP[a][c].num;
244 ALTRO_MAP[index].mod=m;
245 ALTRO_MAP[index].row=row;
246 ALTRO_MAP[index].col=col;
247 ALTRO_MAP[index].gain=gain;
248 ALTRO_MAP[index].rcu=r;
249 ALTRO_MAP[index].branch=b;
250 ALTRO_MAP[index].card=f;
251 ALTRO_MAP[index].chip=a;
252 ALTRO_MAP[index].chan=c;
253 ALTRO_MAP[index].csp=csp;
254 ALTRO_MAP[index].num=num;
255 ALTRO_MAP[index].hid=Geo2hid(m,gain,row,col);
256 hdw2geo[m][r][b][f][a][c]=index;
257 if((row>=0)&&(row< N_XCOLUMNS_MOD))
258 if((col>=0)&&(col<N_ZROWS_MOD))
259 if((gain>=0)&&(gain<N_GAINS)) geo2hdw[m][gain][row][col]=index;
264 // Check if geo2hdw map table is filled
266 for(int m=0; m<N_MODULES; m++)
267 for(int g=0; g<N_GAINS;g++)
268 for(int r=0; r< N_XCOLUMNS_MOD; r++)
269 for(int c=0; c< N_ZROWS_MOD; c++)
271 assert(geo2hdw[m][g][r][c] >= 0);
274 // Check if hdw2geo map table is filled
276 for(int m=0; m<N_MODULES; m++)
277 for(int r=0; r<N_RCUS; r++)
278 for(int b=0; b<N_BRANCHES; b++)
279 for(int f=0; f<N_FEECS; f++)
280 for(int a=0; a<N_ALTROS; a++)
281 for(int c=0; c<N_ALTROCHANNELS; c++)
283 assert(hdw2geo[m][r][b][f][a][c] >= 0);
287 ////////////////////////////////////////////////////////////////////////
288 // Return histogramm id from histogramm name or -1 on error.
289 // extractHid("hMax011426")=11426;
290 ////////////////////////////////////////////////////////////////////////
293 AliHLTPHOSMapper::ExtractHid(char *objName){
296 if(strlen(objName)<7) return -1;
297 int hid=strtol(&objName[strlen(objName)-6],&perr,10);
298 if(strlen(perr))return -1;
302 ////////////////////////////////////////////////////////////////////////
303 // Print geometry and hardware information for given histogramm
304 // printHistMapInfo("hMax011426");
305 // hid mod gain row col rcu bran fee chip chan csp num
306 // 011426 0 1 14 26 0 0 13 3 14 14 62
307 ////////////////////////////////////////////////////////////////////////
310 AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
311 int hid=ExtractHid(objName);
313 int mod=Hid2mod(hid);
314 int gain=Hid2gain(hid);
315 int row=Hid2row(hid);
316 int col=Hid2col(hid);
317 int index=geo2hdw[mod][gain][row][col]; assert(index>=0);
318 int rcu = ALTRO_MAP[index].rcu;
319 int bran = ALTRO_MAP[index].branch;
320 int fec = ALTRO_MAP[index].card;
321 int chip = ALTRO_MAP[index].chip;
322 int chan = ALTRO_MAP[index].chan;
323 int csp = ALTRO_MAP[index].csp;
324 int num = ALTRO_MAP[index].num;
325 printf("%s attributes:\nhid\tmod\tgain\trow\tcol\trcu\tbran\tfee\tchip\tchan\tcsp\tnum\n",objName);
326 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);