]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - HLT/PHOS/AliHLTPHOSMapper.cxx
- Bug fix: in the creation/reading of the trigger DCS values, the HV and currents...
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
... / ...
CommitLineData
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//
25//
26
27#include "AliPHOSEMCAGeometry.h"
28#include "AliHLTPHOSMapper.h"
29#include "AliHLTPHOSConstants.h"
30#include "AliHLTLogging.h"
31#include "Rtypes.h"
32#include "unistd.h"
33#include <iostream>
34
35using namespace PhosHLTConst;
36AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(),
37 fHw2geomapPtr(0),
38 fIsInitializedMapping(false),
39 fSpecificationMapPtr(0)
40 // fPHOSGeometry(0)
41{
42 InitAltroMapping();
43 InitDDLSpecificationMapping();
44 // fPHOSGeometry = new AliPHOSEMCAGeometry();
45
46}
47
48
49AliHLTPHOSMapper::~AliHLTPHOSMapper()
50{
51 delete [] fHw2geomapPtr;
52 fHw2geomapPtr = 0;
53}
54
55void
56AliHLTPHOSMapper::InitAltroMapping()
57{
58 // Loads mapping between Altro addresses and geometrical addresses from file
59
60 // char filename[256];
61 char *base = getenv("ALICE_ROOT");
62 int nChannels = 0;
63 int maxaddr = 0;
64 int tmpHwaddr = 0;
65 int tmpZRow = 0;
66 int tmpXCol = 0;
67 int tmpGain = 0;
68 int res = 0;
69 if(base !=0)
70 {
71 sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
72
73 FILE *fp = fopen(fFilepath, "r");
74 if(fp != 0)
75 {
76 res = fscanf(fp, "%d", &nChannels);
77 res = fscanf(fp, "%d", &maxaddr);
78 fHw2geomapPtr = new fAltromap[maxaddr +1];
79
80 for(int i=0; i< maxaddr + 1 ; i ++)
81 {
82 fHw2geomapPtr[i].fXCol = 0;
83 fHw2geomapPtr[i].fZRow = 0;
84 fHw2geomapPtr[i].fGain = 0;
85 }
86
87 for(int i=0; i<nChannels; i ++)
88 {
89 res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
90 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
91 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
92 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
93 }
94 fIsInitializedMapping = true;
95 fclose(fp);
96 }
97 else
98 {
99 fIsInitializedMapping = false;
100 }
101 }
102 else
103 {
104 fIsInitializedMapping = false;
105 }
106}
107
108void
109AliHLTPHOSMapper::InitDDLSpecificationMapping()
110{
111 fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
112 for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
113 {
114
115 fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
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
140 fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
141 fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
142 }
143}
144
145
146bool
147AliHLTPHOSMapper::GetIsInitializedMapping()
148{
149 return fIsInitializedMapping;
150}
151
152
153char*
154AliHLTPHOSMapper::GetFilePath()
155{
156 return fFilepath;
157}
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);
191
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}
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}