Fix for the reverse engineering display
[u/mrichter/AliRoot.git] / RAW / AliAltroMapping.cxx
CommitLineData
5802cf2d 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
17// The mapping is read from an external mapping files
18// The class is used by TPC,PHOS and FMD
19// Author: C.Cheshkov
20
21#include "AliAltroMapping.h"
22#include "AliLog.h"
23#include <Riostream.h>
24//#include <stdlib.h>
25
26
27ClassImp(AliAltroMapping)
28
29//_____________________________________________________________________________
30AliAltroMapping::AliAltroMapping(const char *mappingFile):
31 fNumberOfChannels(0),
32 fMaxHWAdress(0),
33 fMinPadRow(0),
34 fMaxPadRow(0),
35 fMaxPad(0),
36 fMapping(NULL),
37 fInvMapping(NULL)
38{
39 // Constructor
40 // Reads the mapping from an external file
41 if (mappingFile)
42 ReadMapping(mappingFile);
43 else
44 AliFatal("Mapping file not specified !");
45}
46
47//_____________________________________________________________________________
48AliAltroMapping::~AliAltroMapping()
49{
50 // destructor
51 if (fMapping) {
52 for (Int_t i = 0; i <= fMaxHWAdress; i++) delete [] fMapping[i];
53 delete [] fMapping;
54 }
55
56 if (fInvMapping) {
57 for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++)
58 delete [] fInvMapping[i];
59 delete [] fInvMapping;
60 }
61
62}
63
64//_____________________________________________________________________________
65AliAltroMapping::AliAltroMapping(const AliAltroMapping& mapping):
66 TObject(mapping),
67 fNumberOfChannels(mapping.fNumberOfChannels),
68 fMaxHWAdress(mapping.fMaxHWAdress),
69 fMinPadRow(mapping.fMinPadRow),
70 fMaxPadRow(mapping.fMaxPadRow),
71 fMaxPad(mapping.fMaxPad),
72 fMapping(mapping.fMapping),
73 fInvMapping(mapping.fInvMapping)
74{
75// Copy Constructor
76
77 Fatal("AliAltroMapping", "copy constructor not implemented");
78}
79
80//_____________________________________________________________________________
81AliAltroMapping& AliAltroMapping::operator = (const AliAltroMapping& /*mapping*/)
82{
83//Assigment operator
84
85 Fatal("operator =", "assignment operator not implemented");
86 return *this;
87}
88
89//_____________________________________________________________________________
90Bool_t AliAltroMapping::ReadMapping(const char *mappingFile)
91{
92 // Initalizes the ALTRO mapping from a file
93 // Look at the TPC module for the format of
94 // the mapping file
95 ifstream in(mappingFile);
96 if (!in) {
97 AliFatal(Form("Missing mapping file (%s) !",mappingFile));
98 return kFALSE;
99 }
100 if (!(in >> fNumberOfChannels)) {
101 AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
102 return kFALSE;
103 }
104 if (!(in >> fMaxHWAdress)) {
105 AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
106 return kFALSE;
107 }
108// if (!(in >> fMinPadRow >> fMaxPadRow)) {
109// AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
110// return kFALSE;
111// }
112// if (!(in >> fMaxPad)) {
113// AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
114// return kFALSE;
115// }
116
117
118 fMinPadRow = 0x7fffffff;
119 fMaxPadRow = 0;
120 fMaxPad = 0;
121 fMapping = new Short_t*[fMaxHWAdress+1];
122 for (Int_t i = 0; i <= fMaxHWAdress; i++) {
123 fMapping[i] = new Short_t[2];
124 fMapping[i][0] = fMapping[i][1] = -1;
125 }
126
127 for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
128 Int_t hwAdress;
129 if (!(in >> hwAdress)) {
130 AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
131 return kFALSE;
132 }
133 if (hwAdress > fMaxHWAdress) {
134 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
135 return kFALSE;
136 }
137 Int_t padrow,pad;
138 if (!(in >> padrow >> pad)) {
139 AliFatal(Form("Syntax of the mapping file is wrong (%s) !",mappingFile));
140 return kFALSE;
141 }
142
143 fMapping[hwAdress][0] = padrow;
144 fMapping[hwAdress][1] = pad;
145
146 if (padrow > fMaxPadRow) fMaxPadRow = padrow;
147 if (padrow < fMinPadRow) fMinPadRow = padrow;
148 if (pad > fMaxPad) fMaxPad = pad;
149 }
150
151 fInvMapping = new Short_t*[fMaxPadRow - fMinPadRow + 1];
152 for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
153 fInvMapping[i] = new Short_t[fMaxPad + 1];
154 for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[i][j] = -1;
155 }
156
157 for(Int_t i = 0; i <= fMaxHWAdress; i++) {
158 Int_t padrow = fMapping[i][0];
159 Int_t pad = fMapping[i][1];
160 if(padrow != -1 && pad != -1)
161 fInvMapping[padrow-fMinPadRow][pad] = i;
162 }
163
164 in.close();
165 return kTRUE;
166}
167
168//_____________________________________________________________________________
169Int_t AliAltroMapping::GetHWAdress(Int_t padrow, Int_t pad) const
170{
171 // Get the content of the mapping array
172 // return -1 in case there is no hardware
173 // adress defined for these pad-row and pad
174 if (!fInvMapping) {
175 AliWarning("Mapping array was not initalized correctly !");
176 return -1;
177 }
178 if (padrow < fMinPadRow || padrow > fMaxPadRow) {
179 AliWarning(Form("Index of pad-row (%d) outside the range (%d -> %d) !",padrow,fMinPadRow,fMaxPadRow));
180 return -1;
181 }
182 if (pad > fMaxPad) {
183 AliWarning(Form("Index of pad (%d) outside the range (0 -> %d) !",pad,fMaxPad));
184 return -1;
185 }
186 Int_t hwAdress = fInvMapping[padrow-fMinPadRow][pad];
187 if (hwAdress == -1)
188 AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
189
190 return hwAdress;
191}
192
193//_____________________________________________________________________________
194Int_t AliAltroMapping::GetPadRow(Int_t hwAdress) const
195{
196 if (!fMapping) {
197 AliWarning("Mapping array was not initalized correctly !");
198 return -1;
199 }
200 if (hwAdress > fMaxHWAdress) {
201 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
202 return -1;
203 }
204 Int_t padrow = fMapping[hwAdress][0];
205 if (padrow == -1)
206 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAdress));
207
208 return padrow;
209}
210
211//_____________________________________________________________________________
212Int_t AliAltroMapping::GetPad(Int_t hwAdress) const
213{
214 if (!fMapping) {
215 AliWarning("Mapping array was not initalized correctly !");
216 return -1;
217 }
218 if (hwAdress > fMaxHWAdress) {
219 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAdress,fMaxHWAdress));
220 return -1;
221 }
222 Int_t pad = fMapping[hwAdress][1];
223 if (pad == -1)
224 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAdress));
225
226 return pad;
227}