]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCAltroMapping.cxx
TrainSetup version of official QA train
[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   fInvMapping(NULL)
35 {
36   // Default constructor
37 }
38
39 //_____________________________________________________________________________
40 AliTPCAltroMapping::AliTPCAltroMapping(const char *mappingFile):
41   AliAltroMapping(mappingFile),
42   fMinPadRow(0),
43   fMaxPadRow(0),
44   fMaxPad(0),
45   fInvMapping(NULL)
46 {
47   // Constructor
48   ReadMapping();
49   CloseMappingFile();
50 }
51
52 //_____________________________________________________________________________
53 AliTPCAltroMapping::~AliTPCAltroMapping()
54 {
55   // destructor
56   if (fInvMapping) delete [] fInvMapping;
57 }
58
59 //_____________________________________________________________________________
60 Bool_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;
73   fMappingSize = 2*(fMaxHWAddress+1);
74   fMapping = new Short_t[fMappingSize];
75   for (Int_t i = 0; i <= fMaxHWAddress; i++) {
76     fMapping[2*i] = fMapping[2*i+1] = -1;
77   }
78  
79   for(Int_t i = 0; i < fNumberOfChannels ; i++) { //5504 is size of irorc mapping at ther moment only for irorc
80     Int_t hwAddress;
81     if (!(*fIn >> hwAddress)) {
82       AliFatal("Syntax of the mapping file is wrong !");
83       return kFALSE;
84     }
85     if (hwAddress > fMaxHWAddress) {
86       AliFatal(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
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  
95     fMapping[2*hwAddress] = padrow;
96     fMapping[2*hwAddress+1] = pad;
97
98     if (padrow > fMaxPadRow) fMaxPadRow = padrow;
99     if (padrow < fMinPadRow) fMinPadRow = padrow;
100     if (pad > fMaxPad) fMaxPad = pad;
101   }
102
103   return kTRUE;
104 }
105
106 //_____________________________________________________________________________
107 Bool_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
119   Int_t nRows = fMaxPadRow - fMinPadRow + 1;
120   Int_t nPads = fMaxPad + 1;
121   Int_t invMappingSize = nRows*nPads;
122
123   fInvMapping = new Short_t[invMappingSize];
124   for (Int_t i = 0; i <= (fMaxPadRow - fMinPadRow); i++) {
125     for (Int_t j = 0; j <= fMaxPad; j++) fInvMapping[nPads*i+j] = -1;
126   }
127
128   for(Int_t i = 0; i <= fMaxHWAddress; i++) {
129     Int_t padrow = fMapping[2*i];
130     Int_t pad = fMapping[2*i+1];
131     if(padrow != -1 && pad != -1)
132       fInvMapping[nPads*(padrow-fMinPadRow)+pad] = i;
133   }
134
135   return kTRUE;
136 }
137
138 //_____________________________________________________________________________
139 Int_t AliTPCAltroMapping::GetHWAddress(Int_t padrow, Int_t pad, Int_t /* sector */)
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) {
145     if (!CreateInvMapping()) return -1;
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   }
155   Int_t hwAddress = fInvMapping[(fMaxPad+1)*(padrow-fMinPadRow)+pad];
156   if (hwAddress == -1)
157     AliWarning(Form("Hardware (ALTRO) adress is not defined for these pad-row (%d) and pad (%d) !",padrow,pad));
158
159   return hwAddress;
160 }
161
162 //_____________________________________________________________________________
163 Int_t AliTPCAltroMapping::GetPadRow(Int_t hwAddress) const
164 {
165   if (!fMapping) {
166     AliWarning("Mapping array was not initalized correctly !");
167     return -1;
168   }
169   if (hwAddress > fMaxHWAddress) {
170     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
171     return -1;
172   }
173   Int_t padrow = fMapping[2*hwAddress];
174   if (padrow == -1)
175     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
176
177   return padrow;
178 }
179
180 //_____________________________________________________________________________
181 Int_t AliTPCAltroMapping::GetPad(Int_t hwAddress) const
182 {
183   if (!fMapping) {
184     AliWarning("Mapping array was not initalized correctly !");
185     return -1;
186   }
187   if (hwAddress > fMaxHWAddress) {
188     AliWarning(Form("Hardware (ALTRO) adress (%d) outside the range (0 -> %d) !",hwAddress,fMaxHWAddress));
189     return -1;
190   }
191   Int_t pad = fMapping[2*hwAddress+1];
192   if (pad == -1)
193     AliWarning(Form("Hardware (ALTRO) adress (%d) is not defined !",hwAddress));
194
195   return pad;
196 }
197
198 //_____________________________________________________________________________
199 Int_t AliTPCAltroMapping::GetSector(Int_t /* hwAddress */) const
200 {
201   AliWarning("Sector index is not contained in the TPC altro mapping !");
202   return -1;
203 }