]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCmon/AliTPCMonitorMappingHandler.cxx
Fixing a bug in one hit entry
[u/mrichter/AliRoot.git] / TPC / TPCmon / 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"
b718d136 50#include <TMath.h>
ca7b8371 51#include "AliLog.h"
52#include <Riostream.h>
b718d136 53#include <string>
47b31621 54#include <TString.h>
ca7b8371 55
c64cb1f6 56using std::ifstream;
57using std::ios;
58
48265b32 59ClassImp(AliTPCMonitorMappingHandler)
60
61//_____________________________________________________________________________________________
37a4e693 62AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(const Char_t* name, const Char_t* title):
ca7b8371 63 TNamed(name,title),
64 fnumofChannels(0),
65 fmaxHWAdress(0),
6f19bddf 66 fsizeofArray(0)
48265b32 67{
68 // Constructor : Initialize mapping arrays
69
d92e4876 70 for(Int_t in = 0; in<159; ++in)
6f19bddf 71 for(Int_t jn = 0; jn<150; ++jn)
72 fmappingChannelinRow[in][jn] = 0;
48265b32 73
6f19bddf 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 }
ca7b8371 81
6f19bddf 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 }
48265b32 90}
91
ca7b8371 92//____________________________________________________________________________
93AliTPCMonitorMappingHandler::AliTPCMonitorMappingHandler(const AliTPCMonitorMappingHandler &maphand) :
94 TNamed(maphand.GetName(),maphand.GetTitle()),
95 fnumofChannels(maphand.fnumofChannels),
96 fmaxHWAdress(maphand.fmaxHWAdress),
6f19bddf 97 fsizeofArray(maphand.fsizeofArray)
ca7b8371 98{
99 // copy constructor
100
101
d92e4876 102 for(Int_t in = 0; in<159; ++in)
6f19bddf 103 for(Int_t jn = 0; jn<150; ++jn)
104 fmappingChannelinRow[in][jn] = maphand.fmappingChannelinRow[in][jn];
ca7b8371 105
6f19bddf 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];
ca7b8371 109
6f19bddf 110 for(Int_t j = 0; j<128; ++j)
111 fecGainMap[i][j] = maphand.fecGainMap[i][j];
112 }
ca7b8371 113
6f19bddf 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 }
ca7b8371 121}
122
123
124//____________________________________________________________________________
125AliTPCMonitorMappingHandler &AliTPCMonitorMappingHandler:: operator= (const AliTPCMonitorMappingHandler& maphand)
126{
127 // assignment operator
6f19bddf 128 if (this == &maphand) return *this;
129
130 fnumofChannels=maphand.fnumofChannels;
131 fmaxHWAdress=maphand.fmaxHWAdress;
132 fsizeofArray=maphand.fsizeofArray;
ca7b8371 133
d92e4876 134 for(Int_t in = 0; in<159; ++in)
6f19bddf 135 for(Int_t jn = 0; jn<150; ++jn)
136 fmappingChannelinRow[in][jn] = maphand.fmappingChannelinRow[in][jn];
ca7b8371 137
6f19bddf 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
ca7b8371 154 return *this;
155}
156
157
48265b32 158//_____________________________________________________________________________________________
159AliTPCMonitorMappingHandler::~AliTPCMonitorMappingHandler()
160{
161 // Destructor
48265b32 162}
163
164//_____________________________________________________________________________________________
6f19bddf 165void AliTPCMonitorMappingHandler::ReadMapping(const char* mapfile)
48265b32 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
48265b32 188 Int_t version = -1;
189 Int_t actPos = 0;
48265b32 190
6f19bddf 191 ifstream infile(mapfile,ios::in);
b718d136 192
6f19bddf 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();
b718d136 201
6f19bddf 202// printf("file: %s - %d\n",mapfile,numLines);
b718d136 203
6f19bddf 204 infile >> version;
205// --numLines;
206
207 infile >> fnumofChannels;
208// --numLines;
48265b32 209
6f19bddf 210 infile >> fmaxHWAdress;
48265b32 211 fsizeofArray = fmaxHWAdress;
6f19bddf 212// --numLines;
1359267b 213
214 //consistency check
215 fnumofChannels=TMath::Abs(fnumofChannels);
6f19bddf 216// fnumofChannels=TMath::Min(fnumofChannels,numLines);
217
218 Int_t val=0;
48265b32 219 for(Int_t i = 0; i < fnumofChannels ; i++) {
6f19bddf 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;
48265b32 232 }
48265b32 233 }
234
6f19bddf 235 infile.close();
48265b32 236}
237
238//_____________________________________________________________________________________________
6f19bddf 239Int_t AliTPCMonitorMappingHandler::ReadFECMapping(const char* u2ftestfile)
48265b32 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
6f19bddf 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 }
48265b32 267 return ncards ;
268}
269
270
271
272//_____________________________________________________________________________________________
273void 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;
fb3305d1 281 Int_t rcupatch = 0;
48265b32 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
6f19bddf 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 }
48265b32 310 }
6f19bddf 311 }
48265b32 312}
313//_____________________________________________________________________________________________
6f19bddf 314void AliTPCMonitorMappingHandler::ReadfecGainMap(const char* fecgainmap)
48265b32 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())
5dbad769 326 {
327 datin >> fecnr ;
328 for(Int_t in = 0; in<128; in++)
48265b32 329 {
5dbad769 330 datin >> val ;
6f19bddf 331 if (fecnr<0 || fecnr>=7000) continue;
5dbad769 332 fecGainMap[fecnr][in] = val;
48265b32 333 }
5dbad769 334 }
48265b32 335}
336
337//_____________________________________________________________________________________________
6f19bddf 338void AliTPCMonitorMappingHandler::ReadRowMappingGlob(const char* fpathtoMappingRowfile)
48265b32 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
47b31621 346 TString readcarry;
347 TString readcarry2;
6f19bddf 348 ifstream in(fpathtoMappingRowfile,ios::in);
48265b32 349
350 for(Int_t i = 0; i < 159 ; i++) {
6f19bddf 351 in >> readcarry; // row number
352 in >> readcarry2; // numof pads
47b31621 353 fmappingChannelinRow[i][0] = readcarry2.Atoi();
354 fmappingChannelinRow[i][1] = TMath::Min(TMath::Abs(readcarry.Atoi()),140); //maximum number of pads is 140
48265b32 355
356 for(Int_t j = 2 ; j < fmappingChannelinRow[i][0]+2 ; j++) {
6f19bddf 357 in >> readcarry;
47b31621 358 fmappingChannelinRow[i][j] = readcarry.Atoi();
48265b32 359 }
360 }
6f19bddf 361 in.close();
48265b32 362}
363
364
365
366//_____________________________________________________________________________________________
fb3305d1 367Int_t AliTPCMonitorMappingHandler::GetNumOfChannels() const
48265b32 368{
369 // Return number of channels
370 return fnumofChannels;
371}
372
373//_____________________________________________________________________________________________
fb3305d1 374Int_t AliTPCMonitorMappingHandler::GetSizeofArray() const
48265b32 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//_____________________________________________________________________________________________
6f19bddf 383const Short_t* AliTPCMonitorMappingHandler::GetLine(Int_t hwaddr) const
48265b32 384{
385 // Return pointer to mapping array for the hardware address hwaddr
6f19bddf 386 const Short_t* retval=0x0;
48265b32 387 if(hwaddr <= fsizeofArray)
388 retval = fmapping[hwaddr];
389 else
390 retval = 0;
391 return retval;
392}
393
394//_____________________________________________________________________________________________
fb3305d1 395Int_t AliTPCMonitorMappingHandler::GetIndex(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 407Int_t AliTPCMonitorMappingHandler::GetPadRow(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 419Int_t AliTPCMonitorMappingHandler::GetPad(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 431Int_t AliTPCMonitorMappingHandler::GetConnector(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 443Int_t AliTPCMonitorMappingHandler::GetPin(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 455Int_t AliTPCMonitorMappingHandler::GetFEC(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 467Int_t AliTPCMonitorMappingHandler::GetFECchannel(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 479Int_t AliTPCMonitorMappingHandler::GetFECconnector(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 491Int_t AliTPCMonitorMappingHandler::GetAltroChannel(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 503Int_t AliTPCMonitorMappingHandler::GetAltro(Int_t hwaddr) const
48265b32 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//_____________________________________________________________________________________________
fb3305d1 516Int_t AliTPCMonitorMappingHandler::GetNumofPads(Int_t row)
48265b32 517{
518 // Return number of pads in row
6f19bddf 519 if(row>=0&&row<159)
48265b32 520 return fmappingChannelinRow[row][0];
521 else {
6f19bddf 522 AliError("Wrong row number");
48265b32 523 return 0;
524 }
525}
526
527//_____________________________________________________________________________________________
528Int_t AliTPCMonitorMappingHandler::GetPadAddInRow(Int_t row,Int_t pad )
529{
530 // Return hardware address for given pad in row
6f19bddf 531 if(row>=0&&row<159)
48265b32 532 return fmappingChannelinRow[row][pad+2];
533 else {
6f19bddf 534 AliError("Wrong row number");
48265b32 535 return 0;
536 }
537}
538
539
540
541//_____________________________________________________________________________________________
fb3305d1 542Int_t AliTPCMonitorMappingHandler::U2fGetFECnr(Int_t index) const
48265b32 543{
544 // Return FEC number for index (FEC number should be equal to index)
545 return fu2ftestmapping[index][0];
546}
547
548//_____________________________________________________________________________________________
fb3305d1 549Int_t AliTPCMonitorMappingHandler::U2fGetSide(Int_t fecnr) const
48265b32 550{
551 // Return side on which FEC is installed
552 return fu2ftestmapping[fecnr][1];
553}
554
555//_____________________________________________________________________________________________
fb3305d1 556Int_t AliTPCMonitorMappingHandler::U2fGetSector(Int_t fecnr) const
48265b32 557{
558 // Return sector in which FEC is installed
559 return fu2ftestmapping[fecnr][2];
560}
561
562//_____________________________________________________________________________________________
fb3305d1 563Int_t AliTPCMonitorMappingHandler::U2fGetRCU(Int_t fecnr) const
48265b32 564{
565 // Rerurn rcu patch in which FEC is installed
566 return fu2ftestmapping[fecnr][3];
567}
568
569//_____________________________________________________________________________________________
fb3305d1 570Int_t AliTPCMonitorMappingHandler::U2fGetFECinRCU(Int_t fecnr) const
48265b32 571{
572 // Return index of FEC in RCU (0-25)
573 return fu2ftestmapping[fecnr][4];
574}
575
576//_____________________________________________________________________________________________
fb3305d1 577Int_t AliTPCMonitorMappingHandler::U2fGetFECinBranch(Int_t fecnr) const
48265b32 578{
579 // Return index of FEC in branch (0-12)
580 return fu2ftestmapping[fecnr][5];
581}
582
583//_____________________________________________________________________________________________
fb3305d1 584Int_t AliTPCMonitorMappingHandler::U2fGetBranch(Int_t fecnr) const
48265b32 585{
586 // Return branch in which FEC is installed (0,1)
587 return fu2ftestmapping[fecnr][6];
588
589}