]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCbase/AliTPCmapper.cxx
doxy: TPC/TPCbase converted
[u/mrichter/AliRoot.git] / TPC / TPCbase / AliTPCmapper.cxx
CommitLineData
bb18c002 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
7d855b04 16/// \class AliTPCmapper
17/// \brief AliTPCmapper
18///
19/// Class to map detector coordinates (row, pad, sector, ...) to
20/// hardware coordinates (RCU, Branch, FEC, Altro, channel, Equipment ID, ...)
21///
22/// There are two different ways to number padrows:
23/// 1) local padrow: for each ROC, 0 ... 62 for an IROC, 0 ... 95 for an OROC,
24/// 2) global padrow: for each sector, from 0 ... 158.
25/// If the global numbering is used, it is denoted by the variable name
26/// globalpadrow in this class.
27///
28/// There are two different ways to number sectors:
29/// 1) Sectors contain one IROC and one OROC and are counted from 0 to 17 on
30/// each of the two sides (A=0 and C=1),
31/// 2) ROCs are numbered from 0 to 71 where the ROCs 0 ... 35 are IROCS and
32/// ROCs 36 ... 71 are OROCs. A ROC is often named "sector" in aliroot,
33/// which can be very confusing!
34///
35/// \author Christian.Lippmann@cern.ch, J.Wiechula@gsi.de
bb18c002 36
bb18c002 37#include <TMath.h>
38#include <TSystem.h>
accfa4d9 39#include <TString.h>
bb18c002 40
41#include "AliTPCmapper.h"
accfa4d9 42#include "AliTPCAltroMapping.h"
43#include "AliTPCROC.h"
44#include "AliLog.h"
bdf99a93 45#include "AliDAQ.h"
bb18c002 46
7d855b04 47/// \cond CLASSIMP
bb18c002 48ClassImp(AliTPCmapper)
7d855b04 49/// \endcond
07b9e95c 50//______________________________________________________________
51AliTPCmapper::AliTPCmapper() :
52 fNside(0),
53 fNsector(0),
54 fNrcu(0),
55 fNbranch(0),
56 fNaltro(0),
57 fNchannel(0),
58 fNpadrow(0),
59 fNpadrowIROC(0),
60 fNpadrowOROC(0),
61 fTpcDdlOffset(0)
62{
63 //
64 // Constructor
65 //
8d95c9e1 66 for ( Int_t i = 0; i < 6; i++ ) fMapping[i]=0;
07b9e95c 67}
bb18c002 68
accfa4d9 69//______________________________________________________________
0e46ed2e 70AliTPCmapper::AliTPCmapper(const char * dirname) :
accfa4d9 71 fNside(0),
72 fNsector(0),
73 fNrcu(0),
74 fNbranch(0),
75 fNaltro(0),
76 fNchannel(0),
77 fNpadrow(0),
78 fNpadrowIROC(0),
79 fNpadrowOROC(0),
fee88714 80 fTpcDdlOffset(0)
accfa4d9 81{
7d855b04 82 /// Constructor
83 ///
84 /// dirname - specify the directory with the ascii Altro mapping files
85
0e46ed2e 86 Init(dirname);
accfa4d9 87}
bb18c002 88
89//______________________________________________________________
accfa4d9 90AliTPCmapper::~AliTPCmapper()
91{
7d855b04 92 /// Destructor
accfa4d9 93
accfa4d9 94 for ( Int_t i = 0; i < fNrcu; i++ ) {
95 delete fMapping[i];
96 fMapping[i] = 0;
97 }
98}
99
100
101//_____________________________________________________________________________
102AliTPCmapper::AliTPCmapper(const AliTPCmapper& mapper) :
103 TObject(mapper),
104 fNside(mapper.fNside),
105 fNsector(mapper.fNsector),
106 fNrcu(mapper.fNrcu),
107 fNbranch(mapper.fNbranch),
108 fNaltro(mapper.fNaltro),
109 fNchannel(mapper.fNchannel),
110 fNpadrow(mapper.fNpadrow),
111 fNpadrowIROC(mapper.fNpadrowIROC),
112 fNpadrowOROC(mapper.fNpadrowOROC),
fee88714 113 fTpcDdlOffset(mapper.fTpcDdlOffset)
accfa4d9 114{
7d855b04 115 /// Copy Constructor
116
5dbad769 117 for ( Int_t i = 0; i < 6; i++ ) fMapping[i]=0;
accfa4d9 118 for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
119}
120
121//_____________________________________________________________________________
122AliTPCmapper& AliTPCmapper::operator = (const AliTPCmapper& mapper)
bb18c002 123{
7d855b04 124 /// Assignment operator
accfa4d9 125
126 if(&mapper == this) return *this;
127 ((TObject *)this)->operator=(mapper);
128
129 for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
accfa4d9 130
131 fNside = mapper.fNside;
132 fNsector = mapper.fNsector;
133 fNrcu = mapper.fNrcu;
134 fNbranch = mapper.fNbranch;
135 fNaltro = mapper.fNaltro;
136 fNchannel = mapper.fNchannel;
137 fNpadrow = mapper.fNpadrow;
138 fNpadrowIROC = mapper.fNpadrowIROC;
139 fNpadrowOROC = mapper.fNpadrowOROC;
bdf99a93 140 fTpcDdlOffset = mapper.fTpcDdlOffset;
accfa4d9 141
142 return *this;
bb18c002 143}
144
145//______________________________________________________________
0e46ed2e 146void AliTPCmapper::Init(const char *dirname)
bb18c002 147{
7d855b04 148 /// Initialize all
149
bdf99a93 150 fNside = 2;
151 fNsector = 18;
152 fNrcu = 6;
153 fNbranch = 2;
154 fNaltro = 8;
df33cb1a 155 fNchannel = 16;
accfa4d9 156
157 // Load and read mapping files. AliTPCAltroMapping contains the mapping for
158 // each patch (rcu).
0e46ed2e 159 TString path;
160 if (dirname==0){
161 path =gSystem->Getenv("ALICE_ROOT");
162 path += "/TPC/mapping/Patch";
163 }else{
164 path = dirname;
165 path +="Patch";
166 }
167
accfa4d9 168 TString path2;
169 for(Int_t i = 0; i < fNrcu; i++) {
170 path2 = path;
171 path2 += i;
172 path2 += ".data";
173 fMapping[i] = new AliTPCAltroMapping(path2.Data());
174 }
175
df33cb1a 176 // Get instance of AliTPCROC object
fee88714 177 AliTPCROC *fROC = AliTPCROC::Instance();
accfa4d9 178 fNpadrowIROC = fROC->GetNRows(0);
179 fNpadrowOROC = fROC->GetNRows(36);
fee88714 180 fNpadrow = fNpadrowIROC+fNpadrowOROC;
bb18c002 181
bdf99a93 182 AliDAQ daq;
183 fTpcDdlOffset = daq.DdlIDOffset("TPC");
184
accfa4d9 185}
bb18c002 186
bb18c002 187
accfa4d9 188//_____________________________________________________________________________
189Int_t AliTPCmapper::GetHWAddress(Int_t roc, Int_t padrow, Int_t pad) const
190{
7d855b04 191 /// Get the hardware address from pad coordinates for a given ROC
192
accfa4d9 193 Int_t patch = GetPatch(roc, padrow, pad);
bdf99a93 194 if ( (patch >= fNrcu) || (patch < 0) ) return -1;
accfa4d9 195 return fMapping[patch]->GetHWAddress(padrow, pad, roc);
196}
197
198
199//_____________________________________________________________________________
bdf99a93 200Int_t AliTPCmapper::GetHWAddressSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 201{
7d855b04 202 /// Get the hardware address from pad coordinates
203
accfa4d9 204 Int_t patch = 0;
5dbad769 205 Int_t hwAddress=-1;
bdf99a93 206 if ( globalpadrow < fNpadrowIROC ) {
207 patch = GetPatch(0, globalpadrow, pad);
5dbad769 208 if (patch>-1)
209 hwAddress = fMapping[patch]->GetHWAddress(globalpadrow, pad, 0);
bdf99a93 210 } else if ( globalpadrow < fNpadrow ) {
211 patch = GetPatch(36, globalpadrow - fNpadrowIROC, pad);
5dbad769 212 if (patch>-1)
213 hwAddress = fMapping[patch]->GetHWAddress(globalpadrow - fNpadrowIROC, pad, 36);
accfa4d9 214 } else {
bdf99a93 215 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
5dbad769 216 hwAddress = -1;
accfa4d9 217 }
5dbad769 218 return hwAddress;
accfa4d9 219}
220
221
222//_____________________________________________________________________________
223Int_t AliTPCmapper::GetRcu(Int_t roc, Int_t padrow, Int_t pad) const
224{
7d855b04 225 /// Get the patch (rcu) index from the pad coordinates. The Roc index is
226 /// needed as well to determine if it is IROC or OROC.
227
accfa4d9 228 return GetPatch(roc, padrow, pad);
229}
230
231
232//_____________________________________________________________________________
233Int_t AliTPCmapper::GetPatch(Int_t roc, Int_t padrow, Int_t pad) const
234{
7d855b04 235 /// Get the patch (rcu) index from the pad coordinates. The Roc index is
236 /// needed as well to determine if it is IROC or OROC.
accfa4d9 237
238 if ( (padrow < 0) || (pad < 0) || (roc < 0) ) {
239 AliWarning(Form("Pad coordinates outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
240 return -1;
241 }
242
243 if ( roc < 36 ) {
df33cb1a 244 // IROC (ROCs 0 ... 35)
accfa4d9 245 Int_t padsInRow = GetNpads(padrow);
246 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
247 AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
248 return -1;
249 }
250 if ( padrow < 30 ) { return 0;
251 } else if ( padrow == 30 ) { // padrow 30 is shared between rcus 0 and 1
252 if ( (pad < 37) || (pad > 48) ) return 1;
253 else return 0;
254 } else if ( padrow < fNpadrowIROC ) { return 1;
255 } else {
256 AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
257 return -1;
258 }
259 } else if ( roc < 72 ) {
df33cb1a 260 // OROC (ROCs 36 ... 71)
accfa4d9 261 Int_t padsInRow = GetNpads(fNpadrowIROC+padrow);
262 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
263 AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
264 return -1;
bb18c002 265 }
accfa4d9 266 if ( padrow < 27 ) { return 2;
267 } else if ( padrow == 27 ) { // padrow 27 is shared between rcus 2 and 3
268 if ( (pad >= 43) && (pad <= 46) ) return 3;
269 else return 2;
270 } else if ( padrow < 54 ) { return 3;
271 } else if ( padrow < 76 ) { return 4;
272 } else if ( padrow == 76) { // padrow 76 is shared between rcus 4 and 5
273 if ( (pad >= 33) && (pad <= 88) ) return 5;
274 else return 4;
275 } else if ( padrow < fNpadrowOROC ) { return 5;
276 } else {
277 AliWarning(Form("Padrow outside range (padrow %d, roc %d) !", padrow, roc));
278 return -1;
279 }
280 }
281 return -1;
282}
bb18c002 283
bb18c002 284
accfa4d9 285//_____________________________________________________________________________
bdf99a93 286Int_t AliTPCmapper::GetRcuSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 287{
7d855b04 288 /// Get the patch (rcu) index from the pad coordinates for a sector
289
bdf99a93 290 return GetPatchSector(globalpadrow, pad);
bb18c002 291}
292
accfa4d9 293
294//_____________________________________________________________________________
bdf99a93 295Int_t AliTPCmapper::GetPatchSector(Int_t globalpadrow, Int_t pad) const
bb18c002 296{
7d855b04 297 /// Get the patch (rcu) index from the pad coordinates for a sector
298
bdf99a93 299 if ( globalpadrow >= fNpadrow ) {
300 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 301 return -1;
302 }
bdf99a93 303 if ( globalpadrow < fNpadrowIROC ) return GetPatch(0, globalpadrow, pad);
304 else return GetPatch(36, globalpadrow-fNpadrowIROC, pad);
accfa4d9 305}
bb18c002 306
bb18c002 307
accfa4d9 308//_____________________________________________________________________________
309Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t hwAddress) const
310{
7d855b04 311 /// Get Pad Row (for a ROC) from the hardware address
312
bdf99a93 313 if ( (patch >= fNrcu) || (patch < 0) ) {
314 AliWarning(Form("Patch index outside range (patch %d) !", patch));
315 return -1;
316 }
accfa4d9 317 return fMapping[patch]->GetPadRow(hwAddress);
318}
bb18c002 319
bb18c002 320
accfa4d9 321//_____________________________________________________________________________
bdf99a93 322 Int_t AliTPCmapper::GetGlobalPadRow(Int_t patch, Int_t hwAddress) const
accfa4d9 323{
7d855b04 324 /// Get Pad Row (for full sector) from the hardware address
325
accfa4d9 326 if ( patch < 2 ) return GetPadRow(patch, hwAddress);
327 else return GetPadRow(patch, hwAddress) + fNpadrowIROC;
328}
bb18c002 329
bb18c002 330
accfa4d9 331//_____________________________________________________________________________
332Int_t AliTPCmapper::GetPad(Int_t patch, Int_t hwAddress) const
333{
7d855b04 334 /// Get Pad index from the hardware address
335
bdf99a93 336 if ( (patch >= fNrcu) || (patch < 0) ) {
337 AliWarning(Form("Patch index outside range (patch %d) !", patch));
338 return -1;
339 }
accfa4d9 340 return fMapping[patch]->GetPad(hwAddress);
341}
bb18c002 342
bb18c002 343
accfa4d9 344//_____________________________________________________________________________
345Int_t AliTPCmapper::GetPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
346 Int_t channel) const
347{
7d855b04 348 /// Get pad row (for a ROC) from hardware coordinates
349
accfa4d9 350 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
351 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
352 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
353 patch, branch, fec, chip, channel));
354 return -1;
355 }
356 return GetPadRow(patch, CodeHWAddress(branch, fec, chip, channel));
357}
bb18c002 358
359
accfa4d9 360//_____________________________________________________________________________
bdf99a93 361Int_t AliTPCmapper::GetGlobalPadRow(Int_t patch, Int_t branch, Int_t fec, Int_t chip,
accfa4d9 362 Int_t channel) const
363{
7d855b04 364 /// Get Pad Row (for full sector) from the hardware address
365
accfa4d9 366 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
367 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
368 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
369 patch, branch, fec, chip, channel));
370 return -1;
371 }
372 if ( patch < 2 ) return GetPadRow(patch, branch, fec, chip, channel);
373 else return GetPadRow(patch, branch, fec, chip, channel) + fNpadrowIROC;
374}
bb18c002 375
bb18c002 376
accfa4d9 377//_____________________________________________________________________________
378 Int_t AliTPCmapper::GetPad(Int_t patch, Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
379{
7d855b04 380 /// Get pad from hardware coordinates
381
accfa4d9 382 if ( (patch >= fNrcu) || (branch >= fNbranch) || (chip >= fNaltro) || (channel >= fNchannel)
383 || (patch < 0) || (branch < 0) || (chip < 0) || (channel < 0) ) {
384 AliWarning(Form("Coordinates outside range (patch %d, branch %d, fec %d, chip %d, channel %d)) !",
385 patch, branch, fec, chip, channel));
386 return -1;
387 }
388 return GetPad(patch, CodeHWAddress(branch, fec, chip, channel));
bb18c002 389}
390
accfa4d9 391
392//_____________________________________________________________________________
393Int_t AliTPCmapper::GetBranch(Int_t roc, Int_t padrow, Int_t pad) const
bb18c002 394{
7d855b04 395 /// Get the branch to which this pad is connected. The FECs connected to
396 /// one RCU are divided into two branches: A(=0) and B(=1). This information
397 /// can be extracted from the hardware address.
398
accfa4d9 399 return DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
400}
bb18c002 401
accfa4d9 402
403//_____________________________________________________________________________
bdf99a93 404Int_t AliTPCmapper::GetBranchSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 405{
7d855b04 406 /// Get Branch from pad coordinates, where globalpadrow is counted
407 /// for a full sector (0 ... 158)
408
bdf99a93 409 return DecodedHWAddressBranch(GetHWAddressSector(globalpadrow, pad));
bb18c002 410}
411
bb18c002 412
accfa4d9 413//_____________________________________________________________________________
414Int_t AliTPCmapper::GetFEChw(Int_t roc, Int_t padrow, Int_t pad) const
415{
7d855b04 416 /// Get the FEC number in hardware numbering. The FECs are numbered from 0 (in the
417 /// center of the partition) to 8 (partition 3, 4, 5), 9 (partition 0, 2), 11
418 /// (partition 1, branch A) or 12 (partition 1, branch B). This information
419 /// can be extracted from the hardware address.
420
accfa4d9 421 return DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
422}
423
bb18c002 424
accfa4d9 425//_____________________________________________________________________________
bdf99a93 426Int_t AliTPCmapper::GetFEChwSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 427{
7d855b04 428 /// Get the FEC number in hardware numbering from pad coordinates, where
429 /// globalpadrow is counted for a full sector (0 ... 158)
430
bdf99a93 431 return DecodedHWAddressFECaddr(GetHWAddressSector(globalpadrow, pad));
accfa4d9 432}
bb18c002 433
bb18c002 434
accfa4d9 435//_____________________________________________________________________________
436Int_t AliTPCmapper::GetFEC(Int_t roc, Int_t padrow, Int_t pad) const
437{
7d855b04 438 /// Get the FEC number in offline-oriented numbering. The FECs are numbered from 0
439 /// 17 (partition 3, 4, 5), 19 (partition 0, 2) or 24 (partition 1).
440
accfa4d9 441 Int_t patch = GetPatch(roc, padrow, pad);
442 Int_t fec = DecodedHWAddressFECaddr(GetHWAddress(roc, padrow, pad));
443 Int_t branch = DecodedHWAddressBranch(GetHWAddress(roc, padrow, pad));
444 if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
445 return HwToOffline(patch, branch, fec);
bb18c002 446}
447
bb18c002 448
accfa4d9 449//_____________________________________________________________________________
bdf99a93 450Int_t AliTPCmapper::GetFECSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 451{
7d855b04 452 /// Get the FEC number in offline-oriented numbering. globalpadrow is
453 /// counted for a full sector (0 ... 158)
454
bdf99a93 455 Int_t patch = GetPatchSector(globalpadrow, pad);
456 Int_t fec = DecodedHWAddressFECaddr(GetHWAddressSector(globalpadrow, pad));
457 Int_t branch = DecodedHWAddressBranch(GetHWAddressSector(globalpadrow, pad));
accfa4d9 458 if ( (fec < 0) || (branch < 0) || (patch < 0) ) return -1;
459 return HwToOffline(patch, branch, fec);
460}
461
bb18c002 462
accfa4d9 463//_____________________________________________________________________________
464Int_t AliTPCmapper::GetChip(Int_t roc, Int_t padrow, Int_t pad) const
465{
7d855b04 466 /// Get Chip (ALTRO) index (0 ... 7) from pad coordinates
467
accfa4d9 468 return DecodedHWAddressChipaddr(GetHWAddress(roc, padrow, pad));
469}
bb18c002 470
471
accfa4d9 472//_____________________________________________________________________________
bdf99a93 473Int_t AliTPCmapper::GetChipSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 474{
7d855b04 475 /// Get Chip (ALTRO) index (0 ... 7) from pad coordinates, where
476 /// globalpadrow is counted for a full sector (0 ... 158)
477
bdf99a93 478 return DecodedHWAddressChipaddr(GetHWAddressSector(globalpadrow, pad));
bb18c002 479}
480
accfa4d9 481
482//_____________________________________________________________________________
483Int_t AliTPCmapper::GetChannel(Int_t roc, Int_t padrow, Int_t pad) const
484{
7d855b04 485 /// Get Channel index (0 ... 15) from pad coordinates
486
accfa4d9 487 return DecodedHWAddressChanneladdr(GetHWAddress(roc, padrow, pad));
bb18c002 488}
489
bb18c002 490
accfa4d9 491//_____________________________________________________________________________
bdf99a93 492Int_t AliTPCmapper::GetChannelSector(Int_t globalpadrow, Int_t pad) const
accfa4d9 493{
7d855b04 494 /// Get Channel index (0 ... 15) from pad coordinates, where
495 /// globalpadrow is counted for a full sector (0 ... 158)
496
bdf99a93 497 return DecodedHWAddressChanneladdr(GetHWAddressSector(globalpadrow, pad));
accfa4d9 498}
499
bb18c002 500
accfa4d9 501//_____________________________________________________________________________
502Int_t AliTPCmapper::CodeHWAddress(Int_t branch, Int_t fec, Int_t chip, Int_t channel) const
503{
7d855b04 504 /// Get Hardware address from channel, altro, fec and branch coordinates
505
accfa4d9 506 return ((branch&1)<<11) + ((fec&0xf)<<7) + ((chip&0x7)<<4) + (channel&0xf);
bb18c002 507}
508
accfa4d9 509
510//_____________________________________________________________________________
511Int_t AliTPCmapper::DecodedHWAddressBranch(Int_t hwAddress) const
512{
7d855b04 513 /// Get branch index (0, 1) from hardware address
514
accfa4d9 515 if ( hwAddress < 0 ) return -1;
516 return ((hwAddress>>11)&1);
517}
518
519
520//_____________________________________________________________________________
521Int_t AliTPCmapper::DecodedHWAddressFECaddr(Int_t hwAddress) const
522{
7d855b04 523 /// Get FEC index (0 ... 12) from hardware address
524
accfa4d9 525 if ( hwAddress < 0 ) return -1;
526 return ((hwAddress>>7)&0xf);
527}
528
529
530//_____________________________________________________________________________
531Int_t AliTPCmapper::DecodedHWAddressChipaddr(Int_t hwAddress) const
532{
7d855b04 533 /// Get ALTRO index (0 ... 7) from hardware address
534
accfa4d9 535 if ( hwAddress < 0 ) return -1;
536 return ((hwAddress>>4)&0x7);
537}
538
539
540//_____________________________________________________________________________
541Int_t AliTPCmapper::DecodedHWAddressChanneladdr(Int_t hwAddress) const
542{
7d855b04 543 /// Get channel index (0 ... 15) from hardware address
544
accfa4d9 545 if ( hwAddress < 0 ) return -1;
546 return ((hwAddress&0xf));
bb18c002 547}
548
accfa4d9 549
bb18c002 550//______________________________________________________________
accfa4d9 551Int_t AliTPCmapper::GetNpads(Int_t roc, Int_t padrow) const{
7d855b04 552 /// Get number of pads in padrow for this ROC.
553
fee88714 554 AliTPCROC *fROC = AliTPCROC::Instance();
555 Int_t retval = fROC->GetNPads((UInt_t)roc, (UInt_t)padrow);
556 return retval;
bb18c002 557}
558
accfa4d9 559
bb18c002 560//______________________________________________________________
bdf99a93 561Int_t AliTPCmapper::GetNpads(Int_t globalpadrow) const{
7d855b04 562 /// Get number of pads in padrow, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 563
bdf99a93 564 if ( globalpadrow >= fNpadrow ) {
565 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 566 return -1;
567 }
bdf99a93 568 if ( globalpadrow < fNpadrowIROC ) return GetNpads(0, globalpadrow); // IROC
569 else return GetNpads(36, globalpadrow - fNpadrowIROC); // OROC
accfa4d9 570
571 return -1;
bb18c002 572}
573
accfa4d9 574
bb18c002 575//______________________________________________________________
accfa4d9 576Int_t AliTPCmapper::GetNpadrows(Int_t roc) const
bb18c002 577{
7d855b04 578 /// Get number of padrows
579
fee88714 580 if (roc < 36) return fNpadrowIROC;
581 else if (roc < 72) return fNpadrowOROC;
582 return -1;
bb18c002 583}
584
accfa4d9 585
bb18c002 586//______________________________________________________________
accfa4d9 587/*
bdf99a93 588Double_t AliTPCmapper::GetPadXlocal(Int_t globalpadrow) const
bb18c002 589{
bdf99a93 590 // Get local x coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 591
bdf99a93 592 if ( globalpadrow >= fNpadrow ) {
593 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 594 return -1.0;
595 }
596
597 //IROC
bdf99a93 598 if ( globalpadrow < fNpadrowIROC )
599 return (852.25 + 7.5*(Double_t)globalpadrow)/10.; //divide by 10 to get cm
0e75e410 600
bdf99a93 601 globalpadrow -= fNpadrowIROC;
accfa4d9 602
bdf99a93 603 if ( globalpadrow < 64 ) //OROC inner part
604 return (10.* globalpadrow + 1351.)/10.; //divide by 10 to get cm
accfa4d9 605
606 //OROC outer part
bdf99a93 607 return (15.*(globalpadrow - 64) + 1993.5)/10.; //divide by 10 to get cm
bb18c002 608}
accfa4d9 609*/
bb18c002 610
611//______________________________________________________________
accfa4d9 612/*
bdf99a93 613Double_t AliTPCmapper::GetPadYlocal(Int_t globalpadrow, Int_t pad) const
bb18c002 614{
bdf99a93 615 // Get local y coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 616
bdf99a93 617 if ( globalpadrow >= fNpadrow ) {
618 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 619 return -1.0;
620 }
621
bdf99a93 622 Int_t padsInRow = GetNpads(globalpadrow);
accfa4d9 623 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
624 AliWarning(Form("Pad index outside range (pad %d) !", pad));
625 return -1.0;
626 }
627
628 //IROC
bdf99a93 629 if ( globalpadrow < fNpadrowIROC )
accfa4d9 630 return (2.* padsInRow - 4.*pad - 2.)*1.e-1; //divide by 10 to get cm
631
632 //OROC
633 return (3.* padsInRow -6.*pad - 3.)*1.e-1; //divide by 10 to get cm
bb18c002 634}
accfa4d9 635*/
bb18c002 636
637//______________________________________________________________
accfa4d9 638/*
bdf99a93 639Double_t AliTPCmapper::GetPadXglobal(Int_t globalpadrow, Int_t pad, Int_t sector) const
bb18c002 640{
bdf99a93 641 // Get global x coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 642
bdf99a93 643 if ( globalpadrow >= fNpadrow ) {
644 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 645 return -1.0;
646 }
647
bdf99a93 648 Int_t padsInRow = GetNpads(globalpadrow);
accfa4d9 649 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
650 AliWarning(Form("Pad index outside range (pad %d) !", pad));
651 return -1.0;
652 }
653
654 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
bdf99a93 655 return GetPadXlocal(globalpadrow) * TMath::Cos(angle) -
656 GetPadYlocal(globalpadrow, pad) * TMath::Sin(angle);
bb18c002 657}
accfa4d9 658*/
bb18c002 659
660//______________________________________________________________
accfa4d9 661/*
bdf99a93 662Double_t AliTPCmapper::GetPadYglobal(Int_t globalpadrow, Int_t pad,Int_t sector) const
bb18c002 663{
bdf99a93 664 // Get global y coordinate of pad, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 665
bdf99a93 666 if ( globalpadrow >= fNpadrow ) {
667 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 668 return -1.0;
669 }
670
bdf99a93 671 Int_t padsInRow = GetNpads(globalpadrow);
accfa4d9 672 if ( (padsInRow < 0) || (pad >= padsInRow) ) {
673 AliWarning(Form("Pad index outside range (pad %d) !", pad));
674 return -1.0;
675 }
676
677 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
bdf99a93 678 return GetPadXlocal(globalpadrow) * TMath::Sin(angle) +
679 GetPadYlocal(globalpadrow, pad) * TMath::Cos(angle);
bb18c002 680}
accfa4d9 681*/
bb18c002 682
683//______________________________________________________________
accfa4d9 684/*
bdf99a93 685Double_t AliTPCmapper::GetPadWidth(Int_t globalpadrow) const
bb18c002 686{
bdf99a93 687 // Get pad width, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 688
bdf99a93 689 if ( globalpadrow >= fNpadrow ) {
690 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 691 return -1.0;
692 }
693
bdf99a93 694 if (globalpadrow < fNpadrowIROC ) // IROC
accfa4d9 695 return 0.4;
696 return 0.6;
bb18c002 697}
accfa4d9 698*/
bb18c002 699
700//______________________________________________________________
accfa4d9 701/*
bdf99a93 702Double_t AliTPCmapper::GetPadLength(Int_t globalpadrow) const
accfa4d9 703{
bdf99a93 704 // Get pad length, where globalpadrow is counted for a full sector (0 ... 158)
accfa4d9 705
bdf99a93 706 if ( globalpadrow >= fNpadrow ) {
707 AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
accfa4d9 708 return -1.0;
709 }
710
bdf99a93 711 if ( globalpadrow < fNpadrowIROC ) return 0.75;
712 if ( globalpadrow < 127 ) return 1.0;
accfa4d9 713 return 1.5;
714}
715*/
716
717//_____________________________________________________________________________
718Int_t AliTPCmapper::GetNfec(Int_t patch) const
bb18c002 719{
7d855b04 720 /// Get size of readout partition (number of FECs) for this rcu (patch) index (0 ... 5)
721
accfa4d9 722 Int_t retval = 0;
723 switch(patch){
724 case(0):
725 retval = 18;
726 break;
727 case(1):
728 retval = 25;
729 break;
730 case(2):
731 retval = 18;
732 break;
733 case(3):
734 retval = 20;
735 break;
736 case(4):
737 retval = 20;
738 break;
739 case(5):
740 retval = 20;
741 break;
742 };
743 return retval;
744}
bb18c002 745
bb18c002 746
accfa4d9 747//_____________________________________________________________________________
748Int_t AliTPCmapper::GetNfec(Int_t patch, Int_t branch) const
749{
7d855b04 750 /// Get size of readout partition (number of FECs) for this branch
751
accfa4d9 752 Int_t retval = 0;
753 switch(patch){
754 case(0):
755 retval = 9;
756 break;
757 case(1):
758 retval = 13;
759 break;
760 case(2):
761 retval = 9;
762 break;
763 case(3):
764 retval = 10;
765 break;
766 case(4):
767 retval = 10;
768 break;
769 case(5):
770 retval = 10;
771 break;
772 };
7d855b04 773
accfa4d9 774 if( (branch == 1) && (patch == 1) ){
775 retval = 12;
776 }
fee88714 777
accfa4d9 778 return retval;
779}
bb18c002 780
bb18c002 781
accfa4d9 782//_____________________________________________________________________________
783Int_t AliTPCmapper::OfflineToHwFec(Int_t patch, Int_t fec) const
784{
7d855b04 785 /// Convert FEC position in offline-like numbering to hardware numbering (fec).
accfa4d9 786
787 if ( (patch < 0) || (fec < 0) ) {
788 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
789 return -1;
790 }
791 if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
792 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
793 return -1;
794 }
795
796 Int_t fecsInBranchA = GetNfec(patch, 0);
797 if ( fec < fecsInBranchA ) // branch A
798 return (fecsInBranchA - 1 - fec);
799 else // branch B
800 return (fec - fecsInBranchA);
801
802 return -1;
bb18c002 803}
804
accfa4d9 805
806//_____________________________________________________________________________
807Int_t AliTPCmapper::OfflineToHwBranch(Int_t patch, Int_t fec) const
808{
7d855b04 809 /// Convert fec position in offline-like numbering to hardware numbering (branch).
accfa4d9 810
811 if ( (patch < 0) || (fec < 0) ) {
812 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
813 return -1;
814 }
815 if ( (patch > 5) || (fec >= GetNfec(patch)) ) {
816 AliWarning(Form("Patch (%d) or Fec number (%d) outside range !", patch, fec));
817 return -1;
818 }
819 if ( fec < GetNfec(patch, 0) ) return 0; // branch A
820 else return 1; // branch B
821
822 return -1;
823}
824
825
826//_____________________________________________________________________________
827Int_t AliTPCmapper::HwToOffline(Int_t patch, Int_t branch, Int_t fec) const
828{
7d855b04 829 /// Convert hardware FEC position (branch, fec) to the offline-oriented numbering
accfa4d9 830
831 if ( (patch < 0) || (fec < 0) || (branch < 0) ) {
832 AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
833 return -1;
834 }
835 if ( (patch > 5) || (branch > 1) || (fec >= GetNfec(patch, branch)) ) {
836 AliWarning(Form("Patch (%d), branch (%d) or Fec number (%d) outside range !", patch, branch, fec));
837 return -1;
838 }
839 Int_t fecsInBranchA = GetNfec(patch, 0);
840 if ( branch == 0 ) // branch A
841 return (fecsInBranchA - 1 - fec);
842 else // branch B
843 return (fec + fecsInBranchA);
844
845 return -1;
846}
847
848
849//_____________________________________________________________________________
850Int_t AliTPCmapper::GetEquipmentID(Int_t roc, Int_t padrow, Int_t pad) const
bb18c002 851{
7d855b04 852 /// Get EqID from pad coordinate. The Roc index is
853 /// needed as well to determine if it is IROC or OROC.
accfa4d9 854
855 Int_t side = GetSideFromRoc(roc);
856 if ( side < 0 ) return -1;
857 Int_t sector = GetSectorFromRoc(roc);
858 if ( sector < 0 ) return -1;
859 Int_t patch = GetPatch(roc, padrow, pad);
860 if ( patch < 0 ) return -1;
861 return GetEquipmentIDfromPatch(side, sector, patch);
862}
863
bb18c002 864
accfa4d9 865//_____________________________________________________________________________
bdf99a93 866Int_t AliTPCmapper::GetEquipmentIDsector(Int_t side, Int_t sector, Int_t globalpadrow, Int_t pad) const
accfa4d9 867{
7d855b04 868 /// Get EqID from pad coordinate, where padrow is counted for a full sector (0 ... 158)
869
bdf99a93 870 Int_t patch = GetPatchSector(globalpadrow, pad);
accfa4d9 871 if ( patch < 0 ) return -1;
872 Int_t roc = GetRocFromPatch(side, sector, patch);
873 if ( roc < 0 ) return -1;
874
bdf99a93 875 if ( globalpadrow < fNpadrowIROC )
876 return GetEquipmentID(roc, globalpadrow, pad);
accfa4d9 877 else
bdf99a93 878 return GetEquipmentID(roc, globalpadrow-fNpadrowIROC, pad);
bb18c002 879}
accfa4d9 880
881
882//_____________________________________________________________________________
883Int_t AliTPCmapper::GetEquipmentIDfromPatch(Int_t side, Int_t sector, Int_t patch) const
884{
7d855b04 885 /// Get EqID from patch (rcu).
accfa4d9 886
887 Int_t roc = GetRocFromPatch(side, sector, patch);
888 Int_t ddl = 0;
889 if (patch < 2) // IROC
890 ddl = roc*2 + patch;
891 else // OROC
892 ddl = (roc-36)*4 + 36*2 + (patch-2);
893 // Add offset. TPC has detectorID = 3
bdf99a93 894 return ddl+fTpcDdlOffset;
accfa4d9 895}
896
897
898//_____________________________________________________________________________
899Int_t AliTPCmapper::GetPatchFromEquipmentID(Int_t equipmentID) const
900{
7d855b04 901 /// Get rcu (patch) index (0 ... 5) from equipment ID
902
accfa4d9 903 Int_t retval = 0;
904
bdf99a93 905 if ( (equipmentID < fTpcDdlOffset) || (equipmentID > 983) ) {
accfa4d9 906 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
907 return -1;
908 }
909 if ( ( (int)equipmentID - 840 ) < 0) retval = (equipmentID-768)%2;
910 else retval = (equipmentID-840)%4 + 2;
911 return retval;
912}
913
914
915//_____________________________________________________________________________
916Int_t AliTPCmapper::GetSideFromEquipmentID(Int_t equipmentID) const
917{
7d855b04 918 /// Get side from Eq ID
919
bdf99a93 920 if ( equipmentID < fTpcDdlOffset ) {
accfa4d9 921 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
922 return -1;
923 }
924 if ( equipmentID < 804 ) return 0;
925 else if ( equipmentID < 840 ) return 1;
926 else if ( equipmentID < 912 ) return 0;
927 else if ( equipmentID < 984 ) return 1;
928 else {
929 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
930 return -1;
931 }
932}
933
934
935//_____________________________________________________________________________
936Int_t AliTPCmapper::GetSectorFromEquipmentID(Int_t equipmentID) const
937{
7d855b04 938 /// Get sector index (0 ... 17) from equipment ID
939
accfa4d9 940 Int_t retval = 0;
df33cb1a 941 if ( (equipmentID < fTpcDdlOffset) || (equipmentID >= fTpcDdlOffset+216) ) {
accfa4d9 942 AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
943 return -1;
944 }
df33cb1a 945 Int_t side = GetSideFromEquipmentID(equipmentID);
946 if ( side < 0 ) return -1;
947
948 if ( (equipmentID - 840) < 0 ) { // IROC
949 if ( side == 0 ) retval = (equipmentID-fTpcDdlOffset)/2;
950 else retval = (equipmentID-fTpcDdlOffset-18*2)/2;
951 } else { // OROC
952 if ( side == 0 ) retval = (equipmentID-840)/4;
953 else retval = (equipmentID-840-18*4)/4;
954 }
accfa4d9 955 return retval;
956}
957
958
959//_____________________________________________________________________________
960Int_t AliTPCmapper::GetRocFromEquipmentID(Int_t equipmentID) const
961{
7d855b04 962 /// Get ROC index (0 ... 71) from equipment ID
963
accfa4d9 964 Int_t side = GetSideFromEquipmentID(equipmentID);
965 if ( side < 0 ) return -1;
966 Int_t sector = GetSectorFromEquipmentID(equipmentID);
967 if ( sector < 0 ) return -1;
968 Int_t patch = GetPatchFromEquipmentID(equipmentID);
969 if ( patch < 0 ) return -1;
970
971 return GetRocFromPatch(side, sector, patch);
972}
973
974
975//_____________________________________________________________________________
976Int_t AliTPCmapper::GetSectorFromRoc(Int_t roc) const
977{
7d855b04 978 /// get the sector number (0 ... 17) from the roc number (0 ... 71)
accfa4d9 979
980 if ( roc < 0 ) {
981 AliWarning(Form("Roc outside range (roc %d) !", roc));
982 return -1;
983 } else if ( roc < 18 ) { // inner sector, A side
984 return roc;
985 } else if ( roc < 36 ) { // inner sector, C side
986 return (roc-18);
987 } else if ( roc < 54 ) { // outer sector, A side
988 return (roc-36);
989 } else if ( roc < 72 ) { // outer sector, C side
990 return (roc-54);
991 } else {
992 AliWarning(Form("Roc outside range (roc %d) !", roc));
993 return -1;
994 }
995}
996
997
998//_____________________________________________________________________________
999Int_t AliTPCmapper::GetSideFromRoc(Int_t roc) const
1000{
7d855b04 1001 /// get the side (0, 1) from the roc number (0 ... 71)
accfa4d9 1002
1003 if ( roc < 0 ) {
1004 AliWarning(Form("Roc outside range (roc %d) !", roc));
1005 return -1;
1006 } else if ( roc < 18 ) { // inner sector, A side
1007 return 0;
1008 } else if ( roc < 36 ) { // inner sector, C side
1009 return 1;
1010 } else if ( roc < 54 ) { // outer sector, A side
1011 return 0;
1012 } else if ( roc < 72 ) { // outer sector, C side
1013 return 1;
7d855b04 1014 } else {
accfa4d9 1015 AliWarning(Form("Roc outside range (roc %d) !", roc));
1016 return -1;
7d855b04 1017 }
accfa4d9 1018}
1019
1020
1021//_____________________________________________________________________________
1022Int_t AliTPCmapper::GetRocFromPatch(Int_t side, Int_t sector, Int_t patch) const
1023{
7d855b04 1024 /// Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and patch (0 ... 5)
accfa4d9 1025
1026 if ( (side < 0) || (side >= fNside) ) {
1027 AliWarning(Form("Side outside range (side %d) !", side));
1028 return -1;
1029 }
1030 if ( (sector < 0) || (sector >= fNsector) ) {
1031 AliWarning(Form("Sector outside range (sector %d) !", sector));
1032 return -1;
1033 }
1034 if ( (patch < 0) || (patch >= fNrcu) ) {
1035 AliWarning(Form("Patch (rcu) outside range (patch %d) !", patch));
1036 return -1;
1037 }
1038
1039 if ( side == 0 ) { // A side
1040 if ( patch < 2 ) return sector; // IROC
1041 else return 36+sector; // OROC
1042 } else { // C side
df33cb1a 1043 if ( patch < 2 ) return 18+sector; // IROC
1044 else return 54+sector; // OROC
accfa4d9 1045 }
1046}
1047
1048
1049//_____________________________________________________________________________
bdf99a93 1050Int_t AliTPCmapper::GetRoc(Int_t side, Int_t sector, Int_t globalpadrow, Int_t pad) const
accfa4d9 1051{
7d855b04 1052 /// Get Roc (0 ... 71) from side (0, 1), sector (0 ... 17) and pad coordinates
accfa4d9 1053
bdf99a93 1054 Int_t patch = GetPatchSector(globalpadrow, pad);
accfa4d9 1055 if ( patch < 0 ) return -1;
1056 return GetRocFromPatch(side, sector, patch);
1057}
1058
1059
1060//_____________________________________________________________________________
1061 Bool_t AliTPCmapper::IsIROC(Int_t roc) const
1062{
7d855b04 1063 /// Is this ROC an IROC?
1064
accfa4d9 1065 if ( roc < 0 ) {
1066 AliWarning(Form("Roc outside range (roc %d) !", roc));
1067 return -1;
1068 } else if ( roc < 36 ) { // inner sector
1069 return true;
1070 } else if ( roc < 72 ) { // outer sector, C side
1071 return false;
1072 } else {
1073 AliWarning(Form("Roc outside range (roc %d) !", roc));
1074 return -1;
1075 }
1076}
1077
1078
1079//_____________________________________________________________________________
1080 Bool_t AliTPCmapper::IsOROC(Int_t roc) const
1081{
7d855b04 1082 /// Is this ROC an OROC?
1083
accfa4d9 1084 if ( roc < 0 ) {
1085 AliWarning(Form("Roc outside range (roc %d) !", roc));
1086 return -1;
1087 } else if ( roc < 36 ) { // inner sector
1088 return false;
1089 } else if ( roc < 72 ) { // outer sector, C side
1090 return true;
1091 } else {
1092 AliWarning(Form("Roc outside range (roc %d) !", roc));
1093 return -1;
1094 }
1095}
1096
1097// EOF