]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
- addign classes to the build system
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the Experimental Nuclear     *
5  * Physics Group, Dep. of Physics                                         *
6  * University of Oslo, Norway, 2006                                       *
7  *                                                                        * 
8  * Author: Per Thomas Hille perthi@fys.uio.no for the ALICE DCS Project.  *
9  * Contributors are mentioned in the code where appropriate.              *
10  * Please report bugs to perthi@fys.uio.no                                * 
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          *
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21 //
22 // Mapping class fro mapping
23 // from hardware address to geometrical address
24 //
25 //
26
27 #include "AliPHOSEMCAGeometry.h"
28 #include "AliHLTPHOSMapper.h"
29 #include "AliHLTPHOSConstants.h"
30 #include "AliHLTLogging.h"
31 #include "Rtypes.h"
32 #include "unistd.h"
33 #include <iostream>
34 #include "AliHLTPHOSCoordinate.h"
35
36 using namespace PhosHLTConst;
37 AliHLTPHOSMapper::AliHLTPHOSMapper():  AliHLTLogging(), 
38                                        fHw2geomapPtr(0),
39                                        fIsInitializedMapping(false),
40                                        fSpecificationMapPtr(0)
41                                        //                              fPHOSGeometry(0)
42 {
43   InitAltroMapping(); 
44   InitDDLSpecificationMapping();
45   //  fPHOSGeometry = new AliPHOSEMCAGeometry();
46
47 }
48
49
50 AliHLTPHOSMapper::~AliHLTPHOSMapper()
51 {
52   delete []  fHw2geomapPtr;
53   fHw2geomapPtr = 0;
54 }
55
56 void
57 AliHLTPHOSMapper::InitAltroMapping()
58 {
59   // Loads mapping between Altro addresses and geometrical addresses from file
60
61   //  char filename[256];
62   char *base =  getenv("ALICE_ROOT");
63   int nChannels = 0;
64   int maxaddr = 0;
65   int tmpHwaddr = 0;
66   int tmpZRow = 0;
67   int tmpXCol = 0;
68   int tmpGain = 0;
69   int res = 0; 
70   if(base !=0)
71     {
72       sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
73       
74       FILE *fp = fopen(fFilepath, "r");
75       if(fp != 0)
76         {
77           res = fscanf(fp, "%d", &nChannels);
78           res = fscanf(fp, "%d", &maxaddr);
79           fHw2geomapPtr = new fAltromap[maxaddr +1]; 
80
81           for(int i=0; i< maxaddr + 1 ; i ++)
82             {
83               fHw2geomapPtr[i].fXCol = 0;
84               fHw2geomapPtr[i].fZRow = 0;
85               fHw2geomapPtr[i].fGain = 0;
86             }
87
88           for(int i=0; i<nChannels; i ++)
89             {
90               res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain);
91               if(tmpGain < 2)
92                 {
93                   fHw2geomapPtr[tmpHwaddr].fXCol   = tmpXCol;
94                   fHw2geomapPtr[tmpHwaddr].fZRow   = tmpZRow;
95                   fHw2geomapPtr[tmpHwaddr].fGain  = tmpGain;
96                 } 
97             }
98           fIsInitializedMapping = true;   
99           fclose(fp);
100         }
101       else
102         {
103           fIsInitializedMapping = false;          
104         }
105     }
106   else
107     {
108       fIsInitializedMapping = false;
109     }
110
111
112 void
113 AliHLTPHOSMapper::InitDDLSpecificationMapping()
114 {
115   fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
116   for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
117     {
118       
119       fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
120       
121       if(ddl%4 == 0)
122         {
123           fSpecificationMapPtr[ddl].fRcuX = 0; 
124           fSpecificationMapPtr[ddl].fRcuZ = 0;
125         }
126       
127       else if(ddl%4 == 1)
128         {
129           fSpecificationMapPtr[ddl].fRcuX = 1; 
130           fSpecificationMapPtr[ddl].fRcuZ = 0;
131         }
132       
133       else if( ddl%4 == 2)
134         {
135           fSpecificationMapPtr[ddl].fRcuX = 2; 
136           fSpecificationMapPtr[ddl].fRcuZ = 0;
137         }
138       else
139         {
140           fSpecificationMapPtr[ddl].fRcuX = 3; 
141           fSpecificationMapPtr[ddl].fRcuZ = 0;
142         }
143       
144       fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
145       fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
146     }
147 }
148
149
150 bool 
151 AliHLTPHOSMapper::GetIsInitializedMapping()
152 {
153   return  fIsInitializedMapping;
154 }
155
156
157 char* 
158 AliHLTPHOSMapper::GetFilePath()
159 {
160   return  fFilepath;
161 }
162
163 UShort_t
164 AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
165 {
166   
167   Short_t index = 0;
168
169   if(specification == 0x00001) index = 0;
170   else if(specification == 0x00002) index = 1;
171   else if(specification == 0x00004) index = 2;
172   else if(specification == 0x00008) index = 3;
173
174   else if(specification == 0x00010) index = 4;
175   else if(specification == 0x00020) index = 5;
176   else if(specification == 0x00040) index = 6;
177   else if(specification == 0x00080) index = 7;
178
179   else if(specification == 0x00100) index = 8;
180   else if(specification == 0x00200) index = 9;
181   else if(specification == 0x00400) index = 10;
182   else if(specification == 0x00800) index = 11;
183
184   else if(specification == 0x01000) index = 12;
185   else if(specification == 0x02000) index = 13;
186   else if(specification == 0x04000) index = 14;
187   else if(specification == 0x08000) index = 15;
188
189   else if(specification == 0x10000) index = 16;
190   else if(specification == 0x20000) index = 17;
191   else if(specification == 0x40000) index = 18;
192   else if(specification == 0x80000) index = 19;
193
194   else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
195   //  HLTError("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d", ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | (fHw2geomapPtr[hwAddress].fGain << 12) | fSpecificationMapPtr[index].fModId << 13),
196   //       fHw2geomapPtr[hwAddress].fXCol,
197   //       fHw2geomapPtr[hwAddress].fZRow, 
198   //       fHw2geomapPtr[hwAddress].fGain);
199   return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
200           ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
201           (fHw2geomapPtr[hwAddress].fGain << 12) |
202           fSpecificationMapPtr[index].fModId << 13);
203 }
204
205
206
207 void
208 AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
209 {
210   channelCoord[0] = channelId&0x3f;
211   channelCoord[1] = (channelId >> 6)&0x3f;
212   channelCoord[2] = (channelId >> 12)&0x1;
213   channelCoord[3] = (channelId >> 13)&0x1f;
214   //  printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
215 }
216
217
218
219 void
220 //AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId,    &AliHLTPHOSCoordinate channelCoord)
221 AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId,    AliHLTPHOSCoordinate &channelCoord)
222 {
223   channelCoord.fX = channelId&0x3f;
224   channelCoord.fZ = (channelId >> 6)&0x3f;
225   channelCoord.fGain = (channelId >> 12)&0x1;
226   channelCoord.fModuleId  = (channelId >> 13)&0x1f;
227   //  printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
228 }
229
230
231
232 void
233 AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
234 {
235   channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
236   channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
237   //  printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
238 }
239
240 Int_t 
241 AliHLTPHOSMapper::GetDDLFromSpec(Int_t specification)
242 {
243   Int_t index = -1;
244   if(specification == 0x00001) index = 0;
245   else if(specification == 0x00002) index = 1;
246   else if(specification == 0x00004) index = 2;
247   else if(specification == 0x00008) index = 3;
248
249   else if(specification == 0x00010) index = 4;
250   else if(specification == 0x00020) index = 5;
251   else if(specification == 0x00040) index = 6;
252   else if(specification == 0x00080) index = 7;
253
254   else if(specification == 0x00100) index = 8;
255   else if(specification == 0x00200) index = 9;
256   else if(specification == 0x00400) index = 10;
257   else if(specification == 0x00800) index = 11;
258
259   else if(specification == 0x01000) index = 12;
260   else if(specification == 0x02000) index = 13;
261   else if(specification == 0x04000) index = 14;
262   else if(specification == 0x08000) index = 15;
263
264   else if(specification == 0x10000) index = 16;
265   else if(specification == 0x20000) index = 17;
266   else if(specification == 0x40000) index = 18;
267   else if(specification == 0x80000) index = 19;
268
269   else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
270
271   return index;
272 }
273
274 Int_t 
275 AliHLTPHOSMapper::GetModuleFromSpec(Int_t specification)
276 {
277   Int_t module = -1;
278       
279   if(specification & 0xf) module = 0;
280   else if((specification >> 4) & 0xf) module = 1;
281   else if((specification >> 8) & 0xf) module = 2;
282   else if((specification >> 12) & 0xf) module = 3;
283   else if((specification >> 16) & 0xf) module = 4;
284  
285   else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);
286
287   return module;
288 }