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