added new files to build system
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
CommitLineData
2f09efe8 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 *
5 * *
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 *
9 * *
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 **************************************************************************/
18
19#include "AliHLTPHOSMapper.h"
20
21AliHLTPHOSMapper::AliHLTPHOSMapper()
22{
23 // printf("\nCreating new mapper\n");
24 InitAltroMapping(0);
25}
26
b60bd496 27/*
2f09efe8 28void
29AliHLTPHOSMapper::GenerateACL(int startZ, int endZ, int startX, int endX, int modID, int acl[RCUS_PER_MODULE][256], unsigned long int afl[RCUS_PER_MODULE])
30{
31
32 for(int i=0; i<RCUS_PER_MODULE; i++)
33 {
34 for(int j=0; j<256; j++)
35 {
36 acl[i][j] = 0;
37 }
38 }
39
40 int index;
41 int aclIndex;
42
43 int rcu = 99;
44 int branch = 99;
45 int card = 99;;
46 int altro = 99;
47 int channel = 99;
48 int csp = 99;
49
50 for(int i = startZ; i <= endZ; i++)
51 {
52 for(int j = startX; j <= endX; j++)
53 {
54 for(int k = 0; k < PHOS_GAINS; k++)
55 {
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;
63
64 if(altro > 0)
65 {
66 altro = altro + 1; //to fix bug in mp
67 }
68
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));
72 }
73 }
74 }
75}
b60bd496 76*/
2f09efe8 77
78void
79AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
80{
81 // Find row & col by CSP
82 int col = csp / 16;
83 int row = csp % 16;
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));
b60bd496 91 assert((chHi>=0)&&(chHi< N_ALTROCHANNELS));
92 assert((chLo>=0)&&(chLo< N_ALTROCHANNELS));
93 assert((chip>=0)&&(chip<N_ALTROS));
2f09efe8 94 // Fill CSP array
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;
100}
101
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 /////////////////////////////////////////////////////////////////
107void
108AliHLTPHOSMapper::InitAltroCspMapping()
109{
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);
146}
147
148//void
149//AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
150//{
151//
152//
153//}
154
155//inline int
156int
157AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
158{
159 return mod*100000+gain*10000+row*100+col;
160}
161
162//inline int
163int
164AliHLTPHOSMapper::Hid2mod(int hid)
165{
166 return hid/100000;
167}
168
169
170//inline int
171int
172AliHLTPHOSMapper::Hid2gain(int hid)
173{
174 return (hid/10000)%10;
175}
176
177//inline int
178int
179AliHLTPHOSMapper::Hid2row(int hid)
180{
181 return (hid/100)%100;
182}
183
184//inline int
185int
186AliHLTPHOSMapper::Hid2col(int hid)
187{
188 return hid%100;
189}
190
191////////////////////////////////////////////////////////////////////////
192// ALTRO mapping first time initialization (do it once in startup time).
193////////////////////////////////////////////////////////////////////////
194
195
196
197//inline void
198//AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
199// initAltroMapping(int)'
200void
201AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
202{
203 //
204 // Init CSP mapping first.
205 //
206 InitAltroCspMapping();
207 //
208
209 // Clear index arrays
210 //
b60bd496 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++)
2f09efe8 215 {
216 geo2hdw[m][g][r][c]=-1;
217 }
218
b60bd496 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++)
2f09efe8 225 {
226 hdw2geo[m][r][b][f][a][c]=-1;
227 }
228 //
229 // Fill all FEE cards via formula
230 //
231 int index=0;
b60bd496 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++)
2f09efe8 238 {
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;
b60bd496 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;
2f09efe8 260 index++;
261 }
262
263 //
264 // Check if geo2hdw map table is filled
265 //
b60bd496 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++)
2f09efe8 270 {
271 assert(geo2hdw[m][g][r][c] >= 0);
272 }
273 //
274 // Check if hdw2geo map table is filled
275 //
b60bd496 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++)
2f09efe8 282 {
283 assert(hdw2geo[m][r][b][f][a][c] >= 0);
284 }
285}
286
287////////////////////////////////////////////////////////////////////////
288// Return histogramm id from histogramm name or -1 on error.
289// extractHid("hMax011426")=11426;
290////////////////////////////////////////////////////////////////////////
291//inline int
292int
293AliHLTPHOSMapper::ExtractHid(char *objName){
294 // char *perr= NULL;
295 char *perr= 0;
296 if(strlen(objName)<7) return -1;
297 int hid=strtol(&objName[strlen(objName)-6],&perr,10);
298 if(strlen(perr))return -1;
299 return hid;
300}
301
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////////////////////////////////////////////////////////////////////////
308//inline void
309void
310AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
311 int hid=ExtractHid(objName);
312 if(hid>=0){
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);
327 }
328}