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():
42 // Default constructor
45 //_____________________________________________________________________________
46 AliCaloAltroMapping::AliCaloAltroMapping(const char *mappingFile):
47 AliAltroMapping(mappingFile),
60 //_____________________________________________________________________________
61 AliCaloAltroMapping::~AliCaloAltroMapping()
64 // Deletes the arrays which have been
65 // allocated during the reading of the
67 if (fInvMappingLow) delete [] fInvMappingLow;
69 if (fInvMappingHigh) delete [] fInvMappingHigh;
72 //_____________________________________________________________________________
73 Bool_t AliCaloAltroMapping::ReadMapping()
75 // Initalizes the ALTRO mapping from a file
76 // Look at the Calo module for the format of
79 AliFatal("Mapping file has not been opened !");
87 fMappingSize = 3*(fMaxHWAddress+1);
88 fMapping = new Short_t[fMappingSize];
89 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
90 fMapping[3*i] = fMapping[3*i+1] = fMapping[3*i+2] = -1;
93 for(Int_t i = 0; i < fNumberOfChannels ; i++) { // 1792 = 2*896 channels connected to each RCU
95 if (!(*fIn >> hwAddress)) {
96 AliFatal("Syntax of the mapping file is wrong !");
99 if (hwAddress > fMaxHWAddress) {
100 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
104 if (!(*fIn >> row >> col >> gain)) {
105 AliFatal("Syntax of the mapping file is wrong !");
109 if (gain < 0 || gain > 1) {
110 AliFatal(Form("Wrong gain value found (%d)! Should be 0 or 1 !",gain));
114 fMapping[3*hwAddress] = row;
115 fMapping[3*hwAddress+1] = col;
116 fMapping[3*hwAddress+2] = gain;
118 if (row > fMaxRow) fMaxRow = row;
119 if (row < fMinRow) fMinRow = row;
120 if (col > fMaxCol) fMaxCol = col;
121 if (col < fMinCol) fMinCol = col;
128 //_____________________________________________________________________________
129 Bool_t AliCaloAltroMapping::CreateInvMapping()
131 // Create the inverse mapping
132 // needed for the simulation of
134 if (fInvMappingLow) return kTRUE;
137 AliWarning("Mapping array was not initalized correctly ! Impossible to create the inverse mapping !");
141 Int_t nRows = fMaxRow - fMinRow + 1;
142 Int_t nCols = fMaxCol - fMinCol + 1;
143 Int_t invMappingSize = nRows*nCols;
145 fInvMappingLow = new Short_t[invMappingSize];
146 fInvMappingHigh = new Short_t[invMappingSize];
147 for (Int_t i = 0; i < nRows; i++) {
148 for (Int_t j = 0; j < nCols; j++) {
149 fInvMappingLow[nCols*i+j] = -1;
150 fInvMappingHigh[nCols*i+j] = -1;
154 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
155 Int_t row = fMapping[3*i];
156 Int_t col = fMapping[3*i+1];
157 Int_t gain = fMapping[3*i+2];
158 if(row != -1 && col != -1) {
160 fInvMappingLow[nCols*(row-fMinRow)+(col-fMinCol)] = i;
162 fInvMappingHigh[nCols*(row-fMinRow)+(col-fMinCol)] = i;
169 //_____________________________________________________________________________
170 Int_t AliCaloAltroMapping::GetHWAddress(Int_t row, Int_t col, Int_t gain)
172 // Get the content of the mapping array
173 // return -1 in case there is no hardware
174 // adress defined for these row-column-gain
175 if (!fInvMappingLow || !fInvMappingHigh) {
176 if (!CreateInvMapping()) return -1;
178 if (row < fMinRow || row > fMaxRow) {
179 AliWarning(Form("Index of row (%d) outside the range (%d -> %d) !",row,fMinRow,fMaxRow));
182 if (col < fMinCol || col > fMaxCol) {
183 AliWarning(Form("Index of column (%d) outside the range (0 -> %d) !",col,fMinCol,fMaxCol));
186 if (gain < 0 || gain > 1) {
187 AliWarning(Form("Invalid gain (%d)! Should be 0 or 1 !",gain));
190 Int_t hwAddress = -1;
192 hwAddress = fInvMappingLow[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
194 hwAddress = fInvMappingHigh[(fMaxCol - fMinCol + 1)*(row-fMinRow)+(col-fMinCol)];
197 AliWarning(Form("Hardware (ALTRO) adress is not defined for these row (%d), column (%d) and gain (%d) !",row,col,gain));
202 //_____________________________________________________________________________
203 Int_t AliCaloAltroMapping::GetPadRow(Int_t hwAddress) const
205 // Return the row index
206 // Note the difference w.r.t to the base class notation
208 AliWarning("Mapping array was not initalized correctly !");
211 if (hwAddress > fMaxHWAddress) {
212 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
215 Int_t row = fMapping[3*hwAddress];
217 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
222 //_____________________________________________________________________________
223 Int_t AliCaloAltroMapping::GetPad(Int_t hwAddress) const
225 // Return the column index
226 // Note the difference w.r.t to the base class notation
228 AliWarning("Mapping array was not initalized correctly !");
231 if (hwAddress > fMaxHWAddress) {
232 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
235 Int_t col = fMapping[3*hwAddress+1];
237 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
242 //_____________________________________________________________________________
243 Int_t AliCaloAltroMapping::GetSector(Int_t hwAddress) const
245 // Return the gain factor (0/1)
246 // Note the difference w.r.t to the base class notation
248 AliWarning("Mapping array was not initalized correctly !");
251 if (hwAddress > fMaxHWAddress) {
252 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
255 Int_t gain = fMapping[3*hwAddress+2];
257 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));