]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
Bug fix, mapping was not correct
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
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
21
22 AliHLTPHOSMapper::AliHLTPHOSMapper() : AliHLTPHOSBase(), hw2geomapPtr(0)
23 {
24   //  printf("\nCreating new mapper\n");
25   InitAltroMapping(); 
26 }
27
28
29 AliHLTPHOSMapper::~AliHLTPHOSMapper()
30 {
31   
32 }
33
34
35 void
36 AliHLTPHOSMapper::InitAltroMapping()
37 {
38   char filename[256];
39   char *base =  getenv("ALICE_ROOT");
40
41   int nChannels = 0;
42   int maxaddr = 0;
43
44   int tmpHwaddr = 0;
45   int tmpZRow = 0;
46   int tmpXCol = 0;
47   int tmpGain = 0;
48
49   if(base !=0)
50     {
51       sprintf(filename,"%s/PHOS/mapping/RCU0.data", base);
52       //      printf("AliHLTPHOSMapper::InitAltroMapping()")
53       FILE *fp = fopen(filename, "r");
54       if(fp != 0)
55         {
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]; 
62
63
64           for(int i=0; i<  nChannels; i ++)
65             {
66               hw2geomapPtr[i].col = 0;
67               hw2geomapPtr[i].row = 0;
68               hw2geomapPtr[i].gain = 0;
69             }
70
71           printf("\n");
72
73           for(int i=0; i<nChannels; i ++)
74             {
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);
77               
78               hw2geomapPtr[tmpHwaddr].col   = tmpXCol;
79               hw2geomapPtr[tmpHwaddr].row   = tmpZRow;
80               hw2geomapPtr[tmpHwaddr].gain  = tmpGain;
81              
82             }
83           
84           printf("\n");
85           //      for(int i=0; i<  nChannels; i ++)
86
87
88           /*Æ
89           for(int i=120; i<  500; i ++)
90             {
91               printf( "%d\t%d\t%d\t%d\n", i,   hw2geomapPtr[i].col, hw2geomapPtr[i].row, hw2geomapPtr[i].gain);
92             }
93           
94           printf("\n");
95           */
96
97
98
99         }
100       else
101         {
102           cout << "ERROR could not find mapping file" << endl;
103         }
104
105     }
106   else
107     {
108       printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
109     }
110
111
112
113
114
115
116
117 /*
118 void 
119 AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
120 {
121   // Find row & col by CSP
122   int col = csp / 16;
123   int row = csp % 16;
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));
134   // Fill CSP array
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;
140 }
141 */
142
143
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  /////////////////////////////////////////////////////////////////
149
150  /*
151 void 
152 AliHLTPHOSMapper::InitAltroCspMapping()
153 {
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);
190
191
192 */
193 //void
194 //AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
195 //{
196 //  
197 //
198 //}
199
200 //inline int 
201
202 /*
203 int
204 AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
205
206   return mod*100000+gain*10000+row*100+col; 
207 }
208
209 //inline int 
210 int 
211 AliHLTPHOSMapper::Hid2mod(int hid)      
212
213   return hid/100000;            
214 }
215
216
217 //inline int 
218 int 
219 AliHLTPHOSMapper::Hid2gain(int hid)     
220
221   return (hid/10000)%10;        
222 }
223
224 //inline int 
225 int 
226 AliHLTPHOSMapper::Hid2row(int hid)      
227
228   return (hid/100)%100;         
229 }
230
231 //inline int 
232 int 
233 AliHLTPHOSMapper::Hid2col(int hid)      
234
235   return hid%100;  
236 }
237
238 ////////////////////////////////////////////////////////////////////////
239 // ALTRO mapping first time initialization (do it once in startup time).
240 ////////////////////////////////////////////////////////////////////////
241
242
243
244 //inline void 
245 //AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
246 //       initAltroMapping(int)'
247 void 
248 AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
249 {
250   //
251   // Init CSP mapping first.
252   //
253   InitAltroCspMapping();
254   //
255
256   // Clear index arrays
257   //
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++)
262           {     
263             geo2hdw[m][g][r][c]=-1; 
264           }
265   
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++)
272               { 
273                 hdw2geo[m][r][b][f][a][c]=-1; 
274               }
275   //
276   // Fill all FEE cards via formula
277   //
278   int index=0;
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++)
285               {
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;
307                 index++;
308               }
309  
310   //
311   // Check if geo2hdw map table is filled
312   //
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++) 
317           {
318             assert(geo2hdw[m][g][r][c] >= 0);
319           }
320   //
321   // Check if hdw2geo map table is filled
322   //
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++) 
329               {
330                 assert(hdw2geo[m][r][b][f][a][c] >= 0);
331               }
332 }
333
334
335 */
336
337 /*
338
339 ////////////////////////////////////////////////////////////////////////
340 // Return histogramm id from histogramm name or -1 on error.
341 // extractHid("hMax011426")=11426;
342 ////////////////////////////////////////////////////////////////////////
343 //inline int 
344 int 
345 AliHLTPHOSMapper::ExtractHid(char *objName){
346   //  char *perr= NULL;
347  char *perr= 0;
348   if(strlen(objName)<7) return -1;
349   int hid=strtol(&objName[strlen(objName)-6],&perr,10);
350   if(strlen(perr))return -1;
351   return hid;
352 }
353
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 ////////////////////////////////////////////////////////////////////////
360 //inline void 
361 void 
362 AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
363   int hid=ExtractHid(objName);
364   if(hid>=0){
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);
379   }
380 }
381
382
383 */