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