]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSMapper.cxx
- bug fix
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
CommitLineData
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 37AliHLTPHOSMapper::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
48AliHLTPHOSMapper::~AliHLTPHOSMapper()
2f09efe8 49{
dc1902d2 50 delete [] fHw2geomapPtr;
51 fHw2geomapPtr = 0;
c37f821f 52}
2f09efe8 53
44175a17 54
55Bool_t
56AliHLTPHOSMapper::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 127void
128AliHLTPHOSMapper::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 }
bf703499 164 fDDLMapInitialised = true;
94594220 165}
166
8efbf5fe 167
dc1902d2 168bool
8efbf5fe 169AliHLTPHOSMapper::GetIsInitializedMapping()
170{
dc1902d2 171 return fIsInitializedMapping;
8efbf5fe 172}
173
44175a17 174Int_t
175AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
8efbf5fe 176{
dc1902d2 177 if (!fDDLMapInitialised) InitDDLSpecificationMapping();
f137c3c5 178
dc1902d2 179 // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset,
180 // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset,
181 // fHw2geomapPtr[hwAddress].fGain);
182 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) |
f137c3c5 183
dc1902d2 184 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
185 (fHw2geomapPtr[hwAddress].fGain << 12) |
186 fSpecificationMapPtr[fDDLId].fModId << 13);
8efbf5fe 187}
94594220 188
44175a17 189Int_t
190AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
94594220 191{
7ac2a5ea 192
dc1902d2 193 if (!fDDLMapInitialised) InitDDLSpecificationMapping();
194
195 Short_t index = 0;
196
197 if (specification == 0x00001) index = 0;
198 else if (specification == 0x00002) index = 1;
199 else if (specification == 0x00004) index = 2;
200 else if (specification == 0x00008) index = 3;
201
202 else if (specification == 0x00010) index = 4;
203 else if (specification == 0x00020) index = 5;
204 else if (specification == 0x00040) index = 6;
205 else if (specification == 0x00080) index = 7;
206
207 else if (specification == 0x00100) index = 8;
208 else if (specification == 0x00200) index = 9;
209 else if (specification == 0x00400) index = 10;
210 else if (specification == 0x00800) index = 11;
211
212 else if (specification == 0x01000) index = 12;
213 else if (specification == 0x02000) index = 13;
214 else if (specification == 0x04000) index = 14;
215 else if (specification == 0x08000) index = 15;
216
217 else if (specification == 0x10000) index = 16;
218 else if (specification == 0x20000) index = 17;
219 else if (specification == 0x40000) index = 18;
220 else if (specification == 0x80000) index = 19;
221
222 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
223
224 // 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),
225 // fHw2geomapPtr[hwAddress].fXCol,
226 // fHw2geomapPtr[hwAddress].fZRow,
227 // fHw2geomapPtr[hwAddress].fGain);
228
229 /* HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset,
230 fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset,
231 fHw2geomapPtr[hwAddress].fGain);*/
232 // HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset);
233 // HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset);
234 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
235 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
236 (fHw2geomapPtr[hwAddress].fGain << 12) |
237 fSpecificationMapPtr[index].fModId << 13);
94594220 238}
239
37ff2dd6 240
241
44175a17 242// void
243// AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
244// {
245// channelCoord[0] = channelId&0x3f;
246// channelCoord[1] = (channelId >> 6)&0x3f;
247// channelCoord[2] = (channelId >> 12)&0x1;
248// channelCoord[3] = (channelId >> 13)&0x1f;
249// // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
250// }
dc1902d2 251//
252//
253//
44175a17 254// void
255// AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord)
256// {
257// channelCoord.fX = channelId&0x3f;
258// channelCoord.fZ = (channelId >> 6)&0x3f;
259// channelCoord.fGain = (channelId >> 12)&0x1;
260// channelCoord.fModuleId = (channelId >> 13)&0x1f;
261// // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
262// }
dc1902d2 263//
264//
265//
44175a17 266// void
267// AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
268// {
269// channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
270// channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
271// // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
272// }
87434909 273
dc1902d2 274Int_t
44175a17 275AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification)
87434909 276{
dc1902d2 277 Int_t index = -1;
278 if (specification == 0x00001) index = 0;
279 else if (specification == 0x00002) index = 1;
280 else if (specification == 0x00004) index = 2;
281 else if (specification == 0x00008) index = 3;
282
283 else if (specification == 0x00010) index = 4;
284 else if (specification == 0x00020) index = 5;
285 else if (specification == 0x00040) index = 6;
286 else if (specification == 0x00080) index = 7;
287
288 else if (specification == 0x00100) index = 8;
289 else if (specification == 0x00200) index = 9;
290 else if (specification == 0x00400) index = 10;
291 else if (specification == 0x00800) index = 11;
292
293 else if (specification == 0x01000) index = 12;
294 else if (specification == 0x02000) index = 13;
295 else if (specification == 0x04000) index = 14;
296 else if (specification == 0x08000) index = 15;
297
298 else if (specification == 0x10000) index = 16;
299 else if (specification == 0x20000) index = 17;
300 else if (specification == 0x40000) index = 18;
301 else if (specification == 0x80000) index = 19;
302
303 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
304
305 return index;
87434909 306}
b48632c9 307
dc1902d2 308Int_t
44175a17 309AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
b48632c9 310{
dc1902d2 311 Int_t module = -1;
312
313 if (specification & 0xf) module = 0;
314 else if ((specification >> 4) & 0xf) module = 1;
315 else if ((specification >> 8) & 0xf) module = 2;
316 else if ((specification >> 12) & 0xf) module = 3;
317 else if ((specification >> 16) & 0xf) module = 4;
318
319 else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);
320
321 return module;
b48632c9 322}