]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorMappingHandler.cxx
No double step.
[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   Revision 1.1  2007/09/17 10:23:31  cvetan
19   New TPC monitoring package from Stefan Kniege. The monitoring package can be started by running TPCMonitor.C macro located in macros folder.
20
21 */ 
22
23 ////////////////////////////////////////////////////////////////////////
24 //
25 // AliTPCMonitorMappingHandler class
26 //
27 // Class for handling mapping information TPC  
28 //  
29 // The mapping information for the TPC front end electornics (pads, front end cards) 
30 // are handled by this class.
31 // The information from the design mapping and from the hardware address can be 
32 // cross checked in the TPCMonitor.C. 
33 // Malfunctioning front end cards can be identified by looking at single channels 
34 // displayed with  the TPCMonitor.  
35 //   
36 // 
37 // Authors: Roland Bramm, 
38 //          Stefan Kniege, IKF, Frankfurt
39 //       
40 /////////////////////////////////////////////////////////////////////////
41
42
43 #include "AliTPCMonitorMappingHandler.h"
44 #include "TH1.h"
45 #include "TLegend.h"
46 #include "AliLog.h"
47 #include <Riostream.h>
48
49 ClassImp(AliTPCMonitorMappingHandler)
50
51 //_____________________________________________________________________________________________
52 AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(Char_t* name, Char_t* title): 
53   TNamed(name,title),
54   fnumofChannels(0),
55   fmaxHWAdress(0),
56   fsizeofArray(0),
57   fmapping(new Short_t*[24000]),
58   fmappingChannelinRow(new Int_t*[160]),
59   fu2ftestmapping(new Short_t*[7000]),
60   fMapHwFECglobal(new Int_t*[24000]),
61   fecGainMap(new Float_t*[7000])
62 {
63   // Constructor : Initialize mapping arrays
64  
65   for(Int_t in = 0; in<160; in++)
66     {
67       Int_t* hold = new Int_t[150]; 
68       for(Int_t jn = 0; jn<150;jn++)  hold[jn]=0;
69       fmappingChannelinRow[in]= hold;
70     }
71   
72   for(Int_t i = 0; i<7000; i++)
73     {
74       Short_t* hold = new Short_t[8]; 
75       for(Int_t j = 0; j<8;j++)  hold[j]=0;
76       fu2ftestmapping[i]= hold;
77     }
78   
79   for(Int_t i = 0; i<24000; i++)
80     {
81       Int_t* hold = new Int_t[2]; 
82       for(Int_t j = 0; j<2;j++)  hold[j]=0;
83       fMapHwFECglobal[i]= hold;
84     }
85   
86   
87   for(Int_t i = 0; i<7000; i++)
88     {
89       Float_t* hold = new Float_t[128]; 
90       for(Int_t j = 0; j<128;j++)  hold[j]=0;
91       fecGainMap[i]= hold;
92     }
93 }
94
95 //____________________________________________________________________________
96 AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(const  AliTPCMonitorMappingHandler &maphand) :
97   TNamed(maphand.GetName(),maphand.GetTitle()),
98   fnumofChannels(maphand.fnumofChannels),
99   fmaxHWAdress(maphand.fmaxHWAdress),
100   fsizeofArray(maphand.fsizeofArray),
101   fmapping(new Short_t*[24000]),
102   fmappingChannelinRow(new Int_t*[160]),
103   fu2ftestmapping(new Short_t*[7000]),
104   fMapHwFECglobal(new Int_t*[24000]),
105   fecGainMap(new Float_t*[7000])
106 {
107   // copy constructor
108  
109  
110   for(Int_t in = 0; in<160; in++)
111     {
112       Int_t* hold = new Int_t[150]; 
113       for(Int_t jn = 0; jn<150;jn++)  hold[jn]=maphand.fmappingChannelinRow[in][jn];
114       fmappingChannelinRow[in]= hold;
115     }
116   
117   for(Int_t i = 0; i<7000; i++)
118     {
119       Short_t* hold = new Short_t[8]; 
120       for(Int_t j = 0; j<8;j++)  hold[j]=maphand.fu2ftestmapping[i][j];
121       fu2ftestmapping[i]= hold;
122     }
123
124   for(Int_t i = 0; i<24000; i++)
125     {
126       Int_t* hold = new Int_t[2]; 
127       for(Int_t j = 0; j<2;j++)  hold[j]=maphand.fMapHwFECglobal[i][j];
128       fMapHwFECglobal[i]= hold;
129     }
130   
131   for(Int_t i = 0; i<7000; i++)
132     {
133       Float_t* hold = new Float_t[128]; 
134       for(Int_t j = 0; j<128;j++)  hold[j]=maphand.fecGainMap[i][j];
135       fecGainMap[i]= hold;
136     }
137
138 }
139
140
141 //____________________________________________________________________________
142 AliTPCMonitorMappingHandler &AliTPCMonitorMappingHandler:: operator= (const AliTPCMonitorMappingHandler& maphand)
143 {
144   // assignment operator
145   if(this!=&maphand)
146     {
147       fnumofChannels=maphand.fnumofChannels;
148       fmaxHWAdress=maphand.fmaxHWAdress;
149       fsizeofArray=maphand.fsizeofArray;
150
151       fmapping = new Short_t*[24000]; // empty
152   
153       
154       fmappingChannelinRow = new Int_t*[160];
155       for(Int_t in = 0; in<160; in++)
156         {
157           Int_t* hold = new Int_t[150]; 
158           for(Int_t jn = 0; jn<150;jn++)  hold[jn]=maphand.fmappingChannelinRow[in][jn];
159           fmappingChannelinRow[in]= hold;
160         }
161       
162       fu2ftestmapping      = new Short_t*[7000];
163       for(Int_t i = 0; i<7000; i++)
164         {
165           Short_t* hold = new Short_t[8]; 
166           for(Int_t j = 0; j<8;j++)  hold[j]=maphand.fu2ftestmapping[i][j];
167           fu2ftestmapping[i]= hold;
168         }
169       
170       fMapHwFECglobal = new Int_t*[24000];
171       for(Int_t i = 0; i<24000; i++)
172         {
173           Int_t* hold = new Int_t[2]; 
174           for(Int_t j = 0; j<2;j++)  hold[j]=maphand.fMapHwFECglobal[i][j];
175           fMapHwFECglobal[i]= hold;
176         }
177       
178       fecGainMap = new Float_t*[7000];
179       for(Int_t i = 0; i<7000; i++)
180         {
181           Float_t* hold = new Float_t[128]; 
182           for(Int_t j = 0; j<128;j++)  hold[j]=maphand.fecGainMap[i][j];
183           fecGainMap[i]= hold;
184         }
185       
186       
187     }
188   return *this;
189 }
190
191
192 //_____________________________________________________________________________________________
193 AliTPCMonitorMappingHandler::~AliTPCMonitorMappingHandler() 
194 {
195   // Destructor
196   Short_t* temp;
197   for(Int_t i = 0; i < 24000 ; i++) {
198     temp = (Short_t *) fmapping[i];
199     if(temp[1] != -1)
200       delete temp;
201   }
202   temp = (Short_t *) fmapping;
203   delete temp;
204   
205   
206   Int_t* temp1;
207   for(Int_t i = 0; i < 24000 ; i++) {
208     temp1 = (Int_t *) fMapHwFECglobal[i];
209     delete temp1;
210   }
211   temp1 = (Int_t *) fMapHwFECglobal;
212   delete temp1;
213  
214   for(Int_t i = 0; i < 7000 ; i++) {
215     temp = (Short_t *) fu2ftestmapping[i];
216     delete temp;
217   }
218  
219   temp = (Short_t *) fu2ftestmapping;
220   delete temp;
221          
222   for(Int_t i = 0; i < 150 ; i++) {
223     temp1= (Int_t *) fmappingChannelinRow[i];
224     delete temp1;
225   }
226   temp1 = (Int_t *) fmappingChannelinRow;
227   delete temp1;
228
229   Float_t* temp2;
230   for(Int_t i = 0; i<7000; i++)
231     {
232       temp2= (Float_t *) fecGainMap[i];
233       delete temp2;
234     }
235   temp2 = (Float_t *) fecGainMap;
236   delete temp2;
237
238         
239 }
240
241 //_____________________________________________________________________________________________
242 void AliTPCMonitorMappingHandler::ReadMapping(char* mapfile)
243 {
244   // Read global Mapping file
245   // Format of data in mapping file:
246   // column 0:  hadrware address
247   // column 1:  readout index in IROC/OROC
248   // column 2:  global pad row number (0-158)
249   // column 3   pad number in row
250   // column 4:  connector
251   // column 5:  pin
252   // column 6:  fec number in IROC/OROC
253   // column 7:  fec channel
254   // column 8:  fec connector
255   // column 9:  altro channel
256   // column 10: altro chip
257  
258   // Mapping data for a given hardware address are placed at the 
259   // index corresponding to the value of the hardware address in 
260   // the fmapping array..
261   // The mapping information for the hardware address 'hwaddr'
262   // can hence be found in fmapping[hwaddr]
263
264
265   Short_t*  mappingRow; 
266   char readcarry[255];
267   Int_t version = -1;
268   Int_t actPos  = 0;
269   Int_t oldPos  = 0;
270
271   ifstream *in = new ifstream();
272   in->open(mapfile);
273   *in >> readcarry;
274   version = atoi(readcarry);
275   
276   *in >> readcarry;
277   fnumofChannels = atoi(readcarry);
278   *in >> readcarry;
279   fmaxHWAdress = atoi(readcarry);
280   fsizeofArray = fmaxHWAdress;
281         
282   Short_t *fmappingEmptyRow = new Short_t[11];
283   for(Int_t i = 0; i < 11 ; i++) {
284     fmappingEmptyRow[i] = 0;
285   }
286   fmappingEmptyRow[1] = -1;
287   for(Int_t i = 0; i < fnumofChannels ; i++) {
288     mappingRow = new Short_t[11];
289     for(Int_t j = 0 ; j < 11 ; j++) {
290       *in >> readcarry;
291       mappingRow[j] = atoi(readcarry);
292     }
293     actPos = mappingRow[0];
294     fmapping[actPos] = mappingRow;
295     if( (actPos - oldPos) > 1) {
296       for(Int_t j = (oldPos+1); j < actPos; j++) {
297         fmapping[j] = fmappingEmptyRow;
298       }
299     }
300     oldPos = actPos;
301     fmapping[actPos][0] = i;
302   }
303   
304   in->close();
305   delete in;
306 }
307
308 //_____________________________________________________________________________________________
309 Int_t  AliTPCMonitorMappingHandler::ReadFECMapping(char* u2ftestfile)
310 {
311   // Read in Mapping of global FEC numbers to branches, rcu patches etc.
312   // Format in Mapping file
313   // column 0: global card number (set to 0 if card number does not exist)
314   // column 1: side of the TPC
315   // column 2: sector on the side   (0-17)
316   // column 3: rcu in the sector    (0-5)
317   // column 4: fec number in rcu    (0-24)
318   // column 5: fec number in branch (0-12)
319   // column 6: branch number        (0,1)
320   // column 7: local hardware address of first channel (not used)
321
322   // Order of data is kept in fu2ftestmapping
323   
324   ifstream datin(u2ftestfile);
325   
326   Int_t carry     = 0;
327   Int_t ncards    = 0;
328  
329   for(Int_t ind = 0; ind<7000; ind++)
330     {
331       for(Int_t entr = 0; entr<8; entr++)
332         {
333           datin >> carry ;
334           fu2ftestmapping[ind][entr] = carry  ;
335           
336           if(entr==0 && carry!=0) ncards++;
337         }
338     }
339   return ncards ;
340 }
341
342  
343
344 //_____________________________________________________________________________________________
345 void AliTPCMonitorMappingHandler::ReadfecHwMap(Int_t sector)
346 {
347   // Create mapping of global FEC numbers to hardware addresses for a given sector
348
349   Int_t  fside           =0;
350   Int_t  fsector        = 0;
351   Int_t  fec            = 0;
352   Int_t  branch         = 0;
353   Int_t  rcu_patch      = 0;
354   Int_t  altrchann      = 0;
355   Int_t  altrchip       = 0;
356   Int_t  nextHwAddress  = 0;
357   Int_t  nfecs          = 0;
358
359   if(sector/18==0) fside =65;
360   else             fside =67;
361   
362   if(sector>18)    fsector= sector-18;
363   else             fsector= sector   ;
364
365   for(Int_t ind = 0; ind<7000; ind++)
366     { 
367       if((Int_t)U2fGetSide(ind)==fside && U2fGetSector(ind)==fsector) 
368         {
369           nfecs++;
370           fec            = U2fGetFECinBranch(ind);
371           branch         = U2fGetBranch(ind);
372           rcu_patch      = U2fGetRCU(ind);
373                   
374           for(Int_t ch = 0; ch<128; ch++)
375             {
376               altrchann      = ch%16;
377               altrchip       = ch/16;
378               
379               nextHwAddress  = (   ((branch&1)<<11) + (fec<<7) + (altrchip<<4) + (altrchann)  + ((rcu_patch-1)<<12) ); 
380               
381               fMapHwFECglobal[nextHwAddress][0] = ind;
382               fMapHwFECglobal[nextHwAddress][1] = ch ;
383             }
384         }
385     }
386 }
387 //_____________________________________________________________________________________________
388 void AliTPCMonitorMappingHandler::ReadfecGainMap(char* fecgainmap)
389 {
390   // Read global gain calibration pap
391   // Format in file :
392   // colummn 0      : FEC number 
393   // colums  1-128  : gain calibration factors 
394   ifstream datin(fecgainmap);
395   
396   Int_t   fecnr  = 0;
397   Float_t val    = 0.0 ;
398   
399   while(!datin.eof())
400     {
401       datin >> fecnr ;
402       for(Int_t in = 0; in<128; in++)
403         {
404           datin >> val ;
405           fecGainMap[fecnr][in] = val;
406         }
407     }
408 }
409
410 //_____________________________________________________________________________________________
411 void  AliTPCMonitorMappingHandler::ReadRowMappingGlob(char* fpathtoMappingRowfile) 
412 {
413   // Read mapping of hardware addresses in rows
414   // Format of file:
415   // column 0:        global row number (0-158)
416   // column 1:        number of pads in this row (npads)
417   // column 2-npads:  hardware addresses for these pads
418  
419   char readcarry[256];
420   char readcarry2[256];
421   ifstream *in = new ifstream();
422   in->open(fpathtoMappingRowfile);
423   
424   for(Int_t i = 0; i < 159 ; i++) {
425     *in >> readcarry;   // row number 
426     *in >> readcarry2;  // numof pads
427     fmappingChannelinRow[i][0] = atoi(readcarry2);
428     fmappingChannelinRow[i][1] = atoi(readcarry);
429     
430     for(Int_t j = 2 ; j < fmappingChannelinRow[i][0]+2 ; j++) {
431       *in >> readcarry;
432       fmappingChannelinRow[i][j] = atoi(readcarry);
433     }
434   }
435   in->close();
436 }
437
438
439
440 //_____________________________________________________________________________________________
441 Int_t AliTPCMonitorMappingHandler::GetNumOfChannels()
442 {
443   // Return number of channels
444   return fnumofChannels;
445 }
446
447 //_____________________________________________________________________________________________
448 Int_t AliTPCMonitorMappingHandler::GetSizeofArray()
449 {
450   // Return sise of global mapping fmapping array.
451   // Value orresponds to max value of hardware addresses
452   return fsizeofArray;
453 }
454
455
456 //_____________________________________________________________________________________________
457 Short_t* AliTPCMonitorMappingHandler::GetLine(Int_t hwaddr)
458 {
459   // Return pointer to mapping array for the hardware address hwaddr 
460   Short_t* retval;
461   if(hwaddr <= fsizeofArray)
462     retval = fmapping[hwaddr];
463   else
464     retval = 0;
465   return retval;
466 }
467
468 //_____________________________________________________________________________________________
469 Int_t AliTPCMonitorMappingHandler::GetIndex(Int_t hwaddr) 
470 {
471   // Return readout index for the hardware address hwaddr
472   Int_t retval;
473   if(hwaddr <= fsizeofArray)
474     retval = fmapping[hwaddr][1];
475   else
476     retval = 0;
477   return retval;
478 }
479
480 //_____________________________________________________________________________________________
481 Int_t AliTPCMonitorMappingHandler::GetPadRow(Int_t hwaddr) 
482 {
483   // Return global pad row  for the hardware address hwaddr 
484   Int_t retval;
485   if(hwaddr <= fsizeofArray)
486     retval = fmapping[hwaddr][2];
487   else
488     retval = 0;
489   return retval;
490 }
491
492 //_____________________________________________________________________________________________
493 Int_t AliTPCMonitorMappingHandler::GetPad(Int_t hwaddr) 
494 {
495   // Return pad number in row for the hardware address hwaddr 
496   Int_t retval;
497   if(hwaddr < fsizeofArray)
498     retval = fmapping[hwaddr][3];
499   else
500     retval = 0;
501   return retval;
502 }
503
504 //_____________________________________________________________________________________________
505 Int_t AliTPCMonitorMappingHandler::GetConnector(Int_t hwaddr) 
506 {
507   // Return connector for the hardware address hwaddr 
508   Int_t retval;
509   if(hwaddr <= fsizeofArray)
510     retval = fmapping[hwaddr][4];
511   else
512     retval = 0;
513   return retval;
514 }
515
516 //_____________________________________________________________________________________________
517 Int_t AliTPCMonitorMappingHandler::GetPin(Int_t hwaddr) 
518 {
519   // Return pin for the hardware address hwaddr 
520   Int_t retval;
521   if(hwaddr <= fsizeofArray)
522     retval = fmapping[hwaddr][5];
523   else
524     retval = 0;
525   return retval;
526 }
527
528 //_____________________________________________________________________________________________
529 Int_t AliTPCMonitorMappingHandler::GetFEC(Int_t hwaddr) 
530 {
531   // Return fec number in IROC/OROC  for the hardware address hwaddr 
532   Int_t retval;
533   if(hwaddr <= fsizeofArray)
534     retval = fmapping[hwaddr][6];
535   else
536     retval = 0;
537   return retval;
538 }
539
540 //_____________________________________________________________________________________________
541 Int_t AliTPCMonitorMappingHandler::GetFECchannel(Int_t hwaddr) 
542 {
543   // Return FEC channel for the hardware address hwaddr 
544   Int_t retval;
545   if(hwaddr < fsizeofArray)
546     retval = fmapping[hwaddr][7];
547   else
548     retval = 0;
549   return retval;
550 }
551
552 //_____________________________________________________________________________________________
553 Int_t AliTPCMonitorMappingHandler::GetFECconnector(Int_t hwaddr) 
554 {
555   // Return FEC connector for the hardware address hwaddr 
556   Int_t retval;
557   if(hwaddr <= fsizeofArray)
558     retval = fmapping[hwaddr][8];
559   else
560     retval = 0;
561   return retval;
562 }
563
564 //_____________________________________________________________________________________________
565 Int_t AliTPCMonitorMappingHandler::GetAltroChannel(Int_t hwaddr) 
566 {
567   // Return Altro channel for the hardware address hwaddr 
568   Int_t retval;
569   if(hwaddr <= fsizeofArray)
570     retval = fmapping[hwaddr][9];
571   else
572     retval = 0;
573   return retval;
574 }
575
576 //_____________________________________________________________________________________________
577 Int_t AliTPCMonitorMappingHandler::GetAltro(Int_t hwaddr) 
578 {
579   // Return Altro chip number in FEC for the hardware address hwaddr 
580   Int_t retval;
581   if(hwaddr <= fsizeofArray)
582     retval = fmapping[hwaddr][10];
583   else
584     retval = 0;
585   return retval;
586 }
587
588
589 //_____________________________________________________________________________________________
590 Int_t AliTPCMonitorMappingHandler::GetNumofPads(Int_t row)
591 {
592   // Return number of pads in row
593   if(row<159)
594     return fmappingChannelinRow[row][0];
595   else  {
596     AliError("Row number to high");
597     return 0;
598   }
599 }
600
601 //_____________________________________________________________________________________________
602 Int_t AliTPCMonitorMappingHandler::GetPadAddInRow(Int_t row,Int_t pad )
603 {
604   // Return hardware address for given pad in row
605   if(row<159)
606     return fmappingChannelinRow[row][pad+2];
607   else {
608     AliError("Row number to high");
609     return 0;
610   }
611 }
612
613
614
615 //_____________________________________________________________________________________________
616 Int_t AliTPCMonitorMappingHandler::U2fGetFECnr(Int_t index)
617 {
618   // Return FEC number for index  (FEC number should be equal to index)
619   return  fu2ftestmapping[index][0];
620 }
621
622 //_____________________________________________________________________________________________
623 Int_t AliTPCMonitorMappingHandler::U2fGetSide(Int_t fecnr)
624 {
625   // Return side on which FEC is installed
626   return  fu2ftestmapping[fecnr][1];
627 }
628
629 //_____________________________________________________________________________________________
630 Int_t AliTPCMonitorMappingHandler::U2fGetSector(Int_t fecnr)
631 {
632   // Return sector in which FEC is installed
633   return  fu2ftestmapping[fecnr][2];
634 }
635
636 //_____________________________________________________________________________________________
637 Int_t AliTPCMonitorMappingHandler::U2fGetRCU(Int_t fecnr)
638 {
639   // Rerurn rcu patch in which FEC is installed
640   return  fu2ftestmapping[fecnr][3];
641 }
642
643 //_____________________________________________________________________________________________
644 Int_t AliTPCMonitorMappingHandler::U2fGetFECinRCU(Int_t fecnr)
645 {
646   // Return index of FEC in RCU (0-25)
647   return  fu2ftestmapping[fecnr][4];
648 }
649
650 //_____________________________________________________________________________________________
651 Int_t AliTPCMonitorMappingHandler::U2fGetFECinBranch(Int_t fecnr)
652 {
653   // Return index of FEC in branch (0-12)
654   return  fu2ftestmapping[fecnr][5];
655 }
656
657 //_____________________________________________________________________________________________
658 Int_t AliTPCMonitorMappingHandler::U2fGetBranch(Int_t fecnr)
659 {
660   // Return branch in which FEC is installed (0,1)
661   return  fu2ftestmapping[fecnr][6];
662     
663 }