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