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():
43 // Default constructor
46 //_____________________________________________________________________________
47 AliCaloAltroMapping::AliCaloAltroMapping(const char *mappingFile):
48 AliAltroMapping(mappingFile),
62 //_____________________________________________________________________________
63 AliCaloAltroMapping::~AliCaloAltroMapping()
66 DeleteMappingArrays();
69 //_____________________________________________________________________________
70 Bool_t AliCaloAltroMapping::ReadMapping()
72 // Initalizes the ALTRO mapping from a file
73 // Look at the Calo module for the format of
76 AliFatal("Mapping file has not been opened !");
84 fMappingSize = 3*(fMaxHWAddress+1);
85 fMapping = new Short_t[fMappingSize];
86 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
87 fMapping[3*i] = fMapping[3*i+1] = fMapping[3*i+2] = -1;
90 for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
92 if (!(*fIn >> hwAddress)) {
93 AliFatal("Syntax of the mapping file is wrong !");
96 if (hwAddress > fMaxHWAddress) {
97 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
101 if (!(*fIn >> row >> col >> gain)) {
102 AliFatal("Syntax of the mapping file is wrong !");
106 if (gain < 0 || gain > 1) {
107 AliFatal(Form("Wrong gain value found (%d)! Should be 0 or 1 !",gain));
111 fMapping[3*hwAddress] = row;
112 fMapping[3*hwAddress+1] = col;
113 fMapping[3*hwAddress+2] = gain;
115 if (row > fMaxRow) fMaxRow = row;
116 if (row < fMinRow) fMinRow = row;
117 if (col > fMaxCol) fMaxCol = col;
118 if (col < fMinCol) fMinCol = col;
122 Int_t nRows = fMaxRow - fMinRow + 1;
123 Int_t nCols = fMaxCol - fMinCol + 1;
124 fInvMappingSize = nRows*nCols;
127 fInvMappingLow = new Short_t[fInvMappingSize];
128 fInvMappingHigh = new Short_t[fInvMappingSize];
129 for (Int_t i = 0; i < nRows; i++) {
130 for (Int_t j = 0; j < nCols; j++) {
131 fInvMappingLow[nCols*i+j] = -1;
132 fInvMappingHigh[nCols*i+j] = -1;
136 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
137 Int_t row = fMapping[3*i];
138 Int_t col = fMapping[3*i+1];
139 Int_t gain = fMapping[3*i+2];
140 if(row != -1 && col != -1) {
142 fInvMappingLow[nCols*(row-fMinRow)+(col-fMinCol)] = i;
144 fInvMappingHigh[nCols*(row-fMinRow)+(col-fMinCol)] = i;
151 //_____________________________________________________________________________
152 Int_t AliCaloAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t gain) const
154 // Get the content of the mapping array
155 // return -1 in case there is no hardware
156 // adress defined for these row-column-gain
157 if (!fInvMappingLow || !fInvMappingHigh) {
158 AliWarning("Mapping array was not initalized correctly !");
161 if (row < fMinRow || row > fMaxRow) {
162 AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
165 if (col < fMinCol || col > fMaxCol) {
166 AliWarning(Form("Index of column (%d) outside the range (0 -> %d) !",col,fMinCol,fMaxCol));
169 if (gain < 0 || gain > 1) {
170 AliWarning(Form("Invalid gain (%d)! Should be 0 or 1 !",gain));
173 Int_t hwAddress = -1;
175 hwAddress = fInvMappingLow[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
177 hwAddress = fInvMappingHigh[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
180 AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and gain (%d) !",row,col,gain));
185 //_____________________________________________________________________________
186 Int_t AliCaloAltroMapping::GetPadRow(Int_t hwAddress) const
188 // Return the row index
189 // Note the difference w.r.t to the base class notation
191 AliWarning("Mapping array was not initalized correctly !");
194 if (hwAddress > fMaxHWAddress) {
195 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
198 Int_t row = fMapping[3*hwAddress];
200 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
205 //_____________________________________________________________________________
206 Int_t AliCaloAltroMapping::GetPad(Int_t hwAddress) const
208 // Return the column index
209 // Note the difference w.r.t to the base class notation
211 AliWarning("Mapping array was not initalized correctly !");
214 if (hwAddress > fMaxHWAddress) {
215 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
218 Int_t col = fMapping[3*hwAddress+1];
220 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
225 //_____________________________________________________________________________
226 Int_t AliCaloAltroMapping::GetSector(Int_t hwAddress) const
228 // Return the gain factor (0/1)
229 // Note the difference w.r.t to the base class notation
231 AliWarning("Mapping array was not initalized correctly !");
234 if (hwAddress > fMaxHWAddress) {
235 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
238 Int_t gain = fMapping[3*hwAddress+2];
240 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
245 //_____________________________________________________________________________
246 void AliCaloAltroMapping::DeleteMappingArrays()
248 // Deletes the arrays which have been
249 // allocated during the reading of the
251 if (fMapping) delete [] fMapping;
253 if (fInvMappingLow) delete [] fInvMappingLow;
255 if (fInvMappingHigh) delete [] fInvMappingHigh;