]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCMapping.cxx
code documentation
[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
36 ClassImp(AliHLTTPCMapping)
37
38 AliHLTTPCMapping::AliHLTTPCMapping(UInt_t patch)
39   :
40   fNHWAdd(0),
41   fMaxHWAdd(0),
42   fCurrentRowMapping(NULL),
43   fCurrentPadMapping(NULL)
44 {
45   // see header file for class documentation
46   // or
47   // refer to README to build package
48   // or
49   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50
51   switch(patch){
52   case 0:
53     if(!fMapping0IsDone){
54       memset(fgRowMapping0, 0, fgkMapping0Size*sizeof(UInt_t));
55       memset(fgPadMapping0, 0, fgkMapping0Size*sizeof(UInt_t));
56       InitializeMap(patch);
57     }
58     fCurrentRowMapping=fgRowMapping0;
59     fCurrentPadMapping=fgPadMapping0;
60     break;
61   case 1:
62     if(!fMapping1IsDone){
63       memset(fgRowMapping1, 0, fgkMapping1Size*sizeof(UInt_t));
64       memset(fgPadMapping1, 0, fgkMapping1Size*sizeof(UInt_t));
65       InitializeMap(patch);
66     }
67     fCurrentRowMapping=fgRowMapping1;
68     fCurrentPadMapping=fgPadMapping1;
69     break;
70   case 2:
71     if(!fMapping2IsDone){
72       memset(fgRowMapping2, 0, fgkMapping2Size*sizeof(UInt_t));
73       memset(fgPadMapping2, 0, fgkMapping2Size*sizeof(UInt_t));
74       InitializeMap(patch);
75     }
76     fCurrentRowMapping=fgRowMapping2;
77     fCurrentPadMapping=fgPadMapping2;
78     break;
79   case 3:
80     if(!fMapping3IsDone){
81       memset(fgRowMapping3, 0, fgkMapping3Size*sizeof(UInt_t));
82       memset(fgPadMapping3, 0, fgkMapping3Size*sizeof(UInt_t));
83       InitializeMap(patch);
84     }
85     fCurrentRowMapping=fgRowMapping3;
86     fCurrentPadMapping=fgPadMapping3;
87     break;
88   case 4:
89     if(!fMapping4IsDone){
90       memset(fgRowMapping4, 0, fgkMapping4Size*sizeof(UInt_t));
91       memset(fgPadMapping4, 0, fgkMapping4Size*sizeof(UInt_t));
92       InitializeMap(patch);
93     }
94     fCurrentRowMapping=fgRowMapping4;
95     fCurrentPadMapping=fgPadMapping4;
96     break;
97   case 5:
98     if(!fMapping5IsDone){
99       memset(fgRowMapping5, 0, fgkMapping5Size*sizeof(UInt_t));
100       memset(fgPadMapping5, 0, fgkMapping5Size*sizeof(UInt_t));
101       InitializeMap(patch);
102     }
103     fCurrentRowMapping=fgRowMapping5;
104     fCurrentPadMapping=fgPadMapping5;
105     break;
106   }
107 }
108
109 Bool_t AliHLTTPCMapping::fMapping0IsDone=kFALSE;
110 Bool_t AliHLTTPCMapping::fMapping1IsDone=kFALSE;
111 Bool_t AliHLTTPCMapping::fMapping2IsDone=kFALSE;
112 Bool_t AliHLTTPCMapping::fMapping3IsDone=kFALSE;
113 Bool_t AliHLTTPCMapping::fMapping4IsDone=kFALSE;
114 Bool_t AliHLTTPCMapping::fMapping5IsDone=kFALSE;
115 UInt_t AliHLTTPCMapping::fgRowMapping0[fgkMapping0Size];
116 UInt_t AliHLTTPCMapping::fgPadMapping0[fgkMapping0Size];
117 UInt_t AliHLTTPCMapping::fgRowMapping1[fgkMapping1Size];
118 UInt_t AliHLTTPCMapping::fgPadMapping1[fgkMapping1Size];
119 UInt_t AliHLTTPCMapping::fgRowMapping2[fgkMapping2Size];
120 UInt_t AliHLTTPCMapping::fgPadMapping2[fgkMapping2Size];
121 UInt_t AliHLTTPCMapping::fgRowMapping3[fgkMapping3Size];
122 UInt_t AliHLTTPCMapping::fgPadMapping3[fgkMapping3Size];
123 UInt_t AliHLTTPCMapping::fgRowMapping4[fgkMapping4Size];
124 UInt_t AliHLTTPCMapping::fgPadMapping4[fgkMapping4Size];
125 UInt_t AliHLTTPCMapping::fgRowMapping5[fgkMapping5Size];
126 UInt_t AliHLTTPCMapping::fgPadMapping5[fgkMapping5Size];
127
128 AliHLTTPCMapping::~AliHLTTPCMapping(){
129   // see header file for class documentation
130 }
131
132 void AliHLTTPCMapping::InitializeMap(UInt_t patch)
133 {
134   // see header file for class documentation
135
136   UInt_t fNRowsToSubtract=0;
137   //The row numbers returned by digit readers used are not from zero always
138   switch(patch){
139   case 0:
140     fNRowsToSubtract=0;
141     break;
142   case 1:
143     fNRowsToSubtract=30;
144     break;
145   case 2:
146     fNRowsToSubtract=0;
147     break;
148   case 3:
149     fNRowsToSubtract=27;
150     break;
151   case 4:
152     fNRowsToSubtract=54;
153     break;
154   case 5:
155     fNRowsToSubtract=76;
156     break;
157   }
158
159   //Making mapping arrays for the given patch
160   ifstream inFile;
161   TString filename;
162   const char* basePath=getenv("ALICE_ROOT");
163   if (basePath) {
164     filename.Form("%s/TPC/mapping/Patch%d.data", basePath,patch);
165   }
166   inFile.open(filename.Data());
167   if (!inFile) {
168     HLTFatal("Unable to open file: %s      This means no mapping is provided.", filename.Data());
169   }
170   else{
171     fNHWAdd=0;
172     if(inFile >> fNHWAdd){
173       if(inFile >> fMaxHWAdd){
174         UInt_t hwAdd=0;
175         UInt_t row=0;
176         UInt_t pad=0;
177         switch(patch){
178         case 0:
179           if(fgkMapping0Size<fMaxHWAdd){
180             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMapping0Size ,fMaxHWAdd);
181             break;
182           }
183           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
184             if (hwAdd>fMaxHWAdd) {
185               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
186               break;
187             }
188             fgRowMapping0[hwAdd]=row-fNRowsToSubtract;
189             fgPadMapping0[hwAdd]=pad;
190           }
191           fMapping0IsDone=kTRUE;
192           break;
193         case 1:
194           if(fgkMapping1Size<fMaxHWAdd){
195             HLTFatal("Max hardware address exceeded for patch %d, max number is %d, number from mapping file is %d.",patch,fgkMapping1Size ,fMaxHWAdd);
196             break;
197           }
198           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
199             if (hwAdd>fMaxHWAdd) {
200               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
201               break;
202             }
203             fgRowMapping1[hwAdd]=row-fNRowsToSubtract;
204             fgPadMapping1[hwAdd]=pad;
205           }
206           fMapping1IsDone=kTRUE;
207           break;
208         case 2:
209           if(fgkMapping2Size<fMaxHWAdd){
210             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping2Size ,fMaxHWAdd);
211             break;
212           }
213           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
214             if (hwAdd>fMaxHWAdd) {
215               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
216               break;
217             }
218             fgRowMapping2[hwAdd]=row-fNRowsToSubtract;
219             fgPadMapping2[hwAdd]=pad;
220           }
221           fMapping2IsDone=kTRUE;
222           break;
223         case 3:
224           if(fgkMapping3Size<fMaxHWAdd){
225             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping3Size ,fMaxHWAdd);
226             break;
227           }
228           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
229             if (hwAdd>fMaxHWAdd) {
230               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
231               break;
232             }
233             fgRowMapping3[hwAdd]=row-fNRowsToSubtract;
234             fgPadMapping3[hwAdd]=pad;
235           }
236           fMapping3IsDone=kTRUE;
237           break;
238         case 4:
239           if(fgkMapping4Size<fMaxHWAdd){
240             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping4Size ,fMaxHWAdd);
241             break;
242           }
243           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
244             if (hwAdd>fMaxHWAdd) {
245               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
246               break;
247             }
248             fgRowMapping4[hwAdd]=row-fNRowsToSubtract;
249             fgPadMapping4[(UInt_t)hwAdd]=(UInt_t)pad;
250           }
251           fMapping4IsDone=kTRUE;
252           break;
253         case 5:
254           if(fgkMapping5Size<fMaxHWAdd){
255             HLTFatal("Max hardware address exceeded for patch %d, max number is %d number from mapping file is %d.",patch,fgkMapping5Size ,fMaxHWAdd);
256             break;
257           }
258           while(inFile>>hwAdd && inFile>>row && inFile>>pad){
259             if (hwAdd>fMaxHWAdd) {
260               HLTFatal("hardware address exceeds max hwAddress %d, mapping file %s corrupted?", fMaxHWAdd);
261               break;
262             }
263             fgRowMapping5[hwAdd]=row-fNRowsToSubtract;
264             fgPadMapping5[hwAdd]=pad;
265           }
266           fMapping5IsDone=kTRUE;
267           break;
268         }
269       }
270     }
271   }
272   inFile.close();
273 }
274
275 UInt_t AliHLTTPCMapping::GetRow(UInt_t hwadd)
276 {
277   // see header file for class documentation
278   assert(fCurrentRowMapping);
279   assert(hwadd<=fMaxHWAdd);
280   if (!fCurrentRowMapping) return 0;
281   if (hwadd>fMaxHWAdd) return 0;
282   return fCurrentRowMapping[hwadd];
283 }
284
285 UInt_t AliHLTTPCMapping::GetPad(UInt_t hwadd)
286 {
287   // see header file for class documentation
288   assert(fCurrentPadMapping);
289   assert(hwadd<=fMaxHWAdd);
290   if (!fCurrentPadMapping) return 0;
291   if (hwadd>fMaxHWAdd) return 0;
292   return fCurrentPadMapping[hwadd];
293 }