]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/Base/AliTPCAltroMapping.cxx
Undoing some unwanted method renames
[u/mrichter/AliRoot.git] / TPC / Base / AliTPCAltroMapping.cxx
CommitLineData
dc43b139 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 in the TPC
17// The mapping is read from an external mapping files
18// Author: C.Cheshkov
19
20#include "AliTPCAltroMapping.h"
21#include "AliLog.h"
22#include <Riostream.h>
23//#include <stdlib.h>
24
25
26ClassImp(AliTPCAltroMapping)
27
44174d11 28//_____________________________________________________________________________
29AliTPCAltroMapping::AliTPCAltroMapping():
30 AliAltroMapping(),
31 fMinPadRow(0),
32 fMaxPadRow(0),
33 fMaxPad(0),
44174d11 34 fInvMapping(NULL)
35{
36 // Default constructor
37}
38
dc43b139 39//_____________________________________________________________________________
40AliTPCAltroMapping::AliTPCAltroMapping(const char *mappingFile):
41 AliAltroMapping(mappingFile),
42 fMinPadRow(0),
43 fMaxPadRow(0),
44 fMaxPad(0),
dc43b139 45 fInvMapping(NULL)
46{
47 // Constructor
48 ReadMapping();
49 CloseMappingFile();
50}
51
52//_____________________________________________________________________________
53AliTPCAltroMapping::~AliTPCAltroMapping()
54{
55 // destructor
573322da 56 if (fInvMapping) delete [] fInvMapping;
dc43b139 57}
58
dc43b139 59//_____________________________________________________________________________
60Bool_t AliTPCAltroMapping::ReadMapping()
61{
62 // Initalizes the ALTRO mapping from a file
63 // Look at the TPC module for the format of
64 // the mapping file
65 if (!fIn) {
66 AliFatal("Mapping file has not been opened !");
67 return kFALSE;
68 }
69
70 fMinPadRow = 0x7fffffff;
71 fMaxPadRow = 0;
72 fMaxPad = 0;
44174d11 73 fMappingSize = 2*(fMaxHWAddress+1);
74 fMapping = new Short_t[fMappingSize];
d11035b8 75 for (Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 76 fMapping[2*i] = fMapping[2*i+1] = -1;
dc43b139 77 }
78
79 for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
d11035b8 80 Int_t hwAddress;
81 if (!(*fIn >> hwAddress)) {
dc43b139 82 AliFatal("Syntax of the mapping file is wrong !");
83 return kFALSE;
84 }
d11035b8 85 if (hwAddress > fMaxHWAddress) {
86 AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 87 return kFALSE;
88 }
89 Int_t padrow,pad;
90 if (!(*fIn >> padrow >> pad)) {
91 AliFatal("Syntax of the mapping file is wrong !");
92 return kFALSE;
93 }
94
44174d11 95 fMapping[2*hwAddress] = padrow;
96 fMapping[2*hwAddress+1] = pad;
dc43b139 97
98 if (padrow > fMaxPadRow) fMaxPadRow = padrow;
99 if (padrow < fMinPadRow) fMinPadRow = padrow;
100 if (pad > fMaxPad) fMaxPad = pad;
101 }
102
573322da 103 return kTRUE;
104}
105
106//_____________________________________________________________________________
107Bool_t AliTPCAltroMapping::CreateInvMapping()
108{
109 // Create the inverse mapping
110 // needed for the simulation of
111 // raw data
112 if (fInvMapping) return kTRUE;
113
114 if (!fMapping) {
115 AliWarning("Mapping array was not initalized correctly ! Impossible to create the inverse mapping !");
116 return kFALSE;
117 }
118
44174d11 119 Int_t nRows = fMaxPadRow - fMinPadRow + 1;
120 Int_t nPads = fMaxPad + 1;
573322da 121 Int_t invMappingSize = nRows*nPads;
44174d11 122
573322da 123 fInvMapping = new Short_t[invMappingSize];
dc43b139 124 for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
44174d11 125 for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[nPads*i+j] = -1;
dc43b139 126 }
127
d11035b8 128 for(Int_t i = 0; i <= fMaxHWAddress; i++) {
44174d11 129 Int_t padrow = fMapping[2*i];
130 Int_t pad = fMapping[2*i+1];
dc43b139 131 if(padrow != -1 && pad != -1)
44174d11 132 fInvMapping[nPads*(padrow-fMinPadRow)+pad] = i;
dc43b139 133 }
134
135 return kTRUE;
136}
137
138//_____________________________________________________________________________
573322da 139Int_t AliTPCAltroMapping::GetHWAddress(Int_t padrow, Int_t pad, Int_t /* sector */)
dc43b139 140{
141 // Get the content of the mapping array
142 // return -1 in case there is no hardware
143 // adress defined for these pad-row and pad
144 if (!fInvMapping) {
573322da 145 if (!CreateInvMapping()) return -1;
dc43b139 146 }
147 if (padrow < fMinPadRow || padrow > fMaxPadRow) {
148 AliWarning(Form("Index of pad-row (%d) outside the range (%d -> %d) !",padrow,fMinPadRow,fMaxPadRow));
149 return -1;
150 }
151 if (pad > fMaxPad) {
152 AliWarning(Form("Index of pad (%d) outside the range (0 -> %d) !",pad,fMaxPad));
153 return -1;
154 }
44174d11 155 Int_t hwAddress = fInvMapping[(fMaxPad+1)*(padrow-fMinPadRow)+pad];
d11035b8 156 if (hwAddress == -1)
dc43b139 157 AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
158
d11035b8 159 return hwAddress;
dc43b139 160}
161
162//_____________________________________________________________________________
d11035b8 163Int_t AliTPCAltroMapping::GetPadRow(Int_t hwAddress) const
dc43b139 164{
165 if (!fMapping) {
166 AliWarning("Mapping array was not initalized correctly !");
167 return -1;
168 }
d11035b8 169 if (hwAddress > fMaxHWAddress) {
170 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 171 return -1;
172 }
44174d11 173 Int_t padrow = fMapping[2*hwAddress];
dc43b139 174 if (padrow == -1)
d11035b8 175 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
dc43b139 176
177 return padrow;
178}
179
180//_____________________________________________________________________________
d11035b8 181Int_t AliTPCAltroMapping::GetPad(Int_t hwAddress) const
dc43b139 182{
183 if (!fMapping) {
184 AliWarning("Mapping array was not initalized correctly !");
185 return -1;
186 }
d11035b8 187 if (hwAddress > fMaxHWAddress) {
188 AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
dc43b139 189 return -1;
190 }
44174d11 191 Int_t pad = fMapping[2*hwAddress+1];
dc43b139 192 if (pad == -1)
d11035b8 193 AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
dc43b139 194
195 return pad;
196}
197
198//_____________________________________________________________________________
d11035b8 199Int_t AliTPCAltroMapping::GetSector(Int_t /* hwAddress */) const
dc43b139 200{
201 AliWarning("Sector index is not contained in the TPC altro mapping !");
202 return -1;
203}