1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 //////////////////////////////////////////////////////////////////////
20 // Author: Henrik Tydesjo //
21 // For easier handling of dead and noisy pixels they are kept in //
22 // container maps (AliITSIntMap). //
23 // The TArrayI objects that are put in the AliITSCalibrationSPD //
24 // objects can be obtained from the methods GetDeadArray and //
26 //////////////////////////////////////////////////////////////////////
28 #include "AliITSOnlineCalibrationSPDhandler.h"
29 #include "AliITSOnlineCalibrationSPD.h"
30 #include "AliITSIntMap.h"
31 #include <TObjArray.h>
37 #ifndef SPD_DA_OFF // you may want to exclude cdb classes, if using this class outside aliroot
38 #include "AliITSCalibrationSPD.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBEntry.h"
43 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler():
45 fModuleMapInited(kFALSE)
48 for (UInt_t module=0; module<240; module++) {
51 fDeadPixelMap[module] = new AliITSIntMap();
52 fNoisyPixelMap[module] = new AliITSIntMap();
56 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(const AliITSOnlineCalibrationSPDhandler& handle):
58 fModuleMapInited(kFALSE)
61 for (UInt_t module=0; module<240; module++) {
62 fNrDead[module] = handle.fNrDead[module];
63 fNrNoisy[module] = handle.fNrNoisy[module];
64 fDeadPixelMap[module] = handle.fDeadPixelMap[module]->Clone();
65 fNoisyPixelMap[module] = handle.fNoisyPixelMap[module]->Clone();
67 fFileLocation = handle.fFileLocation;
70 AliITSOnlineCalibrationSPDhandler::~AliITSOnlineCalibrationSPDhandler() {
74 AliITSOnlineCalibrationSPDhandler& AliITSOnlineCalibrationSPDhandler::operator=(const AliITSOnlineCalibrationSPDhandler& handle) {
75 // assignment operator
78 for (UInt_t module=0; module<240; module++) {
79 fNrDead[module] = handle.fNrDead[module];
80 fNrNoisy[module] = handle.fNrNoisy[module];
81 fDeadPixelMap[module] = handle.fDeadPixelMap[module]->Clone();
82 fNoisyPixelMap[module] = handle.fNoisyPixelMap[module]->Clone();
84 fFileLocation = handle.fFileLocation;
89 void AliITSOnlineCalibrationSPDhandler::ClearMaps() {
90 // clear the lists of dead and noisy
95 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFiles() {
96 // read dead and noisy files from file location. returns true if at least one file found
97 Bool_t returnval=kFALSE;
98 for (UInt_t module=0; module<240; module++) {
99 if (ReadFromFile(module)) {
105 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile(UInt_t module) {
106 // read dead and noisy files for module from file location.
107 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
108 return ReadFromFileName(fileName.Data());
110 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFileName(const char *fileName) {
111 // read dead and noisy from file fileName
112 AliITSOnlineCalibrationSPD* calib;
113 FILE* fp0 = fopen(fileName, "r");
114 if (fp0 == NULL) {return kFALSE;}
117 TFile file(fileName, "READ");
119 file.GetObject("AliITSOnlineCalibrationSPD", calib);
122 UInt_t module = calib->GetModuleNr();
123 Int_t nrDead=calib->GetNrDead();
124 for (Int_t index=0; index<nrDead; index++) {
125 UInt_t colM=calib->GetDeadColAt(index);
126 UInt_t row=calib->GetDeadRowAt(index);
127 SetDeadPixelM(module,colM,row);
129 Int_t nrNoisy=calib->GetNrNoisy();
130 for (Int_t index=0; index<nrNoisy; index++) {
131 UInt_t colM=calib->GetNoisyColAt(index);
132 UInt_t row=calib->GetNoisyRowAt(index);
133 SetNoisyPixelM(module,colM,row);
140 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFiles() {
141 // read dead files from file location. returns true if at least one file found
142 Bool_t returnval=kFALSE;
143 for (UInt_t module=0; module<240; module++) {
144 if (ReadDeadFromFile(module)) {
150 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(UInt_t module) {
151 // read dead for module from file location.
152 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
153 return ReadDeadFromFileName(fileName.Data());
155 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFileName(const char *fileName) {
156 // read dead from file fileName
157 AliITSOnlineCalibrationSPD* calib;
158 FILE* fp0 = fopen(fileName, "r");
159 if (fp0 == NULL) {return kFALSE;}
162 TFile file(fileName, "READ");
164 file.GetObject("AliITSOnlineCalibrationSPD", calib);
167 UInt_t module = calib->GetModuleNr();
168 Int_t nrDead=calib->GetNrDead();
169 for (Int_t index=0; index<nrDead; index++) {
170 UInt_t colM=calib->GetDeadColAt(index);
171 UInt_t row=calib->GetDeadRowAt(index);
172 SetDeadPixelM(module,colM,row);
179 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFiles() {
180 // read noisy files from file location. returns true if at least one file found
181 Bool_t returnval=kFALSE;
182 for (UInt_t module=0; module<240; module++) {
183 if (ReadNoisyFromFile(module)) {
189 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(UInt_t module) {
190 // read noisy for module from file location.
191 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
192 return ReadNoisyFromFileName(fileName.Data());
194 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFileName(const char *fileName) {
195 // read noisy from file fileName
196 AliITSOnlineCalibrationSPD* calib;
197 FILE* fp0 = fopen(fileName, "r");
198 if (fp0 == NULL) {return kFALSE;}
201 TFile file(fileName, "READ");
203 file.GetObject("AliITSOnlineCalibrationSPD", calib);
206 UInt_t module = calib->GetModuleNr();
207 Int_t nrNoisy=calib->GetNrNoisy();
208 for (Int_t index=0; index<nrNoisy; index++) {
209 UInt_t colM=calib->GetNoisyColAt(index);
210 UInt_t row=calib->GetNoisyRowAt(index);
211 SetNoisyPixelM(module,colM,row);
220 UInt_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromText(const char *fileName) {
221 // read dead from a text file (lines with eqId,hs,chip,col,row). returns nr of pixels added (not already there)
224 textFile.open(fileName, ifstream::in);
225 if (textFile.fail()) {
226 Error("AliITSOnlineCalibrationSPDhandler::ReadDeadFromText","No noisy text file (%s) present.",fileName);
230 UInt_t eqId,hs,chip,col,row;
231 textFile >> eqId; if (textFile.eof()) break;
232 textFile >> hs; if (textFile.eof()) break;
233 textFile >> chip; if (textFile.eof()) break;
234 textFile >> col; if (textFile.eof()) break;
236 if (SetDeadPixel(eqId,hs,chip,col,row)) {
239 if (textFile.eof()) break;
246 UInt_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText(const char *fileName) {
247 // read noisy from a text file (lines with eqId,hs,chip,col,row). returns nr of pixels added (not already here)
250 textFile.open(fileName, ifstream::in);
251 if (textFile.fail()) {
252 Error("AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText","No noisy text file (%s) present.",fileName);
256 UInt_t eqId,hs,chip,col,row;
257 textFile >> eqId; if (textFile.eof()) break;
258 textFile >> hs; if (textFile.eof()) break;
259 textFile >> chip; if (textFile.eof()) break;
260 textFile >> col; if (textFile.eof()) break;
262 if (SetNoisyPixel(eqId,hs,chip,col,row)) {
265 if (textFile.eof()) break;
274 Bool_t AliITSOnlineCalibrationSPDhandler::ReadModuleFromDB(UInt_t module, Int_t runNr) {
275 // reads dead and noisy pixels from DB for given module and runNr
276 AliCDBManager* man = AliCDBManager::Instance();
277 if(!man->IsDefaultStorageSet()) {
278 man->SetDefaultStorage("local://$ALICE_ROOT");
280 AliCDBEntry *cdbEntry = man->Get("ITS/Calib/CalibSPD", runNr);
283 spdEntry = (TObjArray*)cdbEntry->GetObject();
284 if(!spdEntry) return kFALSE;
287 Warning("AliITSOnlineCalibrationSPDhandler::ReadModuleFromDB","Calibration for run %d not found in database.",runNr);
290 AliITSCalibrationSPD* calibSPD;
291 calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
292 UInt_t nrDead = calibSPD->GetNrDead();
293 for (UInt_t index=0; index<nrDead; index++) {
294 UInt_t colM = calibSPD->GetDeadColAt(index);
295 UInt_t row = calibSPD->GetDeadRowAt(index);
296 SetDeadPixelM(module,colM,row);
298 UInt_t nrNoisy = calibSPD->GetNrNoisy();
299 for (UInt_t index=0; index<nrNoisy; index++) {
300 UInt_t colM = calibSPD->GetNoisyColAt(index);
301 UInt_t row = calibSPD->GetNoisyRowAt(index);
302 SetNoisyPixelM(module,colM,row);
304 spdEntry->SetOwner(kTRUE);
309 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromDB(Int_t runNr) {
310 // reads dead and noisy pixels from DB for given runNr
311 // note that you may want to clear the lists (if they are not empty) before reading
312 AliCDBManager* man = AliCDBManager::Instance();
313 if(!man->IsDefaultStorageSet()) {
314 man->SetDefaultStorage("local://$ALICE_ROOT");
316 AliCDBEntry *cdbEntry = man->Get("ITS/Calib/CalibSPD", runNr);
319 spdEntry = (TObjArray*)cdbEntry->GetObject();
320 if(!spdEntry) return kFALSE;
323 Warning("AliITSOnlineCalibrationSPDhandler::ReadFromDB","Calibration for run %d not found in database.",runNr);
326 AliITSCalibrationSPD* calibSPD;
327 for (UInt_t module=0; module<240; module++) {
328 // printf("Reading module %d\n",module);
329 calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
330 UInt_t nrDead = calibSPD->GetNrDead();
331 for (UInt_t index=0; index<nrDead; index++) {
332 UInt_t colM = calibSPD->GetDeadColAt(index);
333 UInt_t row = calibSPD->GetDeadRowAt(index);
334 SetDeadPixelM(module,colM,row);
336 UInt_t nrNoisy = calibSPD->GetNrNoisy();
337 for (UInt_t index=0; index<nrNoisy; index++) {
338 UInt_t colM = calibSPD->GetNoisyColAt(index);
339 UInt_t row = calibSPD->GetNoisyRowAt(index);
340 SetNoisyPixelM(module,colM,row);
343 spdEntry->SetOwner(kTRUE);
348 Bool_t AliITSOnlineCalibrationSPDhandler::WriteToDB(Int_t runNrStart, Int_t runNrEnd) {
349 // writes dead and noisy pixels to DB for given runNr
350 // overwrites any previous entries
351 AliCDBManager* man = AliCDBManager::Instance();
352 if(!man->IsDefaultStorageSet()) {
353 man->SetDefaultStorage("local://$ALICE_ROOT");
355 AliCDBMetaData* metaData = new AliCDBMetaData();
356 metaData->SetResponsible("Henrik Tydesjo");
357 metaData->SetComment("Created by AliITSOnlineCalibrationSPDhandler.");
358 AliCDBId idCalSPD("ITS/Calib/CalibSPD",runNrStart,runNrEnd);
359 TObjArray* spdEntry = new TObjArray(240);
360 spdEntry->SetOwner(kTRUE);
361 for(UInt_t module=0; module<240; module++){
362 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
364 // *** this is temporarily hard coded here ********************
365 // (later these parameters will be separated from the cal.obj.)
366 calObj->SetThresholds(3000, 250);
367 calObj->SetBiasVoltage(18.182);
368 calObj->SetNoiseParam(0,0);
369 // CouplingRaw changed to 0.055 (fine tuning), was 0.047 in PDC06
370 calObj->SetCouplingParam(0.,0.055);
371 // *** remove later...
372 // ************************************************************
374 spdEntry->Add(calObj);
376 for(UInt_t module=0; module<240; module++){
377 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrDead( GetNrDead(module) );
378 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetDeadList( GetDeadArray(module) );
379 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( GetNrNoisy(module) );
380 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( GetNoisyArray(module) );
382 AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
391 void AliITSOnlineCalibrationSPDhandler::WriteToFilesAlways() {
392 // write the lists of dead and noisy to files (only if there are >0 dead or noisy pixels)
393 for (UInt_t module=0; module<240; module++) {
397 void AliITSOnlineCalibrationSPDhandler::WriteToFiles() {
398 // write the lists of dead and noisy to files (only if there are >0 dead or noisy pixels)
399 for (UInt_t module=0; module<240; module++) {
400 if (fNrDead[module]+fNrNoisy[module] > 0) {
405 void AliITSOnlineCalibrationSPDhandler::WriteToFile(UInt_t module) {
406 // write the lists of dead and noisy for module to file
407 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
408 calib->SetModuleNr(module);
409 calib->SetDeadList(GetDeadArray(module));
410 calib->SetNoisyList(GetNoisyArray(module));
411 calib->SetNrDead(GetNrDead(module));
412 calib->SetNrNoisy(GetNrNoisy(module));
413 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
414 TFile file(fileName.Data(), "RECREATE");
415 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
419 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFiles() {
420 // write the lists of dead to files (only if there are >0 dead pixels)
421 for (UInt_t module=0; module<240; module++) {
422 if (fNrDead[module] > 0) {
423 WriteDeadToFile(module);
427 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFile(UInt_t module) {
428 // write the lists of dead for module to file
429 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
430 calib->SetModuleNr(module);
431 calib->SetDeadList(GetDeadArray(module));
432 calib->SetNrDead(GetNrDead(module));
433 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
434 TFile file(fileName.Data(), "RECREATE");
435 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
439 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFiles() {
440 // write the lists of noisy to files (only if there are >0 dead pixels)
441 for (UInt_t module=0; module<240; module++) {
442 if (fNrNoisy[module] > 0) {
443 printf("writing noisy to file for module %d\n",module);
444 WriteNoisyToFile(module);
448 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFile(UInt_t module) {
449 // write the lists of noisy for module to file
450 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
451 calib->SetModuleNr(module);
452 calib->SetNoisyList(GetNoisyArray(module));
453 calib->SetNrNoisy(GetNrNoisy(module));
454 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
455 TFile file(fileName.Data(), "RECREATE");
456 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
461 TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArray(UInt_t module) {
462 // get a TArrayI of the dead pixels (format for the AliITSCalibrationSPD object)
464 returnArray.Set(GetNrDead(module)*2);
465 fDeadPixelMap[module]->PrepareSerialize(); // for tree ordered values
466 for (UInt_t index=0; index<GetNrDead(module); index++) {
467 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
468 Int_t colM = GetColMFromKey(key);
469 Int_t row = GetRowFromKey(key);
470 returnArray.AddAt(colM,index*2);
471 returnArray.AddAt(row,index*2+1);
475 TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArray(UInt_t module) {
476 // get a TArrayI of the noisy pixels (format for the AliITSCalibrationSPD object)
478 returnArray.Set(GetNrNoisy(module)*2);
479 fNoisyPixelMap[module]->PrepareSerialize(); // for tree ordered values
480 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
481 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
482 Int_t colM = GetColMFromKey(key);
483 Int_t row = GetRowFromKey(key);
484 returnArray.AddAt(colM,index*2);
485 returnArray.AddAt(row,index*2+1);
490 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
491 // reset the dead pixel map
492 for (UInt_t module=0; module<240; module++) {
494 fDeadPixelMap[module]->Clear();
498 void AliITSOnlineCalibrationSPDhandler::ResetDeadForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
499 // clear the noisy pixels for this chip
500 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
501 for (UInt_t col=0; col<32; col++) {
502 for (UInt_t row=0; row<256; row++) {
503 Int_t key = GetKey(eqId,hs,chip,col,row);
504 if (fDeadPixelMap[module]->Remove(key)) {
511 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
512 // set a dead pixel, returns false if pixel is already dead
513 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
514 Int_t key = GetKey(eqId,hs,chip,col,row);
515 //!!! // if noisy we dont want to add it...
516 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
517 if (fDeadPixelMap[module]->Insert(key,module)) {
524 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row) {
525 // set a dead pixel, returns false if pixel is already dead
526 UInt_t eqId = GetEqIdFromOffline(module);
527 UInt_t hs = GetHSFromOffline(module);
528 UInt_t chip = GetChipFromOffline(module,colM);
529 UInt_t col = GetColFromOffline(colM);
530 Int_t key = GetKey(eqId,hs,chip,col,row);
531 //!!! // if noisy we dont want to add it...
532 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
533 if (fDeadPixelMap[module]->Insert(key,module)) {
540 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetDeadPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
541 // unset a dead pixel, returns false if pixel is not dead
542 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
543 Int_t key = GetKey(eqId,hs,chip,col,row);
544 if (fDeadPixelMap[module]->Remove(key)) {
551 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row) {
552 // unset a dead pixel, returns false if pixel is not dead
553 UInt_t eqId = GetEqIdFromOffline(module);
554 UInt_t hs = GetHSFromOffline(module);
555 UInt_t chip = GetChipFromOffline(module,colM);
556 UInt_t col = GetColFromOffline(colM);
557 Int_t key = GetKey(eqId,hs,chip,col,row);
558 if (fDeadPixelMap[module]->Remove(key)) {
565 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadKey(Int_t key) const {
566 // is this pixel noisy?
567 UInt_t eqId = GetEqIdFromKey(key);
568 UInt_t hs = GetHSFromKey(key);
569 UInt_t chip = GetChipFromKey(key);
570 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
571 return IsPixelDeadMKey(module,key);
574 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadMKey(UInt_t module, Int_t key) const {
575 // is this pixel dead?
576 if ( fDeadPixelMap[module]->Find(key) != NULL ) {
584 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
585 // is the pixel dead?
586 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
587 Int_t key = GetKey(eqId,hs,chip,col,row);
588 return IsPixelDeadMKey(module,key);
591 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadM(UInt_t module, UInt_t colM, UInt_t row) {
592 // is the pixel dead?
593 UInt_t eqId = GetEqIdFromOffline(module);
594 UInt_t hs = GetHSFromOffline(module);
595 UInt_t chip = GetChipFromOffline(module,colM);
596 UInt_t col = GetColFromOffline(colM);
597 Int_t key = GetKey(eqId,hs,chip,col,row);
598 return IsPixelDeadMKey(module,key);
601 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead() const {
602 // returns the total nr of dead pixels
604 for (UInt_t module=0; module<240; module++) {
605 nrDead+=fNrDead[module];
610 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead(UInt_t module) const {
611 // returns the number of dead pixels for a certain module
613 return fNrDead[module];
620 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt(UInt_t module, UInt_t index) {
621 // get eqId for the dead pixel at position index in list of dead
622 if (index<GetNrDead(module)) {
623 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
624 return GetEqIdFromKey(key);
627 Error("AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt", "Index %d out of bounds.", index);
631 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAt(UInt_t module, UInt_t index) {
632 // get hs for the dead pixel at position index in list of dead
633 if (index<GetNrDead(module)) {
634 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
635 return GetHSFromKey(key);
638 Error("AliITSOnlineCalibrationSPDhandler::GetDeadHSAt", "Index %d out of bounds.", index);
642 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAt(UInt_t module, UInt_t index) {
643 // get chip for the dead pixel at position index in list of dead
644 if (index<GetNrDead(module)) {
645 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
646 return GetChipFromKey(key);
649 Error("AliITSOnlineCalibrationSPDhandler::GetDeadChipAt", "Index %d out of bounds.", index);
653 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t module, UInt_t index) {
654 // get column for the dead pixel at position index in list of dead
655 if (index<GetNrDead(module)) {
656 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
657 return GetColFromKey(key);
660 Error("AliITSOnlineCalibrationSPDhandler::GetDeadColAt", "Index %d out of bounds.", index);
664 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t module, UInt_t index) {
665 // get row for the dead pixel at position index in list of dead
666 if (index<GetNrDead(module)) {
667 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
668 return GetRowFromKey(key);
671 Error("AliITSOnlineCalibrationSPDhandler::GetDeadRowAt", "Index %d out of bounds.", index);
676 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
677 // clear the list of noisy pixels
678 for (UInt_t module=0; module<240; module++) {
680 fNoisyPixelMap[module]->Clear();
683 void AliITSOnlineCalibrationSPDhandler::ResetNoisyForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
684 // clear the noisy pixels for this chip
685 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
686 for (UInt_t col=0; col<32; col++) {
687 for (UInt_t row=0; row<256; row++) {
688 Int_t key = GetKey(eqId,hs,chip,col,row);
689 if (fNoisyPixelMap[module]->Remove(key)) {
697 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
698 // set a noisy pixel, returns false if already there
699 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
700 Int_t key = GetKey(eqId,hs,chip,col,row);
701 //!!! // if dead before - remove from the dead list
702 //!!! UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
703 //!!! if (fDeadPixelMap.Remove(key)) {
704 //!!! fNrDead[module]--;
706 if (fNoisyPixelMap[module]->Insert(key,col)) {
713 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row) {
714 // set a noisy pixel, returns false if already there
715 UInt_t eqId = GetEqIdFromOffline(module);
716 UInt_t hs = GetHSFromOffline(module);
717 UInt_t chip = GetChipFromOffline(module,colM);
718 UInt_t col = GetColFromOffline(colM);
719 Int_t key = GetKey(eqId,hs,chip,col,row);
720 //!!! // if dead before - remove from the dead list
721 //!!! if (fDeadPixelMap[module]->Remove(key)) {
722 //!!! fNrDead[module]--;
724 if (fNoisyPixelMap[module]->Insert(key,col)) {
731 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetNoisyPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
732 // unset a noisy pixel, returns false if not there
733 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
734 Int_t key = GetKey(eqId,hs,chip,col,row);
735 if (fNoisyPixelMap[module]->Remove(key)) {
742 Bool_t AliITSOnlineCalibrationSPDhandler::UnSetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row) {
743 // unset a noisy pixel, returns false if not there
744 UInt_t eqId = GetEqIdFromOffline(module);
745 UInt_t hs = GetHSFromOffline(module);
746 UInt_t chip = GetChipFromOffline(module,colM);
747 UInt_t col = GetColFromOffline(colM);
748 Int_t key = GetKey(eqId,hs,chip,col,row);
749 if (fNoisyPixelMap[module]->Remove(key)) {
756 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyKey(Int_t key) const {
757 // is this pixel noisy?
758 UInt_t eqId = GetEqIdFromKey(key);
759 UInt_t hs = GetHSFromKey(key);
760 UInt_t chip = GetChipFromKey(key);
761 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
762 return IsPixelNoisyMKey(module,key);
765 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyMKey(UInt_t module, Int_t key) const {
766 // is this pixel noisy?
767 if ( fNoisyPixelMap[module]->Find(key) != NULL ) {
775 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
776 // is this pixel noisy?
777 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
778 Int_t key = GetKey(eqId,hs,chip,col,row);
779 return IsPixelNoisyMKey(module,key);
782 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyM(UInt_t module, UInt_t colM, UInt_t row) {
783 // is this pixel noisy?
784 UInt_t eqId = GetEqIdFromOffline(module);
785 UInt_t hs = GetHSFromOffline(module);
786 UInt_t chip = GetChipFromOffline(module,colM);
787 UInt_t col = GetColFromOffline(colM);
788 Int_t key = GetKey(eqId,hs,chip,col,row);
789 return IsPixelNoisyMKey(module,key);
792 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy() const {
793 // returns the total nr of noisy pixels
795 for (UInt_t module=0; module<240; module++) {
796 nrNoisy+=fNrNoisy[module];
801 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy(UInt_t module) const {
802 // returns the number of noisy pixels for a certain module
804 return fNrNoisy[module];
811 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt(UInt_t module, UInt_t index) {
812 // get chip for the noisy pixel at position index in list of noisy
813 if (index<GetNrNoisy(module)) {
814 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
815 return GetEqIdFromKey(key);
818 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt", "Index %d out of bounds.", index);
822 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt(UInt_t module, UInt_t index) {
823 // get chip for the noisy pixel at position index in list of noisy
824 if (index<GetNrNoisy(module)) {
825 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
826 return GetHSFromKey(key);
829 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt", "Index %d out of bounds.", index);
833 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt(UInt_t module, UInt_t index) {
834 // get chip for the noisy pixel at position index in list of noisy
835 if (index<GetNrNoisy(module)) {
836 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
837 return GetChipFromKey(key);
840 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt", "Index %d out of bounds.", index);
844 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t module, UInt_t index) {
845 // get column for the noisy pixel at position index in list of noisy
846 if (index<GetNrNoisy(module)) {
847 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
848 return GetColFromKey(key);
851 Warning("AliITSOnlineCalibrationSPDhandler::GetNoisyColAt", "Index %d out of bounds.", index);
855 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t module, UInt_t index) {
856 // get row for the noisy pixel at position index in list of noisy
857 if (index<GetNrNoisy(module)) {
858 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
859 return GetRowFromKey(key);
862 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt", "Index %d out of bounds.", index);
867 void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
868 // print the dead pixels to screen
869 printf("-----------------------------------\n");
870 printf("Dead Pixels: (eqId,hs,chip,col,row)\n");
871 printf("-----------------------------------\n");
872 for (UInt_t module=0; module<240; module++) {
873 for (UInt_t index=0; index<GetNrDead(module); index++) {
874 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
875 UInt_t eqId = GetEqIdFromKey(key);
876 UInt_t hs = GetHSFromKey(key);
877 UInt_t chip = GetChipFromKey(key);
878 UInt_t col = GetColFromKey(key);
879 UInt_t row = GetRowFromKey(key);
880 printf("%d,%d,%d,%d,%d\n",eqId,hs,chip,col,row);
885 void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
886 // print the dead pixels to screen
887 printf("-----------------------------------\n");
888 printf("Noisy Pixels: (eqId,hs,chip,col,row)\n");
889 printf("-----------------------------------\n");
890 for (UInt_t module=0; module<240; module++) {
891 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
892 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
893 UInt_t eqId = GetEqIdFromKey(key);
894 UInt_t hs = GetHSFromKey(key);
895 UInt_t chip = GetChipFromKey(key);
896 UInt_t col = GetColFromKey(key);
897 UInt_t row = GetRowFromKey(key);
898 printf("%d,%d,%d,%d,%d\n",eqId,hs,chip,col,row);
903 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
904 // returns nr of dead in this' lists and not in other's lists
906 for (UInt_t module=0; module<240; module++) {
907 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
908 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
909 UInt_t eqId = GetEqIdFromKey(key);
910 UInt_t hs = GetHSFromKey(key);
911 UInt_t chip = GetChipFromKey(key);
912 UInt_t col = GetColFromKey(key);
913 UInt_t row = GetRowFromKey(key);
914 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
922 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
923 // returns nr of noisy in this' lists and not in other's lists
925 for (UInt_t module=0; module<240; module++) {
926 for (UInt_t ind1=0; ind1<fNrNoisy[module]; ind1++) {
927 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind1);
928 UInt_t eqId = GetEqIdFromKey(key);
929 UInt_t hs = GetHSFromKey(key);
930 UInt_t chip = GetChipFromKey(key);
931 UInt_t col = GetColFromKey(key);
932 UInt_t row = GetRowFromKey(key);
933 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
941 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDiff(AliITSOnlineCalibrationSPDhandler* other) const {
942 // returns nr of dead/noisy in this' lists and not in other's lists
943 return GetNrDeadDiff(other) + GetNrNoisyDiff(other);
946 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDiff(AliITSOnlineCalibrationSPDhandler* other) const {
947 // returns handler with dead/noisy in this' lists, except for those in other's lists
948 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
949 for (UInt_t module=0; module<240; module++) {
950 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
951 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
952 UInt_t eqId = GetEqIdFromKey(key);
953 UInt_t hs = GetHSFromKey(key);
954 UInt_t chip = GetChipFromKey(key);
955 UInt_t col = GetColFromKey(key);
956 UInt_t row = GetRowFromKey(key);
957 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
958 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
961 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
962 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
963 UInt_t eqId = GetEqIdFromKey(key);
964 UInt_t hs = GetHSFromKey(key);
965 UInt_t chip = GetChipFromKey(key);
966 UInt_t col = GetColFromKey(key);
967 UInt_t row = GetRowFromKey(key);
968 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
969 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
976 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
977 // returns handler with dead in this' lists, except for those in other's lists
978 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
979 for (UInt_t module=0; module<240; module++) {
980 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
981 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
982 UInt_t eqId = GetEqIdFromKey(key);
983 UInt_t hs = GetHSFromKey(key);
984 UInt_t chip = GetChipFromKey(key);
985 UInt_t col = GetColFromKey(key);
986 UInt_t row = GetRowFromKey(key);
987 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
988 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
995 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
996 // returns handler with noisy in this' lists, except for those in other's lists
997 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
998 for (UInt_t module=0; module<240; module++) {
999 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
1000 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
1001 UInt_t eqId = GetEqIdFromKey(key);
1002 UInt_t hs = GetHSFromKey(key);
1003 UInt_t chip = GetChipFromKey(key);
1004 UInt_t col = GetColFromKey(key);
1005 UInt_t row = GetRowFromKey(key);
1006 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
1007 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
1014 void AliITSOnlineCalibrationSPDhandler::InitModuleMaps() {
1015 // initializes the module mapping arrays needed for the methods below (GetEqIdFromOffline etc.)
1016 for (UInt_t iDDL=0; iDDL<20; iDDL++) {
1017 for (UInt_t iModule=0; iModule<12; iModule++) {
1018 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(iDDL,iModule);
1019 fiDDL[module] = iDDL;
1020 fiModule[module] = iModule;
1025 void AliITSOnlineCalibrationSPDhandler::GenerateDCSConfigFile(const Char_t* fileName) {
1026 // generates an ascii file in the format as the one produced by online da (but with dummy runNr=0)
1028 dcsfile.open(fileName);
1029 dcsfile << "[SPD SCAN]\n";
1030 dcsfile << "RunNumber=" << "0" << "\n"; // dummy value
1031 dcsfile << "Type=" << "4" << "\n";
1032 dcsfile << "Router=" << "0" << "\n"; // dummy value
1033 dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values
1034 dcsfile << "[NOISY]\n";
1035 for (UInt_t module=0; module<240; module++) {
1036 UInt_t headkey=20*10*6;
1037 for (UInt_t ind=0; ind<fNrNoisy[module]; ind++) {
1038 UInt_t newkey = GetNoisyEqIdAt(module,ind)*10*6 +
1039 GetNoisyHSAt(module,ind)*10 +
1040 GetNoisyChipAt(module,ind);
1041 if (newkey!=headkey) { // print eqId,hs,chip header
1043 dcsfile << "-" << newkey/(6*10) << "," << (newkey%(6*10))/10 << "," << (newkey%(6*10))%10 << "\n";
1045 dcsfile << GetNoisyColAt(module,ind) << "," << GetNoisyRowAt(module,ind) << "\n";
1051 UInt_t AliITSOnlineCalibrationSPDhandler::GetEqIdFromOffline(UInt_t module) {
1052 // module to eqId mapping
1053 if (!fModuleMapInited) InitModuleMaps();
1054 return fiDDL[module];
1056 UInt_t AliITSOnlineCalibrationSPDhandler::GetHSFromOffline(UInt_t module) {
1057 // module to hs mapping
1058 if (!fModuleMapInited) InitModuleMaps();
1059 return fiModule[module]/2;
1061 UInt_t AliITSOnlineCalibrationSPDhandler::GetChipFromOffline(UInt_t module, UInt_t colM) {
1062 // module,colM to chip mapping
1063 if (!fModuleMapInited) InitModuleMaps();
1064 return colM/32 + 5*(fiModule[module]%2);
1066 UInt_t AliITSOnlineCalibrationSPDhandler::GetColFromOffline(UInt_t colM) const {
1067 // colM to col mapping