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