]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSMapper.cxx
084e7caf90930b1ff0f80447828644a86b719424
[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 "AliHLTPHOSConstants.h"
29 #include "AliHLTLogging.h"
30 #include "Rtypes.h"
31 #include "unistd.h"
32 #include <iostream>
33
34 using namespace PhosHLTConst;
35 AliHLTPHOSMapper::AliHLTPHOSMapper():  AliHLTLogging(), 
36                                        fHw2geomapPtr(0),
37                                        fIsInitializedMapping(false),
38                                        fSpecificationMapPtr(0)
39 {
40   InitAltroMapping(); 
41   InitDDLSpecificationMapping();
42 }
43
44
45 AliHLTPHOSMapper::~AliHLTPHOSMapper()
46 {
47   delete []  fHw2geomapPtr;
48   fHw2geomapPtr = 0;
49 }
50
51 void
52 AliHLTPHOSMapper::InitAltroMapping()
53 {
54   // Loads mapping between Altro addresses and geometrical addresses from file
55
56   //  char filename[256];
57   char *base =  getenv("ALICE_ROOT");
58   int nChannels = 0;
59   int maxaddr = 0;
60   int tmpHwaddr = 0;
61   int tmpZRow = 0;
62   int tmpXCol = 0;
63   int tmpGain = 0;
64   int res = 0; //OD to get rid of warnings
65   if(base !=0)
66     {
67       sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
68       
69       FILE *fp = fopen(fFilepath, "r");
70       if(fp != 0)
71         {
72           res = fscanf(fp, "%d", &nChannels);
73           res = fscanf(fp, "%d", &maxaddr);
74           fHw2geomapPtr = new fAltromap[maxaddr +1]; 
75
76           for(int i=0; i< maxaddr + 1 ; i ++)
77             {
78               fHw2geomapPtr[i].fXCol = 0;
79               fHw2geomapPtr[i].fZRow = 0;
80               fHw2geomapPtr[i].fGain = 0;
81             }
82
83           for(int i=0; i<nChannels; i ++)
84             {
85               res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow,  &tmpGain);
86               fHw2geomapPtr[tmpHwaddr].fXCol   = tmpXCol;
87               fHw2geomapPtr[tmpHwaddr].fZRow   = tmpZRow;
88               fHw2geomapPtr[tmpHwaddr].fGain  = tmpGain;
89             }
90           fIsInitializedMapping = true;   
91           fclose(fp);
92         }
93       else
94         {
95           fIsInitializedMapping = false;          
96         }
97     }
98   else
99     {
100       fIsInitializedMapping = false;
101     }
102
103
104 void
105 AliHLTPHOSMapper::InitDDLSpecificationMapping()
106 {
107   fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::N_MODULES*PhosHLTConst::N_RCUS_PER_MODULE];
108   for(Int_t ddl = 0; ddl < PhosHLTConst::N_MODULES*PhosHLTConst::N_RCUS_PER_MODULE; ddl++)
109     {
110       
111       fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::N_RCUS_PER_MODULE;
112       
113       if(ddl%4 == 0)
114         {
115           fSpecificationMapPtr[ddl].fRcuX = 0; 
116           fSpecificationMapPtr[ddl].fRcuZ = 0;
117         }
118       
119       else if(ddl%4 == 1)
120         {
121           fSpecificationMapPtr[ddl].fRcuX = 0; 
122           fSpecificationMapPtr[ddl].fRcuZ = 1;
123         }
124       
125       else if( ddl%4 == 2)
126         {
127           fSpecificationMapPtr[ddl].fRcuX = 1; 
128           fSpecificationMapPtr[ddl].fRcuZ = 0;
129         }
130       else
131         {
132           fSpecificationMapPtr[ddl].fRcuX = 1; 
133           fSpecificationMapPtr[ddl].fRcuZ = 1;
134         }
135       
136       fSpecificationMapPtr[ddl].fRcuZOffset = N_ZROWS_RCU*(fSpecificationMapPtr[ddl].fRcuZ);
137       fSpecificationMapPtr[ddl].fRcuXOffset = N_XCOLUMNS_RCU*(fSpecificationMapPtr[ddl].fRcuX);
138     }
139 }
140
141
142 bool 
143 AliHLTPHOSMapper::GetIsInitializedMapping()
144 {
145   return  fIsInitializedMapping;
146 }
147
148
149 char* 
150 AliHLTPHOSMapper::GetFilePath()
151 {
152   return  fFilepath;
153 }
154
155 UShort_t
156 AliHLTPHOSMapper::GetChannelID(Int_t specification, Int_t hwAddress)
157 {
158   
159   Short_t index = 0;
160
161   if(specification == 0x00001) index = 0;
162   else if(specification == 0x00002) index = 1;
163   else if(specification == 0x00004) index = 2;
164   else if(specification == 0x00008) index = 3;
165
166   else if(specification == 0x00010) index = 4;
167   else if(specification == 0x00020) index = 5;
168   else if(specification == 0x00040) index = 6;
169   else if(specification == 0x00080) index = 7;
170
171   else if(specification == 0x00100) index = 8;
172   else if(specification == 0x00200) index = 9;
173   else if(specification == 0x00400) index = 10;
174   else if(specification == 0x00800) index = 11;
175
176   else if(specification == 0x01000) index = 12;
177   else if(specification == 0x02000) index = 13;
178   else if(specification == 0x04000) index = 14;
179   else if(specification == 0x08000) index = 15;
180
181   else if(specification == 0x10000) index = 16;
182   else if(specification == 0x20000) index = 17;
183   else if(specification == 0x40000) index = 18;
184   else if(specification == 0x80000) index = 19;
185
186   else HLTError("Specification 0x%X not consistent with single DDL in PHOS", specification);
187
188   return ((fHw2geomapPtr[hwAddress].fXCol + fSpecificationMapPtr[index].fRcuXOffset) |
189           ((fHw2geomapPtr[hwAddress].fZRow + fSpecificationMapPtr[index].fRcuZOffset) << 6) |
190           (fHw2geomapPtr[hwAddress].fGain << 12) |
191           fSpecificationMapPtr[index].fModId << 13);
192 }
193
194 void
195 AliHLTPHOSMapper::GetChannelCoord(UShort_t channelId, UShort_t* channelCoord)
196 {
197   channelCoord[0] = channelId&0x3f;
198   channelCoord[1] = (channelId >> 6)&0x3f;
199   channelCoord[2] = (channelId >> 12)&0x1;
200   channelCoord[3] = (channelId >> 13)&0x1f;
201 }