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