]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/TPCbase/AliTPCAltroMapping.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / TPC / TPCbase / 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 /// \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 ClassImp(AliTPCAltroMapping)
30 /// \endcond
31
32 //_____________________________________________________________________________
33 AliTPCAltroMapping::AliTPCAltroMapping():
34   AliAltroMapping(),
35   fMinPadRow(0),
36   fMaxPadRow(0),
37   fMaxPad(0),
38   fInvMapping(NULL)
39 {
40   // Default constructor
41 }
42
43 //_____________________________________________________________________________
44 AliTPCAltroMapping::AliTPCAltroMapping(const char *mappingFile):
45   AliAltroMapping(mappingFile),
46   fMinPadRow(0),
47   fMaxPadRow(0),
48   fMaxPad(0),
49   fInvMapping(NULL)
50 {
51   /// Constructor
52
53   ReadMapping();
54   CloseMappingFile();
55 }
56
57 //_____________________________________________________________________________
58 AliTPCAltroMapping::~AliTPCAltroMapping()
59 {
60   /// destructor
61
62   if (fInvMapping) delete [] fInvMapping;
63 }
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   if (!fIn) {
73     AliFatal("Mapping file has not been opened !");
74     return kFALSE;
75   }
76
77   fMinPadRow = 0x7fffffff;
78   fMaxPadRow = 0;
79   fMaxPad = 0;
80   fMappingSize = 2*(fMaxHWAddress+1);
81   fMapping = new Short_t[fMappingSize];
82   for (Int_t i = 0; i <= fMaxHWAddress; i++) {
83     fMapping[2*i] = fMapping[2*i+1] = -1;
84   }
85  
86   for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
87     Int_t hwAddress;
88     if (!(*fIn >> hwAddress)) {
89       AliFatal("Syntax of the mapping file is wrong !");
90       return kFALSE;
91     }
92     if (hwAddress > fMaxHWAddress) {
93       AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
94       return kFALSE;
95     }
96     Int_t padrow,pad;
97     if (!(*fIn >> padrow >> pad)) {
98       AliFatal("Syntax of the mapping file is wrong !");
99       return kFALSE;
100     }
101  
102     fMapping[2*hwAddress] = padrow;
103     fMapping[2*hwAddress+1] = pad;
104
105     if (padrow > fMaxPadRow) fMaxPadRow = padrow;
106     if (padrow < fMinPadRow) fMinPadRow = padrow;
107     if (pad > fMaxPad) fMaxPad = pad;
108   }
109
110   return kTRUE;
111 }
112
113 //_____________________________________________________________________________
114 Bool_t AliTPCAltroMapping::CreateInvMapping()
115 {
116   /// Create the inverse mapping
117   /// needed for the simulation of
118   /// raw data
119
120   if (fInvMapping) return kTRUE;
121
122   if (!fMapping) {
123     AliWarning("Mapping array was not initalized correctly ! Impossible to create the inverse mapping !");
124     return kFALSE;
125   }
126
127   Int_t nRows = fMaxPadRow - fMinPadRow + 1;
128   Int_t nPads = fMaxPad + 1;
129   Int_t invMappingSize = nRows*nPads;
130
131   fInvMapping = new Short_t[invMappingSize];
132   for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
133     for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[nPads*i+j] = -1;
134   }
135
136   for(Int_t i = 0; i <= fMaxHWAddress; i++) {
137     Int_t padrow = fMapping[2*i];
138     Int_t pad = fMapping[2*i+1];
139     if(padrow != -1 && pad != -1)
140       fInvMapping[nPads*(padrow-fMinPadRow)+pad] = i;
141   }
142
143   return kTRUE;
144 }
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   if (!fInvMapping) {
154     if (!CreateInvMapping()) return -1;
155   }
156   if (padrow < fMinPadRow || padrow > fMaxPadRow) {
157     AliWarning(Form("Index of pad-row (%d) outside the range (%d -> %d) !",padrow,fMinPadRow,fMaxPadRow));
158     return -1;
159   }
160   if (pad > fMaxPad) {
161     AliWarning(Form("Index of pad (%d) outside the range (0 -> %d) !",pad,fMaxPad));
162     return -1;
163   }
164   Int_t hwAddress = fInvMapping[(fMaxPad+1)*(padrow-fMinPadRow)+pad];
165   if (hwAddress == -1)
166     AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
167
168   return hwAddress;
169 }
170
171 //_____________________________________________________________________________
172 Int_t AliTPCAltroMapping::GetPadRow(Int_t hwAddress) const
173 {
174   if (!fMapping) {
175     AliWarning("Mapping array was not initalized correctly !");
176     return -1;
177   }
178   if (hwAddress > fMaxHWAddress) {
179     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
180     return -1;
181   }
182   Int_t padrow = fMapping[2*hwAddress];
183   if (padrow == -1)
184     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
185
186   return padrow;
187 }
188
189 //_____________________________________________________________________________
190 Int_t AliTPCAltroMapping::GetPad(Int_t hwAddress) const
191 {
192   if (!fMapping) {
193     AliWarning("Mapping array was not initalized correctly !");
194     return -1;
195   }
196   if (hwAddress > fMaxHWAddress) {
197     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
198     return -1;
199   }
200   Int_t pad = fMapping[2*hwAddress+1];
201   if (pad == -1)
202     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
203
204   return pad;
205 }
206
207 //_____________________________________________________________________________
208 Int_t AliTPCAltroMapping::GetSector(Int_t /* hwAddress */) const
209 {
210   AliWarning("Sector index is not contained in the TPC altro mapping !");
211   return -1;
212 }