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 *
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 *
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 **************************************************************************/
22 // Mapping class fro mapping
23 // from hardware address to geometrical address
27 #include "AliPHOSEMCAGeometry.h"
28 #include "AliHLTPHOSMapper.h"
29 #include "AliHLTPHOSConstants.h"
30 #include "AliHLTLogging.h"
34 #include "AliHLTPHOSCoordinate.h"
36 using namespace PhosHLTConst;
37 AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(),
39 fIsInitializedMapping(false),
40 fSpecificationMapPtr(0)
44 InitDDLSpecificationMapping();
45 // fPHOSGeometry = new AliPHOSEMCAGeometry();
50 AliHLTPHOSMapper::~AliHLTPHOSMapper()
52 delete [] fHw2geomapPtr;
57 AliHLTPHOSMapper::InitAltroMapping()
59 // Loads mapping between Altro addresses and geometrical addresses from file
61 // char filename[256];
62 char *base = getenv("ALICE_ROOT");
72 sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
74 FILE *fp = fopen(fFilepath, "r");
77 res = fscanf(fp, "%d", &nChannels);
78 res = fscanf(fp, "%d", &maxaddr);
79 fHw2geomapPtr = new fAltromap[maxaddr +1];
81 for(int i=0; i< maxaddr + 1 ; i ++)
83 fHw2geomapPtr[i].fXCol = 0;
84 fHw2geomapPtr[i].fZRow = 0;
85 fHw2geomapPtr[i].fGain = 0;
88 for(int i=0; i<nChannels; i ++)
90 res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
93 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
94 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
95 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
98 fIsInitializedMapping = true;
103 fIsInitializedMapping = false;
108 fIsInitializedMapping = false;
113 AliHLTPHOSMapper::InitDDLSpecificationMapping()
115 fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
116 for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
119 fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
123 fSpecificationMapPtr[ddl].fRcuX = 0;
124 fSpecificationMapPtr[ddl].fRcuZ = 0;
129 fSpecificationMapPtr[ddl].fRcuX = 1;
130 fSpecificationMapPtr[ddl].fRcuZ = 0;
135 fSpecificationMapPtr[ddl].fRcuX = 2;
136 fSpecificationMapPtr[ddl].fRcuZ = 0;
140 fSpecificationMapPtr[ddl].fRcuX = 3;
141 fSpecificationMapPtr[ddl].fRcuZ = 0;
144 fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
145 fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
151 AliHLTPHOSMapper::GetIsInitializedMapping()
153 return fIsInitializedMapping;
158 AliHLTPHOSMapper::GetFilePath()
164 AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
169 if(specification == 0x00001) index = 0;
170 else if(specification == 0x00002) index = 1;
171 else if(specification == 0x00004) index = 2;
172 else if(specification == 0x00008) index = 3;
174 else if(specification == 0x00010) index = 4;
175 else if(specification == 0x00020) index = 5;
176 else if(specification == 0x00040) index = 6;
177 else if(specification == 0x00080) index = 7;
179 else if(specification == 0x00100) index = 8;
180 else if(specification == 0x00200) index = 9;
181 else if(specification == 0x00400) index = 10;
182 else if(specification == 0x00800) index = 11;
184 else if(specification == 0x01000) index = 12;
185 else if(specification == 0x02000) index = 13;
186 else if(specification == 0x04000) index = 14;
187 else if(specification == 0x08000) index = 15;
189 else if(specification == 0x10000) index = 16;
190 else if(specification == 0x20000) index = 17;
191 else if(specification == 0x40000) index = 18;
192 else if(specification == 0x80000) index = 19;
194 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
195 // 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),
196 // fHw2geomapPtr[hwAddress].fXCol,
197 // fHw2geomapPtr[hwAddress].fZRow,
198 // fHw2geomapPtr[hwAddress].fGain);
199 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
200 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
201 (fHw2geomapPtr[hwAddress].fGain << 12) |
202 fSpecificationMapPtr[index].fModId << 13);
208 AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
210 channelCoord[0] = channelId&0x3f;
211 channelCoord[1] = (channelId >> 6)&0x3f;
212 channelCoord[2] = (channelId >> 12)&0x1;
213 channelCoord[3] = (channelId >> 13)&0x1f;
214 // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
220 //AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, &AliHLTPHOSCoordinate channelCoord)
221 AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord)
223 channelCoord.fX = channelId&0x3f;
224 channelCoord.fZ = (channelId >> 6)&0x3f;
225 channelCoord.fGain = (channelId >> 12)&0x1;
226 channelCoord.fModuleId = (channelId >> 13)&0x1f;
227 // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
233 AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
235 channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
236 channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
237 // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
241 AliHLTPHOSMapper::GetDDLFromSpec(Int_t specification)
244 if(specification == 0x00001) index = 0;
245 else if(specification == 0x00002) index = 1;
246 else if(specification == 0x00004) index = 2;
247 else if(specification == 0x00008) index = 3;
249 else if(specification == 0x00010) index = 4;
250 else if(specification == 0x00020) index = 5;
251 else if(specification == 0x00040) index = 6;
252 else if(specification == 0x00080) index = 7;
254 else if(specification == 0x00100) index = 8;
255 else if(specification == 0x00200) index = 9;
256 else if(specification == 0x00400) index = 10;
257 else if(specification == 0x00800) index = 11;
259 else if(specification == 0x01000) index = 12;
260 else if(specification == 0x02000) index = 13;
261 else if(specification == 0x04000) index = 14;
262 else if(specification == 0x08000) index = 15;
264 else if(specification == 0x10000) index = 16;
265 else if(specification == 0x20000) index = 17;
266 else if(specification == 0x40000) index = 18;
267 else if(specification == 0x80000) index = 19;
269 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
275 AliHLTPHOSMapper::GetModuleFromSpec(Int_t specification)
279 if(specification & 0xf) module = 0;
280 else if((specification >> 4) & 0xf) module = 1;
281 else if((specification >> 8) & 0xf) module = 2;
282 else if((specification >> 12) & 0xf) module = 3;
283 else if((specification >> 16) & 0xf) module = 4;
285 else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);