]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSMapper.cxx
Small bug fixes (mainly in mapping) and some clean up
[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);
947064ec 90 if(tmpGain < 2)
91 {
92 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
93 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
94 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
95 }
c37f821f 96 }
8efbf5fe 97 fIsInitializedMapping = true;
98 fclose(fp);
c37f821f 99 }
100 else
101 {
8efbf5fe 102 fIsInitializedMapping = false;
2f09efe8 103 }
104 }
c37f821f 105 else
106 {
8efbf5fe 107 fIsInitializedMapping = false;
c37f821f 108 }
c37f821f 109}
110
94594220 111void
112AliHLTPHOSMapper::InitDDLSpecificationMapping()
113{
27029341 114 fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
115 for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
94594220 116 {
117
27029341 118 fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
94594220 119
120 if(ddl%4 == 0)
121 {
122 fSpecificationMapPtr[ddl].fRcuX = 0;
123 fSpecificationMapPtr[ddl].fRcuZ = 0;
124 }
125
126 else if(ddl%4 == 1)
127 {
947064ec 128 fSpecificationMapPtr[ddl].fRcuX = 1;
129 fSpecificationMapPtr[ddl].fRcuZ = 0;
94594220 130 }
131
132 else if( ddl%4 == 2)
133 {
947064ec 134 fSpecificationMapPtr[ddl].fRcuX = 2;
94594220 135 fSpecificationMapPtr[ddl].fRcuZ = 0;
136 }
137 else
138 {
947064ec 139 fSpecificationMapPtr[ddl].fRcuX = 3;
140 fSpecificationMapPtr[ddl].fRcuZ = 0;
94594220 141 }
142
27029341 143 fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
144 fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
94594220 145 }
146}
147
8efbf5fe 148
149bool
150AliHLTPHOSMapper::GetIsInitializedMapping()
151{
152 return fIsInitializedMapping;
153}
154
155
156char*
157AliHLTPHOSMapper::GetFilePath()
158{
159 return fFilepath;
160}
94594220 161
162UShort_t
163AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
164{
165
166 Short_t index = 0;
167
168 if(specification == 0x00001) index = 0;
169 else if(specification == 0x00002) index = 1;
170 else if(specification == 0x00004) index = 2;
171 else if(specification == 0x00008) index = 3;
172
173 else if(specification == 0x00010) index = 4;
174 else if(specification == 0x00020) index = 5;
175 else if(specification == 0x00040) index = 6;
176 else if(specification == 0x00080) index = 7;
177
178 else if(specification == 0x00100) index = 8;
179 else if(specification == 0x00200) index = 9;
180 else if(specification == 0x00400) index = 10;
181 else if(specification == 0x00800) index = 11;
182
183 else if(specification == 0x01000) index = 12;
184 else if(specification == 0x02000) index = 13;
185 else if(specification == 0x04000) index = 14;
186 else if(specification == 0x08000) index = 15;
187
188 else if(specification == 0x10000) index = 16;
189 else if(specification == 0x20000) index = 17;
190 else if(specification == 0x40000) index = 18;
191 else if(specification == 0x80000) index = 19;
192
193 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
947064ec 194 // 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),
195 // fHw2geomapPtr[hwAddress].fXCol,
196 // fHw2geomapPtr[hwAddress].fZRow,
197 // fHw2geomapPtr[hwAddress].fGain);
94594220 198 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
199 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
200 (fHw2geomapPtr[hwAddress].fGain << 12) |
201 fSpecificationMapPtr[index].fModId << 13);
202}
203
204void
205AliHLTPHOSMapper::GetChannelCoord(UShort_t channelId, UShort_t* channelCoord)
206{
207 channelCoord[0] = channelId&0x3f;
208 channelCoord[1] = (channelId >> 6)&0x3f;
209 channelCoord[2] = (channelId >> 12)&0x1;
210 channelCoord[3] = (channelId >> 13)&0x1f;
947064ec 211 // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
94594220 212}
87434909 213
214void
215AliHLTPHOSMapper::GetLocalCoord(UShort_t channelId, Float_t* channelCoord)
216{
217 channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
218 channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
947064ec 219 // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
87434909 220}
221
222Int_t
223AliHLTPHOSMapper::GetDDLFromSpec(Int_t specification)
224{
225 Int_t index = -1;
226 if(specification == 0x00001) index = 0;
227 else if(specification == 0x00002) index = 1;
228 else if(specification == 0x00004) index = 2;
229 else if(specification == 0x00008) index = 3;
230
231 else if(specification == 0x00010) index = 4;
232 else if(specification == 0x00020) index = 5;
233 else if(specification == 0x00040) index = 6;
234 else if(specification == 0x00080) index = 7;
235
236 else if(specification == 0x00100) index = 8;
237 else if(specification == 0x00200) index = 9;
238 else if(specification == 0x00400) index = 10;
239 else if(specification == 0x00800) index = 11;
240
241 else if(specification == 0x01000) index = 12;
242 else if(specification == 0x02000) index = 13;
243 else if(specification == 0x04000) index = 14;
244 else if(specification == 0x08000) index = 15;
245
246 else if(specification == 0x10000) index = 16;
247 else if(specification == 0x20000) index = 17;
248 else if(specification == 0x40000) index = 18;
249 else if(specification == 0x80000) index = 19;
250
251 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
252
253 return index;
254}