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