2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
6 * Primary Authors: Kenneth Aamodt <kenneth@ift.uib.no> *
7 * for The ALICE HLT Project. *
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 **************************************************************************/
18 /** @file AliHLTTPCMapping.cxx
19 @author Kenneth Aamodt
21 @brief A mapping class for the TPC.
24 // see header file for class documentation //
26 // refer to README to build package //
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt //
34 #include "AliHLTTPCMapping.h"
35 #include "AliHLTTPCTransform.h"
37 ClassImp(AliHLTTPCMapping)
39 AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
42 fCurrentRowMapping(NULL),
43 fCurrentPadMapping(NULL),
48 // see header file for class documentation
50 // refer to README to build package
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 assert(patch<fgkNofPatches);
55 if (patch>=fgkNofPatches) fPatch=0; // just to avoid boundary overflow
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);
68 if(!fgMappingIsDone[patch]){
69 ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]);
70 fgMappingIsDone[patch]=kTRUE;
72 fCurrentRowMapping=fgRowMapping[patch];
73 fCurrentPadMapping=fgPadMapping[patch];
74 fMaxHWAdd=fgkMappingSize[patch];
77 Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
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
95 UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
96 UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
97 UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize];
98 UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
99 UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
100 UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize];
101 UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
102 UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
103 UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize];
104 UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
105 UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
106 UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize];
107 UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
108 UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
109 UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize];
110 UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
111 UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
112 UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize];
114 UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
115 AliHLTTPCMapping::fgRowMapping0,
116 AliHLTTPCMapping::fgRowMapping1,
117 AliHLTTPCMapping::fgRowMapping2,
118 AliHLTTPCMapping::fgRowMapping3,
119 AliHLTTPCMapping::fgRowMapping4,
120 AliHLTTPCMapping::fgRowMapping5
123 UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
124 AliHLTTPCMapping::fgPadMapping0,
125 AliHLTTPCMapping::fgPadMapping1,
126 AliHLTTPCMapping::fgPadMapping2,
127 AliHLTTPCMapping::fgPadMapping3,
128 AliHLTTPCMapping::fgPadMapping4,
129 AliHLTTPCMapping::fgPadMapping5
132 UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
133 AliHLTTPCMapping::fgHwaMapping0,
134 AliHLTTPCMapping::fgHwaMapping1,
135 AliHLTTPCMapping::fgHwaMapping2,
136 AliHLTTPCMapping::fgHwaMapping3,
137 AliHLTTPCMapping::fgHwaMapping4,
138 AliHLTTPCMapping::fgHwaMapping5
141 AliHLTTPCMapping::~AliHLTTPCMapping(){
142 // see header file for class documentation
145 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
147 // see header file for class documentation
148 // method is deprecated, just kept as history for a while
150 UInt_t fNRowsToSubtract=0;
151 //The row numbers returned by digit readers used are not from zero always
173 //Making mapping arrays for the given patch
176 const char* basePath=getenv("ALICE_ROOT");
178 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
180 inFile.open(filename.Data());
182 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
186 if(inFile >> nHWAdd){
187 if(inFile >> fMaxHWAdd){
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);
197 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
198 if (hwAdd>fMaxHWAdd) {
199 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
202 fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
203 fgPadMapping0[hwAdd]=pad;
205 fgMappingIsDone[patch]=kTRUE;
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);
212 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
213 if (hwAdd>fMaxHWAdd) {
214 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
217 fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
218 fgPadMapping1[hwAdd]=pad;
220 fgMappingIsDone[patch]=kTRUE;
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);
227 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
228 if (hwAdd>fMaxHWAdd) {
229 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
232 fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
233 fgPadMapping2[hwAdd]=pad;
235 fgMappingIsDone[patch]=kTRUE;
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);
242 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
243 if (hwAdd>fMaxHWAdd) {
244 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
247 fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
248 fgPadMapping3[hwAdd]=pad;
250 fgMappingIsDone[patch]=kTRUE;
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);
257 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
258 if (hwAdd>fMaxHWAdd) {
259 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
262 fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
263 fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
265 fgMappingIsDone[patch]=kTRUE;
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);
272 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
273 if (hwAdd>fMaxHWAdd) {
274 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
277 fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
278 fgPadMapping5[hwAdd]=pad;
280 fgMappingIsDone[patch]=kTRUE;
289 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
291 // see header file for class documentation
292 assert(fCurrentRowMapping);
293 if (!fCurrentRowMapping) return 0;
294 if (hwadd>fMaxHWAdd) return 0;
295 return fCurrentRowMapping[hwadd];
298 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
300 // see header file for class documentation
301 assert(fCurrentPadMapping);
302 if (!fCurrentPadMapping) return 0;
303 if (hwadd>fMaxHWAdd) return 0;
304 return fCurrentPadMapping[hwadd];
307 UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const
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];
319 Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const
321 // see header file for class documentation
322 //Making mapping arrays for the given patch
325 assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL);
326 if (!rowArray || !padArray || !hwaArray) return kFALSE;
328 memset(rowArray, 0, arraySize*sizeof(rowArray[0]));
329 memset(padArray, 0, arraySize*sizeof(padArray[0]));
330 memset(hwaArray, 0, hwaMappingSize*sizeof(padArray[0]));
334 const char* basePath=getenv("ALICE_ROOT");
336 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
338 inFile.open(filename.Data());
340 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
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);
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);
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;
368 UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd];
369 assert(hwaIndex<hwaMappingSize);
370 if (hwaIndex<hwaMappingSize) {
371 hwaArray[hwaIndex]=hwAdd;
380 Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
382 if (hwadd>fMaxHWAdd){