Update for Ds
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSPD.cxx
CommitLineData
fcf95fc7 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 **************************************************************************/
5bfe44ce 15
fcf95fc7 16#include "AliITSCalibrationSPD.h"
590d15ee 17///////////////////////////////////////////////////////////////////////////
18// Calibration class for set:ITS
19// Specific subdetector implementation for
20// Silicon pixels
21//
22// Modified by D. Elia, G.E. Bruno, H. Tydesjo
590d15ee 23///////////////////////////////////////////////////////////////////////////
b15de2d2 24
478d804c 25ClassImp(AliITSCalibrationSPD)
590d15ee 26
fcf95fc7 27//______________________________________________________________________
28AliITSCalibrationSPD::AliITSCalibrationSPD():
29AliITSCalibration(),
6727e2db 30fNrBad(0),
31fBadChannels(0){
fcf95fc7 32 // constructor
33
fcf95fc7 34 SetDataType("simulated");
478d804c 35 ClearBad();
36}
37//____________________________________________________________________________
38void AliITSCalibrationSPD::ClearBad() {
39 // clear all bad pixels (single+chips)
40 fBadChannels.Reset();
41 fNrBad=0;
42 for (UInt_t chip=0; chip<5; chip++) {
43 fBadChip[chip]=kFALSE;
44 }
fcf95fc7 45}
5bfe44ce 46//____________________________________________________________________________
6727e2db 47void AliITSCalibrationSPD::AddBad(UInt_t col, UInt_t row) {
478d804c 48 // add single bad pixel
6727e2db 49 fBadChannels.Set(fNrBad*2+2);
50 fBadChannels.AddAt(col,fNrBad*2);
51 fBadChannels.AddAt(row,fNrBad*2+1);
52 fNrBad++;
5bfe44ce 53}
590d15ee 54//____________________________________________________________________________
478d804c 55void AliITSCalibrationSPD::SetChipBad(UInt_t chip) {
56 // set full chip bad
c65bdda2 57 if (chip>=5) {AliError("Wrong chip number");
0586b4f5 58 }
59 else {
60 fBadChip[chip]=kTRUE;
61 }
478d804c 62}
63//____________________________________________________________________________
64void AliITSCalibrationSPD::UnSetChipBad(UInt_t chip) {
65 // unset full chip bad
c65bdda2 66 if (chip>=5 ) {AliError("Wrong chip number");
0586b4f5 67 }
68 else {
69 fBadChip[chip]=kFALSE;
70 }
478d804c 71}
72//____________________________________________________________________________
73Int_t AliITSCalibrationSPD::GetBadColAt(UInt_t index) const {
6727e2db 74 // Get column of index-th bad pixel
478d804c 75 if ((Int_t)index<GetNrBadSingle()) {
6727e2db 76 return fBadChannels.At(index*2);
5bfe44ce 77 }
478d804c 78 else {
79 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
80 Int_t badChipsFound =0;
81 for (UInt_t chip=0; chip<5; chip++) {
82 if (fBadChip[chip]) badChipsFound++;
83 if (badChipIndex==badChipsFound-1) {
84 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
85 return chip*32 + badPixelIndex/256;
86 }
87 }
88 }
89 AliError(Form("Index %d is out of bounds - returning -1",index));
5bfe44ce 90 return -1;
91}
590d15ee 92//____________________________________________________________________________
478d804c 93Int_t AliITSCalibrationSPD::GetBadRowAt(UInt_t index) const {
6727e2db 94 // Get row of index-th bad pixel
478d804c 95 if ((Int_t)index<GetNrBadSingle()) {
6727e2db 96 return fBadChannels.At(index*2+1);
5bfe44ce 97 }
478d804c 98 else {
99 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
100 Int_t badChipsFound =0;
101 for (UInt_t chip=0; chip<5; chip++) {
102 if (fBadChip[chip]) badChipsFound++;
103 if (badChipIndex==badChipsFound-1) {
104 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
105 return badPixelIndex%256;
106 }
5bfe44ce 107 }
108 }
478d804c 109 AliError(Form("Index %d is out of bounds - returning -1",index));
110 return -1;
5bfe44ce 111}
8d37cc87 112//____________________________________________________________________________
478d804c 113void AliITSCalibrationSPD::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const {
114 // i: is the i-th bad pixel in single bad pixel list
8d37cc87 115 // row: is the corresponding row (-1 if i is out of range)
116 // col: is the corresponding column (-1 if i is out of range)
117 row = -1;
118 col = -1;
478d804c 119 if(index>=0 && index<GetNrBadSingle()){
120 col = GetBadColAt(index);
121 row = GetBadRowAt(index);
8d37cc87 122 return;
123 }
478d804c 124 else {
125 if (index>=0) {
126 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
127 Int_t badChipsFound =0;
128 for (UInt_t chip=0; chip<5; chip++) {
129 if (fBadChip[chip]) badChipsFound++;
130 if (badChipIndex==badChipsFound-1) {
131 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
132 col = chip*32 + badPixelIndex/256;
133 row = badPixelIndex%256;
134 return;
135 }
136 }
137 }
138 }
139 AliError(Form("Index %d is out of bounds - nothing done",index));
8d37cc87 140}
1bdd39a1 141//___________________________________________________________________________
478d804c 142Int_t AliITSCalibrationSPD::GetNrBad() const {
143 // Total number of bad pixels (including bad chips) in a given module
144 Int_t bad=0;
145 // single pixels:
146 bad+=fNrBad;
147 // whole chips:
148 for (UInt_t chip=0; chip<5; chip++) {
149 bad+=fBadChip[chip]*32*256;
150 }
151 return bad;
1bdd39a1 152}
153//___________________________________________________________________________
154Int_t AliITSCalibrationSPD::GetNrBadInChip(Int_t chip) const {
478d804c 155 // Total number of bad pixels (including bad chips) in a given chip: chip range [0,4]
156 if(chip<0 || chip>4) {AliError("Wrong chip number"); return -1;}
157 if (fBadChip[chip]) return 32*256;
158 else {
159 Int_t bad=0;
160 for (UInt_t i=0; i<fNrBad; i++) {
161 Int_t col = GetBadColAt(i);
162 if (col!=-1) {
163 if (GetChipIndexFromCol(col)==chip) bad++;
164 }
165 }
166 return bad;
167 }
168}
169//___________________________________________________________________________
170Int_t AliITSCalibrationSPD::GetNrBadInColumn(Int_t col) const {
171 // Total number of bad pixels (including bad chips) in a given column: col. range [0,159]
172 if(col<0 || col>159) {AliError("Wrong column number"); return -1;}
173 if (fBadChip[GetChipIndexFromCol(col)]) return 256;
174 else {
175 Int_t bad=0;
176 for (UInt_t i=0; i<fNrBad; i++) {
177 if (GetBadColAt(i)==col) bad++;
178 }
179 return bad;
180 }
181}
182//______________________________________________________________________
183Bool_t AliITSCalibrationSPD::IsBad() const {
184 // Are all chips of this module bad?
185 for (UInt_t chip=0; chip<5; chip++) {
186 if (!fBadChip[chip]) return kFALSE;
187 }
188 return kTRUE;
189}
190//______________________________________________________________________
191Bool_t AliITSCalibrationSPD::IsChipBad(Int_t chip) const {
192 // Is the full chip bad?
193 return (GetNrBadInChip(chip)==32*256);
194}
195//______________________________________________________________________
196Bool_t AliITSCalibrationSPD::IsColumnBad(Int_t col) const {
197 // Is the full column bad?
198 return (GetNrBadInColumn(col)==256);
199}
200//____________________________________________________________________________
201Bool_t AliITSCalibrationSPD::IsPixelBad(Int_t col, Int_t row) const {
202 // Is this pixel bad?
203 if(col<0 || col>159) {AliError("Wrong column number"); return kFALSE;}
204 Int_t chip = GetChipIndexFromCol(col);
205 if (fBadChip[chip]) return kTRUE;
206 for (UInt_t i=0; i<fNrBad; i++) {
207 if (GetBadColAt(i)==col && GetBadRowAt(i)==row) {
208 return kTRUE;
209 }
210 }
211 return kFALSE;
212}
213//______________________________________________________________________
214Int_t AliITSCalibrationSPD::GetChipIndexFromCol(UInt_t col) const {
215 // returns chip index for specific column
216 if(col>=160) {AliWarning("Wrong column number"); return -1;}
217 return col/32;
218}
219//______________________________________________________________________
220void AliITSCalibrationSPD::SetNrBad(UInt_t /*nr*/) {
221 // should not be used anymore !!!
222 AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
1bdd39a1 223}
14089bc5 224//______________________________________________________________________
225void AliITSCalibrationSPD::Streamer(TBuffer &R__b) {
226 // Stream an object of class AliITSCalibrationSPD.
227 UInt_t R__s, R__c;
228 if (R__b.IsReading()) {
229 Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
230 AliITSCalibration::Streamer(R__b);
bb292d31 231 if (R__v >= 8) {
232 R__b >> fNrBad;
14089bc5 233 fBadChannels.Streamer(R__b);
478d804c 234 R__b.ReadStaticArray((bool*)fBadChip);
14089bc5 235 }
236 else {
bb292d31 237 Double_t dummy;
238 R__b >> dummy;
239 R__b >> dummy;
240 R__b >> dummy;
241 R__b >> dummy;
242 R__b >> dummy;
243 R__b >> dummy;
244 R__b >> dummy;
245 R__b >> fNrBad;
246 if (R__v == 7) {
478d804c 247 fBadChannels.Streamer(R__b);
bb292d31 248 R__b.ReadStaticArray((bool*)fBadChip);
478d804c 249 }
250 else {
bb292d31 251 if (R__v == 6) {
252 fBadChannels.Streamer(R__b);
253 }
254 else {
255 TArrayI fBadChannelsV1;
256 fBadChannelsV1.Streamer(R__b);
257 fBadChannels.Set(fNrBad*2);
258 for (UInt_t i=0; i<fNrBad*2; i++) {
259 fBadChannels[i] = fBadChannelsV1[i];
260 }
261 }
262 for (UInt_t i=0; i<5; i++) {
263 fBadChip[i]=kFALSE;
478d804c 264 }
14089bc5 265 }
266 }
267 R__b.CheckByteCount(R__s, R__c, AliITSCalibrationSPD::IsA());
268 }
269 else {
270 R__c = R__b.WriteVersion(AliITSCalibrationSPD::IsA(), kTRUE);
271 AliITSCalibration::Streamer(R__b);
14089bc5 272 R__b << fNrBad;
273 fBadChannels.Streamer(R__b);
478d804c 274 R__b.WriteArray(fBadChip, 5);
14089bc5 275 R__b.SetByteCount(R__c, kTRUE);
276 }
277}