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 //
31 #include "AliHLTTPCMapping.h"
32 #include "AliHLTTPCTransform.h"
36 ClassImp(AliHLTTPCMapping)
38 AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
41 fCurrentRowMapping(NULL),
42 fCurrentPadMapping(NULL),
47 // see header file for class documentation
49 // refer to README to build package
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53 assert(patch<fgkNofPatches);
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
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);
71 if(!fgMappingIsDone[patch]){
72 ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]);
73 fgMappingIsDone[patch]=kTRUE;
75 fCurrentRowMapping=fgRowMapping[patch];
76 fCurrentPadMapping=fgPadMapping[patch];
77 fMaxHWAdd=fgkMappingSize[patch];
80 Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
89 const UInt_t AliHLTTPCMapping::fgkMappingSize[fgkNofPatches]={
90 AliHLTTPCMapping::fgkMapping0Size,
91 AliHLTTPCMapping::fgkMapping1Size,
92 AliHLTTPCMapping::fgkMapping2Size,
93 AliHLTTPCMapping::fgkMapping3Size,
94 AliHLTTPCMapping::fgkMapping4Size,
95 AliHLTTPCMapping::fgkMapping5Size
98 UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
99 UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
100 UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize];
101 UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
102 UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
103 UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize];
104 UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
105 UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
106 UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize];
107 UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
108 UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
109 UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize];
110 UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
111 UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
112 UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize];
113 UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
114 UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
115 UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize];
117 UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
118 AliHLTTPCMapping::fgRowMapping0,
119 AliHLTTPCMapping::fgRowMapping1,
120 AliHLTTPCMapping::fgRowMapping2,
121 AliHLTTPCMapping::fgRowMapping3,
122 AliHLTTPCMapping::fgRowMapping4,
123 AliHLTTPCMapping::fgRowMapping5
126 UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
127 AliHLTTPCMapping::fgPadMapping0,
128 AliHLTTPCMapping::fgPadMapping1,
129 AliHLTTPCMapping::fgPadMapping2,
130 AliHLTTPCMapping::fgPadMapping3,
131 AliHLTTPCMapping::fgPadMapping4,
132 AliHLTTPCMapping::fgPadMapping5
135 UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
136 AliHLTTPCMapping::fgHwaMapping0,
137 AliHLTTPCMapping::fgHwaMapping1,
138 AliHLTTPCMapping::fgHwaMapping2,
139 AliHLTTPCMapping::fgHwaMapping3,
140 AliHLTTPCMapping::fgHwaMapping4,
141 AliHLTTPCMapping::fgHwaMapping5
144 AliHLTTPCMapping::~AliHLTTPCMapping(){
145 // see header file for class documentation
148 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
150 // see header file for class documentation
151 // method is deprecated, just kept as history for a while
153 UInt_t fNRowsToSubtract=0;
154 //The row numbers returned by digit readers used are not from zero always
176 //Making mapping arrays for the given patch
179 const char* basePath=getenv("ALICE_ROOT");
181 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
183 inFile.open(filename.Data());
185 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
189 if(inFile >> nHWAdd){
190 if(inFile >> fMaxHWAdd){
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);
200 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
201 if (hwAdd>fMaxHWAdd) {
202 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
205 fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
206 fgPadMapping0[hwAdd]=pad;
208 fgMappingIsDone[patch]=kTRUE;
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);
215 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
216 if (hwAdd>fMaxHWAdd) {
217 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
220 fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
221 fgPadMapping1[hwAdd]=pad;
223 fgMappingIsDone[patch]=kTRUE;
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);
230 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
231 if (hwAdd>fMaxHWAdd) {
232 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
235 fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
236 fgPadMapping2[hwAdd]=pad;
238 fgMappingIsDone[patch]=kTRUE;
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);
245 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
246 if (hwAdd>fMaxHWAdd) {
247 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
250 fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
251 fgPadMapping3[hwAdd]=pad;
253 fgMappingIsDone[patch]=kTRUE;
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);
260 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
261 if (hwAdd>fMaxHWAdd) {
262 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
265 fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
266 fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
268 fgMappingIsDone[patch]=kTRUE;
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);
275 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
276 if (hwAdd>fMaxHWAdd) {
277 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
280 fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
281 fgPadMapping5[hwAdd]=pad;
283 fgMappingIsDone[patch]=kTRUE;
292 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
294 // see header file for class documentation
295 assert(fCurrentRowMapping);
296 if (!fCurrentRowMapping) return 0;
297 if (hwadd>fMaxHWAdd) return 0;
298 return fCurrentRowMapping[hwadd];
301 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
303 // see header file for class documentation
304 assert(fCurrentPadMapping);
305 if (!fCurrentPadMapping) return 0;
306 if (hwadd>fMaxHWAdd) return 0;
307 return fCurrentPadMapping[hwadd];
310 UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const
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];
322 Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const
324 // see header file for class documentation
325 //Making mapping arrays for the given patch
328 assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL);
329 if (!rowArray || !padArray || !hwaArray) return kFALSE;
331 memset(rowArray, -1, arraySize*sizeof(rowArray[0]));
332 memset(padArray, -1, arraySize*sizeof(padArray[0]));
333 memset(hwaArray, -1, hwaMappingSize*sizeof(padArray[0]));
337 const char* basePath=getenv("ALICE_ROOT");
339 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
341 inFile.open(filename.Data());
343 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
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);
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);
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;
371 UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd];
372 assert(hwaIndex<hwaMappingSize);
373 if (hwaIndex<hwaMappingSize) {
374 hwaArray[hwaIndex]=hwAdd;
383 Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
385 if (hwadd>fMaxHWAdd){