]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCMapping.cxx
c91a86547f2a3bdf1c7189e4b3983183e597103e
[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 #if __GNUC__>= 3
31 using namespace std;
32 #endif
33 #include <cassert>
34 #include "AliHLTTPCMapping.h"
35 #include "AliHLTTPCTransform.h"
36
37 ClassImp(AliHLTTPCMapping)
38
39 AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
40   :
41   fCurrentRowMapping(NULL),
42   fCurrentPadMapping(NULL),
43   fNHWAdd(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   switch(patch){
54   case 0:
55     if(!fgMapping0IsDone){
56       memset(fgRowMapping0, 0, fgkMapping0Size*sizeof(UInt_t));
57       memset(fgPadMapping0, 0, fgkMapping0Size*sizeof(UInt_t));
58       InitializeMap(patch);
59     }
60     fCurrentRowMapping=fgRowMapping0;
61     fCurrentPadMapping=fgPadMapping0;
62     fMaxHWAdd=fgkMapping0Size;
63     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
64     break;
65   case 1:
66     if(!fgMapping1IsDone){
67       memset(fgRowMapping1, 0, fgkMapping1Size*sizeof(UInt_t));
68       memset(fgPadMapping1, 0, fgkMapping1Size*sizeof(UInt_t));
69       InitializeMap(patch);
70     }
71     fCurrentRowMapping=fgRowMapping1;
72     fCurrentPadMapping=fgPadMapping1;
73     fMaxHWAdd=fgkMapping1Size;
74     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
75     break;
76   case 2:
77     if(!fgMapping2IsDone){
78       memset(fgRowMapping2, 0, fgkMapping2Size*sizeof(UInt_t));
79       memset(fgPadMapping2, 0, fgkMapping2Size*sizeof(UInt_t));
80       InitializeMap(patch);
81     }
82     fCurrentRowMapping=fgRowMapping2;
83     fCurrentPadMapping=fgPadMapping2;
84     fMaxHWAdd=fgkMapping2Size;
85     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
86     break;
87   case 3:
88     if(!fgMapping3IsDone){
89       memset(fgRowMapping3, 0, fgkMapping3Size*sizeof(UInt_t));
90       memset(fgPadMapping3, 0, fgkMapping3Size*sizeof(UInt_t));
91       InitializeMap(patch);
92     }
93     fCurrentRowMapping=fgRowMapping3;
94     fCurrentPadMapping=fgPadMapping3;
95     fMaxHWAdd=fgkMapping3Size;
96     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
97     break;
98   case 4:
99     if(!fgMapping4IsDone){
100       memset(fgRowMapping4, 0, fgkMapping4Size*sizeof(UInt_t));
101       memset(fgPadMapping4, 0, fgkMapping4Size*sizeof(UInt_t));
102       InitializeMap(patch);
103     }
104     fCurrentRowMapping=fgRowMapping4;
105     fCurrentPadMapping=fgPadMapping4;
106     fMaxHWAdd=fgkMapping4Size;
107     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
108     break;
109   case 5:
110     if(!fgMapping5IsDone){
111       memset(fgRowMapping5, 0, fgkMapping5Size*sizeof(UInt_t));
112       memset(fgPadMapping5, 0, fgkMapping5Size*sizeof(UInt_t));
113       InitializeMap(patch);
114     }
115     fCurrentRowMapping=fgRowMapping5;
116     fCurrentPadMapping=fgPadMapping5;
117     fMaxHWAdd=fgkMapping5Size;
118     fRowOffset=AliHLTTPCTransform::GetFirstRow(patch);
119     break;
120   }
121 }
122
123 Bool_t AliHLTTPCMapping::fgMapping0IsDone=kFALSE;
124 Bool_t AliHLTTPCMapping::fgMapping1IsDone=kFALSE;
125 Bool_t AliHLTTPCMapping::fgMapping2IsDone=kFALSE;
126 Bool_t AliHLTTPCMapping::fgMapping3IsDone=kFALSE;
127 Bool_t AliHLTTPCMapping::fgMapping4IsDone=kFALSE;
128 Bool_t AliHLTTPCMapping::fgMapping5IsDone=kFALSE;
129 UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
130 UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
131 UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
132 UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
133 UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
134 UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
135 UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
136 UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
137 UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
138 UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
139 UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
140 UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
141
142 AliHLTTPCMapping::~AliHLTTPCMapping(){
143   // see header file for class documentation
144 }
145
146 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
147 {
148   // see header file for class documentation
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     fNHWAdd=0;
186     if(inFile >> fNHWAdd){
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(fgkMapping0Size<fMaxHWAdd){
194             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMapping0Size ,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           fgMapping0IsDone=kTRUE;
206           break;
207         case 1:
208           if(fgkMapping1Size<fMaxHWAdd){
209             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMapping1Size ,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           fgMapping1IsDone=kTRUE;
221           break;
222         case 2:
223           if(fgkMapping2Size<fMaxHWAdd){
224             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping2Size ,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           fgMapping2IsDone=kTRUE;
236           break;
237         case 3:
238           if(fgkMapping3Size<fMaxHWAdd){
239             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping3Size ,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           fgMapping3IsDone=kTRUE;
251           break;
252         case 4:
253           if(fgkMapping4Size<fMaxHWAdd){
254             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping4Size ,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           fgMapping4IsDone=kTRUE;
266           break;
267         case 5:
268           if(fgkMapping5Size<fMaxHWAdd){
269             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping5Size ,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           fgMapping5IsDone=kTRUE;
281           break;
282         }
283       }
284     }
285   }
286   inFile.close();
287 }
288
289 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd) const
290 {
291   // see header file for class documentation
292   assert(fCurrentRowMapping);
293   //  assert(hwadd<=fMaxHWAdd);
294   if (!fCurrentRowMapping) return 0;
295   if (hwadd>fMaxHWAdd) return 0;
296   return fCurrentRowMapping[hwadd];
297 }
298
299 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd) const
300 {
301   // see header file for class documentation
302   assert(fCurrentPadMapping);
303   //  assert(hwadd<=fMaxHWAdd);
304   if (!fCurrentPadMapping) return 0;
305   if (hwadd>fMaxHWAdd) return 0;
306   return fCurrentPadMapping[hwadd];
307 }
308
309 Bool_t AliHLTTPCMapping::IsValidHWAddress(UInt_t hwadd) const
310 {
311   if (hwadd>fMaxHWAdd){
312     return kFALSE;
313   }
314   else{
315     return kTRUE;
316   }
317 }