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