]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineCalibrationSPDhandler.cxx
New SPD pre-processor (H. Tydesjo)
[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 void 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   ReadFromFile(fileName);
100 }
101 void AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile() {
102   // read dead from default file
103   Char_t fileName[200];
104   sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
105   ReadDeadFromFile(fileName);
106 }
107 void AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile() {
108   // read noisy from default file
109   Char_t fileName[200];
110   sprintf(fileName,"%s/SPD_DeadNoisy_%d.root",fFileLocation,fModuleNr);
111   ReadNoisyFromFile(fileName);
112 }
113
114 void 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) {}
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 }
144 void AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(Char_t* fileName) {
145   // read dead from file fileName (clear the previous list of dead pixels)
146   ResetDead();
147   AliITSOnlineCalibrationSPD* calib;
148   FILE* fp0 = fopen(fileName, "r");
149   if (fp0 == NULL) {}
150   else {
151     fclose(fp0);
152     TFile file(fileName, "READ");
153     if (file.IsOpen()) {
154       file.GetObject("AliITSOnlineCalibrationSPD", calib);
155       file.Close();
156       if (calib!=NULL) {
157         SetModuleNr(calib->GetModuleNr());
158         Int_t nrDead=calib->GetNrDead();
159         for (Int_t index=0; index<nrDead; index++) {
160           Int_t col=calib->GetDeadColAt(index);
161           Int_t row=calib->GetDeadRowAt(index);
162           SetDeadPixel(col,row);
163         }
164       }
165     }
166   }
167 }
168 void AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(Char_t* fileName) {
169   // read noisy from file fileName (clear the previous list of noisy pixels)
170   ResetNoisy();
171   AliITSOnlineCalibrationSPD* calib;
172   FILE* fp0 = fopen(fileName, "r");
173   if (fp0 == NULL) {}
174   else {
175     fclose(fp0);
176     TFile file(fileName, "READ");
177     if (file.IsOpen()) {
178       file.GetObject("AliITSOnlineCalibrationSPD", calib);
179       file.Close();
180       if (calib!=NULL) {
181         SetModuleNr(calib->GetModuleNr());
182         Int_t nrNoisy=calib->GetNrNoisy();
183         for (Int_t index=0; index<nrNoisy; index++) {
184           Int_t col=calib->GetNoisyColAt(index);
185           Int_t row=calib->GetNoisyRowAt(index);
186           SetNoisyPixel(col,row);
187         }
188       }
189     }
190   }
191 }
192
193 TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArray() {
194   // get a TArrayI of the dead pixels (format for the AliITSCalibrationSPD object)
195   TArrayI returnArray;
196   returnArray.Set(GetNrDead()*2);
197   for (UInt_t index=0; index<fDeadPixelMap.GetNrEntries(); index++) {
198     Int_t key = fDeadPixelMap.GetKey(index);
199     Int_t col = GetColFromKey(key);
200     Int_t row = GetRowFromKey(key);
201     returnArray.AddAt(col,index*2);
202     returnArray.AddAt(row,index*2+1);
203   }
204   return returnArray;
205 }
206
207 TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArray() {
208   // get a TArrayI of the noisy pixels (format for the AliITSCalibrationSPD object)
209   TArrayI returnArray;
210   returnArray.Set(GetNrNoisy()*2);
211   for (UInt_t index=0; index<fNoisyPixelMap.GetNrEntries(); index++) {
212     Int_t key = fNoisyPixelMap.GetKey(index);
213     Int_t col = GetColFromKey(key);
214     Int_t row = GetRowFromKey(key);
215     returnArray.AddAt(col,index*2);
216     returnArray.AddAt(row,index*2+1);
217   }
218   return returnArray;
219 }
220
221 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
222   fDeadPixelMap.Clear();
223 }
224
225
226 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(Int_t col, Int_t row) {
227   // set a dead pixel, returns false if pixel is already dead or noisy
228   Int_t key = GetKey(col,row);
229   // if noisy we dont want to add it...
230   if (fNoisyPixelMap.Find(key) != NULL) return kFALSE;
231   return fDeadPixelMap.Insert(key,col);
232 }
233
234 Int_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t index) const {
235   // get column for the dead pixel at position index in list of dead
236   if (index<fDeadPixelMap.GetNrEntries()) {
237     Int_t key = fDeadPixelMap.GetKey(index);
238     return GetColFromKey(key);
239   }
240   else return 0;
241 }
242
243 Int_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t index) const {
244   // get row for the dead pixel at position index in list of dead
245   if (index<fDeadPixelMap.GetNrEntries()) {
246     Int_t key = fDeadPixelMap.GetKey(index);
247     return GetRowFromKey(key);
248   }
249   else return 0;
250 }
251
252 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(Int_t col, Int_t row) const {
253   // is the pixel dead?
254   Int_t key = GetKey(col,row);
255   if ( fDeadPixelMap.Find(key) != NULL) {
256     return kTRUE;
257   }
258   else {
259     return kFALSE;
260   }
261 }
262
263 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
264   // clear the list of noisy pixels
265   fNoisyPixelMap.Clear();
266 }
267
268 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(Int_t col, Int_t row) {
269   // set a noisy pixel, returns false if already there
270   Int_t key = GetKey(col,row);
271   // if dead before - remove from the dead list 
272   fDeadPixelMap.Remove(key);
273   return fNoisyPixelMap.Insert(key,col);
274 }
275
276 Int_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t index) const {
277   // get column for the noisy pixel at position index in list of noisy
278   if (index<fNoisyPixelMap.GetNrEntries()) {
279     Int_t key = fNoisyPixelMap.GetKey(index);
280     return GetColFromKey(key);
281   }
282   else return 0;
283 }
284
285 Int_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t index) const {
286   // get row for the noisy pixel at position index in list of noisy
287   if (index<fNoisyPixelMap.GetNrEntries()) {
288     Int_t key = fNoisyPixelMap.GetKey(index);
289     return GetRowFromKey(key);
290   }
291   else return 0;
292 }
293
294 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(Int_t col, Int_t row) const {
295   // is this pixel noisy?
296   Int_t key = GetKey(col,row);
297   if ( fNoisyPixelMap.Find(key) != NULL ) {
298     return kTRUE;
299   }
300   else {
301     return kFALSE;
302   }
303 }
304
305 void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
306   // print the dead pixels to screen
307   printf("-----------------------\n");
308   printf("Dead Pixels Module %d:\n",fModuleNr);
309   printf("-----------------------\n");
310   for (UInt_t index=0; index<fDeadPixelMap.GetNrEntries(); index++) {
311     Int_t key = fDeadPixelMap.GetKey(index);
312     Int_t col = GetColFromKey(key);
313     Int_t row = GetRowFromKey(key);
314     printf("%d,%d\n",col,row);
315   }
316 }
317
318 void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
319   // print the noisy pixels to screen
320   printf("-----------------------\n");
321   printf("Noisy Pixels Module %d:\n",fModuleNr);
322   printf("-----------------------\n");
323   for (UInt_t index=0; index<fNoisyPixelMap.GetNrEntries(); index++) {
324     Int_t key = fNoisyPixelMap.GetKey(index);
325     Int_t col = GetColFromKey(key);
326     Int_t row = GetRowFromKey(key);
327     printf("%d,%d\n",col,row);
328   }
329 }