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