]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
Cosmetics
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
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 "AliHLTPHOSMapper.h"
28 #include "unistd.h"
29 #include <iostream>
30 #include "AliHLTPHOSCoordinate.h"
31
32 AliHLTPHOSMapper::AliHLTPHOSMapper():  
33    AliHLTCaloMapper(0,"PHOS") 
34    ,fIsInitializedMapping(false)
35    ,fModuleId(-1)
36    ,fDDLId(-1)
37 {
38   InitDDLSpecificationMapping();
39   sprintf(fFilepath, "./");
40 }
41
42
43 AliHLTPHOSMapper::~AliHLTPHOSMapper()
44 {
45   delete []  fHw2geomapPtr;
46   fHw2geomapPtr = 0;
47 }
48
49
50 Bool_t
51 AliHLTPHOSMapper::InitAltroMapping(const unsigned long specification)
52 {
53   // Loads mapping between Altro addresses and geometrical addresses from file
54
55   //  HLTError("Initialising ALTRO map");
56
57   fDDLId = GetDDLFromSpec(specification);
58   Int_t modId = GetModuleFromSpec(specification);
59
60   char *base =  getenv("ALICE_ROOT");
61
62   if ( base )
63     {
64       if ( modId != fModuleId )
65         {
66           fModuleId = modId;
67           if ( base )
68             {
69               sprintf ( fFilepath,"%s/PHOS/mapping/Mod%dRCU0.data", base, GetModuleFromSpec ( specification ) );
70               int nChannels = 0;
71               int maxaddr = 0;
72               int tmpHwaddr = 0;
73               int tmpZRow = 0;
74               int tmpXCol = 0;
75               int tmpGain = 0;
76               int res = 0;
77
78               FILE *fp = fopen ( fFilepath, "r" );
79               if ( fp != 0 )
80                 {
81                   res = fscanf ( fp, "%d", &nChannels );
82                   res = fscanf ( fp, "%d", &maxaddr );
83                   if (fHw2geomapPtr)
84                     {
85                       delete fHw2geomapPtr;
86                     }
87                   fHw2geomapPtr = new fAltromap[maxaddr +1];
88
89                   for ( int i=0; i< maxaddr + 1 ; i ++ )
90                     {
91                       fHw2geomapPtr[i].fXCol = 0;
92                       fHw2geomapPtr[i].fZRow = 0;
93                       fHw2geomapPtr[i].fGain = 0;
94                     }
95
96                   for ( int i=0; i<nChannels; i ++ )
97                     {
98                       res = fscanf ( fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain );
99                       if ( tmpGain < 2 )
100                         {
101                           fHw2geomapPtr[tmpHwaddr].fXCol   = tmpXCol;
102                           fHw2geomapPtr[tmpHwaddr].fZRow   = tmpZRow;
103                           fHw2geomapPtr[tmpHwaddr].fGain  = tmpGain;
104                         }
105                     }
106                   fIsInitializedMapping = true;
107                   fclose ( fp );
108                 }
109               else
110                 {
111                   fIsInitializedMapping = false;
112                 }
113             }
114         }
115     }
116    else 
117    {
118       fIsInitializedMapping = false;
119    }
120    
121    return fIsInitializedMapping;
122 }
123    
124
125 void
126 AliHLTPHOSMapper::InitDDLSpecificationMapping()
127 {
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++)
131     {
132       
133       fSpecificationMapPtr[ddl].fModId = ddl/fCaloConstants->GetNRCUSPERMODULE();
134       
135       if(ddl%4 == 0)
136         {
137           fSpecificationMapPtr[ddl].fRcuX = 0; 
138           fSpecificationMapPtr[ddl].fRcuZ = 0;
139         }
140       
141       else if(ddl%4 == 1)
142         {
143           fSpecificationMapPtr[ddl].fRcuX = 1; 
144           fSpecificationMapPtr[ddl].fRcuZ = 0;
145         }
146       
147       else if( ddl%4 == 2)
148         {
149           fSpecificationMapPtr[ddl].fRcuX = 2; 
150           fSpecificationMapPtr[ddl].fRcuZ = 0;
151         }
152       else
153         {
154           fSpecificationMapPtr[ddl].fRcuX = 3; 
155           fSpecificationMapPtr[ddl].fRcuZ = 0;
156         }
157       
158       fSpecificationMapPtr[ddl].fRcuZOffset = fCaloConstants->GetNZROWSRCU()*(fSpecificationMapPtr[ddl].fRcuZ);
159       fSpecificationMapPtr[ddl].fRcuXOffset = fCaloConstants->GetNXCOLUMNSRCU()*(fSpecificationMapPtr[ddl].fRcuX);
160
161     }
162 }
163
164
165 bool 
166 AliHLTPHOSMapper::GetIsInitializedMapping()
167 {
168   return  fIsInitializedMapping;
169 }
170
171 Int_t
172 AliHLTPHOSMapper::GetChannelID(Int_t hwAddress)
173 {
174
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) |
179
180           ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[fDDLId].fRcuZOffset) << 6) |
181           (fHw2geomapPtr[hwAddress].fGain << 12) |
182           fSpecificationMapPtr[fDDLId].fModId << 13);
183 }
184
185 Int_t
186 AliHLTPHOSMapper::GetChannelID(AliHLTUInt32_t specification, Int_t hwAddress)
187 {
188   
189   Short_t index = 0;
190
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;
195
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;
200
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;
205
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;
210
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;
215
216   else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
217
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);
222
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);
232 }
233
234
235
236 // void
237 // AliHLTPHOSMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
238 // {
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]);
244 // }
245 // 
246 // 
247 // 
248 // void
249 // AliHLTPHOSMapper::ChannelId2Coordinate(const UShort_t channelId,    AliHLTPHOSCoordinate &channelCoord)
250 // {
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]);
256 // }
257 // 
258 // 
259 // 
260 // void
261 // AliHLTPHOSMapper::GetLocalCoord(const UShort_t channelId, Float_t* channelCoord)
262 // {
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]);
266 // }
267
268 Int_t 
269 AliHLTPHOSMapper::GetDDLFromSpec(AliHLTUInt32_t specification)
270 {
271   Int_t index = -1;
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;
276
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;
281
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;
286
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;
291
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;
296
297   else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
298
299   return index;
300 }
301
302 Int_t 
303 AliHLTPHOSMapper::GetModuleFromSpec(AliHLTUInt32_t specification)
304 {
305   Int_t module = -1;
306       
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;
312  
313   else HLTError("Specification 0x%X not consistent with single module in PHOS", specification);
314
315   return module;
316 }