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