]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
Corrected list of libraries to resolve all symbols
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
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         AliHLTCaloMapper(0,"PHOS")
39         ,fIsInitializedMapping(false)
40         ,fDDLMapInitialised(false)
41         ,fModuleId(-1)
42         ,fDDLId(-1)
43 {
44     sprintf(fFilepath, "./");
45 }
46
47
48 AliHLTPHOSMapper::~AliHLTPHOSMapper()
49 {
50     delete []  fHw2geomapPtr;
51     fHw2geomapPtr = 0;
52 }
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     if (!fDDLMapInitialised) InitDDLSpecificationMapping();
63
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     }
74
75     AliCaloAltroMapping *map = dynamic_cast<AliCaloAltroMapping*>(maps->At(modId*fCaloConstants->GetNRCUSPERMODULE()));
76     
77     if(!map)
78     {
79         HLTError("Cannot retrieve ALTRO mappings!!");
80         fIsInitializedMapping = false;
81         return false;
82     }
83
84     if ( modId != fModuleId )
85     {
86         fModuleId = modId;
87
88 //        int nChannels = 0;
89         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         if (fHw2geomapPtr)
96         {
97             delete [] fHw2geomapPtr;
98         }
99         fHw2geomapPtr = new fAltromap[maxaddr];
100         Int_t hwAdds[maxaddr];
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 ++ )
114         {
115            Int_t add = hwAdds[i];
116             if (map->GetSector(add) < 2)
117             {
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;
124     }
125     else
126     {
127         fIsInitializedMapping = false;
128     }
129
130     return fIsInitializedMapping;
131 }
132
133
134 void
135 AliHLTPHOSMapper::InitDDLSpecificationMapping()
136 {
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++)
140     {
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);
169
170     }
171     fDDLMapInitialised = true;
172 }
173
174
175 bool
176 AliHLTPHOSMapper::GetIsInitializedMapping()
177 {
178     return  fIsInitializedMapping;
179 }
180
181 Int_t
182 AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
183 {
184     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     return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) |
190
191             ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
192             (fHw2geomapPtr[hwAddress].fGain << 12) |
193             fSpecificationMapPtr[fDDLId].fModId << 13);
194 }
195
196 Int_t
197 AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
198 {
199
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);
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     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;
313 }
314
315 Int_t
316 AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
317 {
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;
329 }