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