]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorMappingHandler.cxx
Partially fixing TClonesArray create / delete
[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 //   while ( std::getline(*in, std::string()) )
284 //     ++numLines;
285 //  in->seekg(0,ios::beg);
286   
287 //   *in >> readcarry;
288 //   version = atoi(readcarry);
289   *in >> version;
290 //   --numLines;
291 //   *in >> readcarry;
292 //   fnumofChannels = atoi(readcarry);
293   *in >> fnumofChannels;
294 //   --numLines;
295   
296 //   *in >> readcarry;
297 //   fmaxHWAdress = atoi(readcarry);
298   *in >> fmaxHWAdress;
299   fsizeofArray = fmaxHWAdress;
300 //   --numLines;
301   
302 //   fnumofChannels=TMath::Min(fnumofChannels,numLines);
303   
304   Short_t *fmappingEmptyRow = new Short_t[11];
305   for(Int_t i = 0; i < 11 ; i++) {
306     fmappingEmptyRow[i] = 0;
307   }
308   fmappingEmptyRow[1] = -1;
309   for(Int_t i = 0; i < fnumofChannels ; i++) {
310     mappingRow = new Short_t[11];
311     for(Int_t j = 0 ; j < 11 ; j++) {
312 //       *in >> readcarry;
313 //       mappingRow[j] = atoi(readcarry);
314       *in >> mappingRow[j];
315     }
316     actPos = mappingRow[0];
317     fmapping[actPos] = mappingRow;
318     if( (actPos - oldPos) > 1) {
319       for(Int_t j = (oldPos+1); j < actPos; j++) {
320         fmapping[j] = fmappingEmptyRow;
321       }
322     }
323     oldPos = actPos;
324     fmapping[actPos][0] = i;
325   }
326   
327   in->close();
328   delete in;
329
330   delete [] fmappingEmptyRow;
331 }
332
333 //_____________________________________________________________________________________________
334 Int_t  AliTPCMonitorMappingHandler::ReadFECMapping(char* u2ftestfile)
335 {
336   // Read in Mapping of global FEC numbers to branches, rcu patches etc.
337   // Format in Mapping file
338   // column 0: global card number (set to 0 if card number does not exist)
339   // column 1: side of the TPC
340   // column 2: sector on the side   (0-17)
341   // column 3: rcu in the sector    (0-5)
342   // column 4: fec number in rcu    (0-24)
343   // column 5: fec number in branch (0-12)
344   // column 6: branch number        (0,1)
345   // column 7: local hardware address of first channel (not used)
346
347   // Order of data is kept in fu2ftestmapping
348   
349   ifstream datin(u2ftestfile);
350   
351   Int_t carry     = 0;
352   Int_t ncards    = 0;
353  
354   for(Int_t ind = 0; ind<7000; ind++)
355     {
356       for(Int_t entr = 0; entr<8; entr++)
357         {
358           datin >> carry ;
359           fu2ftestmapping[ind][entr] = carry  ;
360           
361           if(entr==0 && carry!=0) ncards++;
362         }
363     }
364   return ncards ;
365 }
366
367  
368
369 //_____________________________________________________________________________________________
370 void AliTPCMonitorMappingHandler::ReadfecHwMap(Int_t sector)
371 {
372   // Create mapping of global FEC numbers to hardware addresses for a given sector
373
374   Int_t  fside           =0;
375   Int_t  fsector        = 0;
376   Int_t  fec            = 0;
377   Int_t  branch         = 0;
378   Int_t  rcupatch      = 0;
379   Int_t  altrchann      = 0;
380   Int_t  altrchip       = 0;
381   Int_t  nextHwAddress  = 0;
382   Int_t  nfecs          = 0;
383
384   if(sector/18==0) fside =65;
385   else             fside =67;
386   
387   if(sector>18)    fsector= sector-18;
388   else             fsector= sector   ;
389
390   for(Int_t ind = 0; ind<7000; ind++)
391     { 
392       if((Int_t)U2fGetSide(ind)==fside && U2fGetSector(ind)==fsector) 
393         {
394           nfecs++;
395           fec            = U2fGetFECinBranch(ind);
396           branch         = U2fGetBranch(ind);
397           rcupatch      = U2fGetRCU(ind);
398                   
399           for(Int_t ch = 0; ch<128; ch++)
400             {
401               altrchann      = ch%16;
402               altrchip       = ch/16;
403               
404               nextHwAddress  = (   ((branch&1)<<11) + (fec<<7) + (altrchip<<4) + (altrchann)  + ((rcupatch-1)<<12) ); 
405               
406               fMapHwFECglobal[nextHwAddress][0] = ind;
407               fMapHwFECglobal[nextHwAddress][1] = ch ;
408             }
409         }
410     }
411 }
412 //_____________________________________________________________________________________________
413 void AliTPCMonitorMappingHandler::ReadfecGainMap(char* fecgainmap)
414 {
415   // Read global gain calibration pap
416   // Format in file :
417   // colummn 0      : FEC number 
418   // colums  1-128  : gain calibration factors 
419   ifstream datin(fecgainmap);
420   
421   Int_t   fecnr  = 0;
422   Float_t val    = 0.0 ;
423   
424   while(!datin.eof())
425   {
426     datin >> fecnr ;
427     for(Int_t in = 0; in<128; in++)
428     {
429       datin >> val ;
430       fecGainMap[fecnr][in] = val;
431     }
432   }
433 }
434
435 //_____________________________________________________________________________________________
436 void  AliTPCMonitorMappingHandler::ReadRowMappingGlob(char* fpathtoMappingRowfile) 
437 {
438   // Read mapping of hardware addresses in rows
439   // Format of file:
440   // column 0:        global row number (0-158)
441   // column 1:        number of pads in this row (npads)
442   // column 2-npads:  hardware addresses for these pads
443  
444   char readcarry[256];
445   char readcarry2[256];
446   ifstream *in = new ifstream();
447   in->open(fpathtoMappingRowfile);
448   
449   for(Int_t i = 0; i < 159 ; i++) {
450     *in >> readcarry;   // row number 
451     *in >> readcarry2;  // numof pads
452     fmappingChannelinRow[i][0] = atoi(readcarry2);
453     fmappingChannelinRow[i][1] = atoi(readcarry);
454     
455     for(Int_t j = 2 ; j < fmappingChannelinRow[i][0]+2 ; j++) {
456       *in >> readcarry;
457       fmappingChannelinRow[i][j] = atoi(readcarry);
458     }
459   }
460   in->close();
461 }
462
463
464
465 //_____________________________________________________________________________________________
466 Int_t AliTPCMonitorMappingHandler::GetNumOfChannels() const
467 {
468   // Return number of channels
469   return fnumofChannels;
470 }
471
472 //_____________________________________________________________________________________________
473 Int_t AliTPCMonitorMappingHandler::GetSizeofArray() const
474 {
475   // Return sise of global mapping fmapping array.
476   // Value orresponds to max value of hardware addresses
477   return fsizeofArray;
478 }
479
480
481 //_____________________________________________________________________________________________
482 Short_t* AliTPCMonitorMappingHandler::GetLine(Int_t hwaddr)const
483 {
484   // Return pointer to mapping array for the hardware address hwaddr 
485   Short_t* retval;
486   if(hwaddr <= fsizeofArray)
487     retval = fmapping[hwaddr];
488   else
489     retval = 0;
490   return retval;
491 }
492
493 //_____________________________________________________________________________________________
494 Int_t AliTPCMonitorMappingHandler::GetIndex(Int_t hwaddr) const
495 {
496   // Return readout index for the hardware address hwaddr
497   Int_t retval;
498   if(hwaddr <= fsizeofArray)
499     retval = fmapping[hwaddr][1];
500   else
501     retval = 0;
502   return retval;
503 }
504
505 //_____________________________________________________________________________________________
506 Int_t AliTPCMonitorMappingHandler::GetPadRow(Int_t hwaddr) const
507 {
508   // Return global pad row  for the hardware address hwaddr 
509   Int_t retval;
510   if(hwaddr <= fsizeofArray)
511     retval = fmapping[hwaddr][2];
512   else
513     retval = 0;
514   return retval;
515 }
516
517 //_____________________________________________________________________________________________
518 Int_t AliTPCMonitorMappingHandler::GetPad(Int_t hwaddr) const
519 {
520   // Return pad number in row for the hardware address hwaddr 
521   Int_t retval;
522   if(hwaddr < fsizeofArray)
523     retval = fmapping[hwaddr][3];
524   else
525     retval = 0;
526   return retval;
527 }
528
529 //_____________________________________________________________________________________________
530 Int_t AliTPCMonitorMappingHandler::GetConnector(Int_t hwaddr) const
531 {
532   // Return connector for the hardware address hwaddr 
533   Int_t retval;
534   if(hwaddr <= fsizeofArray)
535     retval = fmapping[hwaddr][4];
536   else
537     retval = 0;
538   return retval;
539 }
540
541 //_____________________________________________________________________________________________
542 Int_t AliTPCMonitorMappingHandler::GetPin(Int_t hwaddr) const
543 {
544   // Return pin for the hardware address hwaddr 
545   Int_t retval;
546   if(hwaddr <= fsizeofArray)
547     retval = fmapping[hwaddr][5];
548   else
549     retval = 0;
550   return retval;
551 }
552
553 //_____________________________________________________________________________________________
554 Int_t AliTPCMonitorMappingHandler::GetFEC(Int_t hwaddr) const
555 {
556   // Return fec number in IROC/OROC  for the hardware address hwaddr 
557   Int_t retval;
558   if(hwaddr <= fsizeofArray)
559     retval = fmapping[hwaddr][6];
560   else
561     retval = 0;
562   return retval;
563 }
564
565 //_____________________________________________________________________________________________
566 Int_t AliTPCMonitorMappingHandler::GetFECchannel(Int_t hwaddr) const
567 {
568   // Return FEC channel for the hardware address hwaddr 
569   Int_t retval;
570   if(hwaddr < fsizeofArray)
571     retval = fmapping[hwaddr][7];
572   else
573     retval = 0;
574   return retval;
575 }
576
577 //_____________________________________________________________________________________________
578 Int_t AliTPCMonitorMappingHandler::GetFECconnector(Int_t hwaddr) const
579 {
580   // Return FEC connector for the hardware address hwaddr 
581   Int_t retval;
582   if(hwaddr <= fsizeofArray)
583     retval = fmapping[hwaddr][8];
584   else
585     retval = 0;
586   return retval;
587 }
588
589 //_____________________________________________________________________________________________
590 Int_t AliTPCMonitorMappingHandler::GetAltroChannel(Int_t hwaddr)  const
591 {
592   // Return Altro channel for the hardware address hwaddr 
593   Int_t retval;
594   if(hwaddr <= fsizeofArray)
595     retval = fmapping[hwaddr][9];
596   else
597     retval = 0;
598   return retval;
599 }
600
601 //_____________________________________________________________________________________________
602 Int_t AliTPCMonitorMappingHandler::GetAltro(Int_t hwaddr)  const
603 {
604   // Return Altro chip number in FEC for the hardware address hwaddr 
605   Int_t retval;
606   if(hwaddr <= fsizeofArray)
607     retval = fmapping[hwaddr][10];
608   else
609     retval = 0;
610   return retval;
611 }
612
613
614 //_____________________________________________________________________________________________
615 Int_t AliTPCMonitorMappingHandler::GetNumofPads(Int_t row) 
616 {
617   // Return number of pads in row
618   if(row<159)
619     return fmappingChannelinRow[row][0];
620   else  {
621     AliError("Row number to high");
622     return 0;
623   }
624 }
625
626 //_____________________________________________________________________________________________
627 Int_t AliTPCMonitorMappingHandler::GetPadAddInRow(Int_t row,Int_t pad )
628 {
629   // Return hardware address for given pad in row
630   if(row<159)
631     return fmappingChannelinRow[row][pad+2];
632   else {
633     AliError("Row number to high");
634     return 0;
635   }
636 }
637
638
639
640 //_____________________________________________________________________________________________
641 Int_t AliTPCMonitorMappingHandler::U2fGetFECnr(Int_t index) const
642 {
643   // Return FEC number for index  (FEC number should be equal to index)
644   return  fu2ftestmapping[index][0];
645 }
646
647 //_____________________________________________________________________________________________
648 Int_t AliTPCMonitorMappingHandler::U2fGetSide(Int_t fecnr) const
649 {
650   // Return side on which FEC is installed
651   return  fu2ftestmapping[fecnr][1];
652 }
653
654 //_____________________________________________________________________________________________
655 Int_t AliTPCMonitorMappingHandler::U2fGetSector(Int_t fecnr) const
656 {
657   // Return sector in which FEC is installed
658   return  fu2ftestmapping[fecnr][2];
659 }
660
661 //_____________________________________________________________________________________________
662 Int_t AliTPCMonitorMappingHandler::U2fGetRCU(Int_t fecnr) const
663 {
664   // Rerurn rcu patch in which FEC is installed
665   return  fu2ftestmapping[fecnr][3];
666 }
667
668 //_____________________________________________________________________________________________
669 Int_t AliTPCMonitorMappingHandler::U2fGetFECinRCU(Int_t fecnr) const
670 {
671   // Return index of FEC in RCU (0-25)
672   return  fu2ftestmapping[fecnr][4];
673 }
674
675 //_____________________________________________________________________________________________
676 Int_t AliTPCMonitorMappingHandler::U2fGetFECinBranch(Int_t fecnr) const
677 {
678   // Return index of FEC in branch (0-12)
679   return  fu2ftestmapping[fecnr][5];
680 }
681
682 //_____________________________________________________________________________________________
683 Int_t AliTPCMonitorMappingHandler::U2fGetBranch(Int_t fecnr) const
684 {
685   // Return branch in which FEC is installed (0,1)
686   return  fu2ftestmapping[fecnr][6];
687     
688 }