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