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) {
56 HLTFatal("invalid partition number %d, allowed range [0,%d]", patch, fgkNofPatches-1);
57 fPatch=0; // just to avoid boundary overflow
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);
72 if(!fgMappingIsDone[patch]){
73 ReadArray(patch, fgkMappingSize[patch], fgRowMapping[patch], fgPadMapping[patch], fgkMappingHwaSize, fgHwaMapping[patch]);
74 fgMappingIsDone[patch]=kTRUE;
76 fCurrentRowMapping=fgRowMapping[patch];
77 fCurrentPadMapping=fgPadMapping[patch];
78 fMaxHWAdd=fgkMappingSize[patch];
81 Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
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
99 UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
100 UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
101 UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize];
102 UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
103 UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
104 UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize];
105 UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
106 UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
107 UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize];
108 UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
109 UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
110 UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize];
111 UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
112 UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
113 UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize];
114 UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
115 UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
116 UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize];
118 UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
119 AliHLTTPCMapping::fgRowMapping0,
120 AliHLTTPCMapping::fgRowMapping1,
121 AliHLTTPCMapping::fgRowMapping2,
122 AliHLTTPCMapping::fgRowMapping3,
123 AliHLTTPCMapping::fgRowMapping4,
124 AliHLTTPCMapping::fgRowMapping5
127 UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
128 AliHLTTPCMapping::fgPadMapping0,
129 AliHLTTPCMapping::fgPadMapping1,
130 AliHLTTPCMapping::fgPadMapping2,
131 AliHLTTPCMapping::fgPadMapping3,
132 AliHLTTPCMapping::fgPadMapping4,
133 AliHLTTPCMapping::fgPadMapping5
136 UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
137 AliHLTTPCMapping::fgHwaMapping0,
138 AliHLTTPCMapping::fgHwaMapping1,
139 AliHLTTPCMapping::fgHwaMapping2,
140 AliHLTTPCMapping::fgHwaMapping3,
141 AliHLTTPCMapping::fgHwaMapping4,
142 AliHLTTPCMapping::fgHwaMapping5
145 AliHLTTPCMapping::~AliHLTTPCMapping(){
146 // see header file for class documentation
149 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
151 // see header file for class documentation
152 // method is deprecated, just kept as history for a while
154 UInt_t fNRowsToSubtract=0;
155 //The row numbers returned by digit readers used are not from zero always
177 //Making mapping arrays for the given patch
180 const char* basePath=getenv("ALICE_ROOT");
182 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
184 inFile.open(filename.Data());
186 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
190 if(inFile >> nHWAdd){
191 if(inFile >> fMaxHWAdd){
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);
201 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
202 if (hwAdd>fMaxHWAdd) {
203 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
206 fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
207 fgPadMapping0[hwAdd]=pad;
209 fgMappingIsDone[patch]=kTRUE;
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);
216 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
217 if (hwAdd>fMaxHWAdd) {
218 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
221 fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
222 fgPadMapping1[hwAdd]=pad;
224 fgMappingIsDone[patch]=kTRUE;
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);
231 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
232 if (hwAdd>fMaxHWAdd) {
233 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
236 fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
237 fgPadMapping2[hwAdd]=pad;
239 fgMappingIsDone[patch]=kTRUE;
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);
246 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
247 if (hwAdd>fMaxHWAdd) {
248 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
251 fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
252 fgPadMapping3[hwAdd]=pad;
254 fgMappingIsDone[patch]=kTRUE;
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);
261 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
262 if (hwAdd>fMaxHWAdd) {
263 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
266 fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
267 fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
269 fgMappingIsDone[patch]=kTRUE;
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);
276 while(inFile>>hwAdd && inFile>>row && inFile>>pad){
277 if (hwAdd>fMaxHWAdd) {
278 HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
281 fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
282 fgPadMapping5[hwAdd]=pad;
284 fgMappingIsDone[patch]=kTRUE;
293 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
295 // see header file for class documentation
296 assert(fCurrentRowMapping);
297 if (!fCurrentRowMapping) return 0;
298 if (hwadd>fMaxHWAdd) return 0;
299 return fCurrentRowMapping[hwadd];
302 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
304 // see header file for class documentation
305 assert(fCurrentPadMapping);
306 if (!fCurrentPadMapping) return 0;
307 if (hwadd>fMaxHWAdd) return 0;
308 return fCurrentPadMapping[hwadd];
311 UInt_t AliHLTTPCMapping::GetHwAddress(UInt_t row, UInt_t pad) const
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];
323 Bool_t AliHLTTPCMapping::ReadArray(UInt_t patch, UInt_t arraySize, UInt_t rowArray[], UInt_t padArray[], UInt_t hwaMappingSize, UInt_t hwaArray[]) const
325 // see header file for class documentation
326 //Making mapping arrays for the given patch
329 assert(rowArray!=NULL || padArray!=NULL || hwaArray!=NULL);
330 if (!rowArray || !padArray || !hwaArray) return kFALSE;
332 memset(rowArray, -1, arraySize*sizeof(rowArray[0]));
333 memset(padArray, -1, arraySize*sizeof(padArray[0]));
334 memset(hwaArray, -1, hwaMappingSize*sizeof(padArray[0]));
338 const char* basePath=getenv("ALICE_ROOT");
340 filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
342 inFile.open(filename.Data());
344 HLTFatal("Unable to open file: %s This means no mapping is provided.", filename.Data());
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);
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);
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;
372 UInt_t hwaIndex=(rowArray[hwAdd]<<fgkMappingHwaRowBitShift) + padArray[hwAdd];
373 assert(hwaIndex<hwaMappingSize);
374 if (hwaIndex<hwaMappingSize) {
375 hwaArray[hwaIndex]=hwAdd;
384 Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
386 if (hwadd>fMaxHWAdd){