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