Modyfing debug levels: level 1 only in ctors/dtors.
[u/mrichter/AliRoot.git] / TPC / 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
16//-------------------------------------------------------------------------
17// AliTPCmapper
18// Origin: Jens Wiechula (j.wiechula@gsi.de)
19//
20// class to map (row,pad,sector) to (RCU, Branch, FEC, Altro, Altro channel)
21// create Altro address
22
23
24#include <stdio.h>
25#include <TMath.h>
26#include <TSystem.h>
27
28#include "AliTPCmapper.h"
29
30
31ClassImp(AliTPCmapper)
32
33
34//______________________________________________________________
35AliTPCmapper::AliTPCmapper()
36{
37 Init();
38 ReadMapping();
39}
40
41//______________________________________________________________
42void AliTPCmapper::Init()
43{
44
45 //Initialize arrays
46 for (Int_t i=0; i<kNrcu; i++){
47 for (Int_t j=0; j<kNbranch; j++){
48 for (Int_t k=0; k<kNfecMax; k++){
49 for (Int_t l=0; l<kNaltro; l++){
50 for (Int_t m=0; m<kNchannel; m++){
51 fAddressToRow[i][j][k][l][m] = -1;
52 fAddressToPad[i][j][k][l][m] = -1;
53 }
54 }
55 }
56 }
57 }
58
59 for (Int_t i=0; i<kNpadrow; i++){
60 for (Int_t j=0; j<kNpadMax; j++){
61 fRowPadToRCU[i][j] = -1;
62 fRowPadToBranch[i][j] = -1;
63 fRowPadToFEC[i][j] = -1;
64 fRowPadToAltro[i][j] = -1;
65 fRowPadToChannel[i][j] = -1;
66 fRowPadToPadsec[i][j] = -1;
67 }
68 }
69
70 for (Int_t i=0; i<kNpadSector; i++){
71 fPadsecToRow[i]=-1;
72 fPadsecToPad[i]=-1;
73 }
74
75// for (Int_t i=0; i<kNaddrSize; i++)
76// fAddressArray[i] = 0;
77
78 strcpy(fMapfileName,gSystem->ExpandPathName("$ALICE_ROOT/TPC/final_mapping.txt"));
79}
80
81//______________________________________________________________
82Int_t AliTPCmapper::ReadMapping()
83{
84 FILE *f_in;
85 char line[255];
86
87 int pad = -1, row = -1;
88 int rcu = -1, bra = -1, fec = -1, alt = -1, chn = -1;
89 int padsec = 0;
90
91
92 f_in = fopen(fMapfileName,"r");
93 if (!f_in){
94 fprintf(stderr, "cannot open file '%s'!\n",fMapfileName);
95 return 1;
96 }
97
98 fgets(line,256,f_in);
99 while (sscanf(line,"%d %d %d %d %d %d %d %d",
100 &padsec, &row, &pad,
101 &rcu, &bra, &fec, &alt, &chn
102 )!=8){
103 fgets(line, 256, f_in);
104 fprintf(stderr,"%s",line);
105 }
106
107 while (!feof(f_in)){
108 sscanf(line,"%d %d %d %d %d %d %d %d",
109 &padsec, &row, &pad,
110 &rcu, &bra, &fec, &alt, &chn
111 );
112 fAddressToRow[rcu][bra][fec][alt][chn] = row;
113 fAddressToPad[rcu][bra][fec][alt][chn] = pad;
114
115 fRowPadToRCU[row][pad] = rcu;
116 fRowPadToBranch[row][pad] = bra;
117 fRowPadToFEC[row][pad] = fec;
118 fRowPadToAltro[row][pad] = alt;
119 fRowPadToChannel[row][pad] = chn;
120 fRowPadToPadsec[row][pad] = padsec;
121
122 fPadsecToRow[padsec] = row;
123 fPadsecToPad[padsec] = pad;
124
125
126
127 fgets(line, 256, f_in);
128 }
129
130 fclose(f_in);
131
132 return 0;
133}
134
135//______________________________________________________________
136void AliTPCmapper::PrintRBFACinfo(Int_t row, Int_t pad)
137{
138 fprintf(stderr,"RCU: %d, Branch: %d, FEC: %2d, Altro: %d, Channel: %2d\n",
139 GetRCUs(row,pad), GetBranchS(row,pad),
140 GetFECs(row,pad), GetAltroS(row,pad),
141 GetChannelS(row,pad));
142
143}
144
145//______________________________________________________________
146Int_t AliTPCmapper::GetPadsInRowS(Int_t row){
147 if ( row == 0 )
148 return 68;
149
150 if ( row < 63 )
151 return 2*(Int_t)(row/3.+33.67);
152
153 row -= 63;
154 Double_t k1=10./6.*tan(TMath::Pi()/18.);
155
156 if ( row < 64 )
157 return 2*(Int_t)(k1 * row + 37.75);
158
159 Double_t k2=15./6.*tan(TMath::Pi()/18.);
160 return 2*(Int_t)(k2 * (row-64) + 56.66);
161}
162
163//______________________________________________________________
164Double_t AliTPCmapper::GetPadXlocalS(Int_t row, Int_t pad){
165 if ( row < 63 ) //IROC
166 return (852.25 + 7.5 * (Double_t)row)*1.e-1; //divide by 10 to get cm
167
168 row -= 63;
169
170 if ( row < 64 ) //OROC inner part
171 return (10.* row + 1351.)*1.e-1; //divide by 10 to get cm
172
173
174 //OROC outer part
175 return (15.*(row - 64) + 1993.5)*1.e-1; //divide by 10 to get cm
176}
177
178//______________________________________________________________
179Double_t AliTPCmapper::GetPadXlocalS(Int_t padsector){
180 Int_t row=GetRowFromPadSector(padsector);
181 Int_t pad=GetPadFromPadSector(padsector);
182 return GetPadXlocalS(row,pad);
183}
184
185//______________________________________________________________
186Double_t AliTPCmapper::GetPadYlocalS(Int_t row, Int_t pad){
187 Int_t padsInRow = GetPadsInRowS(row);
188
189 if ( row < 63 ) //IROC
190 return (2.* padsInRow - 4.*pad - 2.)*1.e-1; //divide by 10 to get cm
191
192 //OROC
193 return (3.* padsInRow -6.*pad - 3.)*1.e-1; //divide by 10 to get cm
194}
195
196//______________________________________________________________
197Double_t AliTPCmapper::GetPadYlocalS(Int_t padsector){
198 Int_t row = GetRowFromPadSector(padsector);
199 Int_t pad = GetPadFromPadSector(padsector);
200 return GetPadYlocalS(row,pad);
201}
202
203//______________________________________________________________
204Double_t AliTPCmapper::GetPadXglobalS(Int_t row, Int_t pad,Int_t sector){
205 Double_t angle = (Double_t)(( sector * 20. ) +10. ) * TMath::DegToRad();
206 return GetPadXlocalS(row,pad)*TMath::Cos(angle) -
207 GetPadYlocalS(row,pad)*TMath::Sin(angle);
208}
209
210//______________________________________________________________
211Double_t AliTPCmapper::GetPadYglobalS(Int_t row, Int_t pad,Int_t sector){
212 Double_t angle = (Double_t)(( sector * 20. ) + 10. ) * TMath::DegToRad();
213 return GetPadXlocalS(row,pad)*TMath::Sin(angle) +
214 GetPadYlocalS(row,pad)*TMath::Cos(angle);
215}
216
217//______________________________________________________________
218Double_t AliTPCmapper::GetPadWidthS(Int_t row)
219{
220 if (row < 63 ) return .4;
221 return .6;
222}
223
224//______________________________________________________________
225Double_t AliTPCmapper::GetPadLengthS(Int_t row)
226{
227 if ( row < 63 ) return .75;
228 if ( row < 127 ) return 1.;
229 return 1.5;
230}
231
232//______________________________________________________________
233Int_t AliTPCmapper::GetAltroAddrwPatch(const Int_t row,const Int_t pad)
234{
235 return GetChannelS(row,pad)+
236 (GetAltroS (row,pad) <<4)+
237 (GetFECs (row,pad) <<7)+
238 (GetBranchS(row,pad) <<11)+
239 (GetRCUs (row,pad) <<12);
240}
241
242//______________________________________________________________
243Int_t AliTPCmapper::GetAltroAddrwPatch(const Int_t padsector)
244{
245 return GetAltroAddrwPatch(GetRowFromPadSector(padsector),GetPadFromPadSector(padsector));
246}
247
248//______________________________________________________________
249Int_t AliTPCmapper::GetRow(Int_t altroaddr)
250{
251 Int_t rcu = (altroaddr>>12)&0x07;
252 Int_t bra = (altroaddr>>11)&0x01;
253 Int_t fec = (altroaddr>>7)&0x0F;
254 Int_t alt = (altroaddr>>4)&0x07;
255 Int_t chn = (altroaddr)&0x0F;
256 return GetRow(rcu,bra,fec,alt,chn);
257}
258
259//______________________________________________________________
260Int_t AliTPCmapper::GetPad(Int_t altroaddr)
261{
262 Int_t rcu = (altroaddr>>12)&0x07;
263 Int_t bra = (altroaddr>>11)&0x01;
264 Int_t fec = (altroaddr>>7)&0x0F;
265 Int_t alt = (altroaddr>>4)&0x07;
266 Int_t chn = (altroaddr)&0x0F;
267 return GetPad(rcu,bra,fec,alt,chn);
268}
269
270//______________________________________________________________
271void AliTPCmapper::PrintAddressArray(Int_t row, Int_t pad)
272{
273 Bool_t a[kNaddrSize];
274
275 Int_t addr = GetAltroAddrwPatch(row,pad);
276 for (Int_t i=0; i<kNaddrSize; i++)
277 a[i] = addr&(Int_t)TMath::Power(2,i);
278
279 fprintf(stderr,"Par|Bro|BC/|Bra| FEC HW | Altro |Altro Chann.| Instruction \n");
280 fprintf(stderr,"ity|adc|AL |nch| Address |Chip Addr| Address | Code \n");
281 fprintf(stderr,"-------------------------------------------------------------------\n");
282 fprintf(stderr," %d | %d | %d | %d | %d %d %d %d | %d %d %d | %d %d %d %d | %d %d %d %d %d\n",
283 a[19],a[18],a[17],a[16],a[15],a[14],a[13],a[12],a[11],
284 a[10],a[9],a[8],a[7],a[6],a[5],a[4],a[3],a[2],a[1],a[0]);
285
286 fprintf(stderr,"-------------------------------------------------------------------\n");
287 fprintf(stderr,"19 |18 |17 |16 |15 14 13 12 |11 10 9 | 8 7 6 5 | 4 3 2 1 0\n\n");
288
289}
290
291//______________________________________________________________
292AliTPCmapper::~AliTPCmapper()
293{
294// delete fAddressArray;
295
296}