]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSMapper.cxx
Add new fast raw data streamer
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
CommitLineData
1b41ab20 1// $Id$
2
2f09efe8 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
af6a2273 21//
22// Mapping class fro mapping
23// from hardware address to geometrical address
24//
25//
26
2f09efe8 27#include "AliHLTPHOSMapper.h"
94594220 28#include "AliHLTPHOSConstants.h"
29#include "AliHLTLogging.h"
30#include "Rtypes.h"
7eb756c1 31#include "unistd.h"
32#include <iostream>
2f09efe8 33
94594220 34using namespace PhosHLTConst;
35AliHLTPHOSMapper::AliHLTPHOSMapper(): AliHLTLogging(),
8efbf5fe 36 fHw2geomapPtr(0),
94594220 37 fIsInitializedMapping(false),
38 fSpecificationMapPtr(0)
2f09efe8 39{
c37f821f 40 InitAltroMapping();
94594220 41 InitDDLSpecificationMapping();
2f09efe8 42}
43
c37f821f 44
45AliHLTPHOSMapper::~AliHLTPHOSMapper()
2f09efe8 46{
a6755e15 47 delete [] fHw2geomapPtr;
48 fHw2geomapPtr = 0;
c37f821f 49}
2f09efe8 50
c37f821f 51void
52AliHLTPHOSMapper::InitAltroMapping()
53{
af6a2273 54 // Loads mapping between Altro addresses and geometrical addresses from file
55
8efbf5fe 56 // char filename[256];
c37f821f 57 char *base = getenv("ALICE_ROOT");
c37f821f 58 int nChannels = 0;
59 int maxaddr = 0;
c37f821f 60 int tmpHwaddr = 0;
61 int tmpZRow = 0;
62 int tmpXCol = 0;
63 int tmpGain = 0;
e304ea31 64 int res = 0; //OD to get rid of warnings
c37f821f 65 if(base !=0)
2f09efe8 66 {
8efbf5fe 67 sprintf(fFilepath,"%s/PHOS/mapping/RCU0.data", base);
68
69 FILE *fp = fopen(fFilepath, "r");
c37f821f 70 if(fp != 0)
2f09efe8 71 {
e304ea31 72 res = fscanf(fp, "%d", &nChannels);
73 res = fscanf(fp, "%d", &maxaddr);
af6a2273 74 fHw2geomapPtr = new fAltromap[maxaddr +1];
c37f821f 75
43dd7c5e 76 for(int i=0; i< maxaddr + 1 ; i ++)
2f09efe8 77 {
af6a2273 78 fHw2geomapPtr[i].fXCol = 0;
79 fHw2geomapPtr[i].fZRow = 0;
80 fHw2geomapPtr[i].fGain = 0;
c37f821f 81 }
82
c37f821f 83 for(int i=0; i<nChannels; i ++)
84 {
e304ea31 85 res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
af6a2273 86 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
87 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
88 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
c37f821f 89 }
8efbf5fe 90 fIsInitializedMapping = true;
91 fclose(fp);
c37f821f 92 }
93 else
94 {
8efbf5fe 95 fIsInitializedMapping = false;
2f09efe8 96 }
97 }
c37f821f 98 else
99 {
8efbf5fe 100 fIsInitializedMapping = false;
c37f821f 101 }
c37f821f 102}
103
94594220 104void
105AliHLTPHOSMapper::InitDDLSpecificationMapping()
106{
27029341 107 fSpecificationMapPtr = new fDDLSpecificationMap[PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE];
108 for(Int_t ddl = 0; ddl < PhosHLTConst::NMODULES*PhosHLTConst::NRCUSPERMODULE; ddl++)
94594220 109 {
110
27029341 111 fSpecificationMapPtr[ddl].fModId = ddl/PhosHLTConst::NRCUSPERMODULE;
94594220 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
27029341 136 fSpecificationMapPtr[ddl].fRcuZOffset = NZROWSRCU*(fSpecificationMapPtr[ddl].fRcuZ);
137 fSpecificationMapPtr[ddl].fRcuXOffset = NXCOLUMNSRCU*(fSpecificationMapPtr[ddl].fRcuX);
94594220 138 }
139}
140
8efbf5fe 141
142bool
143AliHLTPHOSMapper::GetIsInitializedMapping()
144{
145 return fIsInitializedMapping;
146}
147
148
149char*
150AliHLTPHOSMapper::GetFilePath()
151{
152 return fFilepath;
153}
94594220 154
155UShort_t
156AliHLTPHOSMapper::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
194void
195AliHLTPHOSMapper::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}