]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineCalibrationSPDhandler.cxx
Updates concerning the geometry: versioning system, new V11hybrid version, bug fixes...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineCalibrationSPDhandler.cxx
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
15 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler():
16   fModuleNr(0),
17   fDeadPixelMap(AliITSIntMap()),
18   fNoisyPixelMap(AliITSIntMap())
19 {}
20
21 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(UInt_t module):
22   fModuleNr(module),
23   fDeadPixelMap(AliITSIntMap()),
24   fNoisyPixelMap(AliITSIntMap())
25 {}
26
27 AliITSOnlineCalibrationSPDhandler::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
44 AliITSOnlineCalibrationSPDhandler::~AliITSOnlineCalibrationSPDhandler() {
45   ClearMaps();
46 }
47
48 AliITSOnlineCalibrationSPDhandler& 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
66 void AliITSOnlineCalibrationSPDhandler::ClearMaps() {
67   // clear the lists of dead and noisy
68   ResetDead();
69   ResetNoisy();
70 }
71
72 void 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
79 void 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
95 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile() {
96   // read dead and noisy from default file
97   Char_t fileName[200];
98   sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
99   return ReadFromFile(fileName);
100 }
101 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile() {
102   // read dead from default file
103   Char_t fileName[200];
104   sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
105   return ReadDeadFromFile(fileName);
106 }
107 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile() {
108   // read noisy from default file
109   Char_t fileName[200];
110   sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
111   return ReadNoisyFromFile(fileName);
112 }
113
114 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile(Char_t* fileName) {
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");
119   if (fp0 == NULL) {return kFALSE;}
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   }
143   return kTRUE;
144 }
145 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(Char_t* fileName) {
146   // read dead from file fileName (clear the previous list of dead pixels)
147   ResetDead();
148   AliITSOnlineCalibrationSPD* calib;
149   FILE* fp0 = fopen(fileName, "r");
150   if (fp0 == NULL) {return kFALSE;}
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   }
168   return kTRUE;
169 }
170 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(Char_t* fileName) {
171   // read noisy from file fileName (clear the previous list of noisy pixels)
172   ResetNoisy();
173   AliITSOnlineCalibrationSPD* calib;
174   FILE* fp0 = fopen(fileName, "r");
175   if (fp0 == NULL) {return kFALSE;}
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   }
193   return kTRUE;
194 }
195
196 TArrayI 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
210 TArrayI 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
224 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
225   fDeadPixelMap.Clear();
226 }
227
228
229 Bool_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
237 Int_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
246 Int_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
255 Bool_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
266 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
267   // clear the list of noisy pixels
268   fNoisyPixelMap.Clear();
269 }
270
271 Bool_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
279 Int_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
288 Int_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
297 Bool_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
308 void 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
321 void 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 }