Line data Source code
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 "AliHLTCaloMapper.h"
28 : #include "AliHLTLogging.h"
29 : #include "Rtypes.h"
30 : #include "unistd.h"
31 : #include <iostream>
32 : #include "AliHLTCaloCoordinate.h"
33 : #include "AliHLTCaloConstantsHandler.h"
34 :
35 : //#include "AliHLTCaloConstants.h"
36 :
37 :
38 : //typedef AliHLTCaloConstantsHandler::fCaloConstants->GetCELLSTEP() CELLSTEP;
39 :
40 : //#define fCaloConstants->GetCELLSTEP() CELLSTEP
41 :
42 :
43 :
44 : //typedef CELLSTEP fCaloConstants->GetCELLSTEP();
45 :
46 6 : ClassImp(AliHLTCaloMapper);
47 :
48 : AliHLTCaloMapper::AliHLTCaloMapper( const unsigned long specification , TString det) :
49 0 : AliHLTCaloConstantsHandler(det),
50 0 : AliHLTLogging(),
51 0 : fHw2geomapPtr(0),
52 0 : fCellSize(0),
53 0 : fSpecification(specification),
54 0 : fIsInitializedMapping(false),
55 0 : fSpecificationMapPtr(0),
56 0 : fCaloDet(det)
57 0 : {
58 : //see header file for class documentation
59 0 : fFilepath[0] = '\0';
60 0 : }
61 :
62 :
63 0 : AliHLTCaloMapper::~AliHLTCaloMapper()
64 0 : {
65 0 : if (fSpecificationMapPtr) delete [] fSpecificationMapPtr;
66 0 : fSpecificationMapPtr = NULL;
67 0 : if (fHw2geomapPtr) delete [] fHw2geomapPtr;
68 0 : fHw2geomapPtr = NULL;
69 0 : }
70 :
71 :
72 : //void AliHLTCaloMapper::InitAltroMapping(){
73 : //Virtual base class
74 : //}
75 :
76 : //void AliHLTCaloMapper::InitDDLSpecificationMapping() {
77 : //Virtual base class
78 : //}
79 :
80 :
81 :
82 : bool
83 : AliHLTCaloMapper::GetIsInitializedMapping()
84 : {
85 0 : return fIsInitializedMapping;
86 : }
87 :
88 :
89 : char*
90 : AliHLTCaloMapper::GetFilePath()
91 : {
92 0 : return fFilepath;
93 : }
94 :
95 :
96 : int
97 : AliHLTCaloMapper::GetChannelID(const AliHLTUInt32_t spec, const Int_t hadd)
98 : {
99 0 : if (!fSpecificationMapPtr) return -ENODEV;
100 0 : Short_t index = GetDDLFromSpec(spec);
101 0 : if( index < 0 )
102 : {
103 0 : HLTError("Specification 0x%X not consistent with single DDL in PHOS", spec);
104 0 : return index;
105 : }
106 : else
107 : {
108 0 : return ((fHw2geomapPtr[hadd].fXCol ) |
109 0 : ((fHw2geomapPtr[hadd].fZRow ) << 6) |
110 0 : (fHw2geomapPtr[hadd].fGain << 12) |
111 0 : fSpecificationMapPtr[index].fModId << 13);
112 : }
113 0 : }
114 :
115 :
116 : void
117 : AliHLTCaloMapper::GetChannelCoord(const UShort_t channelId, UShort_t* channelCoord)
118 : {
119 0 : channelCoord[0] = channelId&0x3f;
120 0 : channelCoord[1] = (channelId >> 6)&0x3f;
121 0 : channelCoord[2] = (channelId >> 12)&0x1;
122 0 : channelCoord[3] = (channelId >> 13)&0x1f;
123 : // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
124 0 : }
125 :
126 : void
127 : AliHLTCaloMapper::ChannelId2Coordinate(const int channelId, AliHLTCaloCoordinate &channelCoord)
128 : {
129 0 : channelCoord.fX = channelId&0x3f;
130 0 : channelCoord.fZ = (channelId >> 6)&0x3f;
131 0 : channelCoord.fGain = (channelId >> 12)&0x1;
132 0 : channelCoord.fModuleId = (channelId >> 13)&0x1f;
133 : // printf("Channel ID: 0x%X Coordinates: x = %d, z = %d, gain = %d\n", channelId, channelCoord[0], channelCoord[1], channelCoord[2]);
134 0 : }
135 :
136 :
137 : void
138 : AliHLTCaloMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
139 : {
140 0 : localCoord[0] = (static_cast<Float_t>(channelId&0x3f) - fCaloConstants->GetNXCOLUMNSMOD()/2)* fCaloConstants->GetCELLSTEP();
141 : // localCoord[0] = (static_cast<Float_t>(channelId&0x3f) - fCaloConstants->GetNXCOLUMNSMOD()/2)*CELLSTEP;
142 0 : localCoord[1] = (static_cast<Float_t>((channelId >> 6)&0x3f) - fCaloConstants->GetNZROWSMOD()/2) * fCaloConstants->GetCELLSTEP();
143 : // printf("Local coordinates: x = %f, z = %f\n", channelCoord[0], channelCoord[1]);
144 0 : }
145 :
146 :
147 : int
148 : AliHLTCaloMapper::GetDDLFromSpec( const AliHLTUInt32_t spec )
149 : {
150 : int tmpIndex = -1;
151 0 : for(int i=0; i < 32; i++ )
152 : {
153 0 : if (spec >> i ==1)
154 : {
155 : tmpIndex = i;
156 0 : break;
157 : }
158 : }
159 : if( tmpIndex < 0)
160 : {
161 : // HLTError("Specification %d, not consistent with any DDL in PHOS or EMCAL", spec );
162 : }
163 :
164 0 : return tmpIndex;
165 : }
166 :
167 :
168 : Int_t
169 : AliHLTCaloMapper::GetModuleFromSpec(UInt_t specification)
170 : {
171 :
172 : Int_t module = -1;
173 : // get rid of too much string operations
174 :
175 : // if (fCaloDet.CompareTo("PHOS") == 0) {
176 :
177 0 : if (fCaloDet[0]=='P') {
178 : // P = is the short for PHOS
179 : // 1 module = 4 bits
180 0 : if(specification & 0xf) module = 0;
181 0 : else if((specification >> 4) & 0xf) module = 1;
182 0 : else if((specification >> 8) & 0xf) module = 2;
183 0 : else if((specification >> 12) & 0xf) module = 3;
184 0 : else if((specification >> 16) & 0xf) module = 4;
185 : else {
186 : HLTDebug("Specification 0x%X not consistent with single module in PHOS", specification);
187 : }
188 :
189 0 : return module;
190 : }
191 : //else if (fCaloDet.CompareTo("EMCAL") == 0) {
192 0 : else if (fCaloDet[0]=='E') {
193 :
194 : // E = is the short for EMCAL
195 : // 1 module = 2 bits
196 0 : if(specification & 0x3) module = 0;
197 0 : else if((specification >> 2) & 0x3) module = 1;
198 0 : else if((specification >> 4) & 0x3) module = 2;
199 0 : else if((specification >> 6) & 0x3) module = 3;
200 0 : else if((specification >> 8) & 0x3) module = 4;
201 0 : else if((specification >> 10) & 0x3) module = 5;
202 0 : else if((specification >> 12) & 0x3) module = 6;
203 0 : else if((specification >> 14) & 0x3) module = 7;
204 0 : else if((specification >> 16) & 0x3) module = 8;
205 0 : else if((specification >> 18) & 0x3) module = 9;
206 : else {
207 : HLTDebug("Specification 0x%X not consistent with single module in EMCAL", specification);
208 : }
209 0 : return module;
210 :
211 : } else {
212 : HLTDebug("Specification 0x%X not consistent with single module in EMCAL or PHOS", specification);
213 : }
214 0 : return module;
215 0 : }
216 :
217 :
218 : unsigned long
219 : AliHLTCaloMapper::GetSpecFromDDLIndex( const int ddlindex )
220 : {
221 0 : int iret = (unsigned long)1 << ddlindex;
222 :
223 : // return ((unsigned long)1) << ddlindex ) ;
224 :
225 0 : return iret;
226 :
227 : }
228 :
|