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