]>
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())); |
c37f821f | 76 | |
dc1902d2 | 77 | if ( modId != fModuleId ) |
44175a17 | 78 | { |
dc1902d2 | 79 | fModuleId = modId; |
80 | ||
81 | // int nChannels = 0; | |
07cc3302 | 82 | int maxaddr = fCaloConstants->GetMAXHWADDRESSES(); |
dc1902d2 | 83 | //int tmpHwaddr = 0; |
84 | //int tmpZRow = 0; | |
85 | //int tmpXCol = 0; | |
86 | //int tmpGain = 0; | |
87 | // int res = 0; | |
88 | if (fHw2geomapPtr) | |
89 | { | |
07cc3302 | 90 | delete [] fHw2geomapPtr; |
dc1902d2 | 91 | } |
92 | fHw2geomapPtr = new fAltromap[maxaddr]; | |
07cc3302 | 93 | Int_t hwAdds[maxaddr]; |
dc1902d2 | 94 | Int_t nCh = 0; |
95 | for (int x = 0; x < fCaloConstants->GetNXCOLUMNSRCU(); x++) | |
96 | { | |
97 | for (int z = 0; z < fCaloConstants->GetNZROWSRCU(); z++) | |
98 | { | |
99 | for(int g = 0; g < fCaloConstants->GetNGAINS(); g++) | |
100 | { | |
101 | hwAdds[nCh] = map->GetHWAddress(x, z, g); | |
102 | nCh++; | |
103 | } | |
104 | } | |
105 | } | |
106 | for ( int i=0; i < nCh; i ++ ) | |
44175a17 | 107 | { |
dc1902d2 | 108 | Int_t add = hwAdds[i]; |
109 | if (map->GetSector(add) < 2) | |
44175a17 | 110 | { |
dc1902d2 | 111 | fHw2geomapPtr[add].fXCol = map->GetPadRow(add); |
112 | fHw2geomapPtr[add].fZRow = map->GetPad(add); | |
113 | fHw2geomapPtr[add].fGain = map->GetSector(add); | |
114 | } | |
115 | } | |
116 | fIsInitializedMapping = true; | |
2f09efe8 | 117 | } |
dc1902d2 | 118 | else |
119 | { | |
120 | fIsInitializedMapping = false; | |
121 | } | |
122 | ||
123 | return fIsInitializedMapping; | |
44175a17 | 124 | } |
dc1902d2 | 125 | |
c37f821f | 126 | |
94594220 | 127 | void |
128 | AliHLTPHOSMapper::InitDDLSpecificationMapping() | |
129 | { | |
dc1902d2 | 130 | fSpecificationMapPtr = new fDDLSpecificationMap[fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE()]; |
131 | // HLTError("NUMBER OF DDLs: %d, map ptr: %d", fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(), fSpecificationMapPtr); | |
132 | for (Int_t ddl = 0; ddl < fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(); ddl++) | |
94594220 | 133 | { |
dc1902d2 | 134 | |
135 | fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE(); | |
136 | ||
137 | if (ddl%4 == 0) | |
138 | { | |
139 | fSpecificationMapPtr[ddl].fRcuX = 0; | |
140 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
141 | } | |
142 | ||
143 | else if (ddl%4 == 1) | |
144 | { | |
145 | fSpecificationMapPtr[ddl].fRcuX = 1; | |
146 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
147 | } | |
148 | ||
149 | else if ( ddl%4 == 2) | |
150 | { | |
151 | fSpecificationMapPtr[ddl].fRcuX = 2; | |
152 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
153 | } | |
154 | else | |
155 | { | |
156 | fSpecificationMapPtr[ddl].fRcuX = 3; | |
157 | fSpecificationMapPtr[ddl].fRcuZ = 0; | |
158 | } | |
159 | ||
160 | fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ); | |
161 | fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX); | |
f137c3c5 | 162 | |
94594220 | 163 | } |
164 | } | |
165 | ||
8efbf5fe | 166 | |
dc1902d2 | 167 | bool |
8efbf5fe | 168 | AliHLTPHOSMapper::GetIsInitializedMapping() |
169 | { | |
dc1902d2 | 170 | return fIsInitializedMapping; |
8efbf5fe | 171 | } |
172 | ||
44175a17 | 173 | Int_t |
174 | AliHLTPHOSMapper::GetChannelID(Int_t hwAddress) | |
8efbf5fe | 175 | { |
dc1902d2 | 176 | if (!fDDLMapInitialised) InitDDLSpecificationMapping(); |
f137c3c5 | 177 | |
dc1902d2 | 178 | // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset, |
179 | // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset, | |
180 | // fHw2geomapPtr[hwAddress].fGain); | |
181 | return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) | | |
f137c3c5 | 182 | |
dc1902d2 | 183 | ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) | |
184 | (fHw2geomapPtr[hwAddress].fGain << 12) | | |
185 | fSpecificationMapPtr[fDDLId].fModId << 13); | |
8efbf5fe | 186 | } |
94594220 | 187 | |
44175a17 | 188 | Int_t |
189 | AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress) | |
94594220 | 190 | { |
7ac2a5ea | 191 | |
dc1902d2 | 192 | if (!fDDLMapInitialised) InitDDLSpecificationMapping(); |
193 | ||
194 | Short_t index = 0; | |
195 | ||
196 | if (specification == 0x00001) index = 0; | |
197 | else if (specification == 0x00002) index = 1; | |
198 | else if (specification == 0x00004) index = 2; | |
199 | else if (specification == 0x00008) index = 3; | |
200 | ||
201 | else if (specification == 0x00010) index = 4; | |
202 | else if (specification == 0x00020) index = 5; | |
203 | else if (specification == 0x00040) index = 6; | |
204 | else if (specification == 0x00080) index = 7; | |
205 | ||
206 | else if (specification == 0x00100) index = 8; | |
207 | else if (specification == 0x00200) index = 9; | |
208 | else if (specification == 0x00400) index = 10; | |
209 | else if (specification == 0x00800) index = 11; | |
210 | ||
211 | else if (specification == 0x01000) index = 12; | |
212 | else if (specification == 0x02000) index = 13; | |
213 | else if (specification == 0x04000) index = 14; | |
214 | else if (specification == 0x08000) index = 15; | |
215 | ||
216 | else if (specification == 0x10000) index = 16; | |
217 | else if (specification == 0x20000) index = 17; | |
218 | else if (specification == 0x40000) index = 18; | |
219 | else if (specification == 0x80000) index = 19; | |
220 | ||
221 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
222 | ||
223 | // 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), | |
224 | // fHw2geomapPtr[hwAddress].fXCol, | |
225 | // fHw2geomapPtr[hwAddress].fZRow, | |
226 | // fHw2geomapPtr[hwAddress].fGain); | |
227 | ||
228 | /* HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset, | |
229 | fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset, | |
230 | fHw2geomapPtr[hwAddress].fGain);*/ | |
231 | // HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset); | |
232 | // HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset); | |
233 | return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) | | |
234 | ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) | | |
235 | (fHw2geomapPtr[hwAddress].fGain << 12) | | |
236 | fSpecificationMapPtr[index].fModId << 13); | |
94594220 | 237 | } |
238 | ||
37ff2dd6 | 239 | |
240 | ||
44175a17 | 241 | // void |
242 | // AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord) | |
243 | // { | |
244 | // channelCoord[0] = channelId&0x3f; | |
245 | // channelCoord[1] = (channelId >> 6)&0x3f; | |
246 | // channelCoord[2] = (channelId >> 12)&0x1; | |
247 | // channelCoord[3] = (channelId >> 13)&0x1f; | |
248 | // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]); | |
249 | // } | |
dc1902d2 | 250 | // |
251 | // | |
252 | // | |
44175a17 | 253 | // void |
254 | // AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord) | |
255 | // { | |
256 | // channelCoord.fX = channelId&0x3f; | |
257 | // channelCoord.fZ = (channelId >> 6)&0x3f; | |
258 | // channelCoord.fGain = (channelId >> 12)&0x1; | |
259 | // channelCoord.fModuleId = (channelId >> 13)&0x1f; | |
260 | // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]); | |
261 | // } | |
dc1902d2 | 262 | // |
263 | // | |
264 | // | |
44175a17 | 265 | // void |
266 | // AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord) | |
267 | // { | |
268 | // channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep; | |
269 | // channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep; | |
270 | // // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]); | |
271 | // } | |
87434909 | 272 | |
dc1902d2 | 273 | Int_t |
44175a17 | 274 | AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification) |
87434909 | 275 | { |
dc1902d2 | 276 | Int_t index = -1; |
277 | if (specification == 0x00001) index = 0; | |
278 | else if (specification == 0x00002) index = 1; | |
279 | else if (specification == 0x00004) index = 2; | |
280 | else if (specification == 0x00008) index = 3; | |
281 | ||
282 | else if (specification == 0x00010) index = 4; | |
283 | else if (specification == 0x00020) index = 5; | |
284 | else if (specification == 0x00040) index = 6; | |
285 | else if (specification == 0x00080) index = 7; | |
286 | ||
287 | else if (specification == 0x00100) index = 8; | |
288 | else if (specification == 0x00200) index = 9; | |
289 | else if (specification == 0x00400) index = 10; | |
290 | else if (specification == 0x00800) index = 11; | |
291 | ||
292 | else if (specification == 0x01000) index = 12; | |
293 | else if (specification == 0x02000) index = 13; | |
294 | else if (specification == 0x04000) index = 14; | |
295 | else if (specification == 0x08000) index = 15; | |
296 | ||
297 | else if (specification == 0x10000) index = 16; | |
298 | else if (specification == 0x20000) index = 17; | |
299 | else if (specification == 0x40000) index = 18; | |
300 | else if (specification == 0x80000) index = 19; | |
301 | ||
302 | else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification); | |
303 | ||
304 | return index; | |
87434909 | 305 | } |
b48632c9 | 306 | |
dc1902d2 | 307 | Int_t |
44175a17 | 308 | AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification) |
b48632c9 | 309 | { |
dc1902d2 | 310 | Int_t module = -1; |
311 | ||
312 | if (specification & 0xf) module = 0; | |
313 | else if ((specification >> 4) & 0xf) module = 1; | |
314 | else if ((specification >> 8) & 0xf) module = 2; | |
315 | else if ((specification >> 12) & 0xf) module = 3; | |
316 | else if ((specification >> 16) & 0xf) module = 4; | |
317 | ||
318 | else HLTError("Specification 0x%X not consistent with single module in PHOS", specification); | |
319 | ||
320 | return module; | |
b48632c9 | 321 | } |