]>
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); |
55 | if (patch>=fgkNofPatches) fPatch=0; // just to avoid boundary overflow | |
56 | ||
57 | // Get the row offset. | |
58 | // we have several possibilities to count the rows: | |
59 | // - A: absolute number: 0 to 158 over all partitions | |
60 | // - B: sectorwise: 0 to 62 for inner, 0 to 95 for outer sector | |
61 | // - C: within a partition: the mappping class is designed to return the | |
62 | // mapping within a partition. | |
63 | // The mapping files use scheme B. We have to subtract the first row. | |
64 | // AliHLTTPCTransform::GetFirstRow returns first row in scheme A. | |
65 | fNofRows=AliHLTTPCTransform::GetNRows(patch); | |
66 | fRowOffset=AliHLTTPCTransform::GetFirstRow(patch); | |
67 | ||
68 | if(!fgMappingIsDone[patch]){ | |
69 | ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]); | |
70 | fgMappingIsDone[patch]=kTRUE; | |
7dceaa9b | 71 | } |
353508b1 | 72 | fCurrentRowMapping=fgRowMapping[patch]; |
73 | fCurrentPadMapping=fgPadMapping[patch]; | |
74 | fMaxHWAdd=fgkMappingSize[patch]; | |
7dceaa9b | 75 | } |
76 | ||
353508b1 | 77 | Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={ |
78 | kFALSE, | |
79 | kFALSE, | |
80 | kFALSE, | |
81 | kFALSE, | |
82 | kFALSE, | |
83 | kFALSE | |
84 | }; | |
85 | ||
86 | const UInt_t AliHLTTPCMapping::fgkMappingSize[fgkNofPatches]={ | |
87 | AliHLTTPCMapping::fgkMapping0Size, | |
88 | AliHLTTPCMapping::fgkMapping1Size, | |
89 | AliHLTTPCMapping::fgkMapping2Size, | |
90 | AliHLTTPCMapping::fgkMapping3Size, | |
91 | AliHLTTPCMapping::fgkMapping4Size, | |
92 | AliHLTTPCMapping::fgkMapping5Size | |
93 | }; | |
94 | ||
7dceaa9b | 95 | UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size]; |
96 | UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size]; | |
353508b1 | 97 | UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize]; |
7dceaa9b | 98 | UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size]; |
99 | UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size]; | |
353508b1 | 100 | UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize]; |
7dceaa9b | 101 | UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size]; |
102 | UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size]; | |
353508b1 | 103 | UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize]; |
7dceaa9b | 104 | UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size]; |
105 | UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size]; | |
353508b1 | 106 | UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize]; |
7dceaa9b | 107 | UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size]; |
108 | UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size]; | |
353508b1 | 109 | UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize]; |
7dceaa9b | 110 | UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size]; |
111 | UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size]; | |
353508b1 | 112 | UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize]; |
113 | ||
114 | UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={ | |
115 | AliHLTTPCMapping::fgRowMapping0, | |
116 | AliHLTTPCMapping::fgRowMapping1, | |
117 | AliHLTTPCMapping::fgRowMapping2, | |
118 | AliHLTTPCMapping::fgRowMapping3, | |
119 | AliHLTTPCMapping::fgRowMapping4, | |
120 | AliHLTTPCMapping::fgRowMapping5 | |
121 | }; | |
122 | ||
123 | UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={ | |
124 | AliHLTTPCMapping::fgPadMapping0, | |
125 | AliHLTTPCMapping::fgPadMapping1, | |
126 | AliHLTTPCMapping::fgPadMapping2, | |
127 | AliHLTTPCMapping::fgPadMapping3, | |
128 | AliHLTTPCMapping::fgPadMapping4, | |
129 | AliHLTTPCMapping::fgPadMapping5 | |
130 | }; | |
131 | ||
132 | UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={ | |
133 | AliHLTTPCMapping::fgHwaMapping0, | |
134 | AliHLTTPCMapping::fgHwaMapping1, | |
135 | AliHLTTPCMapping::fgHwaMapping2, | |
136 | AliHLTTPCMapping::fgHwaMapping3, | |
137 | AliHLTTPCMapping::fgHwaMapping4, | |
138 | AliHLTTPCMapping::fgHwaMapping5 | |
139 | }; | |
7dceaa9b | 140 | |
141 | AliHLTTPCMapping::~AliHLTTPCMapping(){ | |
142 | // see header file for class documentation | |
143 | } | |
144 | ||
145 | void AliHLTTPCMapping::InitializeMap(UInt_t patch) | |
146 | { | |
147 | // see header file for class documentation | |
353508b1 | 148 | // method is deprecated, just kept as history for a while |
7dceaa9b | 149 | |
150 | UInt_t fNRowsToSubtract=0; | |
151 | //The row numbers returned by digit readers used are not from zero always | |
152 | switch(patch){ | |
153 | case 0: | |
154 | fNRowsToSubtract=0; | |
155 | break; | |
156 | case 1: | |
157 | fNRowsToSubtract=30; | |
158 | break; | |
159 | case 2: | |
160 | fNRowsToSubtract=0; | |
161 | break; | |
162 | case 3: | |
163 | fNRowsToSubtract=27; | |
164 | break; | |
165 | case 4: | |
166 | fNRowsToSubtract=54; | |
167 | break; | |
168 | case 5: | |
169 | fNRowsToSubtract=76; | |
170 | break; | |
171 | } | |
172 | ||
173 | //Making mapping arrays for the given patch | |
174 | ifstream inFile; | |
175 | TString filename; | |
176 | const char* basePath=getenv("ALICE_ROOT"); | |
177 | if (basePath) { | |
178 | filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch); | |
179 | } | |
180 | inFile.open(filename.Data()); | |
181 | if (!inFile) { | |
182 | HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data()); | |
183 | } | |
184 | else{ | |
353508b1 | 185 | UInt_t nHWAdd=0; |
186 | if(inFile >> nHWAdd){ | |
7dceaa9b | 187 | if(inFile >> fMaxHWAdd){ |
188 | UInt_t hwAdd=0; | |
189 | UInt_t row=0; | |
190 | UInt_t pad=0; | |
191 | switch(patch){ | |
192 | case 0: | |
353508b1 | 193 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
194 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 195 | break; |
196 | } | |
197 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 198 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 199 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
200 | break; | |
201 | } | |
202 | fgRowMapping0[hwAdd]=row-fNRowsToSubtract; | |
203 | fgPadMapping0[hwAdd]=pad; | |
204 | } | |
353508b1 | 205 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 206 | break; |
207 | case 1: | |
353508b1 | 208 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
209 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 210 | break; |
211 | } | |
212 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 213 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 214 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
215 | break; | |
216 | } | |
217 | fgRowMapping1[hwAdd]=row-fNRowsToSubtract; | |
218 | fgPadMapping1[hwAdd]=pad; | |
219 | } | |
353508b1 | 220 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 221 | break; |
222 | case 2: | |
353508b1 | 223 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
224 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 225 | break; |
226 | } | |
227 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 228 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 229 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
230 | break; | |
231 | } | |
232 | fgRowMapping2[hwAdd]=row-fNRowsToSubtract; | |
233 | fgPadMapping2[hwAdd]=pad; | |
234 | } | |
353508b1 | 235 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 236 | break; |
237 | case 3: | |
353508b1 | 238 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
239 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 240 | break; |
241 | } | |
242 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 243 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 244 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
245 | break; | |
246 | } | |
247 | fgRowMapping3[hwAdd]=row-fNRowsToSubtract; | |
248 | fgPadMapping3[hwAdd]=pad; | |
249 | } | |
353508b1 | 250 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 251 | break; |
252 | case 4: | |
353508b1 | 253 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
254 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 255 | break; |
256 | } | |
257 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 258 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 259 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
260 | break; | |
261 | } | |
262 | fgRowMapping4[hwAdd]=row-fNRowsToSubtract; | |
263 | fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad; | |
264 | } | |
353508b1 | 265 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 266 | break; |
267 | case 5: | |
353508b1 | 268 | if(fgkMappingSize[patch]<fMaxHWAdd){ |
269 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMappingSize[patch] ,fMaxHWAdd); | |
7dceaa9b | 270 | break; |
271 | } | |
272 | while(inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
8252a538 | 273 | if (hwAdd>fMaxHWAdd) { |
7dceaa9b | 274 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd); |
275 | break; | |
276 | } | |
277 | fgRowMapping5[hwAdd]=row-fNRowsToSubtract; | |
278 | fgPadMapping5[hwAdd]=pad; | |
279 | } | |
353508b1 | 280 | fgMappingIsDone[patch]=kTRUE; |
7dceaa9b | 281 | break; |
282 | } | |
283 | } | |
284 | } | |
285 | } | |
286 | inFile.close(); | |
287 | } | |
288 | ||
a74855c2 | 289 | UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const |
7dceaa9b | 290 | { |
291 | // see header file for class documentation | |
292 | assert(fCurrentRowMapping); | |
7dceaa9b | 293 | if (!fCurrentRowMapping) return 0; |
d2f725e4 | 294 | if (hwadd>fMaxHWAdd) return 0; |
7dceaa9b | 295 | return fCurrentRowMapping[hwadd]; |
296 | } | |
297 | ||
a74855c2 | 298 | UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const |
7dceaa9b | 299 | { |
300 | // see header file for class documentation | |
301 | assert(fCurrentPadMapping); | |
7dceaa9b | 302 | if (!fCurrentPadMapping) return 0; |
d2f725e4 | 303 | if (hwadd>fMaxHWAdd) return 0; |
7dceaa9b | 304 | return fCurrentPadMapping[hwadd]; |
305 | } | |
d2f725e4 | 306 | |
353508b1 | 307 | UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const |
308 | { | |
309 | // see header file for class documentation | |
310 | assert(fPatch<fgkNofPatches); | |
311 | assert(fgHwaMapping[fPatch]); | |
312 | UInt_t hwaIndex=(row<<fgkMappingHwaRowBitShift) + pad; | |
313 | if (hwaIndex<fgkMappingHwaSize) { | |
314 | return (fgHwaMapping[fPatch])[hwaIndex]; | |
315 | } | |
316 | return ~((UInt_t)0); | |
317 | } | |
318 | ||
319 | Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const | |
320 | { | |
321 | // see header file for class documentation | |
322 | //Making mapping arrays for the given patch | |
323 | Bool_t result=kTRUE; | |
324 | ||
325 | assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL); | |
326 | if (!rowArray || !padArray || !hwaArray) return kFALSE; | |
327 | ||
328 | memset(rowArray, 0, arraySize*sizeof(rowArray[0])); | |
329 | memset(padArray, 0, arraySize*sizeof(padArray[0])); | |
330 | memset(hwaArray, 0, hwaMappingSize*sizeof(padArray[0])); | |
331 | ||
332 | ifstream inFile; | |
333 | TString filename; | |
334 | const char* basePath=getenv("ALICE_ROOT"); | |
335 | if (basePath) { | |
336 | filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch); | |
337 | } | |
338 | inFile.open(filename.Data()); | |
339 | if (!inFile) { | |
340 | HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data()); | |
341 | return kFALSE; | |
342 | } | |
343 | ||
344 | UInt_t nHWAdd=0; | |
345 | UInt_t maxHWAdd=0; | |
346 | if(inFile >> nHWAdd){ | |
347 | if(inFile >> maxHWAdd){ | |
348 | if(arraySize<maxHWAdd){ | |
349 | HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch, arraySize ,fMaxHWAdd); | |
350 | result=kFALSE; | |
351 | } | |
352 | UInt_t hwAdd=0; | |
353 | UInt_t row=0; | |
354 | UInt_t pad=0; | |
355 | while(result && inFile>>hwAdd && inFile>>row && inFile>>pad){ | |
356 | if (hwAdd>maxHWAdd) { | |
357 | HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", maxHWAdd); | |
358 | result=kFALSE; | |
359 | break; | |
360 | } | |
361 | Int_t dummy=0; | |
362 | // AliHLTTPCTransform::GetFirstRow returns first row in scheme A. | |
363 | // We have to transform to scheme B by AliHLTTPCTransform::Slice2Sector. | |
364 | Int_t offsetSchemeB=0; | |
365 | AliHLTTPCTransform::Slice2Sector(0, fRowOffset, dummy, offsetSchemeB); | |
366 | rowArray[hwAdd]=row-offsetSchemeB; | |
367 | padArray[hwAdd]=pad; | |
368 | UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd]; | |
369 | assert(hwaIndex<hwaMappingSize); | |
370 | if (hwaIndex<hwaMappingSize) { | |
371 | hwaArray[hwaIndex]=hwAdd; | |
372 | } | |
373 | } | |
374 | } | |
375 | } | |
376 | inFile.close(); | |
377 | return result; | |
378 | } | |
379 | ||
d2f725e4 | 380 | Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const |
381 | { | |
382 | if (hwadd>fMaxHWAdd){ | |
383 | return kFALSE; | |
384 | } | |
385 | else{ | |
386 | return kTRUE; | |
387 | } | |
388 | } |