]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCMonitorMappingHandler.cxx
-fiorellas update
[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 #include <TString.h>
55
56 ClassImp(AliTPCMonitorMappingHandler)
57
58 //_____________________________________________________________________________________________
59 AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(const Char_t* name, const Char_t* title): 
60   TNamed(name,title),
61   fnumofChannels(0),
62   fmaxHWAdress(0),
63   fsizeofArray(0)
64 {
65   // Constructor : Initialize mapping arrays
66  
67   for(Int_t in = 0; in<159; ++in)
68     for(Int_t jn = 0; jn<150; ++jn)
69       fmappingChannelinRow[in][jn] = 0;
70   
71   for(Int_t i = 0; i<7000; ++i){
72     for(Int_t j = 0; j<8; ++j)
73       fu2ftestmapping[i][j] = 0;
74     
75     for(Int_t j = 0; j<128; ++j)
76       fecGainMap[i][j] = 0.;
77   }
78   
79   for(Int_t i = 0; i<24000; ++i){
80     for(Int_t j = 0; j<2; ++j)
81       fMapHwFECglobal[i][j]=0;
82     
83     for (Int_t j=0; j<11; ++j)
84       fmapping[i][j]=0;
85     fmapping[i][1]=-1;
86   }
87 }
88
89 //____________________________________________________________________________
90 AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(const  AliTPCMonitorMappingHandler &maphand) :
91   TNamed(maphand.GetName(),maphand.GetTitle()),
92   fnumofChannels(maphand.fnumofChannels),
93   fmaxHWAdress(maphand.fmaxHWAdress),
94   fsizeofArray(maphand.fsizeofArray)
95 {
96   // copy constructor
97  
98  
99   for(Int_t in = 0; in<159; ++in)
100     for(Int_t jn = 0; jn<150; ++jn)
101       fmappingChannelinRow[in][jn] = maphand.fmappingChannelinRow[in][jn];
102   
103   for(Int_t i = 0; i<7000; ++i){
104     for(Int_t j = 0; j<8; ++j)
105       fu2ftestmapping[i][j] = maphand.fu2ftestmapping[i][j];
106
107     for(Int_t j = 0; j<128; ++j)
108       fecGainMap[i][j] = maphand.fecGainMap[i][j];
109   }
110
111   for(Int_t i = 0; i<24000; ++i){
112     for (Int_t j = 0; j<2; ++j)
113       fMapHwFECglobal[i][j]=maphand.fMapHwFECglobal[i][j];
114
115     for (Int_t j=0; j<11; ++j)
116       fmapping[i][j] = maphand.fmapping[i][j];
117   }
118 }
119
120
121 //____________________________________________________________________________
122 AliTPCMonitorMappingHandler &AliTPCMonitorMappingHandler:: operator= (const AliTPCMonitorMappingHandler& maphand)
123 {
124   // assignment operator
125   if (this == &maphand) return *this;
126
127   fnumofChannels=maphand.fnumofChannels;
128   fmaxHWAdress=maphand.fmaxHWAdress;
129   fsizeofArray=maphand.fsizeofArray;
130
131   for(Int_t in = 0; in<159; ++in)
132     for(Int_t jn = 0; jn<150; ++jn)
133       fmappingChannelinRow[in][jn] = maphand.fmappingChannelinRow[in][jn];
134   
135   for(Int_t i = 0; i<7000; ++i){
136     for(Int_t j = 0; j<8; ++j)
137       fu2ftestmapping[i][j]=maphand.fu2ftestmapping[i][j];
138
139     for(Int_t j = 0; j<128; ++j)
140       fecGainMap[i][j] = maphand.fecGainMap[i][j];
141   }
142
143   for(Int_t i = 0; i<24000; ++i){
144     for(Int_t j = 0; j<2; ++j)
145       fMapHwFECglobal[i][j] = maphand.fMapHwFECglobal[i][j];
146
147     for (Int_t j=0; j<11; ++j)
148       fmapping[i][j] = maphand.fmapping[i][j];
149   }
150
151   return *this;
152 }
153
154
155 //_____________________________________________________________________________________________
156 AliTPCMonitorMappingHandler::~AliTPCMonitorMappingHandler() 
157 {
158   // Destructor
159 }
160
161 //_____________________________________________________________________________________________
162 void AliTPCMonitorMappingHandler::ReadMapping(const char* mapfile)
163 {
164   // Read global Mapping file
165   // Format of data in mapping file:
166   // column 0:  hadrware address
167   // column 1:  readout index in IROC/OROC
168   // column 2:  global pad row number (0-158)
169   // column 3   pad number in row
170   // column 4:  connector
171   // column 5:  pin
172   // column 6:  fec number in IROC/OROC
173   // column 7:  fec channel
174   // column 8:  fec connector
175   // column 9:  altro channel
176   // column 10: altro chip
177  
178   // Mapping data for a given hardware address are placed at the 
179   // index corresponding to the value of the hardware address in 
180   // the fmapping array..
181   // The mapping information for the hardware address 'hwaddr'
182   // can hence be found in fmapping[hwaddr]
183
184
185   Int_t version = -1;
186   Int_t actPos  = 0;
187
188   ifstream infile(mapfile,ios::in);
189
190 //   printf("file1: %s\n",mapfile);
191   if (!infile.is_open()) return;
192 //   int numLines = 0;
193 //   std::string line;
194 //   while ( std::getline(infile, line) )
195 //     ++numLines;
196 //   infile.seekg(0,ios::beg);
197 //   infile.clear();
198
199 //   printf("file: %s - %d\n",mapfile,numLines);
200   
201   infile >> version;
202 //   --numLines;
203
204   infile >> fnumofChannels;
205 //   --numLines;
206   
207   infile >> fmaxHWAdress;
208   fsizeofArray = fmaxHWAdress;
209 //   --numLines;
210
211   //consistency check
212   fnumofChannels=TMath::Abs(fnumofChannels);
213 //   fnumofChannels=TMath::Min(fnumofChannels,numLines);
214
215   Int_t val=0;
216   for(Int_t i = 0; i < fnumofChannels ; i++) {
217     //get hw address
218     infile >> actPos;
219
220     //set first value of hw address to channel number
221     if (actPos>0 && actPos<24000)
222       fmapping[actPos][0] = (Short_t)i;
223
224     //loop over channel parameters
225     for(Int_t j = 1 ; j < 11 ; j++) {
226       infile >> val;
227       if (actPos>0 && actPos<24000)
228         fmapping[actPos][j] = (Short_t)val;
229     }
230   }
231   
232   infile.close();
233 }
234
235 //_____________________________________________________________________________________________
236 Int_t  AliTPCMonitorMappingHandler::ReadFECMapping(const char* u2ftestfile)
237 {
238   // Read in Mapping of global FEC numbers to branches, rcu patches etc.
239   // Format in Mapping file
240   // column 0: global card number (set to 0 if card number does not exist)
241   // column 1: side of the TPC
242   // column 2: sector on the side   (0-17)
243   // column 3: rcu in the sector    (0-5)
244   // column 4: fec number in rcu    (0-24)
245   // column 5: fec number in branch (0-12)
246   // column 6: branch number        (0,1)
247   // column 7: local hardware address of first channel (not used)
248
249   // Order of data is kept in fu2ftestmapping
250   
251   ifstream datin(u2ftestfile);
252   
253   Int_t carry     = 0;
254   Int_t ncards    = 0;
255  
256   for(Int_t ind = 0; ind<7000; ind++) {
257       for(Int_t entr = 0; entr<8; entr++) {
258         datin >> carry ;
259         fu2ftestmapping[ind][entr] = carry  ;
260
261         if(entr==0 && carry!=0) ncards++;
262       }
263   }
264   return ncards ;
265 }
266
267  
268
269 //_____________________________________________________________________________________________
270 void AliTPCMonitorMappingHandler::ReadfecHwMap(Int_t sector)
271 {
272   // Create mapping of global FEC numbers to hardware addresses for a given sector
273
274   Int_t  fside           =0;
275   Int_t  fsector        = 0;
276   Int_t  fec            = 0;
277   Int_t  branch         = 0;
278   Int_t  rcupatch      = 0;
279   Int_t  altrchann      = 0;
280   Int_t  altrchip       = 0;
281   Int_t  nextHwAddress  = 0;
282   Int_t  nfecs          = 0;
283
284   if(sector/18==0) fside =65;
285   else             fside =67;
286   
287   if(sector>18)    fsector= sector-18;
288   else             fsector= sector   ;
289
290   for(Int_t ind = 0; ind<7000; ind++) { 
291     if((Int_t)U2fGetSide(ind)==fside && U2fGetSector(ind)==fsector) {
292       nfecs++;
293       fec            = U2fGetFECinBranch(ind);
294       branch         = U2fGetBranch(ind);
295       rcupatch      = U2fGetRCU(ind);
296
297       for(Int_t ch = 0; ch<128; ch++) {
298         altrchann      = ch%16;
299         altrchip       = ch/16;
300
301         nextHwAddress  = (   ((branch&1)<<11) + (fec<<7) + (altrchip<<4) + (altrchann)  + ((rcupatch-1)<<12) );
302
303         if (nextHwAddress<0 || nextHwAddress>=24000) continue;
304         fMapHwFECglobal[nextHwAddress][0] = ind;
305         fMapHwFECglobal[nextHwAddress][1] = ch ;
306       }
307     }
308   }
309 }
310 //_____________________________________________________________________________________________
311 void AliTPCMonitorMappingHandler::ReadfecGainMap(const char* fecgainmap)
312 {
313   // Read global gain calibration pap
314   // Format in file :
315   // colummn 0      : FEC number 
316   // colums  1-128  : gain calibration factors 
317   ifstream datin(fecgainmap);
318   
319   Int_t   fecnr  = 0;
320   Float_t val    = 0.0 ;
321   
322   while(!datin.eof())
323   {
324     datin >> fecnr ;
325     for(Int_t in = 0; in<128; in++)
326     {
327       datin >> val ;
328       if (fecnr<0 || fecnr>=7000) continue;
329       fecGainMap[fecnr][in] = val;
330     }
331   }
332 }
333
334 //_____________________________________________________________________________________________
335 void  AliTPCMonitorMappingHandler::ReadRowMappingGlob(const char* fpathtoMappingRowfile) 
336 {
337   // Read mapping of hardware addresses in rows
338   // Format of file:
339   // column 0:        global row number (0-158)
340   // column 1:        number of pads in this row (npads)
341   // column 2-npads:  hardware addresses for these pads
342  
343   TString readcarry;
344   TString readcarry2;
345   ifstream in(fpathtoMappingRowfile,ios::in);
346   
347   for(Int_t i = 0; i < 159 ; i++) {
348     in >> readcarry;   // row number
349     in >> readcarry2;  // numof pads
350     fmappingChannelinRow[i][0] = readcarry2.Atoi();
351     fmappingChannelinRow[i][1] = TMath::Min(TMath::Abs(readcarry.Atoi()),140); //maximum number of pads is 140
352     
353     for(Int_t j = 2 ; j < fmappingChannelinRow[i][0]+2 ; j++) {
354       in >> readcarry;
355       fmappingChannelinRow[i][j] = readcarry.Atoi();
356     }
357   }
358   in.close();
359 }
360
361
362
363 //_____________________________________________________________________________________________
364 Int_t AliTPCMonitorMappingHandler::GetNumOfChannels() const
365 {
366   // Return number of channels
367   return fnumofChannels;
368 }
369
370 //_____________________________________________________________________________________________
371 Int_t AliTPCMonitorMappingHandler::GetSizeofArray() const
372 {
373   // Return sise of global mapping fmapping array.
374   // Value orresponds to max value of hardware addresses
375   return fsizeofArray;
376 }
377
378
379 //_____________________________________________________________________________________________
380 const Short_t* AliTPCMonitorMappingHandler::GetLine(Int_t hwaddr) const
381 {
382   // Return pointer to mapping array for the hardware address hwaddr 
383   const Short_t* retval=0x0;
384   if(hwaddr <= fsizeofArray)
385     retval = fmapping[hwaddr];
386   else
387     retval = 0;
388   return retval;
389 }
390
391 //_____________________________________________________________________________________________
392 Int_t AliTPCMonitorMappingHandler::GetIndex(Int_t hwaddr) const
393 {
394   // Return readout index for the hardware address hwaddr
395   Int_t retval;
396   if(hwaddr <= fsizeofArray)
397     retval = fmapping[hwaddr][1];
398   else
399     retval = 0;
400   return retval;
401 }
402
403 //_____________________________________________________________________________________________
404 Int_t AliTPCMonitorMappingHandler::GetPadRow(Int_t hwaddr) const
405 {
406   // Return global pad row  for the hardware address hwaddr 
407   Int_t retval;
408   if(hwaddr <= fsizeofArray)
409     retval = fmapping[hwaddr][2];
410   else
411     retval = 0;
412   return retval;
413 }
414
415 //_____________________________________________________________________________________________
416 Int_t AliTPCMonitorMappingHandler::GetPad(Int_t hwaddr) const
417 {
418   // Return pad number in row for the hardware address hwaddr 
419   Int_t retval;
420   if(hwaddr < fsizeofArray)
421     retval = fmapping[hwaddr][3];
422   else
423     retval = 0;
424   return retval;
425 }
426
427 //_____________________________________________________________________________________________
428 Int_t AliTPCMonitorMappingHandler::GetConnector(Int_t hwaddr) const
429 {
430   // Return connector for the hardware address hwaddr 
431   Int_t retval;
432   if(hwaddr <= fsizeofArray)
433     retval = fmapping[hwaddr][4];
434   else
435     retval = 0;
436   return retval;
437 }
438
439 //_____________________________________________________________________________________________
440 Int_t AliTPCMonitorMappingHandler::GetPin(Int_t hwaddr) const
441 {
442   // Return pin for the hardware address hwaddr 
443   Int_t retval;
444   if(hwaddr <= fsizeofArray)
445     retval = fmapping[hwaddr][5];
446   else
447     retval = 0;
448   return retval;
449 }
450
451 //_____________________________________________________________________________________________
452 Int_t AliTPCMonitorMappingHandler::GetFEC(Int_t hwaddr) const
453 {
454   // Return fec number in IROC/OROC  for the hardware address hwaddr 
455   Int_t retval;
456   if(hwaddr <= fsizeofArray)
457     retval = fmapping[hwaddr][6];
458   else
459     retval = 0;
460   return retval;
461 }
462
463 //_____________________________________________________________________________________________
464 Int_t AliTPCMonitorMappingHandler::GetFECchannel(Int_t hwaddr) const
465 {
466   // Return FEC channel for the hardware address hwaddr 
467   Int_t retval;
468   if(hwaddr < fsizeofArray)
469     retval = fmapping[hwaddr][7];
470   else
471     retval = 0;
472   return retval;
473 }
474
475 //_____________________________________________________________________________________________
476 Int_t AliTPCMonitorMappingHandler::GetFECconnector(Int_t hwaddr) const
477 {
478   // Return FEC connector for the hardware address hwaddr 
479   Int_t retval;
480   if(hwaddr <= fsizeofArray)
481     retval = fmapping[hwaddr][8];
482   else
483     retval = 0;
484   return retval;
485 }
486
487 //_____________________________________________________________________________________________
488 Int_t AliTPCMonitorMappingHandler::GetAltroChannel(Int_t hwaddr)  const
489 {
490   // Return Altro channel for the hardware address hwaddr 
491   Int_t retval;
492   if(hwaddr <= fsizeofArray)
493     retval = fmapping[hwaddr][9];
494   else
495     retval = 0;
496   return retval;
497 }
498
499 //_____________________________________________________________________________________________
500 Int_t AliTPCMonitorMappingHandler::GetAltro(Int_t hwaddr)  const
501 {
502   // Return Altro chip number in FEC for the hardware address hwaddr 
503   Int_t retval;
504   if(hwaddr <= fsizeofArray)
505     retval = fmapping[hwaddr][10];
506   else
507     retval = 0;
508   return retval;
509 }
510
511
512 //_____________________________________________________________________________________________
513 Int_t AliTPCMonitorMappingHandler::GetNumofPads(Int_t row) 
514 {
515   // Return number of pads in row
516   if(row>=0&&row<159)
517     return fmappingChannelinRow[row][0];
518   else  {
519     AliError("Wrong row number");
520     return 0;
521   }
522 }
523
524 //_____________________________________________________________________________________________
525 Int_t AliTPCMonitorMappingHandler::GetPadAddInRow(Int_t row,Int_t pad )
526 {
527   // Return hardware address for given pad in row
528   if(row>=0&&row<159)
529     return fmappingChannelinRow[row][pad+2];
530   else {
531     AliError("Wrong row number");
532     return 0;
533   }
534 }
535
536
537
538 //_____________________________________________________________________________________________
539 Int_t AliTPCMonitorMappingHandler::U2fGetFECnr(Int_t index) const
540 {
541   // Return FEC number for index  (FEC number should be equal to index)
542   return  fu2ftestmapping[index][0];
543 }
544
545 //_____________________________________________________________________________________________
546 Int_t AliTPCMonitorMappingHandler::U2fGetSide(Int_t fecnr) const
547 {
548   // Return side on which FEC is installed
549   return  fu2ftestmapping[fecnr][1];
550 }
551
552 //_____________________________________________________________________________________________
553 Int_t AliTPCMonitorMappingHandler::U2fGetSector(Int_t fecnr) const
554 {
555   // Return sector in which FEC is installed
556   return  fu2ftestmapping[fecnr][2];
557 }
558
559 //_____________________________________________________________________________________________
560 Int_t AliTPCMonitorMappingHandler::U2fGetRCU(Int_t fecnr) const
561 {
562   // Rerurn rcu patch in which FEC is installed
563   return  fu2ftestmapping[fecnr][3];
564 }
565
566 //_____________________________________________________________________________________________
567 Int_t AliTPCMonitorMappingHandler::U2fGetFECinRCU(Int_t fecnr) const
568 {
569   // Return index of FEC in RCU (0-25)
570   return  fu2ftestmapping[fecnr][4];
571 }
572
573 //_____________________________________________________________________________________________
574 Int_t AliTPCMonitorMappingHandler::U2fGetFECinBranch(Int_t fecnr) const
575 {
576   // Return index of FEC in branch (0-12)
577   return  fu2ftestmapping[fecnr][5];
578 }
579
580 //_____________________________________________________________________________________________
581 Int_t AliTPCMonitorMappingHandler::U2fGetBranch(Int_t fecnr) const
582 {
583   // Return branch in which FEC is installed (0,1)
584   return  fu2ftestmapping[fecnr][6];
585     
586 }