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