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