]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSOnlineCalibrationSPDhandler.cxx
Adding comment lines to class description needed for Root documentation,
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineCalibrationSPDhandler.cxx
CommitLineData
b15de2d2 1//////////////////////////////////////////////////////////////////////
2// Author: Henrik Tydesjo //
3// For easier handling of dead and noisy pixels they are kept in //
4// container maps (AliITSIntMap). //
5// The TArrayI objects that are put in the AliITSCalibrationSPD //
6// objects can be obtained from the methods GetDeadArray and //
7// GetNoisyArray. //
8//////////////////////////////////////////////////////////////////////
9
10#include "AliITSOnlineCalibrationSPDhandler.h"
11#include "AliITSOnlineCalibrationSPD.h"
12#include <TArrayI.h>
13#include <TFile.h>
14
15AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler():
16 fModuleNr(0),
17 fDeadPixelMap(AliITSIntMap()),
18 fNoisyPixelMap(AliITSIntMap())
19{}
20
21AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(UInt_t module):
22 fModuleNr(module),
23 fDeadPixelMap(AliITSIntMap()),
24 fNoisyPixelMap(AliITSIntMap())
25{}
26
27AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(const AliITSOnlineCalibrationSPDhandler& handle):
28 fModuleNr(handle.fModuleNr),
29 fDeadPixelMap(AliITSIntMap()),
30 fNoisyPixelMap(AliITSIntMap())
31{
32 // copy constructor
33 UInt_t nrDead = handle.GetNrDead();
34 for (UInt_t index=0; index<nrDead; index++) {
35 this->SetDeadPixel(handle.GetDeadColAt(index),handle.GetDeadRowAt(index));
36 }
37 UInt_t nrNoisy = handle.GetNrNoisy();
38 for (UInt_t index=0; index<nrNoisy; index++) {
39 this->SetNoisyPixel(handle.GetNoisyColAt(index),handle.GetNoisyRowAt(index));
40 }
41 sprintf(fFileLocation,"%s",handle.fFileLocation);
42}
43
44AliITSOnlineCalibrationSPDhandler::~AliITSOnlineCalibrationSPDhandler() {
45 ClearMaps();
46}
47
48AliITSOnlineCalibrationSPDhandler& AliITSOnlineCalibrationSPDhandler::operator=(const AliITSOnlineCalibrationSPDhandler& handle) {
49 // assignment operator
50 if (this!=&handle) {
51 this->ClearMaps();
52 fModuleNr = handle.fModuleNr;
53 UInt_t nrDead = handle.GetNrDead();
54 for (UInt_t index=0; index<nrDead; index++) {
55 this->SetDeadPixel(handle.GetDeadColAt(index),handle.GetDeadRowAt(index));
56 }
57 UInt_t nrNoisy = handle.GetNrNoisy();
58 for (UInt_t index=0; index<nrNoisy; index++) {
59 this->SetNoisyPixel(handle.GetNoisyColAt(index),handle.GetNoisyRowAt(index));
60 }
61 sprintf(fFileLocation,"%s",handle.fFileLocation);
62 }
63 return *this;
64}
65
66void AliITSOnlineCalibrationSPDhandler::ClearMaps() {
67 // clear the lists of dead and noisy
68 ResetDead();
69 ResetNoisy();
70}
71
72void AliITSOnlineCalibrationSPDhandler::WriteToFile() {
73 // write the lists of dead and noisy to default file
74 Char_t fileName[200];
75 sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
76 WriteToFile(fileName);
77}
78
79void AliITSOnlineCalibrationSPDhandler::WriteToFile(Char_t* fileName) {
80 // write the lists of dead and noisy to file fileName
81 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
82 calib->SetModuleNr(GetModuleNr());
83 calib->SetDeadList(GetDeadArray());
84 calib->SetNoisyList(GetNoisyArray());
85 calib->SetNrDead(GetNrDead());
86 calib->SetNrNoisy(GetNrNoisy());
87
88 TFile file(fileName, "RECREATE");
89 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
90 file.Close();
91
92 delete calib;
93}
94
03fc6773 95Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile() {
b15de2d2 96 // read dead and noisy from default file
97 Char_t fileName[200];
98 sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
03fc6773 99 return ReadFromFile(fileName);
b15de2d2 100}
03fc6773 101Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile() {
b15de2d2 102 // read dead from default file
103 Char_t fileName[200];
104 sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
03fc6773 105 return ReadDeadFromFile(fileName);
b15de2d2 106}
03fc6773 107Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile() {
b15de2d2 108 // read noisy from default file
109 Char_t fileName[200];
110 sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
03fc6773 111 return ReadNoisyFromFile(fileName);
b15de2d2 112}
113
03fc6773 114Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile(Char_t* fileName) {
b15de2d2 115 // read dead and noisy from file fileName (clear the previous list of dead and noisy pixels)
116 ClearMaps();
117 AliITSOnlineCalibrationSPD* calib;
118 FILE* fp0 = fopen(fileName, "r");
03fc6773 119 if (fp0 == NULL) {return kFALSE;}
b15de2d2 120 else {
121 fclose(fp0);
122 TFile file(fileName, "READ");
123 if (file.IsOpen()) {
124 file.GetObject("AliITSOnlineCalibrationSPD", calib);
125 file.Close();
126 if (calib!=NULL) {
127 SetModuleNr(calib->GetModuleNr());
128 Int_t nrDead=calib->GetNrDead();
129 for (Int_t index=0; index<nrDead; index++) {
130 Int_t col=calib->GetDeadColAt(index);
131 Int_t row=calib->GetDeadRowAt(index);
132 SetDeadPixel(col,row);
133 }
134 Int_t nrNoisy=calib->GetNrNoisy();
135 for (Int_t index=0; index<nrNoisy; index++) {
136 Int_t col=calib->GetNoisyColAt(index);
137 Int_t row=calib->GetNoisyRowAt(index);
138 SetNoisyPixel(col,row);
139 }
140 }
141 }
142 }
03fc6773 143 return kTRUE;
b15de2d2 144}
03fc6773 145Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(Char_t* fileName) {
b15de2d2 146 // read dead from file fileName (clear the previous list of dead pixels)
147 ResetDead();
148 AliITSOnlineCalibrationSPD* calib;
149 FILE* fp0 = fopen(fileName, "r");
03fc6773 150 if (fp0 == NULL) {return kFALSE;}
b15de2d2 151 else {
152 fclose(fp0);
153 TFile file(fileName, "READ");
154 if (file.IsOpen()) {
155 file.GetObject("AliITSOnlineCalibrationSPD", calib);
156 file.Close();
157 if (calib!=NULL) {
158 SetModuleNr(calib->GetModuleNr());
159 Int_t nrDead=calib->GetNrDead();
160 for (Int_t index=0; index<nrDead; index++) {
161 Int_t col=calib->GetDeadColAt(index);
162 Int_t row=calib->GetDeadRowAt(index);
163 SetDeadPixel(col,row);
164 }
165 }
166 }
167 }
03fc6773 168 return kTRUE;
b15de2d2 169}
03fc6773 170Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(Char_t* fileName) {
b15de2d2 171 // read noisy from file fileName (clear the previous list of noisy pixels)
172 ResetNoisy();
173 AliITSOnlineCalibrationSPD* calib;
174 FILE* fp0 = fopen(fileName, "r");
03fc6773 175 if (fp0 == NULL) {return kFALSE;}
b15de2d2 176 else {
177 fclose(fp0);
178 TFile file(fileName, "READ");
179 if (file.IsOpen()) {
180 file.GetObject("AliITSOnlineCalibrationSPD", calib);
181 file.Close();
182 if (calib!=NULL) {
183 SetModuleNr(calib->GetModuleNr());
184 Int_t nrNoisy=calib->GetNrNoisy();
185 for (Int_t index=0; index<nrNoisy; index++) {
186 Int_t col=calib->GetNoisyColAt(index);
187 Int_t row=calib->GetNoisyRowAt(index);
188 SetNoisyPixel(col,row);
189 }
190 }
191 }
192 }
03fc6773 193 return kTRUE;
b15de2d2 194}
195
196TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArray() {
197 // get a TArrayI of the dead pixels (format for the AliITSCalibrationSPD object)
198 TArrayI returnArray;
199 returnArray.Set(GetNrDead()*2);
200 for (UInt_t index=0; index<fDeadPixelMap.GetNrEntries(); index++) {
201 Int_t key = fDeadPixelMap.GetKey(index);
202 Int_t col = GetColFromKey(key);
203 Int_t row = GetRowFromKey(key);
204 returnArray.AddAt(col,index*2);
205 returnArray.AddAt(row,index*2+1);
206 }
207 return returnArray;
208}
209
210TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArray() {
211 // get a TArrayI of the noisy pixels (format for the AliITSCalibrationSPD object)
212 TArrayI returnArray;
213 returnArray.Set(GetNrNoisy()*2);
214 for (UInt_t index=0; index<fNoisyPixelMap.GetNrEntries(); index++) {
215 Int_t key = fNoisyPixelMap.GetKey(index);
216 Int_t col = GetColFromKey(key);
217 Int_t row = GetRowFromKey(key);
218 returnArray.AddAt(col,index*2);
219 returnArray.AddAt(row,index*2+1);
220 }
221 return returnArray;
222}
223
224void AliITSOnlineCalibrationSPDhandler::ResetDead() {
225 fDeadPixelMap.Clear();
226}
227
228
229Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(Int_t col, Int_t row) {
230 // set a dead pixel, returns false if pixel is already dead or noisy
231 Int_t key = GetKey(col,row);
232 // if noisy we dont want to add it...
233 if (fNoisyPixelMap.Find(key) != NULL) return kFALSE;
234 return fDeadPixelMap.Insert(key,col);
235}
236
237Int_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t index) const {
238 // get column for the dead pixel at position index in list of dead
239 if (index<fDeadPixelMap.GetNrEntries()) {
240 Int_t key = fDeadPixelMap.GetKey(index);
241 return GetColFromKey(key);
242 }
243 else return 0;
244}
245
246Int_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t index) const {
247 // get row for the dead pixel at position index in list of dead
248 if (index<fDeadPixelMap.GetNrEntries()) {
249 Int_t key = fDeadPixelMap.GetKey(index);
250 return GetRowFromKey(key);
251 }
252 else return 0;
253}
254
255Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(Int_t col, Int_t row) const {
256 // is the pixel dead?
257 Int_t key = GetKey(col,row);
258 if ( fDeadPixelMap.Find(key) != NULL) {
259 return kTRUE;
260 }
261 else {
262 return kFALSE;
263 }
264}
265
266void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
267 // clear the list of noisy pixels
268 fNoisyPixelMap.Clear();
269}
270
271Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(Int_t col, Int_t row) {
272 // set a noisy pixel, returns false if already there
273 Int_t key = GetKey(col,row);
274 // if dead before - remove from the dead list
275 fDeadPixelMap.Remove(key);
276 return fNoisyPixelMap.Insert(key,col);
277}
278
279Int_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t index) const {
280 // get column for the noisy pixel at position index in list of noisy
281 if (index<fNoisyPixelMap.GetNrEntries()) {
282 Int_t key = fNoisyPixelMap.GetKey(index);
283 return GetColFromKey(key);
284 }
285 else return 0;
286}
287
288Int_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t index) const {
289 // get row for the noisy pixel at position index in list of noisy
290 if (index<fNoisyPixelMap.GetNrEntries()) {
291 Int_t key = fNoisyPixelMap.GetKey(index);
292 return GetRowFromKey(key);
293 }
294 else return 0;
295}
296
297Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(Int_t col, Int_t row) const {
298 // is this pixel noisy?
299 Int_t key = GetKey(col,row);
300 if ( fNoisyPixelMap.Find(key) != NULL ) {
301 return kTRUE;
302 }
303 else {
304 return kFALSE;
305 }
306}
307
308void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
309 // print the dead pixels to screen
310 printf("-----------------------\n");
311 printf("Dead Pixels Module %d:\n",fModuleNr);
312 printf("-----------------------\n");
313 for (UInt_t index=0; index<fDeadPixelMap.GetNrEntries(); index++) {
314 Int_t key = fDeadPixelMap.GetKey(index);
315 Int_t col = GetColFromKey(key);
316 Int_t row = GetRowFromKey(key);
317 printf("%d,%d\n",col,row);
318 }
319}
320
321void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
322 // print the noisy pixels to screen
323 printf("-----------------------\n");
324 printf("Noisy Pixels Module %d:\n",fModuleNr);
325 printf("-----------------------\n");
326 for (UInt_t index=0; index<fNoisyPixelMap.GetNrEntries(); index++) {
327 Int_t key = fNoisyPixelMap.GetKey(index);
328 Int_t col = GetColFromKey(key);
329 Int_t row = GetRowFromKey(key);
330 printf("%d,%d\n",col,row);
331 }
332}