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, 2007 *
7 : * *
8 : * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT 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 : #include "AliHLTEMCALMapper.h"
22 : #include "assert.h"
23 : #include "AliHLTCaloConstants.h"
24 : #include "AliHLTCaloCoordinate.h"
25 : #include "TString.h"
26 : #include <memory>
27 :
28 : using EMCAL::NXCOLUMNSMOD;
29 : using EMCAL::NZROWSMOD;
30 : using EMCAL::NMODULES;
31 : using EMCAL::NRCUSPERMODULE;
32 : using EMCAL::NRCUSPERSECTOR;
33 : using EMCAL::MAXHWADDR;
34 : using EMCAL::MAXCHANNELS;
35 :
36 0 : AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
37 0 : {
38 0 : fCellSize = 6;
39 0 : InitAltroMapping(specification);
40 0 : InitDDLSpecificationMapping();
41 0 : fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
42 0 : }
43 :
44 :
45 0 : AliHLTEMCALMapper::~AliHLTEMCALMapper()
46 0 : {
47 :
48 0 : }
49 :
50 :
51 : void
52 : AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
53 : {
54 0 : localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2) * fCellSize;
55 0 : localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
56 0 : }
57 :
58 :
59 : Bool_t
60 : AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
61 : {
62 0 : TString base(getenv("ALICE_ROOT"));
63 0 : int nChannels = 0;
64 0 : int maxaddr = 0; // keep as dummy for now
65 0 : int tmpHwaddr = 0;
66 0 : int tmpZRow = 0;
67 0 : int tmpXCol = 0;
68 0 : int tmpGain = 0;
69 : int res = 0;
70 0 : fIsInitializedMapping = false;
71 :
72 0 : if(!base.IsNull())
73 : {
74 0 : snprintf(fFilepath,FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base.Data(), DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
75 0 : snprintf(fFilepath, FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base.Data(), DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
76 :
77 0 : FILE * fp = fopen(fFilepath, "r");
78 0 : if(fp != 0)
79 : {
80 0 : res = fscanf(fp, "%d\n", &nChannels);
81 0 : if (res!=1) return false;
82 0 : res = fscanf(fp, "%d\n", &maxaddr);
83 0 : if (res!=1) return false;
84 : // fHw2geomapPtr = new fAltromap[maxaddr +1];
85 0 : fHw2geomapPtr = new fAltromap[MAXHWADDR +1];
86 :
87 0 : for(int i=0; i< MAXHWADDR + 1 ; i ++)
88 : //for(int i=0; i< maxaddr + 1 ; i ++)
89 : {
90 0 : fHw2geomapPtr[i].fXCol = 0;
91 0 : fHw2geomapPtr[i].fZRow = 0;
92 0 : fHw2geomapPtr[i].fGain = 0;
93 : }
94 : // MAXCHANNELS
95 0 : if( nChannels > 0 && nChannels <= MAXCHANNELS )
96 : {
97 0 : for(int i=0; i<nChannels; i ++)
98 : {
99 0 : res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
100 0 : if (res!=4) return false;
101 :
102 0 : if(tmpGain < 2)
103 : {
104 0 : if( tmpHwaddr <= MAXHWADDR && tmpHwaddr >= 0 )
105 : {
106 0 : fHw2geomapPtr[tmpHwaddr].fXCol = (char)tmpXCol;
107 0 : fHw2geomapPtr[tmpHwaddr].fZRow = (char)tmpZRow;
108 0 : fHw2geomapPtr[tmpHwaddr].fGain = (char)tmpGain;
109 0 : }
110 : }
111 : }
112 0 : fIsInitializedMapping = true;
113 0 : }
114 : else
115 : {
116 0 : fIsInitializedMapping = false;
117 : }
118 0 : fclose(fp);
119 : }
120 : else
121 : {
122 0 : fIsInitializedMapping = false;
123 : }
124 0 : }
125 : else
126 : {
127 0 : fIsInitializedMapping = false;
128 : }
129 :
130 0 : return fIsInitializedMapping;
131 0 : }
132 :
133 :
134 : void
135 : AliHLTEMCALMapper::InitDDLSpecificationMapping()
136 : {
137 0 : if (fSpecificationMapPtr) delete [] fSpecificationMapPtr;
138 0 : fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
139 :
140 0 : for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
141 : {
142 0 : fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
143 : }
144 0 : }
145 :
146 : const char*
147 : AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
148 : {
149 : const int rnamelen=256;
150 : static char rname[rnamelen];
151 : char tmpSide;
152 :
153 0 : if ( ddlIndex%NRCUSPERSECTOR <2)
154 : {
155 : tmpSide = 'A';
156 0 : }
157 : else
158 : {
159 : tmpSide = 'C';
160 : }
161 0 : int tmprcuindex = ddlIndex%2;
162 0 : snprintf(rname, rnamelen, "RCU%d%c.data", tmprcuindex, tmpSide );
163 : //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
164 0 : return rname;
165 : }
166 :
167 : int AliHLTEMCALMapper::GetDDLFromSpec( const AliHLTUInt32_t spec ){
168 : /* New handling: specification is the DDL number in EMCAL */
169 0 : return int(spec);
170 : }
171 :
172 : int AliHLTEMCALMapper::GetModuleFromSpec(UInt_t specification){
173 : /* New handling: specification is the DDL number in EMCAL */
174 0 : if(specification >= 40) return -1;
175 0 : return int(specification / 2);
176 0 : }
177 :
178 : void AliHLTEMCALMapper::FixCoordinate(AliHLTCaloCoordinate &coord){
179 : /*
180 : * Port from AliEMCALGeometry::ShiftOnlineToOfflineCellIndexes,
181 : * fixes mapping problem in the DCAL. See documentation in AliEMCALGeometry
182 : * for more information.
183 : */
184 0 : if ( coord.fModuleId == 13 || coord.fModuleId == 15 || coord.fModuleId == 17 )
185 : {
186 : // DCal odd SMs
187 0 : coord.fZ -= 16; // Same cabling mapping as for EMCal, not considered offline.
188 0 : }
189 0 : else if ( coord.fModuleId == 18 || coord.fModuleId == 19 )
190 : {
191 : // DCal 1/3 SMs
192 0 : coord.fX -= 16; // Needed due to cabling mistake.
193 0 : }
194 0 : }
|