]>
Commit | Line | Data |
---|---|---|
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 | ||
35 | using namespace PhosHLTConst; | |
36 | AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(), | |
37 | fHw2geomapPtr(0), | |
38 | fIsInitializedMapping(false), | |
39 | fSpecificationMapPtr(0) | |
40 | // fPHOSGeometry(0) | |
41 | { | |
42 | InitAltroMapping(); | |
43 | InitDDLSpecificationMapping(); | |
44 | // fPHOSGeometry = new AliPHOSEMCAGeometry(); | |
45 | ||
46 | } | |
47 | ||
48 | ||
49 | AliHLTPHOSMapper::~AliHLTPHOSMapper() | |
50 | { | |
51 | delete [] fHw2geomapPtr; | |
52 | fHw2geomapPtr = 0; | |
53 | } | |
54 | ||
55 | void | |
56 | AliHLTPHOSMapper::InitAltroMapping() | |
57 | { | |
58 | // Loads mapping between Altro addresses and geometrical addresses from file | |
59 | ||
60 | // char filename[256]; | |
61 | char *base = getenv("ALICE_ROOT"); | |
62 | int nChannels = 0; | |
63 | int maxaddr = 0; | |
64 | int tmpHwaddr = 0; | |
65 | int tmpZRow = 0; | |
66 | int tmpXCol = 0; | |
67 | int tmpGain = 0; | |
68 | int res = 0; | |
69 | if(base !=0) | |
70 | { | |
71 | sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base); | |
72 | ||
73 | FILE *fp = fopen(fFilepath, "r"); | |
74 | if(fp != 0) | |
75 | { | |
76 | res = fscanf(fp, "%d", &nChannels); | |
77 | res = fscanf(fp, "%d", &maxaddr); | |
78 | fHw2geomapPtr = new fAltromap[maxaddr +1]; | |
79 | ||
80 | for(int i=0; i< maxaddr + 1 ; i ++) | |
81 | { | |
82 | fHw2geomapPtr[i].fXCol = 0; | |
83 | fHw2geomapPtr[i].fZRow = 0; | |
84 | fHw2geomapPtr[i].fGain = 0; | |
85 | } | |
86 | ||
87 | for(int i=0; i<nChannels; i ++) | |
88 | { | |
89 | res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain); | |
90 | if(tmpGain < 2) | |
91 | { | |
92 | fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol; | |
93 | fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow; | |
94 | fHw2geomapPtr[tmpHwaddr].fGain = tmpGain; | |
95 | } | |
96 | } | |
97 | fIsInitializedMapping = true; | |
98 | fclose(fp); | |
99 | } | |
100 | else | |
101 | { | |
102 | fIsInitializedMapping = false; | |
103 | } | |
104 | } | |
105 | else | |
106 | { | |
107 | fIsInitializedMapping = false; | |
108 | } | |
109 | } | |
110 | ||
111 | void | |
112 | AliHLTPHOSMapper::InitDDLSpecificationMapping() | |
113 | { | |
114 | fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE]; | |
115 | for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++) | |
116 | { | |
117 | ||
118 | fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE; | |
119 | ||
120 | if(ddl%4 == 0) | |
121 | { | |
122 | fSpecificationMapPtr[ddl].fRcuX = 0; | |
123 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
124 | } | |
125 | ||
126 | else if(ddl%4 == 1) | |
127 | { | |
128 | fSpecificationMapPtr[ddl].fRcuX = 1; | |
129 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
130 | } | |
131 | ||
132 | else if( ddl%4 == 2) | |
133 | { | |
134 | fSpecificationMapPtr[ddl].fRcuX = 2; | |
135 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
136 | } | |
137 | else | |
138 | { | |
139 | fSpecificationMapPtr[ddl].fRcuX = 3; | |
140 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
141 | } | |
142 | ||
143 | fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ); | |
144 | fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX); | |
145 | } | |
146 | } | |
147 | ||
148 | ||
149 | bool | |
150 | AliHLTPHOSMapper::GetIsInitializedMapping() | |
151 | { | |
152 | return fIsInitializedMapping; | |
153 | } | |
154 | ||
155 | ||
156 | char* | |
157 | AliHLTPHOSMapper::GetFilePath() | |
158 | { | |
159 | return fFilepath; | |
160 | } | |
161 | ||
162 | UShort_t | |
163 | AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress) | |
164 | { | |
165 | ||
166 | Short_t index = 0; | |
167 | ||
168 | if(specification == 0x00001) index = 0; | |
169 | else if(specification == 0x00002) index = 1; | |
170 | else if(specification == 0x00004) index = 2; | |
171 | else if(specification == 0x00008) index = 3; | |
172 | ||
173 | else if(specification == 0x00010) index = 4; | |
174 | else if(specification == 0x00020) index = 5; | |
175 | else if(specification == 0x00040) index = 6; | |
176 | else if(specification == 0x00080) index = 7; | |
177 | ||
178 | else if(specification == 0x00100) index = 8; | |
179 | else if(specification == 0x00200) index = 9; | |
180 | else if(specification == 0x00400) index = 10; | |
181 | else if(specification == 0x00800) index = 11; | |
182 | ||
183 | else if(specification == 0x01000) index = 12; | |
184 | else if(specification == 0x02000) index = 13; | |
185 | else if(specification == 0x04000) index = 14; | |
186 | else if(specification == 0x08000) index = 15; | |
187 | ||
188 | else if(specification == 0x10000) index = 16; | |
189 | else if(specification == 0x20000) index = 17; | |
190 | else if(specification == 0x40000) index = 18; | |
191 | else if(specification == 0x80000) index = 19; | |
192 | ||
193 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
194 | // 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), | |
195 | // fHw2geomapPtr[hwAddress].fXCol, | |
196 | // fHw2geomapPtr[hwAddress].fZRow, | |
197 | // fHw2geomapPtr[hwAddress].fGain); | |
198 | return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) | | |
199 | ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | | |
200 | (fHw2geomapPtr[hwAddress].fGain << 12) | | |
201 | fSpecificationMapPtr[index].fModId << 13); | |
202 | } | |
203 | ||
204 | void | |
205 | AliHLTPHOSMapper::GetChannelCoord(UShort_t channelId, UShort_t* channelCoord) | |
206 | { | |
207 | channelCoord[0] = channelId&0x3f; | |
208 | channelCoord[1] = (channelId >> 6)&0x3f; | |
209 | channelCoord[2] = (channelId >> 12)&0x1; | |
210 | channelCoord[3] = (channelId >> 13)&0x1f; | |
211 | // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]); | |
212 | } | |
213 | ||
214 | void | |
215 | AliHLTPHOSMapper::GetLocalCoord(UShort_t channelId, Float_t* channelCoord) | |
216 | { | |
217 | channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep; | |
218 | channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep; | |
219 | // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]); | |
220 | } | |
221 | ||
222 | Int_t | |
223 | AliHLTPHOSMapper::GetDDLFromSpec(Int_t specification) | |
224 | { | |
225 | Int_t index = -1; | |
226 | if(specification == 0x00001) index = 0; | |
227 | else if(specification == 0x00002) index = 1; | |
228 | else if(specification == 0x00004) index = 2; | |
229 | else if(specification == 0x00008) index = 3; | |
230 | ||
231 | else if(specification == 0x00010) index = 4; | |
232 | else if(specification == 0x00020) index = 5; | |
233 | else if(specification == 0x00040) index = 6; | |
234 | else if(specification == 0x00080) index = 7; | |
235 | ||
236 | else if(specification == 0x00100) index = 8; | |
237 | else if(specification == 0x00200) index = 9; | |
238 | else if(specification == 0x00400) index = 10; | |
239 | else if(specification == 0x00800) index = 11; | |
240 | ||
241 | else if(specification == 0x01000) index = 12; | |
242 | else if(specification == 0x02000) index = 13; | |
243 | else if(specification == 0x04000) index = 14; | |
244 | else if(specification == 0x08000) index = 15; | |
245 | ||
246 | else if(specification == 0x10000) index = 16; | |
247 | else if(specification == 0x20000) index = 17; | |
248 | else if(specification == 0x40000) index = 18; | |
249 | else if(specification == 0x80000) index = 19; | |
250 | ||
251 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
252 | ||
253 | return index; | |
254 | } |