]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCMapping.cxx
Fixing trigg.class issue
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCMapping.cxx
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 #include <cassert>
31 #include "AliHLTTPCMapping.h"
32 #include "AliHLTTPCTransform.h"
33
34 using namespace std;
35
36 ClassImp(AliHLTTPCMapping)
37
38 AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
39   :
40   fPatch(patch),
41   fCurrentRowMapping(NULL),
42   fCurrentPadMapping(NULL),
43   fNofRows(0),
44   fMaxHWAdd(0),
45   fRowOffset(0)
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
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
57     return;
58   }
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;
74   }
75   fCurrentRowMapping=fgRowMapping[patch];
76   fCurrentPadMapping=fgPadMapping[patch];
77   fMaxHWAdd=fgkMappingSize[patch];
78 }
79
80 Bool_t AliHLTTPCMapping::fgMappingIsDone[fgkNofPatches]={
81   kFALSE,
82   kFALSE,
83   kFALSE,
84   kFALSE,
85   kFALSE,
86   kFALSE
87 };
88
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
96 };
97
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];
116
117 UInt_t* AliHLTTPCMapping::fgRowMapping[fgkNofPatches]={
118   AliHLTTPCMapping::fgRowMapping0,
119   AliHLTTPCMapping::fgRowMapping1,
120   AliHLTTPCMapping::fgRowMapping2,
121   AliHLTTPCMapping::fgRowMapping3,
122   AliHLTTPCMapping::fgRowMapping4,
123   AliHLTTPCMapping::fgRowMapping5
124 };
125
126 UInt_t* AliHLTTPCMapping::fgPadMapping[fgkNofPatches]={
127   AliHLTTPCMapping::fgPadMapping0,
128   AliHLTTPCMapping::fgPadMapping1,
129   AliHLTTPCMapping::fgPadMapping2,
130   AliHLTTPCMapping::fgPadMapping3,
131   AliHLTTPCMapping::fgPadMapping4,
132   AliHLTTPCMapping::fgPadMapping5
133 };
134
135 UInt_t* AliHLTTPCMapping::fgHwaMapping[fgkNofPatches]={
136   AliHLTTPCMapping::fgHwaMapping0,
137   AliHLTTPCMapping::fgHwaMapping1,
138   AliHLTTPCMapping::fgHwaMapping2,
139   AliHLTTPCMapping::fgHwaMapping3,
140   AliHLTTPCMapping::fgHwaMapping4,
141   AliHLTTPCMapping::fgHwaMapping5
142 };
143
144 AliHLTTPCMapping::~AliHLTTPCMapping(){
145   // see header file for class documentation
146 }
147
148 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
149 {
150   // see header file for class documentation
151   // method is deprecated, just kept as history for a while
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{
188     UInt_t nHWAdd=0;
189     if(inFile >> nHWAdd){
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:
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);
198             break;
199           }
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);
203               break;
204             }
205             fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
206             fgPadMapping0[hwAdd]=pad;
207           }
208           fgMappingIsDone[patch]=kTRUE;
209           break;
210         case 1:
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);
213             break;
214           }
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);
218               break;
219             }
220             fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
221             fgPadMapping1[hwAdd]=pad;
222           }
223           fgMappingIsDone[patch]=kTRUE;
224           break;
225         case 2:
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);
228             break;
229           }
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);
233               break;
234             }
235             fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
236             fgPadMapping2[hwAdd]=pad;
237           }
238           fgMappingIsDone[patch]=kTRUE;
239           break;
240         case 3:
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);
243             break;
244           }
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);
248               break;
249             }
250             fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
251             fgPadMapping3[hwAdd]=pad;
252           }
253           fgMappingIsDone[patch]=kTRUE;
254           break;
255         case 4:
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);
258             break;
259           }
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);
263               break;
264             }
265             fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
266             fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
267           }
268           fgMappingIsDone[patch]=kTRUE;
269           break;
270         case 5:
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);
273             break;
274           }
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);
278               break;
279             }
280             fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
281             fgPadMapping5[hwAdd]=pad;
282           }
283           fgMappingIsDone[patch]=kTRUE;
284           break;
285         }
286       }
287     }
288   }
289   inFile.close();
290 }
291
292 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
293 {
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];
299 }
300
301 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
302 {
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];
308 }
309
310 UInt_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
322 Bool_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
331   memset(rowArray, -1, arraySize*sizeof(rowArray[0]));
332   memset(padArray, -1, arraySize*sizeof(padArray[0]));
333   memset(hwaArray, -1, hwaMappingSize*sizeof(padArray[0]));
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
383 Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
384 {
385   if (hwadd>fMaxHWAdd){
386     return kFALSE;
387   }
388   else{
389     return kTRUE;
390   }
391 }