]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - HLT/TPCLib/AliHLTTPCMapping.cxx
Adding helper macro to initialise the environment for dHLT specific work.
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCMapping.cxx
... / ...
CommitLineData
1// $Id$
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
31using namespace std;
32#endif
33#include <cassert>
34#include "AliHLTTPCMapping.h"
35#include "AliHLTTPCTransform.h"
36
37ClassImp(AliHLTTPCMapping)
38
39AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
40 :
41 fPatch(patch),
42 fCurrentRowMapping(NULL),
43 fCurrentPadMapping(NULL),
44 fNofRows(0),
45 fMaxHWAdd(0),
46 fRowOffset(0)
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
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;
71 }
72 fCurrentRowMapping=fgRowMapping[patch];
73 fCurrentPadMapping=fgPadMapping[patch];
74 fMaxHWAdd=fgkMappingSize[patch];
75}
76
77Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
78 kFALSE,
79 kFALSE,
80 kFALSE,
81 kFALSE,
82 kFALSE,
83 kFALSE
84};
85
86const 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
95UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
96UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
97UInt_t AliHLTTPCMapping::fgHwaMapping0[fgkMappingHwaSize];
98UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
99UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
100UInt_t AliHLTTPCMapping::fgHwaMapping1[fgkMappingHwaSize];
101UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
102UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
103UInt_t AliHLTTPCMapping::fgHwaMapping2[fgkMappingHwaSize];
104UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
105UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
106UInt_t AliHLTTPCMapping::fgHwaMapping3[fgkMappingHwaSize];
107UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
108UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
109UInt_t AliHLTTPCMapping::fgHwaMapping4[fgkMappingHwaSize];
110UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
111UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
112UInt_t AliHLTTPCMapping::fgHwaMapping5[fgkMappingHwaSize];
113
114UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
115 AliHLTTPCMapping::fgRowMapping0,
116 AliHLTTPCMapping::fgRowMapping1,
117 AliHLTTPCMapping::fgRowMapping2,
118 AliHLTTPCMapping::fgRowMapping3,
119 AliHLTTPCMapping::fgRowMapping4,
120 AliHLTTPCMapping::fgRowMapping5
121};
122
123UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
124 AliHLTTPCMapping::fgPadMapping0,
125 AliHLTTPCMapping::fgPadMapping1,
126 AliHLTTPCMapping::fgPadMapping2,
127 AliHLTTPCMapping::fgPadMapping3,
128 AliHLTTPCMapping::fgPadMapping4,
129 AliHLTTPCMapping::fgPadMapping5
130};
131
132UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
133 AliHLTTPCMapping::fgHwaMapping0,
134 AliHLTTPCMapping::fgHwaMapping1,
135 AliHLTTPCMapping::fgHwaMapping2,
136 AliHLTTPCMapping::fgHwaMapping3,
137 AliHLTTPCMapping::fgHwaMapping4,
138 AliHLTTPCMapping::fgHwaMapping5
139};
140
141AliHLTTPCMapping::~AliHLTTPCMapping(){
142 // see header file for class documentation
143}
144
145void AliHLTTPCMapping::InitializeMap(UInt_t patch)
146{
147 // see header file for class documentation
148 // method is deprecated, just kept as history for a while
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{
185 UInt_t nHWAdd=0;
186 if(inFile >> nHWAdd){
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:
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);
195 break;
196 }
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);
200 break;
201 }
202 fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
203 fgPadMapping0[hwAdd]=pad;
204 }
205 fgMappingIsDone[patch]=kTRUE;
206 break;
207 case 1:
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);
210 break;
211 }
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);
215 break;
216 }
217 fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
218 fgPadMapping1[hwAdd]=pad;
219 }
220 fgMappingIsDone[patch]=kTRUE;
221 break;
222 case 2:
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);
225 break;
226 }
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);
230 break;
231 }
232 fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
233 fgPadMapping2[hwAdd]=pad;
234 }
235 fgMappingIsDone[patch]=kTRUE;
236 break;
237 case 3:
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);
240 break;
241 }
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);
245 break;
246 }
247 fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
248 fgPadMapping3[hwAdd]=pad;
249 }
250 fgMappingIsDone[patch]=kTRUE;
251 break;
252 case 4:
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);
255 break;
256 }
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);
260 break;
261 }
262 fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
263 fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
264 }
265 fgMappingIsDone[patch]=kTRUE;
266 break;
267 case 5:
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);
270 break;
271 }
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);
275 break;
276 }
277 fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
278 fgPadMapping5[hwAdd]=pad;
279 }
280 fgMappingIsDone[patch]=kTRUE;
281 break;
282 }
283 }
284 }
285 }
286 inFile.close();
287}
288
289UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
290{
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];
296}
297
298UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
299{
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];
305}
306
307UInt_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
319Bool_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
380Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
381{
382 if (hwadd>fMaxHWAdd){
383 return kFALSE;
384 }
385 else{
386 return kTRUE;
387 }
388}