]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorMappingHandler.cxx
New method to get the ratio between the expected and actual cluster shape. Will be...
[u/mrichter/AliRoot.git] / TPC / AliTPCMonitorMappingHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17   $Log$
18 */ 
19
20 #include "AliTPCMonitorMappingHandler.h"
21 ClassImp(AliTPCMonitorMappingHandler)
22
23 //_____________________________________________________________________________________________
24 AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(Char_t* name, Char_t* title): TNamed(name,title)
25 {
26   // Constructor : Initialize mapping arrays
27  
28   fmapping = new Short_t*[24000];
29
30
31   fmappingChannelinRow = new Int_t*[160];
32   for(Int_t in = 0; in<160; in++)
33     {
34       Int_t* hold = new Int_t[150]; 
35       for(Int_t jn = 0; jn<150;jn++)  hold[jn]=0;
36       fmappingChannelinRow[in]= hold;
37     }
38   
39
40   fu2ftestmapping      = new Short_t*[7000];
41   for(Int_t i = 0; i<7000; i++)
42     {
43       Short_t* hold = new Short_t[8]; 
44       for(Int_t j = 0; j<8;j++)  hold[j]=0;
45       fu2ftestmapping[i]= hold;
46     }
47
48   fMapHwFECglobal = new Int_t*[24000];
49   for(Int_t i = 0; i<24000; i++)
50     {
51       Int_t* hold = new Int_t[2]; 
52       for(Int_t j = 0; j<2;j++)  hold[j]=0;
53       fMapHwFECglobal[i]= hold;
54     }
55   
56   fecGainMap = new Float_t*[7000];
57   for(Int_t i = 0; i<7000; i++)
58     {
59       Float_t* hold = new Float_t[128]; 
60       for(Int_t j = 0; j<128;j++)  hold[j]=0;
61       fecGainMap[i]= hold;
62     }
63 }
64
65 //_____________________________________________________________________________________________
66 AliTPCMonitorMappingHandler::~AliTPCMonitorMappingHandler() 
67 {
68   // Destructor
69   Short_t* temp;
70   for(Int_t i = 0; i < 24000 ; i++) {
71     temp = (Short_t *) fmapping[i];
72     if(temp[1] != -1)
73       delete temp;
74   }
75   temp = (Short_t *) fmapping;
76   delete temp;
77   
78   
79   Int_t* temp1;
80   for(Int_t i = 0; i < 24000 ; i++) {
81     temp1 = (Int_t *) fMapHwFECglobal[i];
82     delete temp1;
83   }
84   temp1 = (Int_t *) fMapHwFECglobal;
85   delete temp1;
86  
87   for(Int_t i = 0; i < 7000 ; i++) {
88     temp = (Short_t *) fu2ftestmapping[i];
89     delete temp;
90   }
91  
92   temp = (Short_t *) fu2ftestmapping;
93   delete temp;
94          
95   for(Int_t i = 0; i < 150 ; i++) {
96     temp1= (Int_t *) fmappingChannelinRow[i];
97     delete temp1;
98   }
99   temp1 = (Int_t *) fmappingChannelinRow;
100   delete temp1;
101
102   Float_t* temp2;
103   for(Int_t i = 0; i<7000; i++)
104     {
105       temp2= (Float_t *) fecGainMap[i];
106       delete temp2;
107     }
108   temp2 = (Float_t *) fecGainMap;
109   delete temp2;
110
111         
112 }
113
114 //_____________________________________________________________________________________________
115 void AliTPCMonitorMappingHandler::ReadMapping(char* mapfile)
116 {
117   // Read global Mapping file
118   // Format of data in mapping file:
119   // column 0:  hadrware address
120   // column 1:  readout index in IROC/OROC
121   // column 2:  global pad row number (0-158)
122   // column 3   pad number in row
123   // column 4:  connector
124   // column 5:  pin
125   // column 6:  fec number in IROC/OROC
126   // column 7:  fec channel
127   // column 8:  fec connector
128   // column 9:  altro channel
129   // column 10: altro chip
130  
131   // Mapping data for a given hardware address are placed at the 
132   // index corresponding to the value of the hardware address in 
133   // the fmapping array..
134   // The mapping information for the hardware address 'hwaddr'
135   // can hence be found in fmapping[hwaddr]
136
137
138  
139   char readcarry[255];
140   Int_t version = -1;
141   Int_t actPos  = 0;
142   Int_t oldPos  = 0;
143
144   ifstream *in = new ifstream();
145   in->open(mapfile);
146   *in >> readcarry;
147   version = atoi(readcarry);
148   
149   *in >> readcarry;
150   fnumofChannels = atoi(readcarry);
151   *in >> readcarry;
152   fmaxHWAdress = atoi(readcarry);
153   fsizeofArray = fmaxHWAdress;
154         
155   Short_t *fmappingEmptyRow = new Short_t[11];
156   for(Int_t i = 0; i < 11 ; i++) {
157     fmappingEmptyRow[i] = 0;
158   }
159   fmappingEmptyRow[1] = -1;
160   for(Int_t i = 0; i < fnumofChannels ; i++) {
161     fmappingRow = new Short_t[11];
162     for(Int_t j = 0 ; j < 11 ; j++) {
163       *in >> readcarry;
164       fmappingRow[j] = atoi(readcarry);
165     }
166     actPos = fmappingRow[0];
167     fmapping[actPos] = fmappingRow;
168     if( (actPos - oldPos) > 1) {
169       for(Int_t j = (oldPos+1); j < actPos; j++) {
170         fmapping[j] = fmappingEmptyRow;
171       }
172     }
173     oldPos = actPos;
174     fmapping[actPos][0] = i;
175   }
176   
177   in->close();
178   delete in;
179 }
180
181 //_____________________________________________________________________________________________
182 Int_t  AliTPCMonitorMappingHandler::ReadFECMapping(char* u2ftestfile)
183 {
184   // Read in Mapping of global FEC numbers to branches, rcu patches etc.
185   // Format in Mapping file
186   // column 0: global card number (set to 0 if card number does not exist)
187   // column 1: side of the TPC
188   // column 2: sector on the side   (0-17)
189   // column 3: rcu in the sector    (0-5)
190   // column 4: fec number in rcu    (0-24)
191   // column 5: fec number in branch (0-12)
192   // column 6: branch number        (0,1)
193   // column 7: local hardware address of first channel (not used)
194
195   // Order of data is kept in fu2ftestmapping
196   
197   ifstream datin(u2ftestfile);
198   
199   Int_t carry     = 0;
200   Int_t ncards    = 0;
201  
202   for(Int_t ind = 0; ind<7000; ind++)
203     {
204       for(Int_t entr = 0; entr<8; entr++)
205         {
206           datin >> carry ;
207           fu2ftestmapping[ind][entr] = carry  ;
208           
209           if(entr==0 && carry!=0) ncards++;
210         }
211     }
212   return ncards ;
213 }
214
215  
216
217 //_____________________________________________________________________________________________
218 void AliTPCMonitorMappingHandler::ReadfecHwMap(Int_t sector)
219 {
220   // Create mapping of global FEC numbers to hardware addresses for a given sector
221
222   Int_t  fside           =0;
223   Int_t  fsector        = 0;
224   Int_t  fec            = 0;
225   Int_t  branch         = 0;
226   Int_t  rcu_patch      = 0;
227   Int_t  altrchann      = 0;
228   Int_t  altrchip       = 0;
229   Int_t  nextHwAddress  = 0;
230   Int_t  nfecs          = 0;
231
232   if(sector/18==0) fside =65;
233   else             fside =67;
234   
235   if(sector>18)    fsector= sector-18;
236   else             fsector= sector   ;
237
238   for(Int_t ind = 0; ind<7000; ind++)
239     { 
240       if((Int_t)U2fGetSide(ind)==fside && U2fGetSector(ind)==fsector) 
241         {
242           nfecs++;
243           fec            = U2fGetFECinBranch(ind);
244           branch         = U2fGetBranch(ind);
245           rcu_patch      = U2fGetRCU(ind);
246                   
247           for(Int_t ch = 0; ch<128; ch++)
248             {
249               altrchann      = ch%16;
250               altrchip       = ch/16;
251               
252               nextHwAddress  = (   ((branch&1)<<11) + (fec<<7) + (altrchip<<4) + (altrchann)  + ((rcu_patch-1)<<12) ); 
253               
254               fMapHwFECglobal[nextHwAddress][0] = ind;
255               fMapHwFECglobal[nextHwAddress][1] = ch ;
256             }
257         }
258     }
259 }
260 //_____________________________________________________________________________________________
261 void AliTPCMonitorMappingHandler::ReadfecGainMap(char* fecgainmap)
262 {
263   // Read global gain calibration pap
264   // Format in file :
265   // colummn 0      : FEC number 
266   // colums  1-128  : gain calibration factors 
267   ifstream datin(fecgainmap);
268   
269   Int_t   fecnr  = 0;
270   Float_t val    = 0.0 ;
271   
272   while(!datin.eof())
273     {
274       datin >> fecnr ;
275       for(Int_t in = 0; in<128; in++)
276         {
277           datin >> val ;
278           fecGainMap[fecnr][in] = val;
279         }
280     }
281 }
282
283 //_____________________________________________________________________________________________
284 void  AliTPCMonitorMappingHandler::ReadRowMappingGlob(char* fpathtoMappingRowfile) 
285 {
286   // Read mapping of hardware addresses in rows
287   // Format of file:
288   // column 0:        global row number (0-158)
289   // column 1:        number of pads in this row (npads)
290   // column 2-npads:  hardware addresses for these pads
291  
292   char readcarry[256];
293   char readcarry2[256];
294   ifstream *in = new ifstream();
295   in->open(fpathtoMappingRowfile);
296   
297   for(Int_t i = 0; i < 159 ; i++) {
298     *in >> readcarry;   // row number 
299     *in >> readcarry2;  // numof pads
300     fmappingChannelinRow[i][0] = atoi(readcarry2);
301     fmappingChannelinRow[i][1] = atoi(readcarry);
302     
303     for(Int_t j = 2 ; j < fmappingChannelinRow[i][0]+2 ; j++) {
304       *in >> readcarry;
305       fmappingChannelinRow[i][j] = atoi(readcarry);
306     }
307   }
308   in->close();
309 }
310
311
312
313 //_____________________________________________________________________________________________
314 Int_t AliTPCMonitorMappingHandler::GetNumOfChannels()
315 {
316   // Return number of channels
317   return fnumofChannels;
318 }
319
320 //_____________________________________________________________________________________________
321 Int_t AliTPCMonitorMappingHandler::GetSizeofArray()
322 {
323   // Return sise of global mapping fmapping array.
324   // Value orresponds to max value of hardware addresses
325   return fsizeofArray;
326 }
327
328
329 //_____________________________________________________________________________________________
330 Short_t* AliTPCMonitorMappingHandler::GetLine(Int_t hwaddr)
331 {
332   // Return pointer to mapping array for the hardware address hwaddr 
333   Short_t* retval;
334   if(hwaddr <= fsizeofArray)
335     retval = fmapping[hwaddr];
336   else
337     retval = 0;
338   return retval;
339 }
340
341 //_____________________________________________________________________________________________
342 Int_t AliTPCMonitorMappingHandler::GetIndex(Int_t hwaddr) 
343 {
344   // Return readout index for the hardware address hwaddr
345   Int_t retval;
346   if(hwaddr <= fsizeofArray)
347     retval = fmapping[hwaddr][1];
348   else
349     retval = 0;
350   return retval;
351 }
352
353 //_____________________________________________________________________________________________
354 Int_t AliTPCMonitorMappingHandler::GetPadRow(Int_t hwaddr) 
355 {
356   // Return global pad row  for the hardware address hwaddr 
357   Int_t retval;
358   if(hwaddr <= fsizeofArray)
359     retval = fmapping[hwaddr][2];
360   else
361     retval = 0;
362   return retval;
363 }
364
365 //_____________________________________________________________________________________________
366 Int_t AliTPCMonitorMappingHandler::GetPad(Int_t hwaddr) 
367 {
368   // Return pad number in row for the hardware address hwaddr 
369   Int_t retval;
370   if(hwaddr < fsizeofArray)
371     retval = fmapping[hwaddr][3];
372   else
373     retval = 0;
374   return retval;
375 }
376
377 //_____________________________________________________________________________________________
378 Int_t AliTPCMonitorMappingHandler::GetConnector(Int_t hwaddr) 
379 {
380   // Return connector for the hardware address hwaddr 
381   Int_t retval;
382   if(hwaddr <= fsizeofArray)
383     retval = fmapping[hwaddr][4];
384   else
385     retval = 0;
386   return retval;
387 }
388
389 //_____________________________________________________________________________________________
390 Int_t AliTPCMonitorMappingHandler::GetPin(Int_t hwaddr) 
391 {
392   // Return pin for the hardware address hwaddr 
393   Int_t retval;
394   if(hwaddr <= fsizeofArray)
395     retval = fmapping[hwaddr][5];
396   else
397     retval = 0;
398   return retval;
399 }
400
401 //_____________________________________________________________________________________________
402 Int_t AliTPCMonitorMappingHandler::GetFEC(Int_t hwaddr) 
403 {
404   // Return fec number in IROC/OROC  for the hardware address hwaddr 
405   Int_t retval;
406   if(hwaddr <= fsizeofArray)
407     retval = fmapping[hwaddr][6];
408   else
409     retval = 0;
410   return retval;
411 }
412
413 //_____________________________________________________________________________________________
414 Int_t AliTPCMonitorMappingHandler::GetFECchannel(Int_t hwaddr) 
415 {
416   // Return FEC channel for the hardware address hwaddr 
417   Int_t retval;
418   if(hwaddr < fsizeofArray)
419     retval = fmapping[hwaddr][7];
420   else
421     retval = 0;
422   return retval;
423 }
424
425 //_____________________________________________________________________________________________
426 Int_t AliTPCMonitorMappingHandler::GetFECconnector(Int_t hwaddr) 
427 {
428   // Return FEC connector for the hardware address hwaddr 
429   Int_t retval;
430   if(hwaddr <= fsizeofArray)
431     retval = fmapping[hwaddr][8];
432   else
433     retval = 0;
434   return retval;
435 }
436
437 //_____________________________________________________________________________________________
438 Int_t AliTPCMonitorMappingHandler::GetAltroChannel(Int_t hwaddr) 
439 {
440   // Return Altro channel for the hardware address hwaddr 
441   Int_t retval;
442   if(hwaddr <= fsizeofArray)
443     retval = fmapping[hwaddr][9];
444   else
445     retval = 0;
446   return retval;
447 }
448
449 //_____________________________________________________________________________________________
450 Int_t AliTPCMonitorMappingHandler::GetAltro(Int_t hwaddr) 
451 {
452   // Return Altro chip number in FEC for the hardware address hwaddr 
453   Int_t retval;
454   if(hwaddr <= fsizeofArray)
455     retval = fmapping[hwaddr][10];
456   else
457     retval = 0;
458   return retval;
459 }
460
461
462 //_____________________________________________________________________________________________
463 Int_t AliTPCMonitorMappingHandler::GetNumofPads(Int_t row)
464 {
465   // Return number of pads in row
466   if(row<159)
467     return fmappingChannelinRow[row][0];
468   else  {
469     AliError("Row number to high");
470     return 0;
471   }
472 }
473
474 //_____________________________________________________________________________________________
475 Int_t AliTPCMonitorMappingHandler::GetPadAddInRow(Int_t row,Int_t pad )
476 {
477   // Return hardware address for given pad in row
478   if(row<159)
479     return fmappingChannelinRow[row][pad+2];
480   else {
481     AliError("Row number to high");
482     return 0;
483   }
484 }
485
486
487
488 //_____________________________________________________________________________________________
489 Int_t AliTPCMonitorMappingHandler::U2fGetFECnr(Int_t index)
490 {
491   // Return FEC number for index  (FEC number should be equal to index)
492   return  fu2ftestmapping[index][0];
493 }
494
495 //_____________________________________________________________________________________________
496 Int_t AliTPCMonitorMappingHandler::U2fGetSide(Int_t fecnr)
497 {
498   // Return side on which FEC is installed
499   return  fu2ftestmapping[fecnr][1];
500 }
501
502 //_____________________________________________________________________________________________
503 Int_t AliTPCMonitorMappingHandler::U2fGetSector(Int_t fecnr)
504 {
505   // Return sector in which FEC is installed
506   return  fu2ftestmapping[fecnr][2];
507 }
508
509 //_____________________________________________________________________________________________
510 Int_t AliTPCMonitorMappingHandler::U2fGetRCU(Int_t fecnr)
511 {
512   // Rerurn rcu patch in which FEC is installed
513   return  fu2ftestmapping[fecnr][3];
514 }
515
516 //_____________________________________________________________________________________________
517 Int_t AliTPCMonitorMappingHandler::U2fGetFECinRCU(Int_t fecnr)
518 {
519   // Return index of FEC in RCU (0-25)
520   return  fu2ftestmapping[fecnr][4];
521 }
522
523 //_____________________________________________________________________________________________
524 Int_t AliTPCMonitorMappingHandler::U2fGetFECinBranch(Int_t fecnr)
525 {
526   // Return index of FEC in branch (0-12)
527   return  fu2ftestmapping[fecnr][5];
528 }
529
530 //_____________________________________________________________________________________________
531 Int_t AliTPCMonitorMappingHandler::U2fGetBranch(Int_t fecnr)
532 {
533   // Return branch in which FEC is installed (0,1)
534   return  fu2ftestmapping[fecnr][6];
535     
536 }