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 "AliHLTPHOSMapper.h"
30 #include "AliHLTPHOSCoordinate.h"
32 AliHLTPHOSMapper::AliHLTPHOSMapper():
33 AliHLTCaloMapper(0,"PHOS")
34 ,fIsInitializedMapping(false)
38 InitDDLSpecificationMapping();
39 sprintf(fFilepath, "./");
43 AliHLTPHOSMapper::~AliHLTPHOSMapper()
45 delete [] fHw2geomapPtr;
51 AliHLTPHOSMapper::InitAltroMapping(const unsigned long specification)
53 // Loads mapping between Altro addresses and geometrical addresses from file
55 // HLTError("Initialising ALTRO map");
57 fDDLId = GetDDLFromSpec(specification);
58 Int_t modId = GetModuleFromSpec(specification);
60 char *base = getenv("ALICE_ROOT");
64 if ( modId != fModuleId )
69 sprintf ( fFilepath,"%s/PHOS/mapping/Mod%dRCU0.data", base, GetModuleFromSpec ( specification ) );
78 FILE *fp = fopen ( fFilepath, "r" );
81 res = fscanf ( fp, "%d", &nChannels );
82 res = fscanf ( fp, "%d", &maxaddr );
87 fHw2geomapPtr = new fAltromap[maxaddr +1];
89 for ( int i=0; i< maxaddr + 1 ; i ++ )
91 fHw2geomapPtr[i].fXCol = 0;
92 fHw2geomapPtr[i].fZRow = 0;
93 fHw2geomapPtr[i].fGain = 0;
96 for ( int i=0; i<nChannels; i ++ )
98 res = fscanf ( fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain );
101 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
102 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
103 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
106 fIsInitializedMapping = true;
111 fIsInitializedMapping = false;
118 fIsInitializedMapping = false;
121 return fIsInitializedMapping;
126 AliHLTPHOSMapper::InitDDLSpecificationMapping()
128 fSpecificationMapPtr = new fDDLSpecificationMap[fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE()];
129 // HLTError("NUMBER OF DDLs: %d, map ptr: %d", fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(), fSpecificationMapPtr);
130 for(Int_t ddl = 0; ddl < fCaloConstants->GetNMODULES()*fCaloConstants->GetNRCUSPERMODULE(); ddl++)
133 fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE();
137 fSpecificationMapPtr[ddl].fRcuX = 0;
138 fSpecificationMapPtr[ddl].fRcuZ = 0;
143 fSpecificationMapPtr[ddl].fRcuX = 1;
144 fSpecificationMapPtr[ddl].fRcuZ = 0;
149 fSpecificationMapPtr[ddl].fRcuX = 2;
150 fSpecificationMapPtr[ddl].fRcuZ = 0;
154 fSpecificationMapPtr[ddl].fRcuX = 3;
155 fSpecificationMapPtr[ddl].fRcuZ = 0;
158 fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ);
159 fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX);
166 AliHLTPHOSMapper::GetIsInitializedMapping()
168 return fIsInitializedMapping;
172 AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
175 // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset,
176 // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset,
177 // fHw2geomapPtr[hwAddress].fGain);
178 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[fDDLId].fRcuXOffset) |
180 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
181 (fHw2geomapPtr[hwAddress].fGain << 12) |
182 fSpecificationMapPtr[fDDLId].fModId << 13);
186 AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
191 if(specification == 0x00001) index = 0;
192 else if(specification == 0x00002) index = 1;
193 else if(specification == 0x00004) index = 2;
194 else if(specification == 0x00008) index = 3;
196 else if(specification == 0x00010) index = 4;
197 else if(specification == 0x00020) index = 5;
198 else if(specification == 0x00040) index = 6;
199 else if(specification == 0x00080) index = 7;
201 else if(specification == 0x00100) index = 8;
202 else if(specification == 0x00200) index = 9;
203 else if(specification == 0x00400) index = 10;
204 else if(specification == 0x00800) index = 11;
206 else if(specification == 0x01000) index = 12;
207 else if(specification == 0x02000) index = 13;
208 else if(specification == 0x04000) index = 14;
209 else if(specification == 0x08000) index = 15;
211 else if(specification == 0x10000) index = 16;
212 else if(specification == 0x20000) index = 17;
213 else if(specification == 0x40000) index = 18;
214 else if(specification == 0x80000) index = 19;
216 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
218 // 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),
219 // fHw2geomapPtr[hwAddress].fXCol,
220 // fHw2geomapPtr[hwAddress].fZRow,
221 // fHw2geomapPtr[hwAddress].fGain);
223 // HLTError("HW add: %d -> x: %d, z: %d, gain: %d", hwAddress, fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset,
224 // fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset,
225 // fHw2geomapPtr[hwAddress].fGain);
226 // HLTError("RCU X offset: %d", fSpecificationMapPtr[index].fRcuXOffset);
227 // HLTError("RCU Z offset: %d", fSpecificationMapPtr[index].fRcuZOffset);
228 return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
229 ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
230 (fHw2geomapPtr[hwAddress].fGain << 12) |
231 fSpecificationMapPtr[index].fModId << 13);
237 // AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
239 // channelCoord[0] = channelId&0x3f;
240 // channelCoord[1] = (channelId >> 6)&0x3f;
241 // channelCoord[2] = (channelId >> 12)&0x1;
242 // channelCoord[3] = (channelId >> 13)&0x1f;
243 // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
249 // AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId, AliHLTPHOSCoordinate &channelCoord)
251 // channelCoord.fX = channelId&0x3f;
252 // channelCoord.fZ = (channelId >> 6)&0x3f;
253 // channelCoord.fGain = (channelId >> 12)&0x1;
254 // channelCoord.fModuleId = (channelId >> 13)&0x1f;
255 // // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
261 // AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
263 // channelCoord[0] = (static_cast<Float_t>(channelId&0x3f) - NXCOLUMNSMOD/2)* fCellStep;
264 // channelCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellStep;
265 // // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
269 AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification)
272 if(specification == 0x00001) index = 0;
273 else if(specification == 0x00002) index = 1;
274 else if(specification == 0x00004) index = 2;
275 else if(specification == 0x00008) index = 3;
277 else if(specification == 0x00010) index = 4;
278 else if(specification == 0x00020) index = 5;
279 else if(specification == 0x00040) index = 6;
280 else if(specification == 0x00080) index = 7;
282 else if(specification == 0x00100) index = 8;
283 else if(specification == 0x00200) index = 9;
284 else if(specification == 0x00400) index = 10;
285 else if(specification == 0x00800) index = 11;
287 else if(specification == 0x01000) index = 12;
288 else if(specification == 0x02000) index = 13;
289 else if(specification == 0x04000) index = 14;
290 else if(specification == 0x08000) index = 15;
292 else if(specification == 0x10000) index = 16;
293 else if(specification == 0x20000) index = 17;
294 else if(specification == 0x40000) index = 18;
295 else if(specification == 0x80000) index = 19;
297 else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
303 AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
307 if(specification & 0xf) module = 0;
308 else if((specification >> 4) & 0xf) module = 1;
309 else if((specification >> 8) & 0xf) module = 2;
310 else if((specification >> 12) & 0xf) module = 3;
311 else if((specification >> 16) & 0xf) module = 4;
313 else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);