1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // This class handles the mapping of the Altro channels in the PHOS/EMCAL
18 // The mapping is read from an external mapping files
21 /// Exported from PHOS to be used also by EMCAL
22 /// November 2006 Gustavo Conesa Balbastre
24 #include "AliCaloAltroMapping.h"
26 #include <Riostream.h>
30 ClassImp(AliCaloAltroMapping)
32 //_____________________________________________________________________________
33 AliCaloAltroMapping::AliCaloAltroMapping(const char *mappingFile):
34 AliAltroMapping(mappingFile),
48 //_____________________________________________________________________________
49 AliCaloAltroMapping::~AliCaloAltroMapping()
52 DeleteMappingArrays();
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)
68 Fatal("AliCaloAltroMapping", "copy constructor not implemented");
71 //_____________________________________________________________________________
72 AliCaloAltroMapping& AliCaloAltroMapping::operator = (const AliCaloAltroMapping& /*mapping*/)
76 Fatal("operator =", "assignment operator not implemented");
80 //_____________________________________________________________________________
81 Bool_t AliCaloAltroMapping::ReadMapping()
83 // Initalizes the ALTRO mapping from a file
84 // Look at the Calo module for the format of
87 AliFatal("Mapping file has not been opened !");
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;
101 for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
103 if (!(*fIn >> hwAddress)) {
104 AliFatal("Syntax of the mapping file is wrong !");
107 if (hwAddress > fMaxHWAddress) {
108 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
112 if (!(*fIn >> row >> col >> gain)) {
113 AliFatal("Syntax of the mapping file is wrong !");
117 if (gain < 0 || gain > 1) {
118 AliFatal(Form("Wrong gain value found (%d)! Should be 0 or 1 !",gain));
122 fMapping[hwAddress][0] = row;
123 fMapping[hwAddress][1] = col;
124 fMapping[hwAddress][2] = gain;
126 if (row > fMaxRow) fMaxRow = row;
127 if (row < fMinRow) fMinRow = row;
128 if (col > fMaxCol) fMaxCol = col;
129 if (col < fMinCol) fMinCol = col;
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;
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) {
150 fInvMappingLow[row-fMinRow][col-fMinCol] = i;
152 fInvMappingHigh[row-fMinRow][col-fMinCol] = i;
159 //_____________________________________________________________________________
160 Int_t AliCaloAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t gain) const
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 !");
169 if (row < fMinRow || row > fMaxRow) {
170 AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
173 if (col < fMinCol || col > fMaxCol) {
174 AliWarning(Form("Index of column (%d) outside the range (0 -> %d) !",col,fMinCol,fMaxCol));
177 if (gain < 0 || gain > 1) {
178 AliWarning(Form("Invalid gain (%d)! Should be 0 or 1 !",gain));
181 Int_t hwAddress = -1;
183 hwAddress = fInvMappingLow[row-fMinRow][col-fMinCol];
185 hwAddress = fInvMappingHigh[row-fMinRow][col-fMinCol];
188 AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and gain (%d) !",row,col,gain));
193 //_____________________________________________________________________________
194 Int_t AliCaloAltroMapping::GetPadRow(Int_t hwAddress) const
196 // Return the row index
197 // Note the difference w.r.t to the base class notation
199 AliWarning("Mapping array was not initalized correctly !");
202 if (hwAddress > fMaxHWAddress) {
203 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
206 Int_t row = fMapping[hwAddress][0];
208 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
213 //_____________________________________________________________________________
214 Int_t AliCaloAltroMapping::GetPad(Int_t hwAddress) const
216 // Return the column index
217 // Note the difference w.r.t to the base class notation
219 AliWarning("Mapping array was not initalized correctly !");
222 if (hwAddress > fMaxHWAddress) {
223 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
226 Int_t col = fMapping[hwAddress][1];
228 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
233 //_____________________________________________________________________________
234 Int_t AliCaloAltroMapping::GetSector(Int_t hwAddress) const
236 // Return the gain factor (0/1)
237 // Note the difference w.r.t to the base class notation
239 AliWarning("Mapping array was not initalized correctly !");
242 if (hwAddress > fMaxHWAddress) {
243 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
246 Int_t gain = fMapping[hwAddress][2];
248 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
253 //_____________________________________________________________________________
254 void AliCaloAltroMapping::DeleteMappingArrays()
256 // Deletes the arrays which have been
257 // allocated during the reading of the
260 for (Int_t i = 0; i <= fMaxHWAddress; i++) delete [] fMapping[i];
264 if (fInvMappingLow) {
265 for (Int_t i = 0; i <= (fMaxRow - fMinRow); i++)
266 delete [] fInvMappingLow[i];
267 delete [] fInvMappingLow;
270 if (fInvMappingHigh) {
271 for (Int_t i = 0; i <= (fMaxRow - fMinRow); i++)
272 delete [] fInvMappingHigh[i];
273 delete [] fInvMappingHigh;