]>
Commit | Line | Data |
---|---|---|
7e914051 | 1 | // $Id$ |
7dceaa9b | 2 | /************************************************************************** |
3 | * This file is property of and copyright by the ALICE HLT Project * | |
4 | * ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Primary Authors: Kenneth Aamodt <kenneth@ift.uib.no> * | |
7 | * for The ALICE HLT Project. * | |
8 | * * | |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
14 | * about the suitability of this software for any purpose. It is * | |
15 | * provided "as is" without express or implied warranty. * | |
16 | **************************************************************************/ | |
17 | ||
18 | /** @file AliHLTTPCMapping.cxx | |
19 | @author Kenneth Aamodt | |
20 | @date | |
21 | @brief A mapping class for the TPC. | |
22 | */ | |
23 | ||
24 | // see header file for class documentation // | |
25 | // or // | |
26 | // refer to README to build package // | |
27 | // or // | |
28 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt // | |
29 | ||
30 | #if __GNUC__>= 3 | |
31 | using namespace std; | |
32 | #endif | |
33 | #include <cassert> | |
34 | #include "AliHLTTPCMapping.h" | |
d2f725e4 | 35 | #include "AliHLTTPCTransform.h" |
7dceaa9b | 36 | |
37 | ClassImp(AliHLTTPCMapping) | |
38 | ||
39 | AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch) | |
40 | : | |
353508b1 | 41 | fPatch(patch), |
7dceaa9b | 42 | fCurrentRowMapping(NULL), |
a74855c2 | 43 | fCurrentPadMapping(NULL), |
353508b1 | 44 | fNofRows(0), |
d2f725e4 | 45 | fMaxHWAdd(0), |
46 | fRowOffset(0) | |
7dceaa9b | 47 | { |
48 | // see header file for class documentation | |
49 | // or | |
50 | // refer to README to build package | |
51 | // or | |
52 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
53 | ||
353508b1 | 54 | assert(patch<fgkNofPatches); |
a22757d4 | 55 | if (patch>=fgkNofPatches) { |
56 | HLTFatal("invalid partition number %d, allowed range [0,%d]", patch, fgkNofPatches-1); | |
57 | fPatch=0; // just to avoid boundary overflow | |
58 | return; | |
59 | } | |
353508b1 | 60 | |
61 | // Get the row offset. | |
62 | // we have several possibilities to count the rows: | |
63 | // - A: absolute number: 0 to 158 over all partitions | |
64 | // - B: sectorwise: 0 to 62 for inner, 0 to 95 for outer sector | |
65 | // - C: within a partition: the mappping class is designed to return the | |
66 | // mapping within a partition. | |
67 | // The mapping files use scheme B. We have to subtract the first row. | |
68 | // AliHLTTPCTransform::GetFirstRow returns first row in scheme A. | |
69 | fNofRows=AliHLTTPCTransform::GetNRows(patch); | |
70 | fRowOffset=AliHLTTPCTransform::GetFirstRow(patch); | |
71 | ||
72 | if(!fgMappingIsDone[patch]){ | |
73 | ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]); | |
74 | fgMappingIsDone[patch]=kTRUE; | |
7dceaa9b | 75 | } |
353508b1 | 76 | fCurrentRowMapping=fgRowMapping[patch]; |
77 | fCurrentPadMapping=fgPadMapping[patch]; | |
78 | fMaxHWAdd=fgkMappingSize[patch]; | |
7dceaa9b | 79 | } |
80 | ||
353508b1 | 81 | Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={ |
82 | kFALSE, | |
83 | kFALSE, | |
84 | kFALSE, | |
85 | kFALSE, | |
86 | kFALSE, | |
87 | kFALSE | |
88 | }; | |
89 | ||
90 | const UInt_t AliHLTTPCMapping::fgkMappingSize[fgkNofPatches]={ | |
91 | AliHLTTPCMapping::fgkMapping0Size, | |
92 | AliHLTTPCMapping::fgkMapping1Size, | |
93 | AliHLTTPCMapping::fgkMapping2Size, | |
94 | AliHLTTPCMapping::fgkMapping3Size, | |
95 | AliHLTTPCMapping::fgkMapping4Size, | |
96 | AliHLTTPCMapping::fgkMapping5Size | |
97 | }; | |
98 | ||
7dceaa9b | 99 | UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size]; |
100 | UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size]; | |
353508b1 | 101 | UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize]; |
7dceaa9b | 102 | UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size]; |
103 | UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size]; | |
353508b1 | 104 | UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize]; |
7dceaa9b | 105 | UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size]; |
106 | UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size]; | |
353508b1 | 107 | UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize]; |
7dceaa9b | 108 | UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size]; |
109 | UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size]; | |
353508b1 | 110 | UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize]; |
7dceaa9b | 111 | UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size]; |
112 | UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size]; | |
353508b1 | 113 | UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize]; |
7dceaa9b | 114 | UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size]; |
115 | UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size]; | |
353508b1 | 116 | UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize]; |
117 | ||
118 | UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={ | |
119 | AliHLTTPCMapping::fgRowMapping0, | |
120 | AliHLTTPCMapping::fgRowMapping1, | |
121 | AliHLTTPCMapping::fgRowMapping2, | |
122 | AliHLTTPCMapping::fgRowMapping3, | |
123 | AliHLTTPCMapping::fgRowMapping4, | |
124 | AliHLTTPCMapping::fgRowMapping5 | |
125 | }; | |
126 | ||
127 | UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={ | |
128 | AliHLTTPCMapping::fgPadMapping0, | |
129 | AliHLTTPCMapping::fgPadMapping1, | |
130 | AliHLTTPCMapping::fgPadMapping2, | |
131 | AliHLTTPCMapping::fgPadMapping3, | |
132 | AliHLTTPCMapping::fgPadMapping4, | |
133 | AliHLTTPCMapping::fgPadMapping5 | |
134 | }; | |
135 | ||
136 | UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={ | |
137 | AliHLTTPCMapping::fgHwaMapping0, | |
138 | AliHLTTPCMapping::fgHwaMapping1, | |
139 | AliHLTTPCMapping::fgHwaMapping2, | |
140 | AliHLTTPCMapping::fgHwaMapping3, | |
141 | AliHLTTPCMapping::fgHwaMapping4, | |
142 | AliHLTTPCMapping::fgHwaMapping5 | |
143 | }; | |
7dceaa9b | 144 | |
145 | AliHLTTPCMapping::~AliHLTTPCMapping(){ | |
146 | // see header file for class documentation | |
147 | } | |
148 | ||
149 | void AliHLTTPCMapping::InitializeMap(UInt_t patch) | |
150 | { | |
151 | // see header file for class documentation | |
353508b1 | 152 | // method is deprecated, just kept as history for a while |
7dceaa9b | 153 | |
154 | UInt_t fNRowsToSubtract=0; | |
155 | //The row numbers returned by digit readers used are not from zero always | |
156 | switch(patch){ | |
157 | case 0: | |
158 | fNRowsToSubtract=0; | |
159 | break; | |
160 | case 1: | |
161 | fNRowsToSubtract=30; | |
162 | break; | |
163 | case 2: | |
164 | fNRowsToSubtract=0; | |
165 | break; | |
166 | case 3: | |
167 | fNRowsToSubtract=27; | |
168 | break; | |
169 | case 4: | |
170 | fNRowsToSubtract=54; | |
171 | break; | |
172 | case 5: | |
173 | fNRowsToSubtract=76; | |
174 | break; | |
175 | } | |
176 | ||
177 | //Making mapping arrays for the given patch | |
178 | ifstream inFile; | |
179 | TString filename; | |
180 | const char* basePath=getenv("ALICE_ROOT"); | |
181 | if (basePath) { | |
182 | filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch); | |
183 | } | |
184 | inFile.open(filename.Data()); | |
185 | if (!inFile) { | |
186 | HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data()); | |
187 | } | |
188 | else{ | |
353508b1 | 189 | UInt_t nHWAdd=0; |
190 | if(inFile >> nHWAdd){ | |
7dceaa9b | 191 | if(inFile >> fMaxHWAdd){ |
192 | UInt_t hwAdd=0; | |
193 | UInt_t row=0; | |
194 | UInt_t pad=0; | |
195 | switch(patch){ | |
196 | case 0: | |
353508b1 | 197 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
198 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 199 | break; |
200 | } | |
201 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 202 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 203 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
204 | break; | |
205 | } | |
206 | fgRowMapping0[hwAdd]=row-fNRowsToSubtract; | |
207 | fgPadMapping0[hwAdd]=pad; | |
208 | } | |
353508b1 | 209 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 210 | break; |
211 | case 1: | |
353508b1 | 212 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
213 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 214 | break; |
215 | } | |
216 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 217 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 218 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
219 | break; | |
220 | } | |
221 | fgRowMapping1[hwAdd]=row-fNRowsToSubtract; | |
222 | fgPadMapping1[hwAdd]=pad; | |
223 | } | |
353508b1 | 224 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 225 | break; |
226 | case 2: | |
353508b1 | 227 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
228 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 229 | break; |
230 | } | |
231 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 232 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 233 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
234 | break; | |
235 | } | |
236 | fgRowMapping2[hwAdd]=row-fNRowsToSubtract; | |
237 | fgPadMapping2[hwAdd]=pad; | |
238 | } | |
353508b1 | 239 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 240 | break; |
241 | case 3: | |
353508b1 | 242 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
243 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 244 | break; |
245 | } | |
246 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 247 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 248 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
249 | break; | |
250 | } | |
251 | fgRowMapping3[hwAdd]=row-fNRowsToSubtract; | |
252 | fgPadMapping3[hwAdd]=pad; | |
253 | } | |
353508b1 | 254 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 255 | break; |
256 | case 4: | |
353508b1 | 257 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
258 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 259 | break; |
260 | } | |
261 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 262 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 263 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
264 | break; | |
265 | } | |
266 | fgRowMapping4[hwAdd]=row-fNRowsToSubtract; | |
267 | fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad; | |
268 | } | |
353508b1 | 269 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 270 | break; |
271 | case 5: | |
353508b1 | 272 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
273 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 274 | break; |
275 | } | |
276 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 277 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 278 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
279 | break; | |
280 | } | |
281 | fgRowMapping5[hwAdd]=row-fNRowsToSubtract; | |
282 | fgPadMapping5[hwAdd]=pad; | |
283 | } | |
353508b1 | 284 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 285 | break; |
286 | } | |
287 | } | |
288 | } | |
289 | } | |
290 | inFile.close(); | |
291 | } | |
292 | ||
a74855c2 | 293 | UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const |
7dceaa9b | 294 | { |
295 | // see header file for class documentation | |
296 | assert(fCurrentRowMapping); | |
7dceaa9b | 297 | if (!fCurrentRowMapping) return 0; |
d2f725e4 | 298 | if (hwadd>fMaxHWAdd) return 0; |
7dceaa9b | 299 | return fCurrentRowMapping[hwadd]; |
300 | } | |
301 | ||
a74855c2 | 302 | UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const |
7dceaa9b | 303 | { |
304 | // see header file for class documentation | |
305 | assert(fCurrentPadMapping); | |
7dceaa9b | 306 | if (!fCurrentPadMapping) return 0; |
d2f725e4 | 307 | if (hwadd>fMaxHWAdd) return 0; |
7dceaa9b | 308 | return fCurrentPadMapping[hwadd]; |
309 | } | |
d2f725e4 | 310 | |
353508b1 | 311 | UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const |
312 | { | |
313 | // see header file for class documentation | |
314 | assert(fPatch<fgkNofPatches); | |
315 | assert(fgHwaMapping[fPatch]); | |
316 | UInt_t hwaIndex=(row<<fgkMappingHwaRowBitShift) + pad; | |
317 | if (hwaIndex<fgkMappingHwaSize) { | |
318 | return (fgHwaMapping[fPatch])[hwaIndex]; | |
319 | } | |
320 | return ~((UInt_t)0); | |
321 | } | |
322 | ||
323 | Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const | |
324 | { | |
325 | // see header file for class documentation | |
326 | //Making mapping arrays for the given patch | |
327 | Bool_t result=kTRUE; | |
328 | ||
329 | assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL); | |
330 | if (!rowArray || !padArray || !hwaArray) return kFALSE; | |
331 | ||
959cfda3 | 332 | memset(rowArray, -1, arraySize*sizeof(rowArray[0])); |
333 | memset(padArray, -1, arraySize*sizeof(padArray[0])); | |
334 | memset(hwaArray, -1, hwaMappingSize*sizeof(padArray[0])); | |
353508b1 | 335 | |
336 | ifstream inFile; | |
337 | TString filename; | |
338 | const char* basePath=getenv("ALICE_ROOT"); | |
339 | if (basePath) { | |
340 | filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch); | |
341 | } | |
342 | inFile.open(filename.Data()); | |
343 | if (!inFile) { | |
344 | HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data()); | |
345 | return kFALSE; | |
346 | } | |
347 | ||
348 | UInt_t nHWAdd=0; | |
349 | UInt_t maxHWAdd=0; | |
350 | if(inFile >> nHWAdd){ | |
351 | if(inFile >> maxHWAdd){ | |
352 | if(arraySize<maxHWAdd){ | |
353 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch, arraySize ,fMaxHWAdd); | |
354 | result=kFALSE; | |
355 | } | |
356 | UInt_t hwAdd=0; | |
357 | UInt_t row=0; | |
358 | UInt_t pad=0; | |
359 | while(result && inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
360 | if (hwAdd>maxHWAdd) { | |
361 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", maxHWAdd); | |
362 | result=kFALSE; | |
363 | break; | |
364 | } | |
365 | Int_t dummy=0; | |
366 | // AliHLTTPCTransform::GetFirstRow returns first row in scheme A. | |
367 | // We have to transform to scheme B by AliHLTTPCTransform::Slice2Sector. | |
368 | Int_t offsetSchemeB=0; | |
369 | AliHLTTPCTransform::Slice2Sector(0, fRowOffset, dummy, offsetSchemeB); | |
370 | rowArray[hwAdd]=row-offsetSchemeB; | |
371 | padArray[hwAdd]=pad; | |
372 | UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd]; | |
373 | assert(hwaIndex<hwaMappingSize); | |
374 | if (hwaIndex<hwaMappingSize) { | |
375 | hwaArray[hwaIndex]=hwAdd; | |
376 | } | |
377 | } | |
378 | } | |
379 | } | |
380 | inFile.close(); | |
381 | return result; | |
382 | } | |
383 | ||
d2f725e4 | 384 | Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const |
385 | { | |
386 | if (hwadd>fMaxHWAdd){ | |
387 | return kFALSE; | |
388 | } | |
389 | else{ | |
390 | return kTRUE; | |
391 | } | |
392 | } |