]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/EMCAL/AliHLTEMCALMapper.cxx
fixing memory leak https://savannah.cern.ch/bugs/?87435
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALMapper.cxx
CommitLineData
88b2ce82 1/**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2007 *
5 * *
6 * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
7 * Contributors are mentioned in the code where appropriate. *
8 * Please report bugs to perthi@fys.uio.no *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
dc3d3428 18
88b2ce82 19#include "AliHLTEMCALMapper.h"
b850c417 20#include "assert.h"
dc3d3428 21#include "AliHLTCaloConstants.h"
4d6be4cd 22
dc3d3428 23using EMCAL::NXCOLUMNSMOD;
24using EMCAL::NZROWSMOD;
25using EMCAL::NMODULES;
26using EMCAL::NRCUSPERMODULE;
27using EMCAL::NRCUSPERSECTOR;
f67ce0df 28using EMCAL::MAXHWADDR;
d468be51 29using EMCAL::MAXCHANNELS;
b850c417 30
1a57dd60 31AliHLTEMCALMapper::AliHLTEMCALMapper(const unsigned long specification ) : AliHLTCaloMapper(specification, "EMCAL")
88b2ce82 32{
b850c417 33 fCellSize = 6;
4d6be4cd 34 InitAltroMapping(specification);
88b2ce82 35 InitDDLSpecificationMapping();
76ffc0ce 36 fIsInitializedMapping = true; //CRAP PTH, must check if the initilization actually went ok
88b2ce82 37}
38
4d6be4cd 39
88b2ce82 40AliHLTEMCALMapper::~AliHLTEMCALMapper()
41{
bf8dec26 42 if (fSpecificationMapPtr) delete [] fSpecificationMapPtr;
43 if (fHw2geomapPtr) delete [] fHw2geomapPtr;
88b2ce82 44}
1a51306a 45
b850c417 46
b850c417 47void
48AliHLTEMCALMapper::GetLocalCoord(const int channelId, Float_t* localCoord) const
49{
50 localCoord[0] = ( ( Float_t )(channelId&0x3f) - NXCOLUMNSMOD/2) * fCellSize;
51 localCoord[1] = ( (Float_t)((channelId >> 6)&0x3f) - NZROWSMOD/2) * fCellSize;
52}
88b2ce82 53
54
44175a17 55Bool_t
4d6be4cd 56AliHLTEMCALMapper::InitAltroMapping(const unsigned long specification )
88b2ce82 57{
88b2ce82 58 char *base = getenv("ALICE_ROOT");
4d6be4cd 59 int nChannels = 0;
f67ce0df 60 int maxaddr = 0; // keep as dummy for now
4d6be4cd 61 int tmpHwaddr = 0;
88b2ce82 62 int tmpZRow = 0;
63 int tmpXCol = 0;
64 int tmpGain = 0;
65 int res = 0;
66
67 if(base !=0)
68 {
1a51306a 69 snprintf(fFilepath,FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base, DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
70 snprintf(fFilepath, FILEPATHMAXLENGTH,"%s/EMCAL/mapping/%s", base, DDL2RcuMapFileName( GetDDLFromSpec( specification ) ) );
b850c417 71
88b2ce82 72 FILE *fp = fopen(fFilepath, "r");
73 if(fp != 0)
74 {
4d6be4cd 75 res = fscanf(fp, "%d\n", &nChannels);
76 res = fscanf(fp, "%d\n", &maxaddr);
f67ce0df 77 // fHw2geomapPtr = new fAltromap[maxaddr +1];
78 fHw2geomapPtr = new fAltromap[MAXHWADDR +1];
79
80 for(int i=0; i< MAXHWADDR + 1 ; i ++)
81 //for(int i=0; i< maxaddr + 1 ; i ++)
88b2ce82 82 {
83 fHw2geomapPtr[i].fXCol = 0;
84 fHw2geomapPtr[i].fZRow = 0;
85 fHw2geomapPtr[i].fGain = 0;
86 }
d468be51 87 // MAXCHANNELS
5a6eb7ff 88 if( nChannels > 0 && nChannels <= MAXCHANNELS )
88b2ce82 89 {
d468be51 90 for(int i=0; i<nChannels; i ++)
88b2ce82 91 {
d468be51 92 res = fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
93
94 if(tmpGain < 2)
f67ce0df 95 {
e1c486ae 96 if( tmpHwaddr <= MAXHWADDR && tmpHwaddr >= 0 )
d468be51 97 {
98 fHw2geomapPtr[tmpHwaddr].fXCol = (char)tmpXCol;
99 fHw2geomapPtr[tmpHwaddr].fZRow = (char)tmpZRow;
100 fHw2geomapPtr[tmpHwaddr].fGain = (char)tmpGain;
101 }
102 }
103 }
104 fIsInitializedMapping = true;
105 }
106 else
107 {
108 fIsInitializedMapping = false;
88b2ce82 109 }
88b2ce82 110 fclose(fp);
111 }
112 else
113 {
4d6be4cd 114 fIsInitializedMapping = false;
88b2ce82 115 }
116 }
117 else
118 {
119 fIsInitializedMapping = false;
120 }
f92dcf21 121
122 return fIsInitializedMapping;
88b2ce82 123}
124
125
126void
127AliHLTEMCALMapper::InitDDLSpecificationMapping()
128{
dc3d3428 129 fSpecificationMapPtr = new fDDLSpecificationMap[NMODULES*NRCUSPERMODULE];
88b2ce82 130
dc3d3428 131 for(Int_t ddl = 0; ddl < NMODULES*NRCUSPERMODULE; ddl++)
88b2ce82 132 {
dc3d3428 133 fSpecificationMapPtr[ddl].fModId = ddl/( NRCUSPERMODULE );
88b2ce82 134 }
135}
136
4d6be4cd 137const char*
138AliHLTEMCALMapper::DDL2RcuMapFileName(const int ddlIndex) const //0=4608, 1=4607 etc...
88b2ce82 139{
197e0087 140 const int rnamelen=256;
141 static char rname[rnamelen];
4d6be4cd 142 char tmpSide;
143
144 if ( ddlIndex%NRCUSPERSECTOR <2)
145 {
146 tmpSide = 'A';
147 }
148 else
149 {
150 tmpSide = 'C';
151 }
b850c417 152 int tmprcuindex = ddlIndex%2;
197e0087 153 snprintf(rname, rnamelen, "RCU%d%c.data", tmprcuindex, tmpSide );
b850c417 154 //sprintf(rname,"RCU%d%c.data", ddlIndex/NRCUSPERSECTOR, tmpSide );
4d6be4cd 155 return rname;
88b2ce82 156}
4d6be4cd 157