]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSMapper.cxx
- fixes due to new PHOS mapping
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
CommitLineData
1b41ab20 1// $Id$
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
87434909 27#include "AliPHOSEMCAGeometry.h"
2f09efe8 28#include "AliHLTPHOSMapper.h"
94594220 29#include "AliHLTPHOSConstants.h"
30#include "AliHLTLogging.h"
31#include "Rtypes.h"
7eb756c1 32#include "unistd.h"
33#include <iostream>
2f09efe8 34
94594220 35using namespace PhosHLTConst;
36AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(),
8efbf5fe 37 fHw2geomapPtr(0),
94594220 38 fIsInitializedMapping(false),
39 fSpecificationMapPtr(0)
87434909 40 // fPHOSGeometry(0)
2f09efe8 41{
c37f821f 42 InitAltroMapping();
94594220 43 InitDDLSpecificationMapping();
87434909 44 // fPHOSGeometry = new AliPHOSEMCAGeometry();
45
2f09efe8 46}
47
c37f821f 48
49AliHLTPHOSMapper::~AliHLTPHOSMapper()
2f09efe8 50{
a6755e15 51 delete [] fHw2geomapPtr;
52 fHw2geomapPtr = 0;
c37f821f 53}
2f09efe8 54
c37f821f 55void
56AliHLTPHOSMapper::InitAltroMapping()
57{
af6a2273 58 // Loads mapping between Altro addresses and geometrical addresses from file
59
8efbf5fe 60 // char filename[256];
c37f821f 61 char *base = getenv("ALICE_ROOT");
c37f821f 62 int nChannels = 0;
63 int maxaddr = 0;
c37f821f 64 int tmpHwaddr = 0;
65 int tmpZRow = 0;
66 int tmpXCol = 0;
67 int tmpGain = 0;
87434909 68 int res = 0;
c37f821f 69 if(base !=0)
2f09efe8 70 {
8efbf5fe 71 sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
72
73 FILE *fp = fopen(fFilepath, "r");
c37f821f 74 if(fp != 0)
2f09efe8 75 {
e304ea31 76 res = fscanf(fp, "%d", &nChannels);
77 res = fscanf(fp, "%d", &maxaddr);
af6a2273 78 fHw2geomapPtr = new fAltromap[maxaddr +1];
c37f821f 79
43dd7c5e 80 for(int i=0; i< maxaddr + 1 ; i ++)
2f09efe8 81 {
af6a2273 82 fHw2geomapPtr[i].fXCol = 0;
83 fHw2geomapPtr[i].fZRow = 0;
84 fHw2geomapPtr[i].fGain = 0;
c37f821f 85 }
86
c37f821f 87 for(int i=0; i<nChannels; i ++)
88 {
e304ea31 89 res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
af6a2273 90 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
91 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
92 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
c37f821f 93 }
8efbf5fe 94 fIsInitializedMapping = true;
95 fclose(fp);
c37f821f 96 }
97 else
98 {
8efbf5fe 99 fIsInitializedMapping = false;
2f09efe8 100 }
101 }
c37f821f 102 else
103 {
8efbf5fe 104 fIsInitializedMapping = false;
c37f821f 105 }
c37f821f 106}
107
94594220 108void
109AliHLTPHOSMapper::InitDDLSpecificationMapping()
110{
27029341 111 fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
112 for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
94594220 113 {
114
27029341 115 fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
94594220 116
117 if(ddl%4 == 0)
118 {
119 fSpecificationMapPtr[ddl].fRcuX = 0;
120 fSpecificationMapPtr[ddl].fRcuZ = 0;
121 }
122
123 else if(ddl%4 == 1)
124 {
125 fSpecificationMapPtr[ddl].fRcuX = 0;
126 fSpecificationMapPtr[ddl].fRcuZ = 1;
127 }
128
129 else if( ddl%4 == 2)
130 {
131 fSpecificationMapPtr[ddl].fRcuX = 1;
132 fSpecificationMapPtr[ddl].fRcuZ = 0;
133 }
134 else
135 {
136 fSpecificationMapPtr[ddl].fRcuX = 1;
137 fSpecificationMapPtr[ddl].fRcuZ = 1;
138 }
139
27029341 140 fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
141 fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
94594220 142 }
143}
144
8efbf5fe 145
146bool
147AliHLTPHOSMapper::GetIsInitializedMapping()
148{
149 return fIsInitializedMapping;
150}
151
152
153char*
154AliHLTPHOSMapper::GetFilePath()
155{
156 return fFilepath;
157}
94594220 158
159UShort_t
160AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
161{
162
163 Short_t index = 0;
164
165 if(specification == 0x00001) index = 0;
166 else if(specification == 0x00002) index = 1;
167 else if(specification == 0x00004) index = 2;
168 else if(specification == 0x00008) index = 3;
169
170 else if(specification == 0x00010) index = 4;
171 else if(specification == 0x00020) index = 5;
172 else if(specification == 0x00040) index = 6;
173 else if(specification == 0x00080) index = 7;
174
175 else if(specification == 0x00100) index = 8;
176 else if(specification == 0x00200) index = 9;
177 else if(specification == 0x00400) index = 10;
178 else if(specification == 0x00800) index = 11;
179
180 else if(specification == 0x01000) index = 12;
181 else if(specification == 0x02000) index = 13;
182 else if(specification == 0x04000) index = 14;
183 else if(specification == 0x08000) index = 15;
184
185 else if(specification == 0x10000) index = 16;
186 else if(specification == 0x20000) index = 17;
187 else if(specification == 0x40000) index = 18;
188 else if(specification == 0x80000) index = 19;
189
190 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
87434909 191
94594220 192 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
193 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
194 (fHw2geomapPtr[hwAddress].fGain << 12) |
195 fSpecificationMapPtr[index].fModId << 13);
196}
197
198void
199AliHLTPHOSMapper::GetChannelCoord(UShort_t channelId, UShort_t* channelCoord)
200{
201 channelCoord[0] = channelId&0x3f;
202 channelCoord[1] = (channelId >> 6)&0x3f;
203 channelCoord[2] = (channelId >> 12)&0x1;
204 channelCoord[3] = (channelId >> 13)&0x1f;
205}
87434909 206
207void
208AliHLTPHOSMapper::GetLocalCoord(UShort_t channelId, Float_t* channelCoord)
209{
210 channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
211 channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
212 channelCoord[2] = (channelId >> 12)&0x1;
213 channelCoord[2] = (channelId >> 13)&0x1f;
214}
215
216Int_t
217AliHLTPHOSMapper::GetDDLFromSpec(Int_t specification)
218{
219 Int_t index = -1;
220 if(specification == 0x00001) index = 0;
221 else if(specification == 0x00002) index = 1;
222 else if(specification == 0x00004) index = 2;
223 else if(specification == 0x00008) index = 3;
224
225 else if(specification == 0x00010) index = 4;
226 else if(specification == 0x00020) index = 5;
227 else if(specification == 0x00040) index = 6;
228 else if(specification == 0x00080) index = 7;
229
230 else if(specification == 0x00100) index = 8;
231 else if(specification == 0x00200) index = 9;
232 else if(specification == 0x00400) index = 10;
233 else if(specification == 0x00800) index = 11;
234
235 else if(specification == 0x01000) index = 12;
236 else if(specification == 0x02000) index = 13;
237 else if(specification == 0x04000) index = 14;
238 else if(specification == 0x08000) index = 15;
239
240 else if(specification == 0x10000) index = 16;
241 else if(specification == 0x20000) index = 17;
242 else if(specification == 0x40000) index = 18;
243 else if(specification == 0x80000) index = 19;
244
245 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
246
247 return index;
248}