AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliTPCAltroMapping.cxx
Go to the documentation of this file.
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 
21 
22 #include "AliTPCAltroMapping.h"
23 #include "AliLog.h"
24 #include <Riostream.h>
25 //#include <stdlib.h>
26 
27 
31 
32 //_____________________________________________________________________________
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 {
52 
53  ReadMapping();
54  CloseMappingFile();
55 }
56 
57 //_____________________________________________________________________________
59 {
61 
62  if (fInvMapping) delete [] fInvMapping;
63 }
64 
65 //_____________________________________________________________________________
67 {
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 //_____________________________________________________________________________
115 {
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 {
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 }
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Short_t * fInvMapping
! Inverse of fMapping
Int_t fMinPadRow
Minimum Index of pad-row.
virtual Bool_t CreateInvMapping()
virtual Int_t GetPadRow(Int_t hwAddress) const
virtual Int_t GetSector(Int_t hwAddress) const
virtual Int_t GetPad(Int_t hwAddress) const
Int_t fMaxPadRow
Maximum Index of pad-row.
virtual Int_t GetHWAddress(Int_t padrow, Int_t pad, Int_t sector)
virtual Bool_t ReadMapping()
Int_t fMaxPad
Maximum Index of pad inside row.