]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCAltroMapping.cxx
Fix array sizes.
[u/mrichter/AliRoot.git] / TPC / AliTPCAltroMapping.cxx
CommitLineData
dc43b139 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// This class handles the mapping of the Altro channels in the TPC
17// The mapping is read from an external mapping files
18// Author: C.Cheshkov
19
20#include "AliTPCAltroMapping.h"
21#include "AliLog.h"
22#include <Riostream.h>
23//#include <stdlib.h>
24
25
26ClassImp(AliTPCAltroMapping)
27
44174d11 28//_____________________________________________________________________________
29AliTPCAltroMapping::AliTPCAltroMapping():
30 AliAltroMapping(),
31 fMinPadRow(0),
32 fMaxPadRow(0),
33 fMaxPad(0),
34 fMapping(NULL),
35 fInvMapping(NULL)
36{
37 // Default constructor
38}
39
dc43b139 40//_____________________________________________________________________________
41AliTPCAltroMapping::AliTPCAltroMapping(const char *mappingFile):
42 AliAltroMapping(mappingFile),
43 fMinPadRow(0),
44 fMaxPadRow(0),
45 fMaxPad(0),
46 fMapping(NULL),
47 fInvMapping(NULL)
48{
49 // Constructor
50 ReadMapping();
51 CloseMappingFile();
52}
53
54//_____________________________________________________________________________
55AliTPCAltroMapping::~AliTPCAltroMapping()
56{
57 // destructor
58 DeleteMappingArrays();
59}
60
dc43b139 61//_____________________________________________________________________________
62Bool_t AliTPCAltroMapping::ReadMapping()
63{
64 // Initalizes the ALTRO mapping from a file
65 // Look at the TPC module for the format of
66 // the mapping file
67 if (!fIn) {
68 AliFatal("Mapping file has not been opened !");
69 return kFALSE;
70 }
71
72 fMinPadRow = 0x7fffffff;
73 fMaxPadRow = 0;
74 fMaxPad = 0;
44174d11 75 fMappingSize = 2*(fMaxHWAddress+1);
76 fMapping = new Short_t[fMappingSize];
d11035b8 77 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 78 fMapping[2*i] = fMapping[2*i+1] = -1;
dc43b139 79 }
80
81 for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
d11035b8 82 Int_t hwAddress;
83 if (!(*fIn >> hwAddress)) {
dc43b139 84 AliFatal("Syntax of the mapping file is wrong !");
85 return kFALSE;
86 }
d11035b8 87 if (hwAddress > fMaxHWAddress) {
88 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 89 return kFALSE;
90 }
91 Int_t padrow,pad;
92 if (!(*fIn >> padrow >> pad)) {
93 AliFatal("Syntax of the mapping file is wrong !");
94 return kFALSE;
95 }
96
44174d11 97 fMapping[2*hwAddress] = padrow;
98 fMapping[2*hwAddress+1] = pad;
dc43b139 99
100 if (padrow > fMaxPadRow) fMaxPadRow = padrow;
101 if (padrow < fMinPadRow) fMinPadRow = padrow;
102 if (pad > fMaxPad) fMaxPad = pad;
103 }
104
44174d11 105 Int_t nRows = fMaxPadRow - fMinPadRow + 1;
106 Int_t nPads = fMaxPad + 1;
107 fInvMappingSize = nRows*nPads;
108
109 fInvMapping = new Short_t[fInvMappingSize];
dc43b139 110 for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
44174d11 111 for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[nPads*i+j] = -1;
dc43b139 112 }
113
d11035b8 114 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 115 Int_t padrow = fMapping[2*i];
116 Int_t pad = fMapping[2*i+1];
dc43b139 117 if(padrow != -1 && pad != -1)
44174d11 118 fInvMapping[nPads*(padrow-fMinPadRow)+pad] = i;
dc43b139 119 }
120
121 return kTRUE;
122}
123
124//_____________________________________________________________________________
d11035b8 125Int_t AliTPCAltroMapping::GetHWAddress(Int_t padrow, Int_t pad, Int_t /* sector */) const
dc43b139 126{
127 // Get the content of the mapping array
128 // return -1 in case there is no hardware
129 // adress defined for these pad-row and pad
130 if (!fInvMapping) {
131 AliWarning("Mapping array was not initalized correctly !");
132 return -1;
133 }
134 if (padrow < fMinPadRow || padrow > fMaxPadRow) {
135 AliWarning(Form("Index of pad-row (%d) outside the range (%d -> %d) !",padrow,fMinPadRow,fMaxPadRow));
136 return -1;
137 }
138 if (pad > fMaxPad) {
139 AliWarning(Form("Index of pad (%d) outside the range (0 -> %d) !",pad,fMaxPad));
140 return -1;
141 }
44174d11 142 Int_t hwAddress = fInvMapping[(fMaxPad+1)*(padrow-fMinPadRow)+pad];
d11035b8 143 if (hwAddress == -1)
dc43b139 144 AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
145
d11035b8 146 return hwAddress;
dc43b139 147}
148
149//_____________________________________________________________________________
d11035b8 150Int_t AliTPCAltroMapping::GetPadRow(Int_t hwAddress) const
dc43b139 151{
152 if (!fMapping) {
153 AliWarning("Mapping array was not initalized correctly !");
154 return -1;
155 }
d11035b8 156 if (hwAddress > fMaxHWAddress) {
157 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 158 return -1;
159 }
44174d11 160 Int_t padrow = fMapping[2*hwAddress];
dc43b139 161 if (padrow == -1)
d11035b8 162 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
dc43b139 163
164 return padrow;
165}
166
167//_____________________________________________________________________________
d11035b8 168Int_t AliTPCAltroMapping::GetPad(Int_t hwAddress) const
dc43b139 169{
170 if (!fMapping) {
171 AliWarning("Mapping array was not initalized correctly !");
172 return -1;
173 }
d11035b8 174 if (hwAddress > fMaxHWAddress) {
175 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 176 return -1;
177 }
44174d11 178 Int_t pad = fMapping[2*hwAddress+1];
dc43b139 179 if (pad == -1)
d11035b8 180 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
dc43b139 181
182 return pad;
183}
184
185//_____________________________________________________________________________
d11035b8 186Int_t AliTPCAltroMapping::GetSector(Int_t /* hwAddress */) const
dc43b139 187{
188 AliWarning("Sector index is not contained in the TPC altro mapping !");
189 return -1;
190}
191
192//_____________________________________________________________________________
193void AliTPCAltroMapping::DeleteMappingArrays()
194{
195 // Deletes the arrays which have been
196 // allocated during the reading of the
197 // mapping file
44174d11 198 if (fMapping) delete [] fMapping;
dc43b139 199
44174d11 200 if (fInvMapping) delete [] fInvMapping;
dc43b139 201}