Fixing memory leaks (Christian)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSMapper.cxx
CommitLineData
2f09efe8 1/**************************************************************************
2 * This file is property of and copyright by the Experimental Nuclear *
3 * Physics Group, Dep. of Physics *
4 * University of Oslo, Norway, 2006 *
5 * *
6 * Author: Per Thomas Hille perthi@fys.uio.no for the ALICE DCS 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 **************************************************************************/
18
af6a2273 19//
20// Mapping class fro mapping
21// from hardware address to geometrical address
22//
23//
24
2f09efe8 25#include "AliHLTPHOSMapper.h"
26
c37f821f 27
af6a2273 28AliHLTPHOSMapper::AliHLTPHOSMapper() : AliHLTPHOSBase(), fHw2geomapPtr(0)
2f09efe8 29{
30 // printf("\nCreating new mapper\n");
c37f821f 31 InitAltroMapping();
2f09efe8 32}
33
c37f821f 34
35AliHLTPHOSMapper::~AliHLTPHOSMapper()
2f09efe8 36{
4c111067 37 delete [] hw2geomapPtr;
38 hw2geomapPtr = 0;
c37f821f 39}
2f09efe8 40
c37f821f 41void
42AliHLTPHOSMapper::InitAltroMapping()
43{
af6a2273 44 // Loads mapping between Altro addresses and geometrical addresses from file
45
c37f821f 46 char filename[256];
47 char *base = getenv("ALICE_ROOT");
c37f821f 48 int nChannels = 0;
49 int maxaddr = 0;
c37f821f 50 int tmpHwaddr = 0;
51 int tmpZRow = 0;
52 int tmpXCol = 0;
53 int tmpGain = 0;
54
55 if(base !=0)
2f09efe8 56 {
c37f821f 57 sprintf(filename,"%s/PHOS/mapping/RCU0.data", base);
af6a2273 58
c37f821f 59 FILE *fp = fopen(filename, "r");
60 if(fp != 0)
2f09efe8 61 {
c37f821f 62 cout << "mapping file found" << endl;
63 fscanf(fp, "%d", &nChannels);
64 fscanf(fp, "%d", &maxaddr);
65 printf("nChannels = %d", nChannels);
66 printf("maxaddr = %d", maxaddr);
af6a2273 67 fHw2geomapPtr = new fAltromap[maxaddr +1];
c37f821f 68
43dd7c5e 69 for(int i=0; i< maxaddr + 1 ; i ++)
2f09efe8 70 {
af6a2273 71 fHw2geomapPtr[i].fXCol = 0;
72 fHw2geomapPtr[i].fZRow = 0;
73 fHw2geomapPtr[i].fGain = 0;
c37f821f 74 }
75
c37f821f 76 for(int i=0; i<nChannels; i ++)
77 {
78 fscanf(fp, "%d %d %d %d\n", &tmpHwaddr, &tmpXCol, &tmpZRow, &tmpGain);
af6a2273 79 fHw2geomapPtr[tmpHwaddr].fXCol = tmpXCol;
80 fHw2geomapPtr[tmpHwaddr].fZRow = tmpZRow;
81 fHw2geomapPtr[tmpHwaddr].fGain = tmpGain;
c37f821f 82 }
2f09efe8 83
c37f821f 84 }
85 else
86 {
87 cout << "ERROR could not find mapping file" << endl;
2f09efe8 88 }
c37f821f 89
2f09efe8 90 }
c37f821f 91 else
92 {
93 printf("AliHLTPHOSMapper::InitAltroMapping(), ERROR environment ALICE_ROOT is not set, cannot find mapping file");
94 }
95
96}
97