]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSAltroMapping.cxx
add AliTPCcalibV0 class (Marian)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSAltroMapping.cxx
CommitLineData
b8018eab 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 PHOS
17// The mapping is read from an external mapping files
18// Author: C.Cheshkov
19
20#include "AliPHOSAltroMapping.h"
21#include "AliLog.h"
22#include <Riostream.h>
23//#include <stdlib.h>
24
25
26ClassImp(AliPHOSAltroMapping)
27
28//_____________________________________________________________________________
29AliPHOSAltroMapping::AliPHOSAltroMapping(const char *mappingFile):
30 AliAltroMapping(mappingFile),
31 fMinRow(0),
32 fMaxRow(0),
33 fMinCol(0),
34 fMaxCol(0),
35 fMapping(NULL),
36 fInvMappingLow(NULL),
37 fInvMappingHigh(NULL)
38{
39 // Constructor
40 ReadMapping();
41 CloseMappingFile();
42}
43
44//_____________________________________________________________________________
45AliPHOSAltroMapping::~AliPHOSAltroMapping()
46{
47 // destructor
48 DeleteMappingArrays();
49}
50
51//_____________________________________________________________________________
52AliPHOSAltroMapping::AliPHOSAltroMapping(const AliPHOSAltroMapping& mapping):
53 AliAltroMapping(mapping),
54 fMinRow(mapping.fMinRow),
55 fMaxRow(mapping.fMaxRow),
56 fMinCol(mapping.fMinCol),
57 fMaxCol(mapping.fMaxCol),
58 fMapping(mapping.fMapping),
59 fInvMappingLow(mapping.fInvMappingLow),
60 fInvMappingHigh(mapping.fInvMappingHigh)
61{
62// Copy Constructor
63
64 Fatal("AliPHOSAltroMapping", "copy constructor not implemented");
65}
66
67//_____________________________________________________________________________
68AliPHOSAltroMapping& AliPHOSAltroMapping::operator = (const AliPHOSAltroMapping& /*mapping*/)
69{
70//Assigment operator
71
72 Fatal("operator =", "assignment operator not implemented");
73 return *this;
74}
75
76//_____________________________________________________________________________
77Bool_t AliPHOSAltroMapping::ReadMapping()
78{
79 // Initalizes the ALTRO mapping from a file
80 // Look at the PHOS module for the format of
81 // the mapping file
82 if (!fIn) {
83 AliFatal("Mapping file has not been opened !");
84 return kFALSE;
85 }
86
87 fMinRow = 0x7fffffff;
88 fMaxRow = 0;
89 fMinCol = 0x7fffffff;
90 fMaxCol = 0;
91 fMapping = new Short_t*[fMaxHWAddress+1];
92 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
93 fMapping[i] = new Short_t[3];
94 fMapping[i][0] = fMapping[i][1] = fMapping[i][2] = -1;
95 }
96
97 for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
98 Int_t hwAddress;
99 if (!(*fIn >> hwAddress)) {
100 AliFatal("Syntax of the mapping file is wrong !");
101 return kFALSE;
102 }
103 if (hwAddress > fMaxHWAddress) {
104 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
105 return kFALSE;
106 }
107 Int_t row,col,gain;
108 if (!(*fIn >> row >> col >> gain)) {
109 AliFatal("Syntax of the mapping file is wrong !");
110 return kFALSE;
111 }
112
113 if (gain < 0 || gain > 1) {
114 AliFatal(Form("Wrong gain value found (%d)! Should be 0 or 1 !",gain));
115 return kFALSE;
116 }
117
118 fMapping[hwAddress][0] = row;
119 fMapping[hwAddress][1] = col;
120 fMapping[hwAddress][2] = gain;
121
122 if (row > fMaxRow) fMaxRow = row;
123 if (row < fMinRow) fMinRow = row;
124 if (col > fMaxCol) fMaxCol = col;
125 if (col < fMinCol) fMinCol = col;
126
127 }
128
129 fInvMappingLow = new Short_t*[fMaxRow - fMinRow + 1];
130 fInvMappingHigh = new Short_t*[fMaxRow - fMinRow + 1];
131 for (Int_t i = 0; i <= (fMaxRow - fMinRow); i++) {
132 fInvMappingLow[i] = new Short_t[fMaxCol - fMinCol + 1];
133 fInvMappingHigh[i] = new Short_t[fMaxCol - fMinCol + 1];
134 for (Int_t j = 0; j <= (fMaxCol - fMinCol); j++) {
135 fInvMappingLow[i][j] = -1;
136 fInvMappingHigh[i][j] = -1;
137 }
138 }
139
140 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
141 Int_t row = fMapping[i][0];
142 Int_t col = fMapping[i][1];
143 Int_t gain = fMapping[i][2];
144 if(row != -1 && col != -1) {
145 if (gain == 0)
146 fInvMappingLow[row-fMinRow][col-fMinCol] = i;
147 if (gain == 1)
148 fInvMappingHigh[row-fMinRow][col-fMinCol] = i;
149 }
150 }
151
152 return kTRUE;
153}
154
155//_____________________________________________________________________________
156Int_t AliPHOSAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t gain) const
157{
158 // Get the content of the mapping array
159 // return -1 in case there is no hardware
160 // adress defined for these row-column-gain
161 if (!fInvMappingLow || !fInvMappingHigh) {
162 AliWarning("Mapping array was not initalized correctly !");
163 return -1;
164 }
165 if (row < fMinRow || row > fMaxRow) {
166 AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
167 return -1;
168 }
169 if (col < fMinCol || col > fMaxCol) {
170 AliWarning(Form("Index of column (%d) outside the range (0 -> %d) !",col,fMinCol,fMaxCol));
171 return -1;
172 }
173 if (gain < 0 || gain > 1) {
174 AliWarning(Form("Invalid gain (%d)! Should be 0 or 1 !",gain));
175 return -1;
176 }
177 Int_t hwAddress = -1;
178 if (gain == 0)
179 hwAddress = fInvMappingLow[row-fMinRow][col-fMinCol];
180 if (gain == 1)
181 hwAddress = fInvMappingHigh[row-fMinRow][col-fMinCol];
182
183 if (hwAddress == -1)
184 AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and gain (%d) !",row,col,gain));
185
186 return hwAddress;
187}
188
189//_____________________________________________________________________________
190Int_t AliPHOSAltroMapping::GetPadRow(Int_t hwAddress) const
191{
192 // Return the row index
193 // Note the difference w.r.t to the base class notation
194 if (!fMapping) {
195 AliWarning("Mapping array was not initalized correctly !");
196 return -1;
197 }
198 if (hwAddress > fMaxHWAddress) {
199 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
200 return -1;
201 }
202 Int_t row = fMapping[hwAddress][0];
203 if (row == -1)
204 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
205
206 return row;
207}
208
209//_____________________________________________________________________________
210Int_t AliPHOSAltroMapping::GetPad(Int_t hwAddress) const
211{
212 // Return the column index
213 // Note the difference w.r.t to the base class notation
214 if (!fMapping) {
215 AliWarning("Mapping array was not initalized correctly !");
216 return -1;
217 }
218 if (hwAddress > fMaxHWAddress) {
219 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
220 return -1;
221 }
222 Int_t col = fMapping[hwAddress][1];
223 if (col == -1)
224 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
225
226 return col;
227}
228
229//_____________________________________________________________________________
230Int_t AliPHOSAltroMapping::GetSector(Int_t hwAddress) const
231{
232 // Return the gain factor (0/1)
233 // Note the difference w.r.t to the base class notation
234 if (!fMapping) {
235 AliWarning("Mapping array was not initalized correctly !");
236 return -1;
237 }
238 if (hwAddress > fMaxHWAddress) {
239 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
240 return -1;
241 }
242 Int_t gain = fMapping[hwAddress][2];
243 if (gain == -1)
244 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
245
246 return gain;
247}
248
249//_____________________________________________________________________________
250void AliPHOSAltroMapping::DeleteMappingArrays()
251{
252 // Deletes the arrays which have been
253 // allocated during the reading of the
254 // mapping file
255 if (fMapping) {
256 for (Int_t i = 0; i <= fMaxHWAddress; i++) delete [] fMapping[i];
257 delete [] fMapping;
258 }
259
260 if (fInvMappingLow) {
261 for (Int_t i = 0; i <= (fMaxRow - fMinRow); i++)
262 delete [] fInvMappingLow[i];
263 delete [] fInvMappingLow;
264 }
265
266 if (fInvMappingHigh) {
267 for (Int_t i = 0; i <= (fMaxRow - fMinRow); i++)
268 delete [] fInvMappingHigh[i];
269 delete [] fInvMappingHigh;
270 }
271}