]>
Commit | Line | Data |
---|---|---|
37ff2dd6 | 1 | // $Id$ |
1b41ab20 | 2 | |
2f09efe8 | 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 | ||
af6a2273 | 21 | // |
22 | // Mapping class fro mapping | |
23 | // from hardware address to geometrical address | |
24 | // | |
25 | // | |
26 | ||
2f09efe8 | 27 | #include "AliHLTPHOSMapper.h" |
7eb756c1 | 28 | #include "unistd.h" |
29 | #include <iostream> | |
37ff2dd6 | 30 | #include "AliHLTPHOSCoordinate.h" |
2f09efe8 | 31 | |
44175a17 | 32 | AliHLTPHOSMapper::AliHLTPHOSMapper(): |
33 | AliHLTCaloMapper(0,"PHOS") | |
f92dcf21 | 34 | ,fIsInitializedMapping(false) |
44175a17 | 35 | ,fModuleId(-1) |
f92dcf21 | 36 | ,fDDLId(-1) |
2f09efe8 | 37 | { |
94594220 | 38 | InitDDLSpecificationMapping(); |
f92dcf21 | 39 | sprintf(fFilepath, "./"); |
2f09efe8 | 40 | } |
41 | ||
c37f821f | 42 | |
43 | AliHLTPHOSMapper::~AliHLTPHOSMapper() | |
2f09efe8 | 44 | { |
a6755e15 | 45 | delete [] fHw2geomapPtr; |
46 | fHw2geomapPtr = 0; | |
c37f821f | 47 | } |
2f09efe8 | 48 | |
44175a17 | 49 | |
50 | Bool_t | |
51 | AliHLTPHOSMapper::InitAltroMapping(const unsigned long specification) | |
c37f821f | 52 | { |
af6a2273 | 53 | // Loads mapping between Altro addresses and geometrical addresses from file |
f137c3c5 | 54 | |
55 | // HLTError("Initialising ALTRO map"); | |
56 | ||
44175a17 | 57 | fDDLId = GetDDLFromSpec(specification); |
58 | Int_t modId = GetModuleFromSpec(specification); | |
af6a2273 | 59 | |
c37f821f | 60 | char *base = getenv("ALICE_ROOT"); |
c37f821f | 61 | |
44175a17 | 62 | if ( base ) |
63 | { | |
64 | if ( modId != fModuleId ) | |
65 | { | |
66 | fModuleId = modId; | |
67 | if ( base ) | |
68 | { | |
69 | sprintf ( fFilepath,"%s/PHOS/mapping/Mod%dRCU0.data", base, GetModuleFromSpec ( specification ) ); | |
70 | int nChannels = 0; | |
71 | int maxaddr = 0; | |
72 | int tmpHwaddr = 0; | |
73 | int tmpZRow = 0; | |
74 | int tmpXCol = 0; | |
75 | int tmpGain = 0; | |
76 | int res = 0; | |
77 | ||
78 | FILE *fp = fopen ( fFilepath, "r" ); | |
79 | if ( fp != 0 ) | |
80 | { | |
81 | res = fscanf ( fp, "%d", &nChannels ); | |
82 | res = fscanf ( fp, "%d", &maxaddr ); | |
83 | if (fHw2geomapPtr) | |
84 | { | |
85 | delete fHw2geomapPtr; | |
86 | } | |
87 | fHw2geomapPtr = new fAltromap[maxaddr +1]; | |
88 | ||
89 | for ( int i=0; i< maxaddr + 1 ; i ++ ) | |
90 | { | |
91 | fHw2geomapPtr[i].fXCol = 0; | |
92 | fHw2geomapPtr[i].fZRow = 0; | |
93 | fHw2geomapPtr[i].fGain = 0; | |
94 | } | |
95 | ||
96 | for ( int i=0; i<nChannels; i ++ ) | |
97 | { | |
98 | res = fscanf ( fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain ); | |
99 | if ( tmpGain < 2 ) | |
100 | { | |
101 | fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol; | |
102 | fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow; | |
103 | fHw2geomapPtr[tmpHwaddr].fGain = tmpGain; | |
104 | } | |
105 | } | |
106 | fIsInitializedMapping = true; | |
107 | fclose ( fp ); | |
108 | } | |
109 | else | |
110 | { | |
111 | fIsInitializedMapping = false; | |
112 | } | |
c37f821f | 113 | } |
2f09efe8 | 114 | } |
115 | } | |
44175a17 | 116 | else |
117 | { | |
8efbf5fe | 118 | fIsInitializedMapping = false; |
44175a17 | 119 | } |
120 | ||
121 | return fIsInitializedMapping; | |
122 | } | |
123 | ||
c37f821f | 124 | |
94594220 | 125 | void |
126 | AliHLTPHOSMapper::InitDDLSpecificationMapping() | |
127 | { | |
44175a17 | 128 | fSpecificationMapPtr = new fDDLSpecificationMap[fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE()]; |
f137c3c5 | 129 | // HLTError("NUMBER OF DDLs: %d, map ptr: %d", fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(), fSpecificationMapPtr); |
44175a17 | 130 | for(Int_t ddl = 0; ddl < fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(); ddl++) |
94594220 | 131 | { |
132 | ||
44175a17 | 133 | fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE(); |
94594220 | 134 | |
135 | if(ddl%4 == 0) | |
136 | { | |
137 | fSpecificationMapPtr[ddl].fRcuX = 0; | |
138 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
139 | } | |
140 | ||
141 | else if(ddl%4 == 1) | |
142 | { | |
947064ec | 143 | fSpecificationMapPtr[ddl].fRcuX = 1; |
144 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
94594220 | 145 | } |
146 | ||
147 | else if( ddl%4 == 2) | |
148 | { | |
947064ec | 149 | fSpecificationMapPtr[ddl].fRcuX = 2; |
94594220 | 150 | fSpecificationMapPtr[ddl].fRcuZ = 0; |
151 | } | |
152 | else | |
153 | { | |
947064ec | 154 | fSpecificationMapPtr[ddl].fRcuX = 3; |
155 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
94594220 | 156 | } |
157 | ||
44175a17 | 158 | fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ); |
f137c3c5 | 159 | fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX); |
160 | ||
94594220 | 161 | } |
162 | } | |
163 | ||
8efbf5fe | 164 | |
165 | bool | |
166 | AliHLTPHOSMapper::GetIsInitializedMapping() | |
167 | { | |
168 | return fIsInitializedMapping; | |
169 | } | |
170 | ||
44175a17 | 171 | Int_t |
172 | AliHLTPHOSMapper::GetChannelID(Int_t hwAddress) | |
8efbf5fe | 173 | { |
f137c3c5 | 174 | |
175 | // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset, | |
176 | // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset, | |
177 | // fHw2geomapPtr[hwAddress].fGain); | |
44175a17 | 178 | return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) | |
f137c3c5 | 179 | |
44175a17 | 180 | ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) | |
181 | (fHw2geomapPtr[hwAddress].fGain << 12) | | |
182 | fSpecificationMapPtr[fDDLId].fModId << 13); | |
8efbf5fe | 183 | } |
94594220 | 184 | |
44175a17 | 185 | Int_t |
186 | AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress) | |
94594220 | 187 | { |
188 | ||
189 | Short_t index = 0; | |
190 | ||
191 | if(specification == 0x00001) index = 0; | |
192 | else if(specification == 0x00002) index = 1; | |
193 | else if(specification == 0x00004) index = 2; | |
194 | else if(specification == 0x00008) index = 3; | |
195 | ||
196 | else if(specification == 0x00010) index = 4; | |
197 | else if(specification == 0x00020) index = 5; | |
198 | else if(specification == 0x00040) index = 6; | |
199 | else if(specification == 0x00080) index = 7; | |
200 | ||
201 | else if(specification == 0x00100) index = 8; | |
202 | else if(specification == 0x00200) index = 9; | |
203 | else if(specification == 0x00400) index = 10; | |
204 | else if(specification == 0x00800) index = 11; | |
205 | ||
206 | else if(specification == 0x01000) index = 12; | |
207 | else if(specification == 0x02000) index = 13; | |
208 | else if(specification == 0x04000) index = 14; | |
209 | else if(specification == 0x08000) index = 15; | |
210 | ||
211 | else if(specification == 0x10000) index = 16; | |
212 | else if(specification == 0x20000) index = 17; | |
213 | else if(specification == 0x40000) index = 18; | |
214 | else if(specification == 0x80000) index = 19; | |
215 | ||
216 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
f137c3c5 | 217 | |
947064ec | 218 | // 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), |
f137c3c5 | 219 | // fHw2geomapPtr[hwAddress].fXCol, |
220 | // fHw2geomapPtr[hwAddress].fZRow, | |
221 | // fHw2geomapPtr[hwAddress].fGain); | |
222 | ||
c67183bb | 223 | /* HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset, |
224 | fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset, | |
225 | fHw2geomapPtr[hwAddress].fGain);*/ | |
f137c3c5 | 226 | // HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset); |
227 | // HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset); | |
94594220 | 228 | return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) | |
229 | ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | | |
230 | (fHw2geomapPtr[hwAddress].fGain << 12) | | |
231 | fSpecificationMapPtr[index].fModId << 13); | |
232 | } | |
233 | ||
37ff2dd6 | 234 | |
235 | ||
44175a17 | 236 | // void |
237 | // AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord) | |
238 | // { | |
239 | // channelCoord[0] = channelId&0x3f; | |
240 | // channelCoord[1] = (channelId >> 6)&0x3f; | |
241 | // channelCoord[2] = (channelId >> 12)&0x1; | |
242 | // channelCoord[3] = (channelId >> 13)&0x1f; | |
243 | // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]); | |
244 | // } | |
245 | // | |
246 | // | |
247 | // | |
248 | // void | |
249 | // AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord) | |
250 | // { | |
251 | // channelCoord.fX = channelId&0x3f; | |
252 | // channelCoord.fZ = (channelId >> 6)&0x3f; | |
253 | // channelCoord.fGain = (channelId >> 12)&0x1; | |
254 | // channelCoord.fModuleId = (channelId >> 13)&0x1f; | |
255 | // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]); | |
256 | // } | |
257 | // | |
258 | // | |
259 | // | |
260 | // void | |
261 | // AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord) | |
262 | // { | |
263 | // channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep; | |
264 | // channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep; | |
265 | // // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]); | |
266 | // } | |
87434909 | 267 | |
268 | Int_t | |
44175a17 | 269 | AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification) |
87434909 | 270 | { |
271 | Int_t index = -1; | |
272 | if(specification == 0x00001) index = 0; | |
273 | else if(specification == 0x00002) index = 1; | |
274 | else if(specification == 0x00004) index = 2; | |
275 | else if(specification == 0x00008) index = 3; | |
276 | ||
277 | else if(specification == 0x00010) index = 4; | |
278 | else if(specification == 0x00020) index = 5; | |
279 | else if(specification == 0x00040) index = 6; | |
280 | else if(specification == 0x00080) index = 7; | |
281 | ||
282 | else if(specification == 0x00100) index = 8; | |
283 | else if(specification == 0x00200) index = 9; | |
284 | else if(specification == 0x00400) index = 10; | |
285 | else if(specification == 0x00800) index = 11; | |
286 | ||
287 | else if(specification == 0x01000) index = 12; | |
288 | else if(specification == 0x02000) index = 13; | |
289 | else if(specification == 0x04000) index = 14; | |
290 | else if(specification == 0x08000) index = 15; | |
291 | ||
292 | else if(specification == 0x10000) index = 16; | |
293 | else if(specification == 0x20000) index = 17; | |
294 | else if(specification == 0x40000) index = 18; | |
295 | else if(specification == 0x80000) index = 19; | |
296 | ||
297 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
298 | ||
299 | return index; | |
300 | } | |
b48632c9 | 301 | |
302 | Int_t | |
44175a17 | 303 | AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification) |
b48632c9 | 304 | { |
305 | Int_t module = -1; | |
306 | ||
307 | if(specification & 0xf) module = 0; | |
308 | else if((specification >> 4) & 0xf) module = 1; | |
309 | else if((specification >> 8) & 0xf) module = 2; | |
310 | else if((specification >> 12) & 0xf) module = 3; | |
311 | else if((specification >> 16) & 0xf) module = 4; | |
312 | ||
313 | else HLTError("Specification 0x%X not consistent with single module in PHOS", specification); | |
314 | ||
315 | return module; | |
316 | } |