]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
som minor changes, committed to be in synch with build system
[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< maxaddr + 1 ; i ++)
65             {
66               hw2geomapPtr[i].col = 0;
67               hw2geomapPtr[i].row = 0;
68               hw2geomapPtr[i].gain = 0;
69             }
70
71
72           printf("\n");
73
74           for(int i=0; i<nChannels; i ++)
75             {
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);
78               
79               hw2geomapPtr[tmpHwaddr].col   = tmpXCol;
80               hw2geomapPtr[tmpHwaddr].row   = tmpZRow;
81               hw2geomapPtr[tmpHwaddr].gain  = tmpGain;
82              
83             }
84           
85           printf("\n");
86           //      for(int i=0; i<  nChannels; i ++)
87
88
89           /*Æ
90           for(int i=120; i<  500; i ++)
91             {
92               printf( "%d\t%d\t%d\t%d\n", i,   hw2geomapPtr[i].col, hw2geomapPtr[i].row, hw2geomapPtr[i].gain);
93             }
94           
95           printf("\n");
96           */
97
98
99
100         }
101       else
102         {
103           cout << "ERROR could not find mapping file" << endl;
104         }
105
106     }
107   else
108     {
109       printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
110     }
111
112
113
114
115
116
117
118 /*
119 void 
120 AliHLTPHOSMapper::AddCsp(int csp, int chip, int chHi, int chLo, int numHi, int numLo)
121 {
122   // Find row & col by CSP
123   int col = csp / 16;
124   int row = csp % 16;
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));
135   // Fill CSP array
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;
141 }
142 */
143
144
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  /////////////////////////////////////////////////////////////////
150
151  /*
152 void 
153 AliHLTPHOSMapper::InitAltroCspMapping()
154 {
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);
191
192
193 */
194 //void
195 //AliHLTPHOSMapper::GeomToAFL(int startZ, int endZ, int startX, int endX, int rcuZ, int rcuX)
196 //{
197 //  
198 //
199 //}
200
201 //inline int 
202
203 /*
204 int
205 AliHLTPHOSMapper::Geo2hid(int mod, int gain, int row, int col)
206
207   return mod*100000+gain*10000+row*100+col; 
208 }
209
210 //inline int 
211 int 
212 AliHLTPHOSMapper::Hid2mod(int hid)      
213
214   return hid/100000;            
215 }
216
217
218 //inline int 
219 int 
220 AliHLTPHOSMapper::Hid2gain(int hid)     
221
222   return (hid/10000)%10;        
223 }
224
225 //inline int 
226 int 
227 AliHLTPHOSMapper::Hid2row(int hid)      
228
229   return (hid/100)%100;         
230 }
231
232 //inline int 
233 int 
234 AliHLTPHOSMapper::Hid2col(int hid)      
235
236   return hid%100;  
237 }
238
239 ////////////////////////////////////////////////////////////////////////
240 // ALTRO mapping first time initialization (do it once in startup time).
241 ////////////////////////////////////////////////////////////////////////
242
243
244
245 //inline void 
246 //AliHLTPHOSMapper::initAltroMapping(int saveMapping=0)
247 //       initAltroMapping(int)'
248 void 
249 AliHLTPHOSMapper::InitAltroMapping(int saveMapping)
250 {
251   //
252   // Init CSP mapping first.
253   //
254   InitAltroCspMapping();
255   //
256
257   // Clear index arrays
258   //
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++)
263           {     
264             geo2hdw[m][g][r][c]=-1; 
265           }
266   
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++)
273               { 
274                 hdw2geo[m][r][b][f][a][c]=-1; 
275               }
276   //
277   // Fill all FEE cards via formula
278   //
279   int index=0;
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++)
286               {
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;
308                 index++;
309               }
310  
311   //
312   // Check if geo2hdw map table is filled
313   //
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++) 
318           {
319             assert(geo2hdw[m][g][r][c] >= 0);
320           }
321   //
322   // Check if hdw2geo map table is filled
323   //
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++) 
330               {
331                 assert(hdw2geo[m][r][b][f][a][c] >= 0);
332               }
333 }
334
335
336 */
337
338 /*
339
340 ////////////////////////////////////////////////////////////////////////
341 // Return histogramm id from histogramm name or -1 on error.
342 // extractHid("hMax011426")=11426;
343 ////////////////////////////////////////////////////////////////////////
344 //inline int 
345 int 
346 AliHLTPHOSMapper::ExtractHid(char *objName){
347   //  char *perr= NULL;
348  char *perr= 0;
349   if(strlen(objName)<7) return -1;
350   int hid=strtol(&objName[strlen(objName)-6],&perr,10);
351   if(strlen(perr))return -1;
352   return hid;
353 }
354
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 ////////////////////////////////////////////////////////////////////////
361 //inline void 
362 void 
363 AliHLTPHOSMapper::PrintHistMapInfo(char *objName){
364   int hid=ExtractHid(objName);
365   if(hid>=0){
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);
380   }
381 }
382
383
384 */