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