]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineCalibrationSPDhandler.cxx
9be664b205cb409850d94b78ed91c15d2a53158c
[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 // Handling of inactive equipments,HSs,chips have been added.       //
6 // A pixel that is either dead or inactive is called SILENT here.   //
7 // The lists of single dead and noisy pixels are separated from the //
8 // information about which eq/hs/chip are inactive.                 //
9 // The TArrayS objects that are put in the AliITSCalibrationSPD     //
10 // objects can be obtained from the methods GetDeadArray and        //
11 // GetNoisyArray.                                                   //
12 //////////////////////////////////////////////////////////////////////   
13
14 #include "AliITSOnlineCalibrationSPDhandler.h"
15 #include "AliITSOnlineCalibrationSPD.h"
16 #include "AliITSIntMap.h"
17 #include <TObjArray.h>
18 #include <TArrayI.h>
19 #include <TArrayS.h>
20 #include <TFile.h>
21 #include <TError.h>
22 #include <fstream>
23
24 #ifndef SPD_DA_OFF // you may want to exclude cdb classes, if using this class outside aliroot
25 #include "AliITSCalibrationSPD.h"
26 #include "AliCDBManager.h"
27 #include "AliCDBEntry.h"
28 #endif
29
30 /* $Id$ */
31
32 //____________________________________________________________________________________________
33 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler():
34   fFileLocation(".")
35 {
36   // constructor
37   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
38     fNrDead[gloChip]=0;
39     fNrNoisy[gloChip]=0;
40     fDeadPixelMap[gloChip] = new AliITSIntMap();
41     fNoisyPixelMap[gloChip] = new AliITSIntMap();    
42   }
43   ActivateALL();
44   UnSetDeadALL();
45 }
46 //____________________________________________________________________________________________
47 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(const AliITSOnlineCalibrationSPDhandler& handle): 
48   fFileLocation(".")
49 {
50   // copy constructor
51   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
52     fNrDead[gloChip] = handle.fNrDead[gloChip];
53     fNrNoisy[gloChip] = handle.fNrNoisy[gloChip];
54     fDeadPixelMap[gloChip] = handle.fDeadPixelMap[gloChip]->Clone();
55     fNoisyPixelMap[gloChip] = handle.fNoisyPixelMap[gloChip]->Clone();
56   }
57   for (UInt_t eq=0; eq<20; eq++) {
58     fActiveEq[eq] = handle.fActiveEq[eq];
59     for (UInt_t hs=0; hs<6; hs++) {
60       fActiveHS[eq][hs] = handle.fActiveHS[eq][hs];
61       for (UInt_t chip=0; chip<10; chip++) {
62         fActiveChip[eq][hs][chip] = handle.fActiveChip[eq][hs][chip];
63       }
64     }
65   }
66   fFileLocation = handle.fFileLocation;
67 }
68 //____________________________________________________________________________________________
69 AliITSOnlineCalibrationSPDhandler::~AliITSOnlineCalibrationSPDhandler() {
70   //  ClearMaps();
71   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
72     delete fDeadPixelMap[gloChip];
73     delete fNoisyPixelMap[gloChip];
74   }
75 }
76 //____________________________________________________________________________________________
77 AliITSOnlineCalibrationSPDhandler& AliITSOnlineCalibrationSPDhandler::operator=(const AliITSOnlineCalibrationSPDhandler& handle) {
78   // assignment operator
79   if (this!=&handle) {
80     this->ClearMaps();
81     for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
82       fNrDead[gloChip] = handle.fNrDead[gloChip];
83       fNrNoisy[gloChip] = handle.fNrNoisy[gloChip];
84       fDeadPixelMap[gloChip] = handle.fDeadPixelMap[gloChip]->Clone();
85       fNoisyPixelMap[gloChip] = handle.fNoisyPixelMap[gloChip]->Clone();
86     }
87     for (UInt_t eq=0; eq<20; eq++) {
88       fActiveEq[eq] = handle.fActiveEq[eq];
89       for (UInt_t hs=0; hs<6; hs++) {
90         fActiveHS[eq][hs] = handle.fActiveHS[eq][hs];
91         for (UInt_t chip=0; chip<10; chip++) {
92           fActiveChip[eq][hs][chip] = handle.fActiveChip[eq][hs][chip];
93         }
94       }
95     }
96     fFileLocation = handle.fFileLocation;
97   }
98   return *this;
99 }
100 //____________________________________________________________________________________________
101 void AliITSOnlineCalibrationSPDhandler::ClearMaps() {
102   // clear the lists of dead and noisy
103   ResetDead();
104   ResetNoisy();
105   ActivateALL();
106 }
107 //____________________________________________________________________________________________
108 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
109   // reset the dead pixel map and inactive eq,hs,chip
110   UnSetDeadALL();
111   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
112     fNrDead[gloChip]=0;
113     fDeadPixelMap[gloChip]->Clear();
114   }
115 }
116 //____________________________________________________________________________________________
117 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
118   // clear the list of noisy pixels
119   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
120     fNrNoisy[gloChip]=0;
121     fNoisyPixelMap[gloChip]->Clear();
122   }
123 }
124 //____________________________________________________________________________________________
125 void AliITSOnlineCalibrationSPDhandler::ResetDeadForChip(UInt_t eq, UInt_t hs, UInt_t chip) {
126   // clear the dead pixels for this chip
127   SetDeadChip(eq,hs,chip,kFALSE);
128   UInt_t gloChip = GetGloChip(eq,hs,chip);
129   for (UInt_t col=0; col<32; col++) {
130     for (UInt_t row=0; row<256; row++) {
131       Int_t key = GetKey(eq,hs,chip,col,row);
132       if (fDeadPixelMap[gloChip]->Remove(key)) {
133         fNrDead[gloChip]--;
134       }
135     }
136   }
137 }
138 //____________________________________________________________________________________________
139 void AliITSOnlineCalibrationSPDhandler::ResetNoisyForChip(UInt_t eq, UInt_t hs, UInt_t chip) {
140   // clear the noisy pixels for this chip
141   UInt_t gloChip = GetGloChip(eq,hs,chip);
142   if (gloChip>=1200) {
143     Error("AliITSOnlineCalibrationSPDhandler::ResetNoisyForChip","global chip nr (%d) out of bounds\n",gloChip);
144     return;
145   }
146   for (UInt_t col=0; col<32; col++) {
147     for (UInt_t row=0; row<256; row++) {
148       Int_t key = GetKey(eq,hs,chip,col,row);
149       if (fNoisyPixelMap[gloChip]->Remove(key)) {
150         fNrNoisy[gloChip]--;
151       }
152     }
153   }
154 }
155 //____________________________________________________________________________________________
156 void AliITSOnlineCalibrationSPDhandler::ResetDeadForEq(UInt_t eq) {
157   // clear the dead pixels for this eq
158   if (eq>=20) {
159     Error("AliITSOnlineCalibrationSPDhandler::ResetDeadForEq", "eq (%d) out of bounds.",eq);
160     return;
161   }
162   for (UInt_t hs=0; hs<6; hs++) {
163     for (UInt_t chip=0; chip<10; chip++) {
164       ResetDeadForChip(eq, hs, chip);
165     }
166   }
167 }
168 //____________________________________________________________________________________________
169 void AliITSOnlineCalibrationSPDhandler::ResetNoisyForEq(UInt_t eq) {
170   // clear the noisy pixels for this eq
171   if (eq>=20) {
172     Error("AliITSOnlineCalibrationSPDhandler::ResetNoisyForEq", "eq (%d) out of bounds.",eq);
173     return;
174   }
175   for (UInt_t hs=0; hs<6; hs++) {
176     for (UInt_t chip=0; chip<10; chip++) {
177       ResetNoisyForChip(eq, hs, chip);
178     }
179   }
180 }
181
182
183 //____________________________________________________________________________________________
184 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFiles() {
185   // read files from file location (active,dead,noisy info). returns true if at least one file found
186   Bool_t b1 = ReadNoisyFromFiles();
187   Bool_t b2 = ReadSilentFromFiles();
188   return (b1 || b2);
189 }
190 //____________________________________________________________________________________________
191 Bool_t AliITSOnlineCalibrationSPDhandler::ReadSilentFromFiles() {
192   // read dead,active files from file location. returns true if at least one file found
193   Bool_t returnval=kFALSE;
194   for (UInt_t eq=0; eq<20; eq++) {
195     if (ReadSilentFromFile(eq)) {
196       returnval=kTRUE;
197     }
198   }
199   return returnval;
200 }
201 //____________________________________________________________________________________________
202 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFiles() {
203   // read dead,active files from file location. returns true if at least one file found
204   Bool_t returnval=kFALSE;
205   for (UInt_t eq=0; eq<20; eq++) {
206     if (ReadDeadFromFile(eq)) {
207       returnval=kTRUE;
208     }
209   }
210   return returnval;
211 }
212 //____________________________________________________________________________________________
213 Bool_t AliITSOnlineCalibrationSPDhandler::ReadSilentFromFile(UInt_t eq) {
214   // read dead file for eq from file location. 
215   TString fileName = Form("%s/SPD_Dead_%d.root",fFileLocation.Data(),eq);
216   return ReadSilentFromFileName(fileName.Data());
217 }
218 //____________________________________________________________________________________________
219 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(UInt_t eq) {
220   // read dead file for eq from file location. 
221   TString fileName = Form("%s/SPD_Dead_%d.root",fFileLocation.Data(),eq);
222   return ReadDeadFromFileName(fileName.Data());
223 }
224 //____________________________________________________________________________________________
225 Bool_t AliITSOnlineCalibrationSPDhandler::ReadSilentFromFileName(const char *fileName) {
226   // read dead from file fileName (including inactive)
227   return ReadDeadFromFileName(fileName, kTRUE);
228 }
229 //____________________________________________________________________________________________
230 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFileName(const char *fileName, Bool_t inactive) {
231   // read dead from file fileName
232   AliITSOnlineCalibrationSPD* calib;
233   FILE* fp0 = fopen(fileName, "r");
234   if (fp0 == NULL) {return kFALSE;}
235   else {
236     fclose(fp0);
237     TFile file(fileName, "READ");
238     if (file.IsOpen()) {
239       file.GetObject("AliITSOnlineCalibrationSPD", calib);
240       file.Close();
241       if (calib!=NULL) {
242         UInt_t nrDead=calib->GetNrBad();
243         for (UInt_t index=0; index<nrDead; index++) {
244           UInt_t key = calib->GetKeyAt(index);
245           UInt_t eq = GetEqIdFromKey(key);
246           UInt_t hs = GetHSFromKey(key);
247           UInt_t chip = GetChipFromKey(key);
248           UInt_t col = GetColFromKey(key);
249           UInt_t row = GetRowFromKey(key);
250           SetDeadPixel(eq,hs,chip,col,row);
251         }
252         UInt_t eq = calib->GetEqNr();
253         if (calib->IsDeadEq()) SetDeadEq(eq);
254         else                   SetDeadEq(eq,kFALSE);
255         for (UInt_t hs=0; hs<6; hs++) {
256           if (calib->IsDeadHS(hs)) SetDeadHS(eq,hs);
257           else                     SetDeadHS(eq,hs,kFALSE);
258           for (UInt_t chip=0; chip<10; chip++) {
259             if (calib->IsDeadChip(hs,chip)) SetDeadChip(eq,hs,chip);
260             else                            SetDeadChip(eq,hs,chip,kFALSE);
261           }
262         }
263         if (inactive) {
264           UInt_t eq = calib->GetEqNr();
265           if (calib->IsActiveEq()) ActivateEq(eq);
266           else                     ActivateEq(eq,kFALSE);
267           for (UInt_t hs=0; hs<6; hs++) {
268             if (calib->IsActiveHS(hs)) ActivateHS(eq,hs);
269             else                       ActivateHS(eq,hs,kFALSE);
270             for (UInt_t chip=0; chip<10; chip++) {
271               if (calib->IsActiveChip(hs,chip)) ActivateChip(eq,hs,chip);
272               else                              ActivateChip(eq,hs,chip,kFALSE);
273             }
274           }
275         }
276       }
277     }
278   }
279   return kTRUE;
280 }
281 //____________________________________________________________________________________________
282 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFiles() {
283   // read noisy files from file location. returns true if at least one file found
284   Bool_t returnval=kFALSE;
285   for (UInt_t eq=0; eq<20; eq++) {
286     if (ReadNoisyFromFile(eq)) {
287       returnval=kTRUE;
288     }
289   }
290   return returnval;
291 }
292 //____________________________________________________________________________________________
293 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(UInt_t eq) {
294   // read noisy file for eq from file location. 
295   TString fileName = Form("%s/SPD_Noisy_%d.root",fFileLocation.Data(),eq);
296   return ReadNoisyFromFileName(fileName.Data());
297 }
298 //____________________________________________________________________________________________
299 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFileName(const char *fileName) {
300   // read noisy from file fileName
301   AliITSOnlineCalibrationSPD* calib;
302   FILE* fp0 = fopen(fileName, "r");
303   if (fp0 == NULL) {return kFALSE;}
304   else {
305     fclose(fp0);
306     TFile file(fileName, "READ");
307     if (file.IsOpen()) {
308       file.GetObject("AliITSOnlineCalibrationSPD", calib);
309       file.Close();
310       if (calib!=NULL) {
311         UInt_t nrNoisy=calib->GetNrBad();
312         for (UInt_t index=0; index<nrNoisy; index++) {
313           UInt_t key = calib->GetKeyAt(index);
314           UInt_t eq = GetEqIdFromKey(key);
315           UInt_t hs = GetHSFromKey(key);
316           UInt_t chip = GetChipFromKey(key);
317           UInt_t col = GetColFromKey(key);
318           UInt_t row = GetRowFromKey(key);
319           SetNoisyPixel(eq,hs,chip,col,row);
320         }
321       }
322     }
323   }
324   return kTRUE;
325 }
326 //____________________________________________________________________________________________
327 UInt_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromText(const char *fileName, UInt_t module) {
328   // read dead from a text file (lines with eq,hs,chip,col,row). returns nr of pixels added (not already here)
329   // insert only those pixels that belong to module (or all if module=240). 
330   UInt_t newNrDead=0;
331   ifstream textFile;
332   textFile.open(fileName, ifstream::in);
333   if (textFile.fail()) {
334     Warning("AliITSOnlineCalibrationSPDhandler::ReadDeadFromText","No dead text file (%s) present.",fileName);
335   }
336   else {
337     while(1) {
338       UInt_t eq,hs,chip,col,row;
339       textFile >> eq; if (textFile.eof()) break;
340       textFile >> hs; if (textFile.eof()) break;
341       textFile >> chip; if (textFile.eof()) break;
342       textFile >> col; if (textFile.eof()) break;
343       textFile >> row; 
344       if (module==240 || (Int_t)module==AliITSRawStreamSPD::GetModuleNumber(eq,hs,chip)){
345         if (SetDeadPixel(eq,hs,chip,col,row)) {
346           newNrDead++;
347         }
348       }
349       if (textFile.eof()) break;
350     }
351     textFile.close();
352   }
353   return newNrDead;
354 }
355 //____________________________________________________________________________________________
356 UInt_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText(const char *fileName, UInt_t module) {
357   // read noisy from a text file (lines with eq,hs,chip,col,row). returns nr of pixels added (not already here)
358   // insert only those pixels that belong to module (or all if module=240). 
359   UInt_t newNrNoisy=0;
360   ifstream textFile;
361   textFile.open(fileName, ifstream::in);
362   if (textFile.fail()) {
363     Warning("AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText","No noisy text file (%s) present.",fileName);
364   }
365   else {
366     while(1) {
367       UInt_t eq,hs,chip,col,row;
368       textFile >> eq; if (textFile.eof()) break;
369       textFile >> hs; if (textFile.eof()) break;
370       textFile >> chip; if (textFile.eof()) break;
371       textFile >> col; if (textFile.eof()) break;
372       textFile >> row; 
373       if (module==240 || (Int_t)module==AliITSRawStreamSPD::GetModuleNumber(eq,hs,chip)){
374         if (SetNoisyPixel(eq,hs,chip,col,row)) {
375           newNrNoisy++;
376         }
377       }
378       if (textFile.eof()) break;
379     }
380     textFile.close();
381   }
382   return newNrNoisy;
383 }
384 //____________________________________________________________________________________________
385 void AliITSOnlineCalibrationSPDhandler::WriteToFilesAlways() {
386   // write the lists of active,dead,noisy to files
387   for (UInt_t eq=0; eq<20; eq++) {
388     WriteSilentToFile(eq);
389     WriteNoisyToFile(eq);
390   }
391 }
392 //____________________________________________________________________________________________
393 UInt_t AliITSOnlineCalibrationSPDhandler::WriteToFiles() {
394   // write the lists of dead and noisy to files (only if there are >0 dead or noisy pixels) , returns nr of files produced
395   return (WriteNoisyToFiles() + WriteSilentToFiles());
396 }
397 //____________________________________________________________________________________________
398 void AliITSOnlineCalibrationSPDhandler::WriteSilentToFilesAlways() {
399   // write the lists of silent to files
400   for (UInt_t eq=0; eq<20; eq++) {
401       WriteSilentToFile(eq);
402   }
403 }
404 //____________________________________________________________________________________________
405 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFilesAlways() {
406   // write the lists of dead to files
407   for (UInt_t eq=0; eq<20; eq++) {
408       WriteDeadToFile(eq);
409   }
410 }
411 //____________________________________________________________________________________________
412 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFilesAlways() {
413   // write the lists of noisy to files
414   for (UInt_t eq=0; eq<20; eq++) {
415     WriteNoisyToFile(eq);
416   }
417 }
418 //____________________________________________________________________________________________
419 UInt_t AliITSOnlineCalibrationSPDhandler::WriteSilentToFiles() {
420   // write the list of silent to file (only if there are >0 silent pixels) , returns nr of files produced
421   UInt_t nrFiles=0;
422   for (UInt_t eq=0; eq<20; eq++) {
423     if (GetNrSilentEq(eq) > 0) {
424       WriteSilentToFile(eq);
425       nrFiles++;
426     }
427   }
428   return nrFiles;
429 }
430 //____________________________________________________________________________________________
431 UInt_t AliITSOnlineCalibrationSPDhandler::WriteDeadToFiles() {
432   // write the list of dead to file (only if there are >0 dead pixels) , returns nr of files produced
433   UInt_t nrFiles=0;
434   for (UInt_t eq=0; eq<20; eq++) {
435     if (GetNrDeadEq(eq) > 0) {
436       WriteDeadToFile(eq);
437       nrFiles++;
438     }
439   }
440   return nrFiles;
441 }
442 //____________________________________________________________________________________________
443 UInt_t AliITSOnlineCalibrationSPDhandler::WriteNoisyToFiles() {
444   // write the list of noisy to file (only if there are >0 noisy pixels) , returns nr of files produced
445   UInt_t nrFiles=0;
446   for (UInt_t eq=0; eq<20; eq++) {
447     if (GetNrNoisyEq(eq) > 0) {
448       WriteNoisyToFile(eq);
449       nrFiles++;
450     }
451   }
452   return nrFiles;
453 }
454 //____________________________________________________________________________________________
455 void AliITSOnlineCalibrationSPDhandler::WriteSilentToFile(UInt_t eq) {
456   WriteDeadToFile(eq,kTRUE);
457 }
458 //____________________________________________________________________________________________
459 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFile(UInt_t eq, Bool_t inactive) {
460   // write the lists of dead (and inactive if input boolean is true) for eq to file
461   AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
462   calib->SetEqNr(eq);
463   calib->SetBadList(GetDeadArrayOnline(eq));
464   calib->SetNrBad(GetNrDeadEq(eq));
465   if (IsDeadEq(eq)) calib->SetDeadEq();
466   else              calib->SetDeadEq(kFALSE);
467   for (UInt_t hs=0; hs<6; hs++) {
468     if (IsDeadHS(eq,hs)) calib->SetDeadHS(hs);
469     else                 calib->SetDeadHS(hs,kFALSE);
470     for (UInt_t chip=0; chip<10; chip++) {
471       if (IsDeadChip(eq,hs,chip)) calib->SetDeadChip(hs,chip);
472       else                        calib->SetDeadChip(hs,chip,kFALSE);
473     }
474   }
475   if (inactive) {
476     if (IsActiveEq(eq)) calib->ActivateEq();
477     else                calib->ActivateEq(kFALSE);
478     for (UInt_t hs=0; hs<6; hs++) {
479       if (IsActiveHS(eq,hs)) calib->ActivateHS(hs);
480       else                   calib->ActivateHS(hs,kFALSE);
481       for (UInt_t chip=0; chip<10; chip++) {
482         if (IsActiveChip(eq,hs,chip)) calib->ActivateChip(hs,chip);
483         else                          calib->ActivateChip(hs,chip,kFALSE);
484       }
485     }
486   }
487   TString fileName = Form("%s/SPD_Dead_%d.root",fFileLocation.Data(),eq);
488   TFile file(fileName.Data(), "RECREATE");
489   file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
490   file.Close();
491   delete calib;
492 }
493 //____________________________________________________________________________________________
494 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFile(UInt_t eq) {
495   // write the lists of noisy for eq to file
496   AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
497   calib->SetEqNr(eq);
498   calib->SetBadList(GetNoisyArrayOnline(eq));
499   calib->SetNrBad(GetNrNoisyEq(eq));
500   TString fileName = Form("%s/SPD_Noisy_%d.root",fFileLocation.Data(),eq);
501   TFile file(fileName.Data(), "RECREATE");
502   file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
503   file.Close();
504   delete calib;
505 }
506 //____________________________________________________________________________________________
507 #ifndef SPD_DA_OFF
508 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadModuleFromDB(UInt_t module, Int_t runNr, Bool_t treeSerial) {
509   // reads dead pixels from DB for given module and runNr
510   AliCDBManager* man = AliCDBManager::Instance();
511   if(!man->IsDefaultStorageSet()) {
512     man->SetDefaultStorage("local://$ALICE_ROOT");
513   }
514   AliCDBEntry *cdbEntry = man->Get("ITS/Calib/SPDDead", runNr);
515   TObjArray* spdEntry;
516   if(cdbEntry) {
517     spdEntry = (TObjArray*)cdbEntry->GetObject();
518     if(!spdEntry) return kFALSE;
519   }
520   else {
521     Warning("AliITSOnlineCalibrationSPDhandler::ReadDeadModuleFromDB","Calibration for run %d not found in database.",runNr);
522     return kFALSE;
523   }
524   AliITSCalibrationSPD* calibSPD;
525   calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
526
527   UInt_t nrDead = calibSPD->GetNrBadSingle();
528   if (nrDead>0) {
529     if (!treeSerial) RecursiveInsertDead(calibSPD,module,0,nrDead-1);
530     else {
531       for (UInt_t index=0; index<nrDead; index++) {
532         UInt_t colM = calibSPD->GetBadColAt(index);
533         UInt_t rowM = calibSPD->GetBadRowAt(index);
534         SetDeadPixelM(module,colM,rowM);
535       }
536     }
537   }
538   for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
539     UInt_t eq,hs,chip,col,row;
540     AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
541     if (calibSPD->IsChipBad(chipIndex)) {
542       SetDeadChip(eq,hs,chip);
543     }
544     else {
545       SetDeadChip(eq,hs,chip,kFALSE);
546     }
547   }
548
549   spdEntry->SetOwner(kTRUE);
550   spdEntry->Clear();
551   return kTRUE;
552 }
553 //____________________________________________________________________________________________
554 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyModuleFromDB(UInt_t module, Int_t runNr, Bool_t treeSerial) {
555   // reads noisy pixels from DB for given module and runNr
556   AliCDBManager* man = AliCDBManager::Instance();
557   if(!man->IsDefaultStorageSet()) {
558     man->SetDefaultStorage("local://$ALICE_ROOT");
559   }
560   AliCDBEntry *cdbEntry = man->Get("ITS/Calib/SPDNoisy", runNr);
561   TObjArray* spdEntry;
562   if(cdbEntry) {
563     spdEntry = (TObjArray*)cdbEntry->GetObject();
564     if(!spdEntry) return kFALSE;
565   }
566   else {
567     Warning("AliITSOnlineCalibrationSPDhandler::ReadNoisyModuleFromDB","Calibration for run %d not found in database.",runNr);
568     return kFALSE;
569   }
570   AliITSCalibrationSPD* calibSPD;
571   calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
572   UInt_t nrNoisy = calibSPD->GetNrBadSingle();
573   if (nrNoisy>0) {
574     if (!treeSerial) RecursiveInsertNoisy(calibSPD,module,0,nrNoisy-1);
575     else {
576       for (UInt_t index=0; index<nrNoisy; index++) {
577         UInt_t colM = calibSPD->GetBadColAt(index);
578         UInt_t rowM = calibSPD->GetBadRowAt(index);
579         SetNoisyPixelM(module,colM,rowM);
580       }
581     }
582   }
583   spdEntry->SetOwner(kTRUE);
584   spdEntry->Clear();
585   return kTRUE;
586 }
587 //____________________________________________________________________________________________
588 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromDB(Int_t runNr, Bool_t treeSerial) {
589   // reads dead and noisy pixels from DB for given runNr
590   // note that you may want to clear the lists (if they are not empty) before reading
591   return (ReadNoisyFromDB(runNr,treeSerial) && ReadDeadFromDB(runNr,treeSerial));
592 }
593 //____________________________________________________________________________________________
594 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromDB(Int_t runNr, Bool_t treeSerial) {
595   // reads dead pixels from DB for given runNr
596   // note that you may want to clear the list (if it is not empty) before reading
597   AliCDBManager* man = AliCDBManager::Instance();
598   if(!man->IsDefaultStorageSet()) {
599     man->SetDefaultStorage("local://$ALICE_ROOT");
600   }
601   AliCDBEntry *cdbEntry = man->Get("ITS/Calib/SPDDead", runNr);
602   TObjArray* spdEntry;
603   if(cdbEntry) {
604     spdEntry = (TObjArray*)cdbEntry->GetObject();
605     if(!spdEntry) return kFALSE;
606   }
607   else {
608     Warning("AliITSOnlineCalibrationSPDhandler::ReadDeadFromDB","Calibration for run %d not found in database.",runNr);
609     return kFALSE;
610   }
611   AliITSCalibrationSPD* calibSPD;
612   for (UInt_t module=0; module<240; module++) {
613     calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
614     UInt_t nrDead = calibSPD->GetNrBadSingle();
615     if (nrDead>0) {
616       if (!treeSerial) RecursiveInsertDead(calibSPD,module,0,nrDead-1);
617       else {
618         for (UInt_t index=0; index<nrDead; index++) {
619           UInt_t colM = calibSPD->GetBadColAt(index);
620           UInt_t rowM = calibSPD->GetBadRowAt(index);
621           SetDeadPixelM(module,colM,rowM);
622         }
623       }
624     }
625     for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
626       UInt_t eq,hs,chip,col,row;
627       AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
628       if (calibSPD->IsChipBad(chipIndex)) {
629         SetDeadChip(eq,hs,chip);
630       }
631       else {
632         SetDeadChip(eq,hs,chip,kFALSE);
633       }
634     }
635   }
636   spdEntry->SetOwner(kTRUE);
637   spdEntry->Clear();
638   return kTRUE;
639 }
640 //____________________________________________________________________________________________
641 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromDB(Int_t runNr, Bool_t treeSerial) {
642   // reads noisy pixels from DB for given runNr
643   // note that you may want to clear the list (if it is not empty) before reading
644   AliCDBManager* man = AliCDBManager::Instance();
645   if(!man->IsDefaultStorageSet()) {
646     man->SetDefaultStorage("local://$ALICE_ROOT");
647   }
648   AliCDBEntry *cdbEntry = man->Get("ITS/Calib/SPDNoisy", runNr);
649   TObjArray* spdEntry;
650   if(cdbEntry) {
651     spdEntry = (TObjArray*)cdbEntry->GetObject();
652     if(!spdEntry) return kFALSE;
653   }
654   else {
655     Warning("AliITSOnlineCalibrationSPDhandler::ReadNoisyFromDB","Calibration for run %d not found in database.",runNr);
656     return kFALSE;
657   }
658   AliITSCalibrationSPD* calibSPD;
659   for (UInt_t module=0; module<240; module++) {
660     calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
661     UInt_t nrNoisy = calibSPD->GetNrBadSingle();
662     if (nrNoisy>0) {    
663       if (!treeSerial) {
664         RecursiveInsertNoisy(calibSPD,module,0,nrNoisy-1);
665       }
666       else {
667         for (UInt_t index=0; index<nrNoisy; index++) {
668           UInt_t colM = calibSPD->GetBadColAt(index);
669           UInt_t rowM = calibSPD->GetBadRowAt(index);
670           SetNoisyPixelM(module,colM,rowM);
671         }
672       }
673     }
674   }
675   spdEntry->SetOwner(kTRUE);
676   spdEntry->Clear();
677   return kTRUE;
678 }
679 //____________________________________________________________________________________________
680 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromCalibObj(TObjArray* calObj) {
681   // reads dead pixels from calib object
682   for (UInt_t module=0; module<240; module++) {
683     AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*)calObj->At(module);
684     for (Int_t i=0; i<calibSPD->GetNrBadSingle(); i++) {
685       SetDeadPixelM(module,calibSPD->GetBadColAt(i),calibSPD->GetBadRowAt(i));
686     }
687     for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
688       UInt_t eq,hs,chip,col,row;
689       AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
690       if (calibSPD->IsChipBad(chipIndex)) {
691         SetDeadChip(eq,hs,chip);
692       }
693       else {
694         SetDeadChip(eq,hs,chip,kFALSE);
695       }
696     }
697   }
698   return kTRUE;
699 }
700 //____________________________________________________________________________________________
701 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromCalibObj(TObjArray* calObj) {
702   // reads noisy pixels from calib object
703   for (UInt_t module=0; module<240; module++) {
704     AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*)calObj->At(module);
705     for (Int_t i=0; i<calibSPD->GetNrBadSingle(); i++) {
706       SetNoisyPixelM(module,calibSPD->GetBadColAt(i),calibSPD->GetBadRowAt(i));
707     }
708   }
709   return kTRUE;
710 }
711 //____________________________________________________________________________________________
712 Bool_t AliITSOnlineCalibrationSPDhandler::WriteToDB(Int_t runNrStart, Int_t runNrEnd) {
713   // writes dead and noisy pixels to DB for given runNrs
714   // overwrites any previous entries
715   return (WriteNoisyToDB(runNrStart,runNrEnd) && WriteDeadToDB(runNrStart,runNrEnd));
716 }
717 //____________________________________________________________________________________________
718 Bool_t AliITSOnlineCalibrationSPDhandler::WriteDeadToDB(Int_t runNrStart, Int_t runNrEnd) {
719   // writes dead pixels to DB for given runNrs
720   // overwrites any previous entries
721   AliCDBManager* man = AliCDBManager::Instance();
722   if(!man->IsDefaultStorageSet()) {
723     man->SetDefaultStorage("local://$ALICE_ROOT");
724   }
725   AliCDBMetaData* metaData = new AliCDBMetaData();
726   metaData->SetResponsible("Henrik Tydesjo");
727   metaData->SetComment("Created by AliITSOnlineCalibrationSPDhandler.");
728   AliCDBId idCalSPD("ITS/Calib/SPDDead",runNrStart,runNrEnd);
729   TObjArray* spdEntry = new TObjArray(240);
730   spdEntry->SetOwner(kTRUE);
731   for(UInt_t module=0; module<240; module++){
732     AliITSCalibrationSPD* calibSPD = new AliITSCalibrationSPD();
733     spdEntry->Add(calibSPD);
734   }
735   for(UInt_t module=0; module<240; module++){
736     AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
737     calibSPD->SetNrBadSingle( GetNrDeadSingle(module) );
738     calibSPD->SetBadList( GetDeadArray(module) );
739     for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
740       UInt_t eq,hs,chip,col,row;
741       AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
742       if (IsSilentChip(eq,hs,chip)) {
743         calibSPD->SetChipBad(chipIndex);
744       }
745       else {
746         calibSPD->UnSetChipBad(chipIndex);
747       }
748     }
749   }
750   AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
751   man->Put(cdbEntry);
752   delete spdEntry;
753   delete cdbEntry;
754   delete metaData;
755   return kTRUE;
756 }
757 //____________________________________________________________________________________________
758 Bool_t AliITSOnlineCalibrationSPDhandler::WriteDeadToDBasNoisy(Int_t runNrStart, Int_t runNrEnd) {
759   // writes dead pixels to DB for given runNrs
760   // overwrites any previous entries
761   AliCDBManager* man = AliCDBManager::Instance();
762   if(!man->IsDefaultStorageSet()) {
763     man->SetDefaultStorage("local://$ALICE_ROOT");
764   }
765   AliCDBMetaData* metaData = new AliCDBMetaData();
766   metaData->SetResponsible("Henrik Tydesjo");
767   metaData->SetComment("Created by AliITSOnlineCalibrationSPDhandler.");
768   AliCDBId idCalSPD("ITS/Calib/SPDNoisy",runNrStart,runNrEnd);
769   TObjArray* spdEntry = new TObjArray(240);
770   spdEntry->SetOwner(kTRUE);
771   for(UInt_t module=0; module<240; module++){
772     AliITSCalibrationSPD* calibSPD = new AliITSCalibrationSPD();
773     spdEntry->Add(calibSPD);
774   }
775   for(UInt_t module=0; module<240; module++){
776     AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
777     calibSPD->SetNrBadSingle( GetNrDeadSingle(module) );
778     calibSPD->SetBadList( GetDeadArray(module) );
779     for (UInt_t chipIndex=0; chipIndex<5; chipIndex++) {
780       UInt_t eq,hs,chip,col,row;
781       AliITSRawStreamSPD::OfflineToOnline(module, chipIndex*32, 0, eq, hs, chip, col, row);
782       if (IsSilentChip(eq,hs,chip)) {
783         calibSPD->SetChipBad(chipIndex);
784       }
785       else {
786         calibSPD->UnSetChipBad(chipIndex);
787       }
788     }
789   }
790   AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
791   man->Put(cdbEntry);
792   delete spdEntry;
793   delete cdbEntry;
794   delete metaData;
795   return kTRUE;
796 }
797 //____________________________________________________________________________________________
798 Bool_t AliITSOnlineCalibrationSPDhandler::WriteNoisyToDB(Int_t runNrStart, Int_t runNrEnd) {
799   // writes noisy pixels to DB for given runNrs
800   // overwrites any previous entries
801   AliCDBManager* man = AliCDBManager::Instance();
802   if(!man->IsDefaultStorageSet()) {
803     man->SetDefaultStorage("local://$ALICE_ROOT");
804   }
805   AliCDBMetaData* metaData = new AliCDBMetaData();
806   metaData->SetResponsible("Henrik Tydesjo");
807   metaData->SetComment("Created by AliITSOnlineCalibrationSPDhandler.");
808   AliCDBId idCalSPD("ITS/Calib/SPDNoisy",runNrStart,runNrEnd);
809   TObjArray* spdEntry = new TObjArray(240);
810   spdEntry->SetOwner(kTRUE);
811   for(UInt_t module=0; module<240; module++){
812     AliITSCalibrationSPD* calibSPD = new AliITSCalibrationSPD();
813     spdEntry->Add(calibSPD);
814   }
815   for(UInt_t module=0; module<240; module++){
816     AliITSCalibrationSPD* calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
817     calibSPD->SetNrBadSingle( GetNrNoisySingle(module) );
818     calibSPD->SetBadList( GetNoisyArray(module) );
819   }
820   AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
821   man->Put(cdbEntry);
822   delete spdEntry;
823   delete cdbEntry;
824   delete metaData;
825   return kTRUE;
826 }
827 //____________________________________________________________________________________________
828 void AliITSOnlineCalibrationSPDhandler::RecursiveInsertDead(AliITSCalibrationSPD* calibSPD, UInt_t module, Int_t lowInd, Int_t highInd) {
829   // inserts dead pixels recursively, used when reading from db
830   if (lowInd>highInd) return;
831   Int_t thisInd = lowInd+(highInd-lowInd)/2;
832   SetDeadPixelM(module,calibSPD->GetBadColAt(thisInd),calibSPD->GetBadRowAt(thisInd));
833   RecursiveInsertDead(calibSPD,module,lowInd,thisInd-1);
834   RecursiveInsertDead(calibSPD,module,thisInd+1,highInd);
835 }
836 //____________________________________________________________________________________________
837 void AliITSOnlineCalibrationSPDhandler::RecursiveInsertNoisy(AliITSCalibrationSPD* calibSPD, UInt_t module, Int_t lowInd, Int_t highInd) {
838   // inserts noisy pixels recursively, used when reading from db
839   if (lowInd>highInd) return;
840   Int_t thisInd = lowInd+(highInd-lowInd)/2;
841   SetNoisyPixelM(module,calibSPD->GetBadColAt(thisInd),calibSPD->GetBadRowAt(thisInd));
842   RecursiveInsertNoisy(calibSPD,module,lowInd,thisInd-1);
843   RecursiveInsertNoisy(calibSPD,module,thisInd+1,highInd);
844 }
845
846 #endif
847 //____________________________________________________________________________________________
848 void AliITSOnlineCalibrationSPDhandler::GenerateDCSConfigFile(const Char_t* fileName) {
849   // generates an ascii file in the format as the one produced by online da (but with dummy runNr=0)
850   ofstream dcsfile;
851   dcsfile.open(fileName);
852   dcsfile << "[SPD SCAN]\n";
853   dcsfile << "RunNumber=" << "0" << "\n"; // dummy value
854   dcsfile << "Type=" << "4" << "\n";
855   dcsfile << "Router=" << "0" << "\n"; // dummy value
856   dcsfile << "ActualDetConfiguration=" << "0,-1,-1\n"; // dummy values
857   dcsfile << "[NOISY]\n";
858   for (UInt_t module=0; module<240; module++) {
859     UInt_t headkey=20*10*6;
860     for (UInt_t ind=0; ind<GetNrNoisy(module); ind++) {
861       UInt_t newkey = GetNoisyEqIdAt(module,ind)*10*6 +
862         GetNoisyHSAt(module,ind)*10 +
863         GetNoisyChipAt(module,ind);
864       if (newkey!=headkey) { // print eq,hs,chip header
865         headkey = newkey;
866         dcsfile << "-" << newkey/(6*10) << "," << (newkey%(6*10))/10 << "," << (newkey%(6*10))%10 << "\n";
867       }
868       dcsfile << GetNoisyColAt(module,ind) << "," << GetNoisyRowAt(module,ind) << "\n";
869     }
870   }
871   dcsfile.close();
872 }
873 //____________________________________________________________________________________________
874 TArrayS AliITSOnlineCalibrationSPDhandler::GetSilentArray(UInt_t module, Bool_t treeSerial) {
875   // get a TArrayS of the silent=dead+inactive pixels (format for the AliITSCalibrationSPD object)
876   // NB! with new implementation of AliITSCalibrationSPD this is not needed anymore
877   TArrayS returnArray;
878
879   UInt_t eq = GetEqIdFromOffline(module);
880   UInt_t hs = GetHSFromOffline(module);
881   UInt_t size=0;
882   if ( !( IsActiveEq(eq) && IsActiveHS(eq,hs) ) ) {
883     size = 8192*5;
884   }
885   else {
886     for (UInt_t ch=0; ch<5; ch++) {
887       UInt_t chip = GetChipFromOffline(module,ch*32);
888       if (!(IsActiveChip(eq,hs,chip))) {
889         size += 8192;
890       }
891       else {
892         UInt_t gloChip = GetGloChip(eq,hs,chip);
893         size += fNrDead[gloChip];
894       }
895     }
896   }
897   returnArray.Set(size*2);
898
899   UInt_t gloIndex=0;
900   if ( !( IsActiveEq(eq) && IsActiveHS(eq,hs) ) ) {
901     for (UInt_t colM=0; colM<160; colM++) {
902       for (UInt_t rowM=0; rowM<256; rowM++) {
903         returnArray.AddAt(colM,gloIndex*2);
904         returnArray.AddAt(rowM,gloIndex*2+1);
905         gloIndex++;
906       }
907     }
908   }
909   else {
910     for (UInt_t ch=0; ch<5; ch++) {
911       UInt_t chip = GetChipFromOffline(module,ch*32);
912       if (!(IsActiveChip(eq,hs,chip))) {
913         for (UInt_t colM=ch*32; colM<ch*32+32; colM++) {
914           for (UInt_t rowM=0; rowM<256; rowM++) {
915             returnArray.AddAt(colM,gloIndex*2);
916             returnArray.AddAt(rowM,gloIndex*2+1);
917             gloIndex++;
918           }
919         }
920       }
921       else {
922         UInt_t gloChip = GetGloChip(eq,hs,chip);
923         if (treeSerial) fDeadPixelMap[gloChip]->PrepareSerialize(); // for tree ordered values
924         else fDeadPixelMap[gloChip]->PrepareSerializeOrdered(); // for key ordered values
925         for (UInt_t index=0; index<fNrDead[gloChip]; index++) {
926           Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
927           Int_t colM = GetColMFromKey(key);
928           Int_t rowM = GetRowMFromKey(key);
929           returnArray.AddAt(colM,gloIndex*2);
930           returnArray.AddAt(rowM,gloIndex*2+1);
931           gloIndex++;
932         }
933       }
934     }
935   }
936   return returnArray;
937 }
938 //____________________________________________________________________________________________
939 TArrayS AliITSOnlineCalibrationSPDhandler::GetDeadArray(UInt_t module, Bool_t treeSerial) {
940   // get a TArrayS of the single dead pixels (format for the AliITSCalibrationSPD object)
941   TArrayS returnArray;
942
943   UInt_t eq = GetEqIdFromOffline(module);
944   UInt_t hs = GetHSFromOffline(module);
945   UInt_t size=GetNrDeadSingle(module);
946   returnArray.Set(size*2);
947   UInt_t gloIndex=0;
948   for (UInt_t ch=0; ch<5; ch++) {
949     UInt_t chip = GetChipFromOffline(module,ch*32);
950     UInt_t gloChip = GetGloChip(eq,hs,chip);
951     if (treeSerial) fDeadPixelMap[gloChip]->PrepareSerialize(); // for tree ordered values
952     else fDeadPixelMap[gloChip]->PrepareSerializeOrdered(); // for key ordered values
953     if (!IsSilentChip(eq,hs,chip)) {
954       for (UInt_t index=0; index<fNrDead[gloChip]; index++) {
955         Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
956         Int_t colM = GetColMFromKey(key);
957         Int_t rowM = GetRowMFromKey(key);
958         returnArray.AddAt(colM,gloIndex*2);
959         returnArray.AddAt(rowM,gloIndex*2+1);
960         gloIndex++;
961       }
962     }
963   }
964   return returnArray;
965 }
966 //____________________________________________________________________________________________
967 TArrayS AliITSOnlineCalibrationSPDhandler::GetNoisyArray(UInt_t module, Bool_t treeSerial) {
968   // get a TArrayS of the single noisy pixels (format for the AliITSCalibrationSPD object)
969   TArrayS returnArray;
970
971   UInt_t eq = GetEqIdFromOffline(module);
972   UInt_t hs = GetHSFromOffline(module);
973   UInt_t size=GetNrNoisySingle(module);
974   returnArray.Set(size*2);
975   UInt_t gloIndex=0;
976   for (UInt_t ch=0; ch<5; ch++) {
977     UInt_t gloChip = GetGloChip(eq,hs,GetChipFromOffline(module,ch*32));
978     if (treeSerial) fNoisyPixelMap[gloChip]->PrepareSerialize(); // for tree ordered values
979     else fNoisyPixelMap[gloChip]->PrepareSerializeOrdered(); // for key ordered values
980     for (UInt_t index=0; index<fNrNoisy[gloChip]; index++) {
981       Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
982       Int_t colM = GetColMFromKey(key);
983       Int_t rowM = GetRowMFromKey(key);
984       returnArray.AddAt(colM,gloIndex*2);
985       returnArray.AddAt(rowM,gloIndex*2+1);
986       gloIndex++;
987     }
988   }
989   return returnArray;
990 }
991 //____________________________________________________________________________________________
992 TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArrayOnline(UInt_t eq) {
993   // get a TArrayI of the single dead pixels (format for the AliITSOnlineCalibrationSPD object)
994   TArrayI returnArray;
995   // fix size of array
996   UInt_t size=0;
997   for (UInt_t hs=0; hs<6; hs++) {
998     for (UInt_t chip=0; chip<10; chip++) {
999       UInt_t gloChip = GetGloChip(eq,hs,chip);
1000       size+=fNrDead[gloChip];
1001     }
1002   }
1003   returnArray.Set(size);
1004   // put keys in array
1005   UInt_t gloIndex=0;
1006   for (UInt_t hs=0; hs<6; hs++) {
1007     for (UInt_t chip=0; chip<10; chip++) {
1008       UInt_t gloChip = GetGloChip(eq,hs,chip);
1009       fDeadPixelMap[gloChip]->PrepareSerialize(); // for tree ordered values
1010       for (UInt_t index=0; index<fNrDead[gloChip]; index++) {
1011         Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
1012         returnArray.AddAt(key,gloIndex);
1013         gloIndex++;
1014       }
1015     }
1016   }
1017   return returnArray;
1018 }
1019 //____________________________________________________________________________________________
1020 TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArrayOnline(UInt_t eq) {
1021   // get a TArrayI of the single noisy pixels (format for the AliITSOnlineCalibrationSPD object)
1022   TArrayI returnArray;
1023   // fix size of array
1024   UInt_t size=0;
1025   for (UInt_t hs=0; hs<6; hs++) {
1026     for (UInt_t chip=0; chip<10; chip++) {
1027       UInt_t gloChip = GetGloChip(eq,hs,chip);
1028       size+=fNrNoisy[gloChip];
1029     }
1030   }
1031   returnArray.Set(size);
1032   // put keys in array
1033   UInt_t gloIndex=0;
1034   for (UInt_t hs=0; hs<6; hs++) {
1035     for (UInt_t chip=0; chip<10; chip++) {
1036       UInt_t gloChip = GetGloChip(eq,hs,chip);
1037       fNoisyPixelMap[gloChip]->PrepareSerialize(); // for tree ordered values
1038       for (UInt_t index=0; index<fNrNoisy[gloChip]; index++) {
1039         Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
1040         returnArray.AddAt(key,gloIndex);
1041         gloIndex++;
1042       }
1043     }
1044   }
1045   return returnArray;
1046 }
1047 //____________________________________________________________________________________________
1048 void AliITSOnlineCalibrationSPDhandler::PrintEqSummary() {
1049 // print summary (nr of dead and noisy) for each equipment
1050   printf("-----------\n");
1051   printf("Eq summary:\n");
1052   printf("-----------\n");
1053   for (UInt_t eq=0; eq<20; eq++) {
1054     printf("Eq %*d: %*d silent(dead+inactive) , %*d dead , %*d noisy\n",2,eq,6,GetNrSilentEq(eq),6,GetNrDeadEq(eq),6,GetNrNoisyEq(eq));
1055   }
1056 }
1057 //____________________________________________________________________________________________
1058 void AliITSOnlineCalibrationSPDhandler::PrintSilent() const {
1059   // print the inactive and dead pixels to screen
1060   printf("-----------------------------------------------------------\n");
1061   printf("Inactive or dead Equipments: (eq  |  module1 .. module12)\n");
1062   printf("-----------------------------------------------------------\n");
1063   for (UInt_t eq=0; eq<20; eq++) {
1064     if (IsSilentEq(eq)) {
1065       printf("%*d  |  ",2,eq);
1066       for (UInt_t hs=0; hs<6; hs++) {
1067         for (UInt_t chip=0; chip<10; chip+=5) {
1068           UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1069           if (hs>0 || chip==5) printf(",");
1070           printf("%*d",3,module);
1071         }
1072       }
1073       printf("\n");
1074     }
1075   }
1076
1077   printf("-----------------------------------------------------------\n");
1078   printf("Inactive or dead Half-staves: (eq,hs  |  module1,module2)\n");
1079   printf("-----------------------------------------------------------\n");
1080   for (UInt_t eq=0; eq<20; eq++) {
1081     if (!IsSilentEq(eq)) {
1082       for (UInt_t hs=0; hs<6; hs++) {
1083         if (IsSilentHS(eq,hs)) {
1084           printf("%*d,%*d  |  ",2,eq,1,hs);
1085           for (UInt_t chip=0; chip<10; chip+=5) {
1086             UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1087             if (chip==5) printf(",");
1088             printf("%*d",3,module);
1089           }
1090           printf("\n");
1091         }
1092       }
1093     }
1094   }
1095
1096   printf("-----------------------------------------------------------\n");
1097   printf("Inactive or dead Chips: (eq,hs,chip  |  module,colM1-colM2)\n");
1098   printf("-----------------------------------------------------------\n");
1099   for (UInt_t eq=0; eq<20; eq++) {
1100     if (!IsSilentEq(eq)) {
1101       for (UInt_t hs=0; hs<6; hs++) {
1102         if (!IsSilentHS(eq,hs)) {
1103           for (UInt_t chip=0; chip<10; chip++) {
1104             if (IsSilentChip(eq,hs,chip)) {
1105               printf("%*d,%*d,%*d  |  ",2,eq,1,hs,1,chip);
1106               UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1107               UInt_t colM1 = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,0);
1108               UInt_t colM2 = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,31);
1109               printf("%*d,%*d-%*d\n",3,module,3,colM1,3,colM2);
1110             }
1111           }
1112         }
1113       }
1114     }
1115   }
1116
1117   PrintDead();
1118
1119 }
1120 //____________________________________________________________________________________________
1121 void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
1122   // print the single dead pixels to screen (disregards inactive eq,hs,chip)
1123   printf("------------------------------------------------------\n");
1124   printf("Dead Pixels: (eq,hs,chip,col,row  |  module,colM,rowM)\n");
1125   printf("------------------------------------------------------\n");
1126   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
1127     for (UInt_t index=0; index<fNrDead[gloChip]; index++) {
1128       Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
1129       UInt_t eq = GetEqIdFromKey(key);
1130       UInt_t hs = GetHSFromKey(key);
1131       UInt_t chip = GetChipFromKey(key);
1132       UInt_t col = GetColFromKey(key);
1133       UInt_t row = GetRowFromKey(key);
1134
1135       UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1136       UInt_t colM = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,col);
1137       UInt_t rowM = AliITSRawStreamSPD::GetOfflineRowFromOnline(eq,hs,chip,row);
1138
1139       printf("%*d,%*d,%*d,%*d,%*d  |  %*d,%*d,%*d\n",2,eq,1,hs,1,chip,2,col,3,row,3,module,3,colM,3,rowM);
1140     }
1141   }
1142 }
1143 //____________________________________________________________________________________________
1144 void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
1145   // print the dead pixels to screen
1146   printf("-------------------------------------------------------\n");
1147   printf("Noisy Pixels: (eq,hs,chip,col,row  |  module,colM,rowM)\n");
1148   printf("-------------------------------------------------------\n");
1149   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
1150     for (UInt_t index=0; index<fNrNoisy[gloChip]; index++) {
1151       Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
1152       UInt_t eq = GetEqIdFromKey(key);
1153       UInt_t hs = GetHSFromKey(key);
1154       UInt_t chip = GetChipFromKey(key);
1155       UInt_t col = GetColFromKey(key);
1156       UInt_t row = GetRowFromKey(key);
1157
1158       UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1159       UInt_t colM = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,col);
1160       UInt_t rowM = AliITSRawStreamSPD::GetOfflineRowFromOnline(eq,hs,chip,row);
1161
1162       printf("%*d,%*d,%*d,%*d,%*d  |  %*d,%*d,%*d\n",2,eq,1,hs,1,chip,2,col,3,row,3,module,3,colM,3,rowM);
1163     }
1164   }
1165 }
1166 //____________________________________________________________________________________________
1167 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
1168   // set a dead pixel, returns false if pixel is already dead
1169   UInt_t gloChip = GetGloChip(eq,hs,chip);
1170   if (gloChip>=1200) {
1171     Error("AliITSOnlineCalibrationSPDhandler::SetDeadPixel", "eq,hs,chip nrs (%d,%d,%d) out of bounds.",eq,hs,chip);
1172     return kFALSE;
1173   }
1174   if (col>=32 && row>=256) {
1175     Error("AliITSOnlineCalibrationSPDhandler::SetDeadPixel", "col,row nrs (%d,%d) out of bounds.",col,row);
1176     return kFALSE;
1177   }
1178   Int_t key = GetKey(eq,hs,chip,col,row);
1179   // if noisy we dont want to add it...
1180   if (fNoisyPixelMap[gloChip]->Find(key) != NULL) return kFALSE;
1181   if (fDeadPixelMap[gloChip]->Insert(key,gloChip)) {
1182     fNrDead[gloChip]++;
1183     return kTRUE;
1184   }
1185   return kFALSE;
1186 }
1187 //____________________________________________________________________________________________
1188 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
1189   // set a noisy pixel, returns false if pixel is already noisy
1190   UInt_t gloChip = GetGloChip(eq,hs,chip);
1191   if (gloChip>=1200) {
1192     Error("AliITSOnlineCalibrationSPDhandler::SetNoisyPixel", "eq,hs,chip nrs (%d,%d,%d) out of bounds.",eq,hs,chip);
1193     return kFALSE;
1194   }
1195   if (col>=32 && row>=256) {
1196     Error("AliITSOnlineCalibrationSPDhandler::SetNoisyPixel", "col,row nrs (%d,%d) out of bounds.",col,row);
1197     return kFALSE;
1198   }
1199   Int_t key = GetKey(eq,hs,chip,col,row);
1200   // if dead before - remove from the dead list 
1201   if (fDeadPixelMap[gloChip]->Remove(key)) {
1202     fNrDead[gloChip]--;
1203   }
1204   if (fNoisyPixelMap[gloChip]->Insert(key,gloChip)) {
1205     fNrNoisy[gloChip]++;
1206     return kTRUE;
1207   }
1208   return kFALSE;
1209 }
1210 //____________________________________________________________________________________________
1211 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixelM(UInt_t module, UInt_t colM, UInt_t rowM) {
1212   // set a dead pixel, returns false if pixel is already dead
1213   UInt_t eq = GetEqIdFromOffline(module);
1214   UInt_t hs = GetHSFromOffline(module);
1215   UInt_t chip = GetChipFromOffline(module,colM);
1216   UInt_t col = GetColFromOffline(module,colM);
1217   UInt_t row = GetRowFromOffline(module,rowM);
1218   return SetDeadPixel(eq,hs,chip,col,row);
1219 }
1220 //____________________________________________________________________________________________
1221 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t rowM) {
1222   // set a noisy pixel, returns false if pixel is already noisy
1223   UInt_t eq = GetEqIdFromOffline(module);
1224   UInt_t hs = GetHSFromOffline(module);
1225   UInt_t chip = GetChipFromOffline(module,colM);
1226   UInt_t col = GetColFromOffline(module,colM);
1227   UInt_t row = GetRowFromOffline(module,rowM);
1228   return SetNoisyPixel(eq,hs,chip,col,row);
1229 }
1230 //____________________________________________________________________________________________
1231 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
1232   // unset a dead pixel, returns false if pixel is not dead
1233   UInt_t gloChip = GetGloChip(eq,hs,chip);
1234   if (gloChip>=1200) {
1235     Error("AliITSOnlineCalibrationSPDhandler::UnSetDeadPixel", "eq,hs,chip nrs (%d,%d,%d) out of bounds.",eq,hs,chip);
1236     return kFALSE;
1237   }
1238   Int_t key = GetKey(eq,hs,chip,col,row);
1239   if (fDeadPixelMap[gloChip]->Remove(key)) {
1240     fNrDead[gloChip]--;
1241     return kTRUE;
1242   }
1243   return kFALSE;
1244 }
1245 //____________________________________________________________________________________________
1246 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetNoisyPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
1247   // unset a noisy pixel, returns false if pixel is not noisy
1248   UInt_t gloChip = GetGloChip(eq,hs,chip);
1249   if (gloChip>=1200) {
1250     Error("AliITSOnlineCalibrationSPDhandler::UnSetNoisyPixel", "eq,hs,chip nrs (%d,%d,%d) out of bounds.",eq,hs,chip);
1251     return kFALSE;
1252   }
1253   Int_t key = GetKey(eq,hs,chip,col,row);
1254   if (fNoisyPixelMap[gloChip]->Remove(key)) {
1255     fNrNoisy[gloChip]--;
1256     return kTRUE;
1257   }
1258   return kFALSE;
1259 }
1260 //____________________________________________________________________________________________
1261 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetDeadPixelM(UInt_t module, UInt_t colM, UInt_t rowM) {
1262   // unset a dead pixel, returns false if pixel is not dead
1263   UInt_t eq = GetEqIdFromOffline(module);
1264   UInt_t hs = GetHSFromOffline(module);
1265   UInt_t chip = GetChipFromOffline(module,colM);
1266   UInt_t col = GetColFromOffline(module,colM);
1267   UInt_t row = GetRowFromOffline(module,rowM);
1268   return UnSetDeadPixel(eq,hs,chip,col,row);
1269 }
1270 //____________________________________________________________________________________________
1271 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t rowM) {
1272   // unset a noisy pixel, returns false if pixel is not noisy
1273   UInt_t eq = GetEqIdFromOffline(module);
1274   UInt_t hs = GetHSFromOffline(module);
1275   UInt_t chip = GetChipFromOffline(module,colM);
1276   UInt_t col = GetColFromOffline(module,colM);
1277   UInt_t row = GetRowFromOffline(module,rowM);
1278   return UnSetNoisyPixel(eq,hs,chip,col,row);
1279 }
1280 //____________________________________________________________________________________________
1281 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelBad(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
1282   // is the pixel bad (silent or noisy)
1283   return (IsPixelSilent(eq,hs,chip,col,row) || IsPixelNoisy(eq,hs,chip,col,row));
1284 }
1285 //____________________________________________________________________________________________
1286 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelSilent(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
1287   // is the pixel silent (dead or inactive)?
1288   UInt_t gloChip = GetGloChip(eq,hs,chip);
1289   if (gloChip>=1200 || col>=32 || row>=256) {
1290     Error("AliITSOnlineCalibrationSPDhandler::IsPixelSilent", "eq,hs,chip,col,row nrs (%d,%d,%d,%d,%d) out of bounds.",eq,hs,chip,col,row);
1291     return kFALSE;
1292   }
1293   if (IsSilentChip(eq,hs,chip)) return kTRUE;
1294   else return IsPixelDead(eq,hs,chip,col,row);
1295 }
1296 //____________________________________________________________________________________________
1297 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
1298   // is the pixel dead?
1299   UInt_t gloChip = GetGloChip(eq,hs,chip);
1300   if (gloChip>=1200 || col>=32 || row>=256) {
1301     Error("AliITSOnlineCalibrationSPDhandler::IsPixelDead", "eq,hs,chip,col,row nrs (%d,%d,%d,%d,%d) out of bounds.",eq,hs,chip,col,row);
1302     return kFALSE;
1303   }
1304   UInt_t key = GetKey(eq,hs,chip,col,row);
1305   if (IsDeadEq(eq) || IsDeadHS(eq,hs) || IsDeadChip(eq,hs,chip)) return kTRUE;
1306   else {
1307     if ( fDeadPixelMap[gloChip]->Find(key) != NULL ) return kTRUE;
1308     else return kFALSE;
1309   }
1310 }
1311 //____________________________________________________________________________________________
1312 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
1313   // is the pixel noisy?
1314   UInt_t gloChip = GetGloChip(eq,hs,chip);
1315   if (gloChip>=1200 || col>=32 || row>=256) {
1316     Error("AliITSOnlineCalibrationSPDhandler::IsPixelNoisy", "eq,hs,chip,col,row nrs (%d,%d,%d) out of bounds.",eq,hs,chip,col,row);
1317     return kFALSE;
1318   }
1319   UInt_t key = GetKey(eq,hs,chip,col,row);
1320   if ( fNoisyPixelMap[gloChip]->Find(key) != NULL ) return kTRUE;
1321   else return kFALSE;
1322 }
1323 //____________________________________________________________________________________________
1324 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelBadM(UInt_t module, UInt_t colM, UInt_t rowM) const {
1325   // is the pixel bad (silent or noisy)?
1326   return (IsPixelSilentM(module,colM,rowM) || IsPixelNoisyM(module,colM,rowM));
1327 }
1328 //____________________________________________________________________________________________
1329 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelSilentM(UInt_t module, UInt_t colM, UInt_t rowM) const {
1330   // is the pixel silent (dead or inactive)?
1331   UInt_t eq = GetEqIdFromOffline(module);
1332   UInt_t hs = GetHSFromOffline(module);
1333   UInt_t chip = GetChipFromOffline(module,colM);
1334   UInt_t col = GetColFromOffline(module,colM);
1335   UInt_t row = GetRowFromOffline(module,rowM);
1336   return IsPixelSilent(eq,hs,chip,col,row);
1337 }
1338 //____________________________________________________________________________________________
1339 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadM(UInt_t module, UInt_t colM, UInt_t rowM) const {
1340   // is the pixel dead?
1341   UInt_t eq = GetEqIdFromOffline(module);
1342   UInt_t hs = GetHSFromOffline(module);
1343   UInt_t chip = GetChipFromOffline(module,colM);
1344   UInt_t col = GetColFromOffline(module,colM);
1345   UInt_t row = GetRowFromOffline(module,rowM);
1346   return IsPixelDead(eq,hs,chip,col,row);
1347 }
1348 //____________________________________________________________________________________________
1349 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyM(UInt_t module, UInt_t colM, UInt_t rowM) const  {
1350   // is the pixel noisy?
1351   UInt_t eq = GetEqIdFromOffline(module);
1352   UInt_t hs = GetHSFromOffline(module);
1353   UInt_t chip = GetChipFromOffline(module,colM);
1354   UInt_t col = GetColFromOffline(module,colM);
1355   UInt_t row = GetRowFromOffline(module,rowM);
1356   return IsPixelNoisy(eq,hs,chip,col,row);
1357 }
1358 //____________________________________________________________________________________________
1359 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelBadKey(Int_t key) const {
1360   // is this pixel silent (dead or inactive)?
1361   UInt_t eq = GetEqIdFromKey(key);
1362   UInt_t hs = GetHSFromKey(key);
1363   UInt_t chip = GetChipFromKey(key);
1364   UInt_t col = GetColFromKey(key);
1365   UInt_t row = GetRowFromKey(key);
1366   return IsPixelBad(eq,hs,chip,col,row);
1367 }
1368 //____________________________________________________________________________________________
1369 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelSilentKey(Int_t key) const {
1370   // is this pixel silent (dead or inactive)?
1371   UInt_t eq = GetEqIdFromKey(key);
1372   UInt_t hs = GetHSFromKey(key);
1373   UInt_t chip = GetChipFromKey(key);
1374   UInt_t col = GetColFromKey(key);
1375   UInt_t row = GetRowFromKey(key);
1376   return IsPixelSilent(eq,hs,chip,col,row);
1377 }
1378 //____________________________________________________________________________________________
1379 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadKey(Int_t key) const {
1380   // is this pixel dead?
1381   UInt_t eq = GetEqIdFromKey(key);
1382   UInt_t hs = GetHSFromKey(key);
1383   UInt_t chip = GetChipFromKey(key);
1384   UInt_t col = GetColFromKey(key);
1385   UInt_t row = GetRowFromKey(key);
1386   return IsPixelDead(eq,hs,chip,col,row);
1387 }
1388 //____________________________________________________________________________________________
1389 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyKey(Int_t key) const {
1390   // is this pixel noisy?
1391   UInt_t eq = GetEqIdFromKey(key);
1392   UInt_t hs = GetHSFromKey(key);
1393   UInt_t chip = GetChipFromKey(key);
1394   UInt_t col = GetColFromKey(key);
1395   UInt_t row = GetRowFromKey(key);
1396   return IsPixelNoisy(eq,hs,chip,col,row);
1397 }
1398 //____________________________________________________________________________________________
1399 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrBad() const {
1400   // returns the total nr of bad pixels (silent or noisy)
1401   UInt_t nrBad=0;
1402   nrBad+=GetNrSilent();
1403   UInt_t nrNoisy = GetNrNoisy();
1404   for (UInt_t i=0; i<nrNoisy; i++) {
1405     UInt_t eq   = GetNoisyEqIdAt(i);
1406     UInt_t hs   = GetNoisyHSAt(i);
1407     UInt_t chip = GetNoisyChipAt(i);
1408     UInt_t col  = GetNoisyColAt(i);
1409     UInt_t row  = GetNoisyRowAt(i);
1410     if (!IsPixelSilent(eq,hs,chip,col,row)) nrBad++;
1411   }
1412   return nrBad;
1413 }
1414 //____________________________________________________________________________________________
1415 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrSilent() const {
1416   // returns the total nr of silent pixels (dead or inactive)
1417   UInt_t nrDead = 0;
1418   for (UInt_t eq=0; eq<20; eq++) {
1419     if (IsSilentEq(eq)) {
1420       nrDead+=81920*6;
1421       continue;
1422     }
1423     for (UInt_t hs=0; hs<6; hs++) {
1424       if (IsSilentHS(eq,hs)) {
1425         nrDead+=81920;
1426         continue;
1427       }
1428       for (UInt_t chip=0; chip<10; chip++) {
1429         if (IsSilentChip(eq,hs,chip)) {
1430           nrDead+=8192;
1431           continue;
1432         }
1433         else {
1434           UInt_t gloChip = GetGloChip(eq,hs,chip);
1435           nrDead+=fNrDead[gloChip];
1436         }
1437       }
1438     }
1439   }
1440   return nrDead;
1441 }
1442 //____________________________________________________________________________________________
1443 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead() const {
1444   // returns the total nr of dead pixels
1445   UInt_t nrDead = 0;
1446   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
1447     nrDead+=fNrDead[gloChip];
1448   }
1449   return nrDead;
1450 }
1451 //____________________________________________________________________________________________
1452 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy() const {
1453   // returns the total nr of noisy pixels
1454   UInt_t nrNoisy = 0;
1455   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
1456     nrNoisy+=fNrNoisy[gloChip];
1457   }
1458   return nrNoisy;
1459 }
1460 //____________________________________________________________________________________________
1461 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt(UInt_t index) const {
1462   // get eq for the dead pixel at position index in list of dead
1463   UInt_t gloChip;
1464   UInt_t chipIndex;
1465   GetChipAndIndexTotDead(index,gloChip,chipIndex);
1466   return GetDeadEqIdAtC2(gloChip,chipIndex);
1467 }
1468 //____________________________________________________________________________________________
1469 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt(UInt_t index) const {
1470   // get eq for the noisy pixel at position index in list of noisy
1471   UInt_t gloChip;
1472   UInt_t chipIndex;
1473   GetChipAndIndexTotNoisy(index,gloChip,chipIndex);
1474   return GetNoisyEqIdAtC2(gloChip,chipIndex);
1475 }
1476 //____________________________________________________________________________________________
1477 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAt(UInt_t index) const {
1478   // get hs for the dead pixel at position index in list of dead
1479   UInt_t gloChip;
1480   UInt_t chipIndex;
1481   GetChipAndIndexTotDead(index,gloChip,chipIndex);
1482   return GetDeadHSAtC2(gloChip,chipIndex);
1483 }
1484 //____________________________________________________________________________________________
1485 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt(UInt_t index) const {
1486   // get hs for the noisy pixel at position index in list of noisy
1487   UInt_t gloChip;
1488   UInt_t chipIndex;
1489   GetChipAndIndexTotNoisy(index,gloChip,chipIndex);
1490   return GetNoisyHSAtC2(gloChip,chipIndex);
1491 }
1492 //____________________________________________________________________________________________
1493 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAt(UInt_t index) const {
1494   // get chip for the dead pixel at position index in list of dead
1495   UInt_t gloChip;
1496   UInt_t chipIndex;
1497   GetChipAndIndexTotDead(index,gloChip,chipIndex);
1498   return GetDeadChipAtC2(gloChip,chipIndex);
1499 }
1500 //____________________________________________________________________________________________
1501 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt(UInt_t index) const {
1502   // get chip for the noisy pixel at position index in list of noisy
1503   UInt_t gloChip;
1504   UInt_t chipIndex;
1505   GetChipAndIndexTotNoisy(index,gloChip,chipIndex);
1506   return GetNoisyChipAtC2(gloChip,chipIndex);
1507 }
1508 //____________________________________________________________________________________________
1509 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t index) const {
1510   // get hs for the dead pixel at position index in list of dead
1511   UInt_t gloChip;
1512   UInt_t chipIndex;
1513   GetChipAndIndexTotDead(index,gloChip,chipIndex);
1514   return GetDeadColAtC2(gloChip,chipIndex);
1515 }
1516 //____________________________________________________________________________________________
1517 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t index) const {
1518   // get hs for the noisy pixel at position index in list of noisy
1519   UInt_t gloChip;
1520   UInt_t chipIndex;
1521   GetChipAndIndexTotNoisy(index,gloChip,chipIndex);
1522   return GetNoisyColAtC2(gloChip,chipIndex);
1523 }
1524 //____________________________________________________________________________________________
1525 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t index) const {
1526   // get hs for the dead pixel at position index in list of dead
1527   UInt_t gloChip;
1528   UInt_t chipIndex;
1529   GetChipAndIndexTotDead(index,gloChip,chipIndex);
1530   return GetDeadRowAtC2(gloChip,chipIndex);
1531 }
1532 //____________________________________________________________________________________________
1533 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t index) const {
1534   // get hs for the noisy pixel at position index in list of noisy
1535   UInt_t gloChip;
1536   UInt_t chipIndex;
1537   GetChipAndIndexTotNoisy(index,gloChip,chipIndex);
1538   return GetNoisyRowAtC2(gloChip,chipIndex);
1539 }
1540 //____________________________________________________________________________________________
1541 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrBad(UInt_t module) const {
1542   // returns the number of bad pixels for a certain module (silent or noisy)
1543   UInt_t nrBad = 0;
1544   nrBad+=GetNrSilent(module);
1545   UInt_t nrNoisy = GetNrNoisy(module);
1546   for (UInt_t i=0; i<nrNoisy; i++) {
1547     UInt_t eq   = GetNoisyEqIdAt(module,i);
1548     UInt_t hs   = GetNoisyHSAt(module,i);
1549     UInt_t chip = GetNoisyChipAt(module,i);
1550     UInt_t col  = GetNoisyColAt(module,i);
1551     UInt_t row  = GetNoisyRowAt(module,i);
1552     if (!IsPixelSilent(eq,hs,chip,col,row)) nrBad++;
1553   }
1554   return nrBad;
1555 }
1556 //____________________________________________________________________________________________
1557 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrSilent(UInt_t module) const {
1558   // returns the number of silent pixels for a certain module (dead or inactive)
1559   if (module>=240) {
1560     Error("AliITSOnlineCalibrationSPDhandler::GetNrSilent", "module nr (%d) out of bounds.",module);
1561     return 0;
1562   }
1563   UInt_t nrSilent = 0;
1564   UInt_t eq = GetEqIdFromOffline(module);
1565   if (IsSilentEq(eq)) return 160*256;
1566   UInt_t hs = GetHSFromOffline(module);
1567   if (IsSilentHS(eq,hs)) return 160*256;
1568   for (UInt_t ch=0; ch<5; ch++) {
1569     UInt_t chip = GetChipFromOffline(module,ch*32);
1570     if (IsSilentChip(eq,hs,chip)) {
1571       nrSilent+=8192;
1572     }
1573     else {
1574       UInt_t gloChip = GetGloChip(eq,hs,chip);
1575       nrSilent+=fNrDead[gloChip];
1576     }
1577   }
1578   return nrSilent;
1579 }
1580 //____________________________________________________________________________________________
1581 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadSingle(UInt_t module) const {
1582   // returns the number of single dead pixels (excluding the ones on silent chips) for a certain module
1583   if (module>=240) {
1584     Error("AliITSOnlineCalibrationSPDhandler::GetNrDeadSingle", "module nr (%d) out of bounds.",module);
1585     return 0;
1586   }
1587   UInt_t nrDead = 0;
1588   UInt_t eq = GetEqIdFromOffline(module);
1589   UInt_t hs = GetHSFromOffline(module);
1590   for (UInt_t ch=0; ch<5; ch++) {
1591     UInt_t chip = GetChipFromOffline(module,ch*32);
1592     if (!IsSilentChip(eq,hs,chip)) {
1593       UInt_t gloChip = GetGloChip(eq,hs,chip);
1594       nrDead+=fNrDead[gloChip];
1595     }
1596   }
1597   return nrDead;
1598 }
1599 //____________________________________________________________________________________________
1600 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisySingle(UInt_t module) const {
1601   // returns the number of noisy pixels for a certain module
1602   return GetNrNoisy(module);
1603 }
1604 //____________________________________________________________________________________________
1605 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead(UInt_t module) const {
1606   // returns the number of dead pixels for a certain module
1607   if (module>=240) {
1608     Error("AliITSOnlineCalibrationSPDhandler::GetNrDead", "module nr (%d) out of bounds.",module);
1609     return 0;
1610   }
1611   UInt_t nrDead = 0;
1612   UInt_t eq = GetEqIdFromOffline(module);
1613   UInt_t hs = GetHSFromOffline(module);
1614   for (UInt_t ch=0; ch<5; ch++) {
1615     UInt_t gloChip = GetGloChip(eq,hs,GetChipFromOffline(module,ch*32));
1616     nrDead+=fNrDead[gloChip];
1617   }
1618   return nrDead;
1619 }
1620 //____________________________________________________________________________________________
1621 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy(UInt_t module) const {
1622   // returns the number of noisy pixels for a certain module
1623   if (module>=240) {
1624     Error("AliITSOnlineCalibrationSPDhandler::GetNrNoisy", "module nr (%d) out of bounds.",module);
1625     return 0;
1626   }
1627   UInt_t nrNoisy = 0;
1628   UInt_t eq = GetEqIdFromOffline(module);
1629   UInt_t hs = GetHSFromOffline(module);
1630   for (UInt_t ch=0; ch<5; ch++) {
1631     UInt_t gloChip = GetGloChip(eq,hs,GetChipFromOffline(module,ch*32));
1632     nrNoisy+=fNrNoisy[gloChip];
1633   }
1634   return nrNoisy;
1635 }
1636 //____________________________________________________________________________________________
1637 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt(UInt_t module, UInt_t index) const {
1638   // get eq for the dead pixel at position index in list of dead
1639   UInt_t gloChip;
1640   UInt_t chipIndex;
1641   GetChipAndIndexDead(module,index,gloChip,chipIndex);
1642   return GetDeadEqIdAtC2(gloChip,chipIndex);
1643 }
1644 //____________________________________________________________________________________________
1645 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt(UInt_t module, UInt_t index) const {
1646   // get eq for the noisy pixel at position index in list of noisy
1647   UInt_t gloChip;
1648   UInt_t chipIndex;
1649   GetChipAndIndexNoisy(module,index,gloChip,chipIndex);
1650   return GetNoisyEqIdAtC2(gloChip,chipIndex);
1651 }
1652 //____________________________________________________________________________________________
1653 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAt(UInt_t module, UInt_t index) const {
1654   // get hs for the dead pixel at position index in list of dead
1655   UInt_t gloChip;
1656   UInt_t chipIndex;
1657   GetChipAndIndexDead(module,index,gloChip,chipIndex);
1658   return GetDeadHSAtC2(gloChip,chipIndex);
1659 }
1660 //____________________________________________________________________________________________
1661 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt(UInt_t module, UInt_t index) const {
1662   // get hs for the noisy pixel at position index in list of noisy
1663   UInt_t gloChip;
1664   UInt_t chipIndex;
1665   GetChipAndIndexNoisy(module,index,gloChip,chipIndex);
1666   return GetNoisyHSAtC2(gloChip,chipIndex);
1667 }
1668 //____________________________________________________________________________________________
1669 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAt(UInt_t module, UInt_t index) const {
1670   // get chip for the dead pixel at position index in list of dead
1671   UInt_t gloChip;
1672   UInt_t chipIndex;
1673   GetChipAndIndexDead(module,index,gloChip,chipIndex);
1674   return GetDeadChipAtC2(gloChip,chipIndex);
1675 }
1676 //____________________________________________________________________________________________
1677 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt(UInt_t module, UInt_t index) const {
1678   // get chip for the noisy pixel at position index in list of noisy
1679   UInt_t gloChip;
1680   UInt_t chipIndex;
1681   GetChipAndIndexNoisy(module,index,gloChip,chipIndex);
1682   return GetNoisyChipAtC2(gloChip,chipIndex);
1683 }
1684 //____________________________________________________________________________________________
1685 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t module, UInt_t index) const {
1686   // get hs for the dead pixel at position index in list of dead
1687   UInt_t gloChip;
1688   UInt_t chipIndex;
1689   GetChipAndIndexDead(module,index,gloChip,chipIndex);
1690   return GetDeadColAtC2(gloChip,chipIndex);
1691 }
1692 //____________________________________________________________________________________________
1693 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t module, UInt_t index) const {
1694   // get hs for the noisy pixel at position index in list of noisy
1695   UInt_t gloChip;
1696   UInt_t chipIndex;
1697   GetChipAndIndexNoisy(module,index,gloChip,chipIndex);
1698   return GetNoisyColAtC2(gloChip,chipIndex);
1699 }
1700 //____________________________________________________________________________________________
1701 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t module, UInt_t index) const {
1702   // get hs for the dead pixel at position index in list of dead
1703   UInt_t gloChip;
1704   UInt_t chipIndex;
1705   GetChipAndIndexDead(module,index,gloChip,chipIndex);
1706   return GetDeadRowAtC2(gloChip,chipIndex);
1707 }
1708 //____________________________________________________________________________________________
1709 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t module, UInt_t index) const {
1710   // get hs for the noisy pixel at position index in list of noisy
1711   UInt_t gloChip;
1712   UInt_t chipIndex;
1713   GetChipAndIndexNoisy(module,index,gloChip,chipIndex);
1714   return GetNoisyRowAtC2(gloChip,chipIndex);
1715 }
1716 //____________________________________________________________________________________________
1717 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrBadEq(UInt_t eq) const {
1718   // returns nr of bad for eq (silent or noisy)
1719   UInt_t nrBad = 0;
1720   nrBad+=GetNrSilentEq(eq);
1721   UInt_t nrNoisy = GetNrNoisy(eq);
1722   for (UInt_t i=0; i<nrNoisy; i++) {
1723     UInt_t hs   = GetNoisyHSAtEq(eq,i);
1724     UInt_t chip = GetNoisyChipAtEq(eq,i);
1725     UInt_t col  = GetNoisyColAtEq(eq,i);
1726     UInt_t row  = GetNoisyRowAtEq(eq,i);
1727     if (!IsPixelSilent(eq,hs,chip,col,row)) nrBad++;
1728   }
1729   return nrBad;
1730 }
1731 //____________________________________________________________________________________________
1732 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrSilentEq(UInt_t eq) const {
1733   // returns nr of silent for eq (dead or inactive)
1734   UInt_t returnval=0;
1735   if (IsSilentEq(eq)) return 81920*6;
1736   for (UInt_t hs=0; hs<6; hs++) {
1737     if (IsSilentHS(eq,hs)) {
1738       returnval+=81920;
1739       continue;
1740     }
1741     for (UInt_t chip=0; chip<10; chip++) {
1742       if (IsSilentChip(eq,hs,chip)) {
1743         returnval+=8192;
1744         continue;
1745       }
1746       else { 
1747         returnval+=GetNrDeadC(eq,hs,chip);
1748       }
1749     }
1750   }
1751   return returnval;
1752 }
1753 //____________________________________________________________________________________________
1754 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadEq(UInt_t eq) const {
1755   // returns nr of dead for eq
1756   UInt_t returnval=0;
1757   for (UInt_t hs=0; hs<6; hs++) {
1758     for (UInt_t chip=0; chip<10; chip++) {
1759       returnval+=GetNrDeadC(eq,hs,chip);
1760     }
1761   }
1762   return returnval;
1763 }
1764 //____________________________________________________________________________________________
1765 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyEq(UInt_t eq) const {
1766   // returns nr of noisy for eq
1767   UInt_t returnval=0;
1768   for (UInt_t hs=0; hs<6; hs++) {
1769     for (UInt_t chip=0; chip<10; chip++) {
1770       returnval+=GetNrNoisyC(eq,hs,chip);
1771     }
1772   }
1773   return returnval;
1774 }
1775 //____________________________________________________________________________________________
1776 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAtEq(UInt_t eq, UInt_t index) const {
1777   // get eq for the dead pixel at position index in list of dead
1778   if (eq<20 && index<GetNrDeadEq(eq)) {
1779     return eq;
1780   }
1781   else {
1782     return 20;
1783   }
1784 }
1785 //____________________________________________________________________________________________
1786 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAtEq(UInt_t eq, UInt_t index) const {
1787   // get eq for the noisy pixel at position index in list of noisy
1788   if (eq<20 && index<GetNrNoisyEq(eq)) {
1789     return eq;
1790   }
1791   else {
1792     return 20;
1793   }
1794 }
1795 //____________________________________________________________________________________________
1796 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAtEq(UInt_t eq, UInt_t index) const {
1797   // get hs for the dead pixel at position index in list of dead
1798   UInt_t gloChip;
1799   UInt_t chipIndex;
1800   GetChipAndIndexEqDead(eq,index,gloChip,chipIndex);
1801   return GetDeadHSAtC2(gloChip,chipIndex);
1802 }
1803 //____________________________________________________________________________________________
1804 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAtEq(UInt_t eq, UInt_t index) const {
1805   // get hs for the noisy pixel at position index in list of noisy
1806   UInt_t gloChip;
1807   UInt_t chipIndex;
1808   GetChipAndIndexEqNoisy(eq,index,gloChip,chipIndex);
1809   return GetNoisyHSAtC2(gloChip,chipIndex);
1810 }
1811 //____________________________________________________________________________________________
1812 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAtEq(UInt_t eq, UInt_t index) const {
1813   // get chip for the dead pixel at position index in list of dead
1814   UInt_t gloChip;
1815   UInt_t chipIndex;
1816   GetChipAndIndexEqDead(eq,index,gloChip,chipIndex);
1817   return GetDeadChipAtC2(gloChip,chipIndex);
1818 }
1819 //____________________________________________________________________________________________
1820 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAtEq(UInt_t eq, UInt_t index) const {
1821   // get chip for the noisy pixel at position index in list of noisy
1822   UInt_t gloChip;
1823   UInt_t chipIndex;
1824   GetChipAndIndexEqNoisy(eq,index,gloChip,chipIndex);
1825   return GetNoisyChipAtC2(gloChip,chipIndex);
1826 }
1827 //____________________________________________________________________________________________
1828 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAtEq(UInt_t eq, UInt_t index) const {
1829   // get hs for the dead pixel at position index in list of dead
1830   UInt_t gloChip;
1831   UInt_t chipIndex;
1832   GetChipAndIndexEqDead(eq,index,gloChip,chipIndex);
1833   return GetDeadColAtC2(gloChip,chipIndex);
1834 }
1835 //____________________________________________________________________________________________
1836 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAtEq(UInt_t eq, UInt_t index) const {
1837   // get hs for the noisy pixel at position index in list of noisy
1838   UInt_t gloChip;
1839   UInt_t chipIndex;
1840   GetChipAndIndexEqNoisy(eq,index,gloChip,chipIndex);
1841   return GetNoisyColAtC2(gloChip,chipIndex);
1842 }
1843 //____________________________________________________________________________________________
1844 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAtEq(UInt_t eq, UInt_t index) const {
1845   // get hs for the dead pixel at position index in list of dead
1846   UInt_t gloChip;
1847   UInt_t chipIndex;
1848   GetChipAndIndexEqDead(eq,index,gloChip,chipIndex);
1849   return GetDeadRowAtC2(gloChip,chipIndex);
1850 }
1851 //____________________________________________________________________________________________
1852 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAtEq(UInt_t eq, UInt_t index) const {
1853   // get hs for the noisy pixel at position index in list of noisy
1854   UInt_t gloChip;
1855   UInt_t chipIndex;
1856   GetChipAndIndexEqNoisy(eq,index,gloChip,chipIndex);
1857   return GetNoisyRowAtC2(gloChip,chipIndex);
1858 }
1859 //____________________________________________________________________________________________
1860 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrBadC(UInt_t eq, UInt_t hs, UInt_t chip) const {
1861   // returns nr of bad for chip (silent or noisy)
1862   UInt_t nrBad = 0;
1863   nrBad+=GetNrSilentC(eq,hs,chip);
1864   UInt_t nrNoisy = GetNrNoisyC(eq,hs,chip);
1865   for (UInt_t i=0; i<nrNoisy; i++) {
1866     UInt_t col  = GetNoisyColAtC(eq,hs,chip,i);
1867     UInt_t row  = GetNoisyRowAtC(eq,hs,chip,i);
1868     if (!IsPixelSilent(eq,hs,chip,col,row)) nrBad++;
1869   }
1870   return nrBad;
1871 }
1872 //____________________________________________________________________________________________
1873 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrSilentC(UInt_t eq, UInt_t hs, UInt_t chip) const {
1874   // returns nr of silent for chip (dead or inactive)
1875   if (IsSilentChip(eq,hs,chip)) return 8192;
1876   else return GetNrDeadC(eq,hs,chip);
1877 }
1878 //____________________________________________________________________________________________
1879 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadC(UInt_t eq, UInt_t hs, UInt_t chip) const {
1880   // returns nr of dead for chip
1881   UInt_t gloChip = GetGloChip(eq,hs,chip);
1882   return GetNrDeadC2(gloChip);
1883 }
1884 //____________________________________________________________________________________________
1885 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyC(UInt_t eq, UInt_t hs, UInt_t chip) const {
1886   // returns nr of noisy for chip
1887   UInt_t gloChip = GetGloChip(eq,hs,chip);
1888   return GetNrNoisyC2(gloChip);
1889 }
1890 //____________________________________________________________________________________________
1891 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1892   UInt_t gloChip = GetGloChip(eq,hs,chip);
1893   return GetDeadEqIdAtC2(gloChip,index);
1894 }
1895 //____________________________________________________________________________________________
1896 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1897   UInt_t gloChip = GetGloChip(eq,hs,chip);
1898   return GetNoisyEqIdAtC2(gloChip,index);
1899 }
1900 //____________________________________________________________________________________________
1901 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1902   UInt_t gloChip = GetGloChip(eq,hs,chip);
1903   return GetDeadHSAtC2(gloChip,index);
1904 }
1905 //____________________________________________________________________________________________
1906 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1907   UInt_t gloChip = GetGloChip(eq,hs,chip);
1908   return GetNoisyHSAtC2(gloChip,index);
1909 }
1910 //____________________________________________________________________________________________
1911 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1912   UInt_t gloChip = GetGloChip(eq,hs,chip);
1913   return GetDeadChipAtC2(gloChip,index);
1914 }
1915 //____________________________________________________________________________________________
1916 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1917   UInt_t gloChip = GetGloChip(eq,hs,chip);
1918   return GetNoisyChipAtC2(gloChip,index);
1919 }
1920 //____________________________________________________________________________________________
1921 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1922   UInt_t gloChip = GetGloChip(eq,hs,chip);
1923   return GetDeadColAtC2(gloChip,index);
1924 }
1925 //____________________________________________________________________________________________
1926 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1927   UInt_t gloChip = GetGloChip(eq,hs,chip);
1928   return GetNoisyColAtC2(gloChip,index);
1929 }
1930 //____________________________________________________________________________________________
1931 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1932   UInt_t gloChip = GetGloChip(eq,hs,chip);
1933   return GetDeadRowAtC2(gloChip,index);
1934 }
1935 //____________________________________________________________________________________________
1936 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1937   UInt_t gloChip = GetGloChip(eq,hs,chip);
1938   return GetNoisyRowAtC2(gloChip,index);
1939 }
1940 //____________________________________________________________________________________________
1941 const Char_t* AliITSOnlineCalibrationSPDhandler::GetDeadPixelAsTextC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1942   // get a string of dead pixel info
1943   TString returnMess = "";
1944   UInt_t gloChip = GetGloChip(eq,hs,chip);
1945   if (gloChip>=1200) {
1946     Error("AliITSOnlineCalibrationSPDhandler::GetDeadPixelAsTextC", "global chip nr (%d) out of bounds.",gloChip);
1947     return returnMess.Data();
1948   }
1949   if (index<fNrDead[gloChip]) {
1950     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
1951     UInt_t col = GetColFromKey(key);
1952     UInt_t row = GetRowFromKey(key);
1953     UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1954     UInt_t colM = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,col);
1955     UInt_t rowM = AliITSRawStreamSPD::GetOfflineRowFromOnline(eq,hs,chip,row);
1956     returnMess = Form("%*d,%*d,%*d,%*d,%*d  |  %*d,%*d,%*d",2,eq,1,hs,1,chip,2,col,3,row,3,module,3,colM,3,rowM);
1957     return returnMess.Data();
1958   }
1959   else {
1960     Error("AliITSOnlineCalibrationSPDhandler::GetDeadPixelAsTextC", "Index %d out of bounds.", index);
1961     return returnMess.Data();
1962   }
1963 }
1964 //____________________________________________________________________________________________
1965 const Char_t* AliITSOnlineCalibrationSPDhandler::GetNoisyPixelAsTextC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const {
1966   // get a string of noisy pixel info
1967   TString returnMess = "";
1968   UInt_t gloChip = GetGloChip(eq,hs,chip);
1969   if (gloChip>=1200) {
1970     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyPixelAsTextC", "global chip nr (%d) out of bounds.",gloChip);
1971     return returnMess.Data();
1972   }
1973   if (index<fNrNoisy[gloChip]) {
1974     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
1975     UInt_t col = GetColFromKey(key);
1976     UInt_t row = GetRowFromKey(key);    
1977     UInt_t module = AliITSRawStreamSPD::GetOfflineModuleFromOnline(eq,hs,chip);
1978     UInt_t colM = AliITSRawStreamSPD::GetOfflineColFromOnline(eq,hs,chip,col);
1979     UInt_t rowM = AliITSRawStreamSPD::GetOfflineRowFromOnline(eq,hs,chip,row);
1980     returnMess = Form("%*d,%*d,%*d,%*d,%*d  |  %*d,%*d,%*d",2,eq,1,hs,1,chip,2,col,3,row,3,module,3,colM,3,rowM);
1981     return returnMess.Data();
1982   }
1983   else {
1984     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyPixelAsTextC", "Index %d out of bounds.", index);
1985     return returnMess.Data();
1986   }
1987 }
1988 //____________________________________________________________________________________________
1989 UInt_t AliITSOnlineCalibrationSPDhandler::AddSilentFrom(AliITSOnlineCalibrationSPDhandler* other) {
1990   // returns number of new silent pixels in this' list (dead or inactive)
1991   UInt_t tmpdead = GetNrSilent();
1992
1993   for (UInt_t eq=0; eq<20; eq++) {
1994     if (!(other->IsActiveEq(eq))) ActivateEq(eq,kFALSE);
1995     if (other->IsDeadEq(eq))      SetDeadEq(eq,kTRUE);
1996     for (UInt_t hs=0; hs<6; hs++) {
1997       if (!(other->IsActiveHS(eq,hs))) ActivateHS(eq,hs,kFALSE);
1998       if (other->IsDeadHS(eq,hs))      SetDeadHS(eq,hs,kTRUE);
1999       for (UInt_t chip=0; chip<10; chip++) {
2000         if (!(other->IsActiveChip(eq,hs,chip))) ActivateChip(eq,hs,chip,kFALSE);
2001         if (other->IsDeadChip(eq,hs,chip))      SetDeadChip(eq,hs,chip,kTRUE);
2002       }
2003     }
2004   }
2005
2006   AddDeadFrom(other);
2007
2008   return GetNrSilent() - tmpdead;
2009 }
2010 //____________________________________________________________________________________________
2011 UInt_t AliITSOnlineCalibrationSPDhandler::AddDeadFrom(AliITSOnlineCalibrationSPDhandler* other) {
2012   // returns number of new dead pixels in this' list
2013   UInt_t returnval=0;
2014   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2015     for (UInt_t ind1=0; ind1<other->fNrDead[gloChip]; ind1++) {
2016       UInt_t eq = other->GetDeadEqIdAtC2(gloChip,ind1);
2017       UInt_t hs   = other->GetDeadHSAtC2(gloChip,ind1);
2018       UInt_t chip = other->GetDeadChipAtC2(gloChip,ind1);
2019       UInt_t col  = other->GetDeadColAtC2(gloChip,ind1);
2020       UInt_t row  = other->GetDeadRowAtC2(gloChip,ind1);
2021       if (SetDeadPixel(eq,hs,chip,col,row)) {
2022         returnval++;
2023       }
2024     }
2025   }
2026   return returnval;
2027 }
2028 //____________________________________________________________________________________________
2029 UInt_t AliITSOnlineCalibrationSPDhandler::AddNoisyFrom(AliITSOnlineCalibrationSPDhandler* other) {
2030   // returns number of new noisy pixels in this' list
2031   UInt_t returnval=0;
2032   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2033     for (UInt_t ind1=0; ind1<other->fNrNoisy[gloChip]; ind1++) {
2034       UInt_t eq = other->GetNoisyEqIdAtC2(gloChip,ind1);
2035       UInt_t hs   = other->GetNoisyHSAtC2(gloChip,ind1);
2036       UInt_t chip = other->GetNoisyChipAtC2(gloChip,ind1);
2037       UInt_t col  = other->GetNoisyColAtC2(gloChip,ind1);
2038       UInt_t row  = other->GetNoisyRowAtC2(gloChip,ind1);
2039       if (SetNoisyPixel(eq,hs,chip,col,row)) {
2040         returnval++;
2041       }
2042     }
2043   }
2044   return returnval;
2045 }
2046 //____________________________________________________________________________________________
2047 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2048   // returns nr of dead/noisy in this' lists and not in other's lists (including inactive)
2049   return GetNrSilentDiff(other) + GetNrNoisyDiff(other);
2050 }
2051 //____________________________________________________________________________________________
2052 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrSilentDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2053   // returns nr of single silent pixels in this' lists and not in other's lists (dead or inactive)
2054   UInt_t returnval=0;
2055   for (UInt_t eq=0; eq<20; eq++) {
2056     for (UInt_t hs=0; hs<6; hs++) {
2057       for (UInt_t chip=0; chip<10; chip++) {
2058         if (!IsActiveEq(eq) || IsDeadEq(eq) || !IsActiveHS(eq,hs) || IsDeadHS(eq,hs) || !IsActiveChip(eq,hs,chip) || IsDeadChip(eq,hs,chip)) {
2059           if (other->IsActiveEq(eq) && !other->IsDeadEq(eq) && other->IsActiveHS(eq,hs) && !other->IsDeadHS(eq,hs) && other->IsActiveChip(eq,hs,chip) && !other->IsDeadChip(eq,hs,chip)) {
2060             // if this is inactive and the other is active...
2061             returnval+= 8192 - other->GetNrDeadC(eq,hs,chip);
2062           }
2063         }
2064         else {
2065           UInt_t gloChip = GetGloChip(eq,hs,chip);
2066           for (UInt_t ind1=0; ind1<fNrDead[gloChip]; ind1++) {
2067             Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(ind1);
2068             UInt_t col = GetColFromKey(key);
2069             UInt_t row = GetRowFromKey(key);
2070             if (!(other->IsPixelSilent(eq,hs,chip,col,row))) {
2071               returnval++;
2072             }
2073           }
2074         }
2075       }
2076     }
2077   }
2078   return returnval;
2079 }
2080 //____________________________________________________________________________________________
2081 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2082   // returns nr of dead in this' lists and not in other's lists
2083   UInt_t returnval=0;
2084   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2085     for (UInt_t ind1=0; ind1<fNrDead[gloChip]; ind1++) {
2086       Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(ind1);
2087       UInt_t eq = GetEqIdFromKey(key);
2088       UInt_t hs = GetHSFromKey(key);
2089       UInt_t chip = GetChipFromKey(key);
2090       UInt_t col = GetColFromKey(key);
2091       UInt_t row = GetRowFromKey(key);
2092       if (!(other->IsPixelDead(eq,hs,chip,col,row))) {
2093         returnval++;
2094       }
2095     }
2096   }
2097   return returnval;
2098 }
2099 //____________________________________________________________________________________________
2100 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2101   // returns nr of noisy in this' lists and not in other's lists
2102   UInt_t returnval=0;
2103   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2104     for (UInt_t ind1=0; ind1<fNrNoisy[gloChip]; ind1++) {
2105       Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(ind1);
2106       UInt_t eq = GetEqIdFromKey(key);
2107       UInt_t hs = GetHSFromKey(key);
2108       UInt_t chip = GetChipFromKey(key);
2109       UInt_t col = GetColFromKey(key);
2110       UInt_t row = GetRowFromKey(key);
2111       if (!(other->IsPixelNoisy(eq,hs,chip,col,row))) {
2112         returnval++;
2113       }
2114     }
2115   }
2116   return returnval;
2117 }
2118 //____________________________________________________________________________________________
2119 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2120   // returns handler with active/dead/noisy in this' lists, removing those that are in other's lists
2121   AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
2122
2123   for (UInt_t eq=0; eq<20; eq++) {
2124     if (!(IsActiveEq(eq))) {
2125       newHandler->ActivateEq(eq,kFALSE);
2126       if (!other->IsActiveEq(eq)) newHandler->ActivateEq(eq);
2127     }
2128     if (IsDeadEq(eq)) {
2129       newHandler->SetDeadEq(eq);
2130       if (other->IsDeadEq(eq)) newHandler->SetDeadEq(eq,kFALSE);
2131     }
2132     for (UInt_t hs=0; hs<6; hs++) {
2133       if (!(IsActiveHS(eq,hs))) {
2134         newHandler->ActivateHS(eq,hs,kFALSE);
2135         if (!other->IsActiveHS(eq,hs)) newHandler->ActivateHS(eq,hs);
2136       }
2137       if (IsDeadHS(eq,hs)) {
2138         newHandler->SetDeadHS(eq,hs);
2139         if (other->IsDeadHS(eq,hs)) newHandler->SetDeadHS(eq,hs,kFALSE);
2140       }
2141       for (UInt_t chip=0; chip<10; chip++) {
2142         if (!(IsActiveChip(eq,hs,chip))) {
2143           newHandler->ActivateChip(eq,hs,chip,kFALSE);
2144           if (!other->IsActiveChip(eq,hs,chip)) newHandler->ActivateHS(eq,hs,chip);
2145         }
2146         if (IsDeadChip(eq,hs,chip)) {
2147           newHandler->SetDeadChip(eq,hs,chip);
2148           if (other->IsDeadChip(eq,hs,chip)) newHandler->SetDeadChip(eq,hs,chip,kFALSE);
2149         }
2150       }
2151     }
2152   }
2153
2154   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2155     for (UInt_t ind1=0; ind1<fNrDead[gloChip]; ind1++) {
2156       Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(ind1);
2157       UInt_t eq = GetEqIdFromKey(key);
2158       UInt_t hs = GetHSFromKey(key);
2159       UInt_t chip = GetChipFromKey(key);
2160       UInt_t col = GetColFromKey(key);
2161       UInt_t row = GetRowFromKey(key);
2162       if (!(other->IsPixelDead(eq,hs,chip,col,row))) {
2163         newHandler->SetDeadPixel(eq,hs,chip,col,row);
2164       }
2165     }
2166   }
2167
2168   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2169     for (UInt_t ind2=0; ind2<fNrNoisy[gloChip]; ind2++) {
2170       Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(ind2);
2171       UInt_t eq = GetEqIdFromKey(key);
2172       UInt_t hs = GetHSFromKey(key);
2173       UInt_t chip = GetChipFromKey(key);
2174       UInt_t col = GetColFromKey(key);
2175       UInt_t row = GetRowFromKey(key);
2176       if (!(other->IsPixelNoisy(eq,hs,chip,col,row))) {
2177         newHandler->SetNoisyPixel(eq,hs,chip,col,row);
2178       }
2179     }
2180   }
2181
2182   return newHandler;
2183 }
2184 //____________________________________________________________________________________________
2185 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetSilentDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2186   // returns handler with active/dead in this' lists, removing those that are in other's lists
2187   AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
2188
2189   for (UInt_t eq=0; eq<20; eq++) {
2190     if (!(IsActiveEq(eq))) {
2191       newHandler->ActivateEq(eq,kFALSE);
2192       if (!other->IsActiveEq(eq)) newHandler->ActivateEq(eq);
2193     }
2194     if (IsDeadEq(eq)) {
2195       newHandler->SetDeadEq(eq);
2196       if (other->IsDeadEq(eq)) newHandler->SetDeadEq(eq,kFALSE);
2197     }
2198     for (UInt_t hs=0; hs<6; hs++) {
2199       if (!(IsActiveHS(eq,hs))) {
2200         newHandler->ActivateHS(eq,hs,kFALSE);
2201         if (!other->IsActiveHS(eq,hs)) newHandler->ActivateHS(eq,hs);
2202       }
2203       if (IsDeadHS(eq,hs)) {
2204         newHandler->SetDeadHS(eq,hs);
2205         if (other->IsDeadHS(eq,hs)) newHandler->SetDeadHS(eq,hs,kFALSE);
2206       }
2207       for (UInt_t chip=0; chip<10; chip++) {
2208         if (!(IsActiveChip(eq,hs,chip))) {
2209           newHandler->ActivateChip(eq,hs,chip,kFALSE);
2210           if (!other->IsActiveChip(eq,hs,chip)) newHandler->ActivateHS(eq,hs,chip);
2211         }
2212         if (IsDeadChip(eq,hs,chip)) {
2213           newHandler->SetDeadChip(eq,hs,chip);
2214           if (other->IsDeadChip(eq,hs,chip)) newHandler->SetDeadChip(eq,hs,chip,kFALSE);
2215         }
2216       }
2217     }
2218   }
2219
2220   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2221     for (UInt_t ind1=0; ind1<fNrDead[gloChip]; ind1++) {
2222       Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(ind1);
2223       UInt_t eq = GetEqIdFromKey(key);
2224       UInt_t hs = GetHSFromKey(key);
2225       UInt_t chip = GetChipFromKey(key);
2226       UInt_t col = GetColFromKey(key);
2227       UInt_t row = GetRowFromKey(key);
2228       if (!(other->IsPixelDead(eq,hs,chip,col,row))) {
2229         newHandler->SetDeadPixel(eq,hs,chip,col,row);
2230       }
2231     }
2232   }
2233
2234   return newHandler;
2235 }
2236 //____________________________________________________________________________________________
2237 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2238   // returns handler with dead in this' lists, except for those in other's lists
2239   AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
2240   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2241     for (UInt_t ind1=0; ind1<fNrDead[gloChip]; ind1++) {
2242       Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(ind1);
2243       UInt_t eq = GetEqIdFromKey(key);
2244       UInt_t hs = GetHSFromKey(key);
2245       UInt_t chip = GetChipFromKey(key);
2246       UInt_t col = GetColFromKey(key);
2247       UInt_t row = GetRowFromKey(key);
2248       if (!(other->IsPixelDead(eq,hs,chip,col,row))) {
2249         newHandler->SetDeadPixel(eq,hs,chip,col,row);
2250       }
2251     }
2252   }
2253   return newHandler;
2254 }
2255 //____________________________________________________________________________________________
2256 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
2257   // returns handler with noisy in this' lists, except for those in other's lists
2258   AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
2259   for (UInt_t gloChip=0; gloChip<1200; gloChip++) {
2260     for (UInt_t ind2=0; ind2<fNrNoisy[gloChip]; ind2++) {
2261       Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(ind2);
2262       UInt_t eq = GetEqIdFromKey(key);
2263       UInt_t hs = GetHSFromKey(key);
2264       UInt_t chip = GetChipFromKey(key);
2265       UInt_t col = GetColFromKey(key);
2266       UInt_t row = GetRowFromKey(key);
2267       if (!(other->IsPixelNoisy(eq,hs,chip,col,row))) {
2268         newHandler->SetNoisyPixel(eq,hs,chip,col,row);
2269       }
2270     }
2271   }
2272   return newHandler;
2273 }
2274 //____________________________________________________________________________________________
2275 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexDead(UInt_t module, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2276   // find gloChip and chipIndex from module and index
2277   if (index<GetNrDead(module)) {
2278     UInt_t eq = GetEqIdFromOffline(module);
2279     UInt_t hs = GetHSFromOffline(module);
2280     
2281     UInt_t glVal=0;
2282     for (UInt_t ch=0; ch<5; ch++) {
2283       gloChip = GetGloChip(eq,hs,GetChipFromOffline(module,ch*32));
2284       if (glVal+fNrDead[gloChip]>index) {
2285         chipIndex = index-glVal;
2286         break;
2287       }
2288       else {
2289         glVal+=fNrDead[gloChip];
2290       }
2291     }
2292
2293   }
2294   else {
2295     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexDead", "Index %d out of bounds.", index);
2296   }
2297 }
2298 //____________________________________________________________________________________________
2299 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexNoisy(UInt_t module, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2300   // find gloChip and chipIndex from module and index
2301   if (index<GetNrNoisy(module)) {
2302     UInt_t eq = GetEqIdFromOffline(module);
2303     UInt_t hs = GetHSFromOffline(module);
2304     
2305     UInt_t glVal=0;
2306     for (UInt_t ch=0; ch<5; ch++) {
2307       gloChip = GetGloChip(eq,hs,GetChipFromOffline(module,ch*32));
2308       if (glVal+fNrNoisy[gloChip]>index) {
2309         chipIndex = index-glVal;
2310         break;
2311       }
2312       else {
2313         glVal+=fNrNoisy[gloChip];
2314       }
2315     }
2316
2317   }
2318   else {
2319     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexNoisy", "Index %d out of bounds.", index);
2320   }
2321 }
2322 //____________________________________________________________________________________________
2323 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexEqDead(UInt_t eq, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2324   // find gloChip and chipIndex from module and index
2325   if (index<GetNrDeadEq(eq)) {
2326
2327     UInt_t glVal=0;
2328     for (UInt_t hs=0; hs<6; hs++) {
2329       for (UInt_t chip=0; chip<10; chip++) {
2330         gloChip = GetGloChip(eq,hs,chip);
2331         if (glVal+fNrDead[gloChip]>index) {
2332           chipIndex = index-glVal;
2333           break;
2334         }
2335         else {
2336           glVal+=fNrDead[gloChip];
2337         }
2338       }
2339     }
2340
2341   }
2342   else {
2343     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexEqDead", "Index %d out of bounds.", index);
2344   }
2345 }
2346 //____________________________________________________________________________________________
2347 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexEqNoisy(UInt_t eq, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2348   // find gloChip and chipIndex from module and index
2349   if (index<GetNrNoisyEq(eq)) {
2350
2351     UInt_t glVal=0;
2352     for (UInt_t hs=0; hs<6; hs++) {
2353       for (UInt_t chip=0; chip<10; chip++) {
2354         gloChip = GetGloChip(eq,hs,chip);
2355         if (glVal+fNrNoisy[gloChip]>index) {
2356           chipIndex = index-glVal;
2357           break;
2358         }
2359         else {
2360           glVal+=fNrNoisy[gloChip];
2361         }
2362       }
2363     }
2364
2365   }
2366   else {
2367     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexEqNoisy", "Index %d out of bounds.", index);
2368   }
2369 }
2370 //____________________________________________________________________________________________
2371 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexTotDead(UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2372   // find gloChip and chipIndex from global index
2373   if (index<GetNrDead()) {
2374     
2375     UInt_t glVal=0;
2376     for (gloChip=0; gloChip<1200; gloChip++) {
2377       if (glVal+fNrDead[gloChip]>index) {
2378         chipIndex = index-glVal;
2379         break;
2380       }
2381       else {
2382         glVal+=fNrDead[gloChip];
2383       }
2384     }
2385
2386   }
2387   else {
2388     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexTotDead", "Index %d out of bounds.", index);
2389   }
2390 }
2391 //____________________________________________________________________________________________
2392 void AliITSOnlineCalibrationSPDhandler::GetChipAndIndexTotNoisy(UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const {
2393   // find gloChip and chipIndex from global index
2394   if (index<GetNrNoisy()) {
2395     
2396     UInt_t glVal=0;
2397     for (gloChip=0; gloChip<1200; gloChip++) {
2398       if (glVal+fNrNoisy[gloChip]>index) {
2399         chipIndex = index-glVal;
2400         break;
2401       }
2402       else {
2403         glVal+=fNrNoisy[gloChip];
2404       }
2405     }
2406
2407   }
2408   else {
2409     Error("AliITSOnlineCalibrationSPDhandler::GetChipAndIndexTotNoisy", "Index %d out of bounds.", index);
2410   }
2411 }
2412 //____________________________________________________________________________________________
2413 UInt_t AliITSOnlineCalibrationSPDhandler::GetEqIdFromOffline(UInt_t module) const {
2414   // module to eq mapping
2415   if (module>=240) {
2416     Error("AliITSOnlineCalibrationSPDhandler::GetEqIdFromOffline", "module nr (%d) out of bounds.",module);
2417     return 20;
2418   }
2419   return AliITSRawStreamSPD::GetOnlineEqIdFromOffline(module);
2420 }
2421 //____________________________________________________________________________________________
2422 UInt_t AliITSOnlineCalibrationSPDhandler::GetHSFromOffline(UInt_t module) const {
2423   // module to hs mapping
2424   if (module>=240) {
2425     Error("AliITSOnlineCalibrationSPDhandler::GetHSFromOffline", "module nr (%d) out of bounds.",module);
2426     return 6;
2427   }
2428   return AliITSRawStreamSPD::GetOnlineHSFromOffline(module);
2429 }
2430 //____________________________________________________________________________________________
2431 UInt_t AliITSOnlineCalibrationSPDhandler::GetChipFromOffline(UInt_t module, UInt_t colM) const {
2432   // module,colM to chip mapping
2433   if (module>=240 || colM>=160) {
2434     Error("AliITSOnlineCalibrationSPDhandler::GetChipFromOffline", "module,colM nrs (%d,%d) out of bounds.",module,colM);
2435     return 10;
2436   }
2437   return AliITSRawStreamSPD::GetOnlineChipFromOffline(module,colM);
2438 }
2439 //____________________________________________________________________________________________
2440 UInt_t AliITSOnlineCalibrationSPDhandler::GetColFromOffline(UInt_t module, UInt_t colM) const {
2441   // colM to col mapping
2442   if (colM>=160) {
2443     Error("AliITSOnlineCalibrationSPDhandler::GetColFromOffline", "colM nr (%d) out of bounds.",colM);
2444     return 160;
2445   }
2446   return AliITSRawStreamSPD::GetOnlineColFromOffline(module,colM);
2447 }
2448 //____________________________________________________________________________________________
2449 UInt_t AliITSOnlineCalibrationSPDhandler::GetRowFromOffline(UInt_t module, UInt_t rowM) const {
2450   // rowM to row mapping
2451   if (rowM>=256) {
2452     Error("AliITSOnlineCalibrationSPDhandler::GetRowFromOffline", "rowM nr (%d) out of bounds.",rowM);
2453     return 256;
2454   }
2455   return AliITSRawStreamSPD::GetOnlineRowFromOffline(module,rowM);
2456 }
2457 //____________________________________________________________________________________________
2458 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadC2(UInt_t gloChip) const {
2459   // returns nr of dead pixels on this chip
2460   if (gloChip>=1200) {
2461     Error("AliITSOnlineCalibrationSPDhandler::GetNrDeadC2", "global chip nr (%d) out of bounds.",gloChip);
2462     return 0;
2463   }
2464   return fNrDead[gloChip];
2465 }
2466 //____________________________________________________________________________________________
2467 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyC2(UInt_t gloChip) const {
2468   // returns nr of noisy pixels on this chip
2469   if (gloChip>=1200) {
2470     Error("AliITSOnlineCalibrationSPDhandler::GetNrNoisyC2", "global chip nr (%d) out of bounds.",gloChip);
2471     return 0;
2472   }
2473   return fNrNoisy[gloChip];
2474 }
2475 //____________________________________________________________________________________________
2476 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAtC2(UInt_t gloChip, UInt_t index) const {
2477   // get eq for the dead pixel at position index in list of dead
2478   if (gloChip>=1200) {
2479     Error("AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAtC", "global chip nr (%d) out of bounds.",gloChip);
2480     return 20;
2481   }
2482   if (index<fNrDead[gloChip]) {
2483     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
2484     return GetEqIdFromKey(key);
2485   }
2486   else {
2487     Error("AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAtC", "Index %d out of bounds.", index);
2488     return 0;
2489   }
2490 }
2491 //____________________________________________________________________________________________
2492 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAtC2(UInt_t gloChip, UInt_t index) const {
2493   // get eq for the noisy pixel at position index in list of noisy
2494   if (gloChip>=1200) {
2495     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAtC", "global chip nr (%d) out of bounds.",gloChip);
2496     return 20;
2497   }
2498   if (index<fNrNoisy[gloChip]) {
2499     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
2500     return GetEqIdFromKey(key);
2501   }
2502   else {
2503     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAtC", "Index %d out of bounds.", index);
2504     return 0;
2505   }
2506 }
2507 //____________________________________________________________________________________________
2508 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAtC2(UInt_t gloChip, UInt_t index) const {
2509   // get hs for the dead pixel at position index in list of dead
2510   if (gloChip>=1200) {
2511     Error("AliITSOnlineCalibrationSPDhandler::GetDeadHSAtC", "global chip nr (%d) out of bounds.",gloChip);
2512     return 20;
2513   }
2514   if (index<fNrDead[gloChip]) {
2515     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
2516     return GetHSFromKey(key);
2517   }
2518   else {
2519     Error("AliITSOnlineCalibrationSPDhandler::GetDeadHSAtC", "Index %d out of bounds.", index);
2520     return 0;
2521   }
2522 }
2523 //____________________________________________________________________________________________
2524 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAtC2(UInt_t gloChip, UInt_t index) const {
2525   // get hs for the noisy pixel at position index in list of noisy
2526   if (gloChip>=1200) {
2527     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyHSAtC", "global chip nr (%d) out of bounds.",gloChip);
2528     return 20;
2529   }
2530   if (index<fNrNoisy[gloChip]) {
2531     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
2532     return GetHSFromKey(key);
2533   }
2534   else {
2535     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyHSAtC", "Index %d out of bounds.", index);
2536     return 0;
2537   }
2538 }
2539 //____________________________________________________________________________________________
2540 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAtC2(UInt_t gloChip, UInt_t index) const {
2541   // get chip for the dead pixel at position index in list of dead
2542   if (gloChip>=1200) {
2543     Error("AliITSOnlineCalibrationSPDhandler::GetDeadChipAtC", "global chip nr (%d) out of bounds.",gloChip);
2544     return 20;
2545   }
2546   if (index<fNrDead[gloChip]) {
2547     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
2548     return GetChipFromKey(key);
2549   }
2550   else {
2551     Error("AliITSOnlineCalibrationSPDhandler::GetDeadChipAtC", "Index %d out of bounds.", index);
2552     return 0;
2553   }
2554 }
2555 //____________________________________________________________________________________________
2556 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAtC2(UInt_t gloChip, UInt_t index) const {
2557   // get chip for the noisy pixel at position index in list of noisy
2558   if (gloChip>=1200) {
2559     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyChipAtC", "global chip nr (%d) out of bounds.",gloChip);
2560     return 20;
2561   }
2562   if (index<fNrNoisy[gloChip]) {
2563     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
2564     return GetChipFromKey(key);
2565   }
2566   else {
2567     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyChipAtC", "Index %d out of bounds.", index);
2568     return 0;
2569   }
2570 }
2571 //____________________________________________________________________________________________
2572 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAtC2(UInt_t gloChip, UInt_t index) const {
2573   // get col for the dead pixel at position index in list of dead
2574   if (gloChip>=1200) {
2575     Error("AliITSOnlineCalibrationSPDhandler::GetDeadColAtC2", "global chip nr (%d) out of bounds.",gloChip);
2576     return 20;
2577   }
2578   if (index<fNrDead[gloChip]) {
2579     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
2580     return GetColFromKey(key);
2581   }
2582   else {
2583     Error("AliITSOnlineCalibrationSPDhandler::GetDeadColAtC2", "Index %d out of bounds.", index);
2584     return 0;
2585   }
2586 }
2587 //____________________________________________________________________________________________
2588 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAtC2(UInt_t gloChip, UInt_t index) const {
2589   // get col for the noisy pixel at position index in list of noisy
2590   if (gloChip>=1200) {
2591     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyColAtC", "global chip nr (%d) out of bounds.",gloChip);
2592     return 20;
2593   }
2594   if (index<fNrNoisy[gloChip]) {
2595     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
2596     return GetColFromKey(key);
2597   }
2598   else {
2599     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyColAtC", "Index %d out of bounds.", index);
2600     return 0;
2601   }
2602 }
2603 //____________________________________________________________________________________________
2604 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAtC2(UInt_t gloChip, UInt_t index) const {
2605   // get row for the dead pixel at position index in list of dead
2606   if (gloChip>=1200) {
2607     Error("AliITSOnlineCalibrationSPDhandler::GetDeadRowAtC", "global chip nr (%d) out of bounds.",gloChip);
2608     return 20;
2609   }
2610   if (index<fNrDead[gloChip]) {
2611     Int_t key = fDeadPixelMap[gloChip]->GetKeyIndex(index);
2612     return GetRowFromKey(key);
2613   }
2614   else {
2615     Error("AliITSOnlineCalibrationSPDhandler::GetDeadRowAtC", "Index %d out of bounds.", index);
2616     return 0;
2617   }
2618 }
2619 //____________________________________________________________________________________________
2620 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAtC2(UInt_t gloChip, UInt_t index) const {
2621   // get row for the noisy pixel at position index in list of noisy
2622   if (gloChip>=1200) {
2623     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyRowAtC", "global chip nr (%d) out of bounds.",gloChip);
2624     return 20;
2625   }
2626   if (index<fNrNoisy[gloChip]) {
2627     Int_t key = fNoisyPixelMap[gloChip]->GetKeyIndex(index);
2628     return GetRowFromKey(key);
2629   }
2630   else {
2631     Error("AliITSOnlineCalibrationSPDhandler::GetNoisyRowAtC", "Index %d out of bounds.", index);
2632     return 0;
2633   }
2634 }
2635 //____________________________________________________________________________________________
2636 void AliITSOnlineCalibrationSPDhandler::ActivateALL() {
2637   // activate all eq,hs,chips
2638   for (UInt_t eq=0; eq<20; eq++) {
2639     ActivateEq(eq);
2640     for (UInt_t hs=0; hs<6; hs++) {
2641       ActivateHS(eq,hs);
2642       for (UInt_t chip=0; chip<10; chip++) {
2643         ActivateChip(eq,hs,chip);
2644       }
2645     }
2646   }
2647 }
2648 //____________________________________________________________________________________________
2649 void AliITSOnlineCalibrationSPDhandler::ActivateEq(UInt_t eq, Bool_t setval) {
2650   // activate eq
2651   if (eq>=20) {
2652     Error("AliITSOnlineCalibrationSPDhandler::ActivateEq", "eq (%d) out of bounds.",eq);
2653     return;
2654   }
2655   fActiveEq[eq] = setval;
2656 }
2657 //____________________________________________________________________________________________
2658 void AliITSOnlineCalibrationSPDhandler::ActivateHS(UInt_t eq, UInt_t hs, Bool_t setval) {
2659   // activate hs
2660   if (eq>=20 || hs>=6) {
2661     Error("AliITSOnlineCalibrationSPDhandler::ActivateHS", "eq,hs (%d,%d) out of bounds.",eq,hs);
2662     return;
2663   }
2664   fActiveHS[eq][hs] = setval;
2665 }
2666 //____________________________________________________________________________________________
2667 void AliITSOnlineCalibrationSPDhandler::ActivateChip(UInt_t eq, UInt_t hs, UInt_t chip, Bool_t setval) {
2668   // activate chip
2669   if (eq>=20 || hs>=6 || chip>=10) {
2670     Error("AliITSOnlineCalibrationSPDhandler::ActivateChip", "eq,hs,chip (%d,%d,%d) out of bounds.",eq,hs,chip);
2671     return;
2672   }
2673   fActiveChip[eq][hs][chip] = setval;
2674 }
2675 //____________________________________________________________________________________________
2676 Bool_t AliITSOnlineCalibrationSPDhandler::IsActiveEq(UInt_t eq) const {
2677   // Is eq active?
2678   if (eq>=20) {
2679     Error("AliITSOnlineCalibrationSPDhandler::IsActiveEq", "eq (%d) out of bounds.",eq);
2680     return kFALSE;
2681   }
2682   return fActiveEq[eq];
2683 }
2684 //____________________________________________________________________________________________
2685 Bool_t AliITSOnlineCalibrationSPDhandler::IsActiveHS(UInt_t eq, UInt_t hs) const {
2686   // Is hs active?
2687   if (eq>=20 || hs>=6) {
2688     Error("AliITSOnlineCalibrationSPDhandler::IsActiveHS", "eq,hs (%d,%d) out of bounds.",eq,hs);
2689     return kFALSE;
2690   }
2691   return fActiveHS[eq][hs];
2692 }
2693 //____________________________________________________________________________________________
2694 Bool_t AliITSOnlineCalibrationSPDhandler::IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
2695   // Is chip active?
2696   if (eq>=20 || hs>=6 || chip>=10) {
2697     Error("AliITSOnlineCalibrationSPDhandler::IsActiveChip", "eq,hs,chip (%d,%d,%d) out of bounds.",eq,hs,chip);
2698     return kFALSE;
2699   }
2700   return fActiveChip[eq][hs][chip];
2701 }
2702 //____________________________________________________________________________________________
2703 void AliITSOnlineCalibrationSPDhandler::UnSetDeadALL() {
2704   // Clear all dead eq,hs,chips
2705   for (UInt_t eq=0; eq<20; eq++) {
2706     SetDeadEq(eq,kFALSE);
2707     for (UInt_t hs=0; hs<6; hs++) {
2708       SetDeadHS(eq,hs,kFALSE);
2709       for (UInt_t chip=0; chip<10; chip++) {
2710         SetDeadChip(eq,hs,chip,kFALSE);
2711       }
2712     }
2713   }
2714 }
2715 //____________________________________________________________________________________________
2716 void AliITSOnlineCalibrationSPDhandler::SetDeadEq(UInt_t eq, Bool_t setval) {
2717   // set eq dead
2718   if (eq>=20) {
2719     Error("AliITSOnlineCalibrationSPDhandler::SetDeadEq", "eq (%d) out of bounds.",eq);
2720     return;
2721   }
2722   fDeadEq[eq] = setval;
2723 }
2724 //____________________________________________________________________________________________
2725 void AliITSOnlineCalibrationSPDhandler::SetDeadHS(UInt_t eq, UInt_t hs, Bool_t setval) {
2726   // set hs dead
2727   if (eq>=20 || hs>=6) {
2728     Error("AliITSOnlineCalibrationSPDhandler::SetDeadHS", "eq,hs (%d,%d) out of bounds.",eq,hs);
2729     return;
2730   }
2731   fDeadHS[eq][hs] = setval;
2732 }
2733 //____________________________________________________________________________________________
2734 void AliITSOnlineCalibrationSPDhandler::SetDeadChip(UInt_t eq, UInt_t hs, UInt_t chip, Bool_t setval) {
2735   // set chip dead
2736   if (eq>=20 || hs>=6 || chip>=10) {
2737     Error("AliITSOnlineCalibrationSPDhandler::SetDeadChip", "eq,hs,chip (%d,%d,%d) out of bounds.",eq,hs,chip);
2738     return;
2739   }
2740   fDeadChip[eq][hs][chip] = setval;
2741 }
2742 //____________________________________________________________________________________________
2743 Bool_t AliITSOnlineCalibrationSPDhandler::IsDeadEq(UInt_t eq) const {
2744   // is eq dead?
2745   if (eq>=20) {
2746     Error("AliITSOnlineCalibrationSPDhandler::IsDeadEq", "eq (%d) out of bounds.",eq);
2747     return kFALSE;
2748   }
2749   return fDeadEq[eq];
2750 }
2751 //____________________________________________________________________________________________
2752 Bool_t AliITSOnlineCalibrationSPDhandler::IsDeadHS(UInt_t eq, UInt_t hs) const {
2753   // is hs dead?
2754   if (eq>=20 || hs>=6) {
2755     Error("AliITSOnlineCalibrationSPDhandler::IsDeadHS", "eq,hs (%d,%d) out of bounds.",eq,hs);
2756     return kFALSE;
2757   }
2758   return fDeadHS[eq][hs];
2759 }
2760 //____________________________________________________________________________________________
2761 Bool_t AliITSOnlineCalibrationSPDhandler::IsDeadChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
2762   // is chip dead?
2763   if (eq>=20 || hs>=6 || chip>=10) {
2764     Error("AliITSOnlineCalibrationSPDhandler::IsDeadChip", "eq,hs,chip (%d,%d,%d) out of bounds.",eq,hs,chip);
2765     return kFALSE;
2766   }
2767   return fDeadChip[eq][hs][chip];
2768 }
2769 //____________________________________________________________________________________________
2770 Bool_t AliITSOnlineCalibrationSPDhandler::IsSilentEq(UInt_t eq) const {
2771   // is eq silent?
2772   if (eq>=20) {
2773     Error("AliITSOnlineCalibrationSPDhandler::IsSilentEq", "eq (%d) out of bounds.",eq);
2774     return kFALSE;
2775   }
2776   return (!IsActiveEq(eq) || IsDeadEq(eq));
2777 }
2778 //____________________________________________________________________________________________
2779 Bool_t AliITSOnlineCalibrationSPDhandler::IsSilentHS(UInt_t eq, UInt_t hs) const {
2780   // is hs silent?
2781   if (eq>=20 || hs>=6) {
2782     Error("AliITSOnlineCalibrationSPDhandler::IsSilentHS", "eq,hs (%d,%d) out of bounds.",eq,hs);
2783     return kFALSE;
2784   }
2785   return (!IsActiveEq(eq) || IsDeadEq(eq) || !IsActiveHS(eq,hs) || IsDeadHS(eq,hs));
2786 }
2787 //____________________________________________________________________________________________
2788 Bool_t AliITSOnlineCalibrationSPDhandler::IsSilentChip(UInt_t eq, UInt_t hs, UInt_t chip) const {
2789   // is chip silent?
2790   if (eq>=20 || hs>=6 || chip>=10) {
2791     Error("AliITSOnlineCalibrationSPDhandler::IsSilentChip", "eq,hs,chip (%d,%d,%d) out of bounds.",eq,hs,chip);
2792     return kFALSE;
2793   }
2794   return (!IsActiveEq(eq) || IsDeadEq(eq) || !IsActiveHS(eq,hs) || IsDeadHS(eq,hs) || !IsActiveChip(eq,hs,chip) || IsDeadChip(eq,hs,chip));
2795 }