1 //////////////////////////////////////////////////////////////////////
2 // Author: Henrik Tydesjo //
3 // For easier handling of dead and noisy pixels they are kept in //
4 // container maps (AliITSIntMap). //
5 // The TArrayI objects that are put in the AliITSCalibrationSPD //
6 // objects can be obtained from the methods GetDeadArray and //
8 //////////////////////////////////////////////////////////////////////
10 #include "AliITSOnlineCalibrationSPDhandler.h"
11 #include "AliITSOnlineCalibrationSPD.h"
12 #include "AliITSIntMap.h"
13 #include <TObjArray.h>
19 #ifndef SPD_DA_OFF // you may want to exclude cdb classes, if using this class outside aliroot
20 #include "AliITSCalibrationSPD.h"
21 #include "AliCDBManager.h"
22 #include "AliCDBEntry.h"
25 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler():
27 fModuleMapInited(kFALSE)
30 for (UInt_t module=0; module<240; module++) {
33 fDeadPixelMap[module] = new AliITSIntMap();
34 fNoisyPixelMap[module] = new AliITSIntMap();
38 AliITSOnlineCalibrationSPDhandler::AliITSOnlineCalibrationSPDhandler(const AliITSOnlineCalibrationSPDhandler& handle):
40 fModuleMapInited(kFALSE)
43 for (UInt_t module=0; module<240; module++) {
44 fNrDead[module] = handle.fNrDead[module];
45 fNrNoisy[module] = handle.fNrNoisy[module];
46 fDeadPixelMap[module] = handle.fDeadPixelMap[module]->Clone();
47 fNoisyPixelMap[module] = handle.fNoisyPixelMap[module]->Clone();
49 fFileLocation = handle.fFileLocation;
52 AliITSOnlineCalibrationSPDhandler::~AliITSOnlineCalibrationSPDhandler() {
56 AliITSOnlineCalibrationSPDhandler& AliITSOnlineCalibrationSPDhandler::operator=(const AliITSOnlineCalibrationSPDhandler& handle) {
57 // assignment operator
60 for (UInt_t module=0; module<240; module++) {
61 fNrDead[module] = handle.fNrDead[module];
62 fNrNoisy[module] = handle.fNrNoisy[module];
63 fDeadPixelMap[module] = handle.fDeadPixelMap[module]->Clone();
64 fNoisyPixelMap[module] = handle.fNoisyPixelMap[module]->Clone();
66 fFileLocation = handle.fFileLocation;
71 void AliITSOnlineCalibrationSPDhandler::ClearMaps() {
72 // clear the lists of dead and noisy
77 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFiles() {
78 // read dead and noisy files from file location. returns true if at least one file found
79 Bool_t returnval=kFALSE;
80 for (UInt_t module=0; module<240; module++) {
81 if (ReadFromFile(module)) {
87 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFile(UInt_t module) {
88 // read dead and noisy files for module from file location.
89 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
90 return ReadFromFileName(fileName.Data());
92 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromFileName(const char *fileName) {
93 // read dead and noisy from file fileName
94 AliITSOnlineCalibrationSPD* calib;
95 FILE* fp0 = fopen(fileName, "r");
96 if (fp0 == NULL) {return kFALSE;}
99 TFile file(fileName, "READ");
101 file.GetObject("AliITSOnlineCalibrationSPD", calib);
104 UInt_t module = calib->GetModuleNr();
105 Int_t nrDead=calib->GetNrDead();
106 for (Int_t index=0; index<nrDead; index++) {
107 UInt_t colM=calib->GetDeadColAt(index);
108 UInt_t row=calib->GetDeadRowAt(index);
109 SetDeadPixelM(module,colM,row);
111 Int_t nrNoisy=calib->GetNrNoisy();
112 for (Int_t index=0; index<nrNoisy; index++) {
113 UInt_t colM=calib->GetNoisyColAt(index);
114 UInt_t row=calib->GetNoisyRowAt(index);
115 SetNoisyPixelM(module,colM,row);
122 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFiles() {
123 // read dead files from file location. returns true if at least one file found
124 Bool_t returnval=kFALSE;
125 for (UInt_t module=0; module<240; module++) {
126 if (ReadDeadFromFile(module)) {
132 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFile(UInt_t module) {
133 // read dead for module from file location.
134 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
135 return ReadDeadFromFileName(fileName.Data());
137 Bool_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromFileName(const char *fileName) {
138 // read dead from file fileName
139 AliITSOnlineCalibrationSPD* calib;
140 FILE* fp0 = fopen(fileName, "r");
141 if (fp0 == NULL) {return kFALSE;}
144 TFile file(fileName, "READ");
146 file.GetObject("AliITSOnlineCalibrationSPD", calib);
149 UInt_t module = calib->GetModuleNr();
150 Int_t nrDead=calib->GetNrDead();
151 for (Int_t index=0; index<nrDead; index++) {
152 UInt_t colM=calib->GetDeadColAt(index);
153 UInt_t row=calib->GetDeadRowAt(index);
154 SetDeadPixelM(module,colM,row);
161 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFiles() {
162 // read noisy files from file location. returns true if at least one file found
163 Bool_t returnval=kFALSE;
164 for (UInt_t module=0; module<240; module++) {
165 if (ReadNoisyFromFile(module)) {
171 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFile(UInt_t module) {
172 // read noisy for module from file location.
173 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
174 return ReadNoisyFromFileName(fileName.Data());
176 Bool_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromFileName(const char *fileName) {
177 // read noisy from file fileName
178 AliITSOnlineCalibrationSPD* calib;
179 FILE* fp0 = fopen(fileName, "r");
180 if (fp0 == NULL) {return kFALSE;}
183 TFile file(fileName, "READ");
185 file.GetObject("AliITSOnlineCalibrationSPD", calib);
188 UInt_t module = calib->GetModuleNr();
189 Int_t nrNoisy=calib->GetNrNoisy();
190 for (Int_t index=0; index<nrNoisy; index++) {
191 UInt_t colM=calib->GetNoisyColAt(index);
192 UInt_t row=calib->GetNoisyRowAt(index);
193 SetNoisyPixelM(module,colM,row);
202 UInt_t AliITSOnlineCalibrationSPDhandler::ReadDeadFromText(const char *fileName) {
203 // read dead from a text file (lines with eqId,hs,chip,col,row). returns nr of pixels added (not already there)
206 textFile.open(fileName, ifstream::in);
207 if (textFile.fail()) {
208 Error("AliITSOnlineCalibrationSPDhandler::ReadDeadFromText","No noisy text file (%s) present.",fileName);
212 UInt_t eqId,hs,chip,col,row;
213 textFile >> eqId; if (textFile.eof()) break;
214 textFile >> hs; if (textFile.eof()) break;
215 textFile >> chip; if (textFile.eof()) break;
216 textFile >> col; if (textFile.eof()) break;
218 if (SetDeadPixel(eqId,hs,chip,col,row)) {
221 if (textFile.eof()) break;
228 UInt_t AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText(const char *fileName) {
229 // read noisy from a text file (lines with eqId,hs,chip,col,row). returns nr of pixels added (not already here)
232 textFile.open(fileName, ifstream::in);
233 if (textFile.fail()) {
234 Error("AliITSOnlineCalibrationSPDhandler::ReadNoisyFromText","No noisy text file (%s) present.",fileName);
238 UInt_t eqId,hs,chip,col,row;
239 textFile >> eqId; if (textFile.eof()) break;
240 textFile >> hs; if (textFile.eof()) break;
241 textFile >> chip; if (textFile.eof()) break;
242 textFile >> col; if (textFile.eof()) break;
244 if (SetNoisyPixel(eqId,hs,chip,col,row)) {
247 if (textFile.eof()) break;
256 Bool_t AliITSOnlineCalibrationSPDhandler::ReadModuleFromDB(UInt_t module, Int_t runNr) {
257 // reads dead and noisy pixels from DB for given module and runNr
258 AliCDBManager* man = AliCDBManager::Instance();
259 if(!man->IsDefaultStorageSet()) {
260 man->SetDefaultStorage("local://$ALICE_ROOT");
262 AliCDBEntry *cdbEntry = man->Get("ITS/Calib/CalibSPD", runNr);
265 spdEntry = (TObjArray*)cdbEntry->GetObject();
266 if(!spdEntry) return kFALSE;
269 Warning("AliITSOnlineCalibrationSPDhandler::ReadModuleFromDB","Calibration for run %d not found in database.",runNr);
272 AliITSCalibrationSPD* calibSPD;
273 calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
274 UInt_t nrDead = calibSPD->GetNrDead();
275 for (UInt_t index=0; index<nrDead; index++) {
276 UInt_t colM = calibSPD->GetDeadColAt(index);
277 UInt_t row = calibSPD->GetDeadRowAt(index);
278 SetDeadPixelM(module,colM,row);
280 UInt_t nrNoisy = calibSPD->GetNrNoisy();
281 for (UInt_t index=0; index<nrNoisy; index++) {
282 UInt_t colM = calibSPD->GetNoisyColAt(index);
283 UInt_t row = calibSPD->GetNoisyRowAt(index);
284 SetNoisyPixelM(module,colM,row);
286 spdEntry->SetOwner(kTRUE);
291 Bool_t AliITSOnlineCalibrationSPDhandler::ReadFromDB(Int_t runNr) {
292 // reads dead and noisy pixels from DB for given runNr
293 // note that you may want to clear the lists (if they are not empty) before reading
294 AliCDBManager* man = AliCDBManager::Instance();
295 if(!man->IsDefaultStorageSet()) {
296 man->SetDefaultStorage("local://$ALICE_ROOT");
298 AliCDBEntry *cdbEntry = man->Get("ITS/Calib/CalibSPD", runNr);
301 spdEntry = (TObjArray*)cdbEntry->GetObject();
302 if(!spdEntry) return kFALSE;
305 Warning("AliITSOnlineCalibrationSPDhandler::ReadFromDB","Calibration for run %d not found in database.",runNr);
308 AliITSCalibrationSPD* calibSPD;
309 for (UInt_t module=0; module<240; module++) {
310 // printf("Reading module %d\n",module);
311 calibSPD = (AliITSCalibrationSPD*) spdEntry->At(module);
312 UInt_t nrDead = calibSPD->GetNrDead();
313 for (UInt_t index=0; index<nrDead; index++) {
314 UInt_t colM = calibSPD->GetDeadColAt(index);
315 UInt_t row = calibSPD->GetDeadRowAt(index);
316 SetDeadPixelM(module,colM,row);
318 UInt_t nrNoisy = calibSPD->GetNrNoisy();
319 for (UInt_t index=0; index<nrNoisy; index++) {
320 UInt_t colM = calibSPD->GetNoisyColAt(index);
321 UInt_t row = calibSPD->GetNoisyRowAt(index);
322 SetNoisyPixelM(module,colM,row);
325 spdEntry->SetOwner(kTRUE);
330 Bool_t AliITSOnlineCalibrationSPDhandler::WriteToDB(Int_t runNrStart, Int_t runNrEnd) {
331 // writes dead and noisy pixels to DB for given runNr
332 // overwrites any previous entries
333 AliCDBManager* man = AliCDBManager::Instance();
334 if(!man->IsDefaultStorageSet()) {
335 man->SetDefaultStorage("local://$ALICE_ROOT");
337 AliCDBMetaData* metaData = new AliCDBMetaData();
338 metaData->SetResponsible("Henrik Tydesjo");
339 metaData->SetComment("Created by AliITSOnlineCalibrationSPDhandler.");
340 AliCDBId idCalSPD("ITS/Calib/CalibSPD",runNrStart,runNrEnd);
341 TObjArray* spdEntry = new TObjArray(240);
342 spdEntry->SetOwner(kTRUE);
343 for(UInt_t module=0; module<240; module++){
344 AliITSCalibrationSPD* calObj = new AliITSCalibrationSPD();
345 spdEntry->Add(calObj);
347 for(UInt_t module=0; module<240; module++){
348 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrDead( GetNrDead(module) );
349 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetDeadList( GetDeadArray(module) );
350 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( GetNrNoisy(module) );
351 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( GetNoisyArray(module) );
353 AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
362 void AliITSOnlineCalibrationSPDhandler::WriteToFiles() {
363 // write the lists of dead and noisy to files (only if there are >0 dead or noisy pixels)
364 for (UInt_t module=0; module<240; module++) {
365 if (fNrDead[module]+fNrNoisy[module] > 0) {
370 void AliITSOnlineCalibrationSPDhandler::WriteToFile(UInt_t module) {
371 // write the lists of dead and noisy for module to file
372 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
373 calib->SetModuleNr(module);
374 calib->SetDeadList(GetDeadArray(module));
375 calib->SetNoisyList(GetNoisyArray(module));
376 calib->SetNrDead(GetNrDead(module));
377 calib->SetNrNoisy(GetNrNoisy(module));
378 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
379 TFile file(fileName.Data(), "RECREATE");
380 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
384 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFiles() {
385 // write the lists of dead to files (only if there are >0 dead pixels)
386 for (UInt_t module=0; module<240; module++) {
387 if (fNrDead[module] > 0) {
388 WriteDeadToFile(module);
392 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFile(UInt_t module) {
393 // write the lists of dead for module to file
394 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
395 calib->SetModuleNr(module);
396 calib->SetDeadList(GetDeadArray(module));
397 calib->SetNrDead(GetNrDead(module));
398 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
399 TFile file(fileName.Data(), "RECREATE");
400 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
404 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFiles() {
405 // write the lists of noisy to files (only if there are >0 dead pixels)
406 for (UInt_t module=0; module<240; module++) {
407 if (fNrNoisy[module] > 0) {
408 printf("writing noisy to file for module %d\n",module);
409 WriteNoisyToFile(module);
413 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFile(UInt_t module) {
414 // write the lists of noisy for module to file
415 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
416 calib->SetModuleNr(module);
417 calib->SetNoisyList(GetNoisyArray(module));
418 calib->SetNrNoisy(GetNrNoisy(module));
419 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
420 TFile file(fileName.Data(), "RECREATE");
421 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
426 TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArray(UInt_t module) {
427 // get a TArrayI of the dead pixels (format for the AliITSCalibrationSPD object)
429 returnArray.Set(GetNrDead(module)*2);
430 fDeadPixelMap[module]->PrepareSerialize(); // for tree ordered values
431 for (UInt_t index=0; index<GetNrDead(module); index++) {
432 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
433 Int_t colM = GetColMFromKey(key);
434 Int_t row = GetRowFromKey(key);
435 returnArray.AddAt(colM,index*2);
436 returnArray.AddAt(row,index*2+1);
440 TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArray(UInt_t module) {
441 // get a TArrayI of the noisy pixels (format for the AliITSCalibrationSPD object)
443 returnArray.Set(GetNrNoisy(module)*2);
444 fNoisyPixelMap[module]->PrepareSerialize(); // for tree ordered values
445 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
446 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
447 Int_t colM = GetColMFromKey(key);
448 Int_t row = GetRowFromKey(key);
449 returnArray.AddAt(colM,index*2);
450 returnArray.AddAt(row,index*2+1);
455 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
456 // reset the dead pixel map
457 for (UInt_t module=0; module<240; module++) {
459 fDeadPixelMap[module]->Clear();
463 void AliITSOnlineCalibrationSPDhandler::ResetDeadForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
464 // clear the noisy pixels for this chip
465 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
466 for (UInt_t col=0; col<32; col++) {
467 for (UInt_t row=0; row<256; row++) {
468 Int_t key = GetKey(eqId,hs,chip,col,row);
469 if (fDeadPixelMap[module]->Remove(key)) {
476 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
477 // set a dead pixel, returns false if pixel is already dead
478 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
479 Int_t key = GetKey(eqId,hs,chip,col,row);
480 //!!! // if noisy we dont want to add it...
481 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
482 if (fDeadPixelMap[module]->Insert(key,module)) {
489 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row) {
490 // set a dead pixel, returns false if pixel is already dead
491 UInt_t eqId = GetEqIdFromOffline(module);
492 UInt_t hs = GetHSFromOffline(module);
493 UInt_t chip = GetChipFromOffline(module,colM);
494 UInt_t col = GetColFromOffline(colM);
495 Int_t key = GetKey(eqId,hs,chip,col,row);
496 //!!! // if noisy we dont want to add it...
497 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
498 if (fDeadPixelMap[module]->Insert(key,module)) {
505 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadKey(Int_t key) const {
506 // is this pixel noisy?
507 UInt_t eqId = GetEqIdFromKey(key);
508 UInt_t hs = GetHSFromKey(key);
509 UInt_t chip = GetChipFromKey(key);
510 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
511 return IsPixelDeadMKey(module,key);
514 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadMKey(UInt_t module, Int_t key) const {
515 // is this pixel dead?
516 if ( fDeadPixelMap[module]->Find(key) != NULL ) {
524 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
525 // is the pixel dead?
526 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
527 Int_t key = GetKey(eqId,hs,chip,col,row);
528 return IsPixelDeadMKey(module,key);
531 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadM(UInt_t module, UInt_t colM, UInt_t row) {
532 // is the pixel dead?
533 UInt_t eqId = GetEqIdFromOffline(module);
534 UInt_t hs = GetHSFromOffline(module);
535 UInt_t chip = GetChipFromOffline(module,colM);
536 UInt_t col = GetColFromOffline(colM);
537 Int_t key = GetKey(eqId,hs,chip,col,row);
538 return IsPixelDeadMKey(module,key);
541 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead() const {
542 // returns the total nr of dead pixels
544 for (UInt_t module=0; module<240; module++) {
545 nrDead+=fNrDead[module];
550 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead(UInt_t module) const {
551 // returns the number of dead pixels for a certain module
553 return fNrDead[module];
560 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt(UInt_t module, UInt_t index) {
561 // get eqId for the dead pixel at position index in list of dead
562 if (index<GetNrDead(module)) {
563 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
564 return GetEqIdFromKey(key);
567 Error("AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt", "Index %d out of bounds.", index);
571 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAt(UInt_t module, UInt_t index) {
572 // get hs for the dead pixel at position index in list of dead
573 if (index<GetNrDead(module)) {
574 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
575 return GetHSFromKey(key);
578 Error("AliITSOnlineCalibrationSPDhandler::GetDeadHSAt", "Index %d out of bounds.", index);
582 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAt(UInt_t module, UInt_t index) {
583 // get chip for the dead pixel at position index in list of dead
584 if (index<GetNrDead(module)) {
585 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
586 return GetChipFromKey(key);
589 Error("AliITSOnlineCalibrationSPDhandler::GetDeadChipAt", "Index %d out of bounds.", index);
593 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t module, UInt_t index) {
594 // get column for the dead pixel at position index in list of dead
595 if (index<GetNrDead(module)) {
596 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
597 return GetColFromKey(key);
600 Error("AliITSOnlineCalibrationSPDhandler::GetDeadColAt", "Index %d out of bounds.", index);
604 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t module, UInt_t index) {
605 // get row for the dead pixel at position index in list of dead
606 if (index<GetNrDead(module)) {
607 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
608 return GetRowFromKey(key);
611 Error("AliITSOnlineCalibrationSPDhandler::GetDeadRowAt", "Index %d out of bounds.", index);
616 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
617 // clear the list of noisy pixels
618 for (UInt_t module=0; module<240; module++) {
620 fNoisyPixelMap[module]->Clear();
623 void AliITSOnlineCalibrationSPDhandler::ResetNoisyForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
624 // clear the noisy pixels for this chip
625 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
626 for (UInt_t col=0; col<32; col++) {
627 for (UInt_t row=0; row<256; row++) {
628 Int_t key = GetKey(eqId,hs,chip,col,row);
629 if (fNoisyPixelMap[module]->Remove(key)) {
637 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
638 // set a noisy pixel, returns false if already there
639 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
640 Int_t key = GetKey(eqId,hs,chip,col,row);
641 //!!! // if dead before - remove from the dead list
642 //!!! UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
643 //!!! if (fDeadPixelMap.Remove(key)) {
644 //!!! fNrDead[module]--;
646 if (fNoisyPixelMap[module]->Insert(key,col)) {
653 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row) {
654 // set a noisy pixel, returns false if already there
655 UInt_t eqId = GetEqIdFromOffline(module);
656 UInt_t hs = GetHSFromOffline(module);
657 UInt_t chip = GetChipFromOffline(module,colM);
658 UInt_t col = GetColFromOffline(colM);
659 Int_t key = GetKey(eqId,hs,chip,col,row);
660 //!!! // if dead before - remove from the dead list
661 //!!! if (fDeadPixelMap[module]->Remove(key)) {
662 //!!! fNrDead[module]--;
664 if (fNoisyPixelMap[module]->Insert(key,col)) {
671 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyKey(Int_t key) const {
672 // is this pixel noisy?
673 UInt_t eqId = GetEqIdFromKey(key);
674 UInt_t hs = GetHSFromKey(key);
675 UInt_t chip = GetChipFromKey(key);
676 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
677 return IsPixelNoisyMKey(module,key);
680 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyMKey(UInt_t module, Int_t key) const {
681 // is this pixel noisy?
682 if ( fNoisyPixelMap[module]->Find(key) != NULL ) {
690 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
691 // is this pixel noisy?
692 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
693 Int_t key = GetKey(eqId,hs,chip,col,row);
694 return IsPixelNoisyMKey(module,key);
697 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyM(UInt_t module, UInt_t colM, UInt_t row) {
698 // is this pixel noisy?
699 UInt_t eqId = GetEqIdFromOffline(module);
700 UInt_t hs = GetHSFromOffline(module);
701 UInt_t chip = GetChipFromOffline(module,colM);
702 UInt_t col = GetColFromOffline(colM);
703 Int_t key = GetKey(eqId,hs,chip,col,row);
704 return IsPixelNoisyMKey(module,key);
707 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy() const {
708 // returns the total nr of noisy pixels
710 for (UInt_t module=0; module<240; module++) {
711 nrNoisy+=fNrNoisy[module];
716 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy(UInt_t module) const {
717 // returns the number of noisy pixels for a certain module
719 return fNrNoisy[module];
726 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt(UInt_t module, UInt_t index) {
727 // get chip for the noisy pixel at position index in list of noisy
728 if (index<GetNrNoisy(module)) {
729 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
730 return GetEqIdFromKey(key);
733 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt", "Index %d out of bounds.", index);
737 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt(UInt_t module, UInt_t index) {
738 // get chip for the noisy pixel at position index in list of noisy
739 if (index<GetNrNoisy(module)) {
740 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
741 return GetHSFromKey(key);
744 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt", "Index %d out of bounds.", index);
748 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt(UInt_t module, UInt_t index) {
749 // get chip for the noisy pixel at position index in list of noisy
750 if (index<GetNrNoisy(module)) {
751 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
752 return GetChipFromKey(key);
755 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt", "Index %d out of bounds.", index);
759 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t module, UInt_t index) {
760 // get column for the noisy pixel at position index in list of noisy
761 if (index<GetNrNoisy(module)) {
762 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
763 return GetColFromKey(key);
766 Warning("AliITSOnlineCalibrationSPDhandler::GetNoisyColAt", "Index %d out of bounds.", index);
770 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t module, UInt_t index) {
771 // get row for the noisy pixel at position index in list of noisy
772 if (index<GetNrNoisy(module)) {
773 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
774 return GetRowFromKey(key);
777 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt", "Index %d out of bounds.", index);
782 void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
783 // print the dead pixels to screen
784 printf("-----------------------------------\n");
785 printf("Dead Pixels: (eqId,hs,chip,col,row)\n");
786 printf("-----------------------------------\n");
787 for (UInt_t module=0; module<240; module++) {
788 for (UInt_t index=0; index<GetNrDead(module); index++) {
789 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
790 UInt_t eqId = GetEqIdFromKey(key);
791 UInt_t hs = GetHSFromKey(key);
792 UInt_t chip = GetChipFromKey(key);
793 UInt_t col = GetColFromKey(key);
794 UInt_t row = GetRowFromKey(key);
795 printf("%d,%d,%d,%d,%d\n",eqId,hs,chip,col,row);
800 void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
801 // print the dead pixels to screen
802 printf("-----------------------------------\n");
803 printf("Noisy Pixels: (eqId,hs,chip,col,row)\n");
804 printf("-----------------------------------\n");
805 for (UInt_t module=0; module<240; module++) {
806 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
807 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
808 UInt_t eqId = GetEqIdFromKey(key);
809 UInt_t hs = GetHSFromKey(key);
810 UInt_t chip = GetChipFromKey(key);
811 UInt_t col = GetColFromKey(key);
812 UInt_t row = GetRowFromKey(key);
813 printf("%d,%d,%d,%d,%d\n",eqId,hs,chip,col,row);
818 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
819 // returns nr of dead in this' lists and not in other's lists
821 for (UInt_t module=0; module<240; module++) {
822 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
823 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
824 UInt_t eqId = GetEqIdFromKey(key);
825 UInt_t hs = GetHSFromKey(key);
826 UInt_t chip = GetChipFromKey(key);
827 UInt_t col = GetColFromKey(key);
828 UInt_t row = GetRowFromKey(key);
829 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
837 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
838 // returns nr of noisy in this' lists and not in other's lists
840 for (UInt_t module=0; module<240; module++) {
841 for (UInt_t ind1=0; ind1<fNrNoisy[module]; ind1++) {
842 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind1);
843 UInt_t eqId = GetEqIdFromKey(key);
844 UInt_t hs = GetHSFromKey(key);
845 UInt_t chip = GetChipFromKey(key);
846 UInt_t col = GetColFromKey(key);
847 UInt_t row = GetRowFromKey(key);
848 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
856 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDiff(AliITSOnlineCalibrationSPDhandler* other) const {
857 // returns nr of dead/noisy in this' lists and not in other's lists
858 return GetNrDeadDiff(other) + GetNrNoisyDiff(other);
861 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDiff(AliITSOnlineCalibrationSPDhandler* other) const {
862 // returns handler with dead/noisy in this' lists, except for those in other's lists
863 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
864 for (UInt_t module=0; module<240; module++) {
865 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
866 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
867 UInt_t eqId = GetEqIdFromKey(key);
868 UInt_t hs = GetHSFromKey(key);
869 UInt_t chip = GetChipFromKey(key);
870 UInt_t col = GetColFromKey(key);
871 UInt_t row = GetRowFromKey(key);
872 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
873 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
876 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
877 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
878 UInt_t eqId = GetEqIdFromKey(key);
879 UInt_t hs = GetHSFromKey(key);
880 UInt_t chip = GetChipFromKey(key);
881 UInt_t col = GetColFromKey(key);
882 UInt_t row = GetRowFromKey(key);
883 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
884 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
891 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
892 // returns handler with dead in this' lists, except for those in other's lists
893 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
894 for (UInt_t module=0; module<240; module++) {
895 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
896 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
897 UInt_t eqId = GetEqIdFromKey(key);
898 UInt_t hs = GetHSFromKey(key);
899 UInt_t chip = GetChipFromKey(key);
900 UInt_t col = GetColFromKey(key);
901 UInt_t row = GetRowFromKey(key);
902 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
903 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
910 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
911 // returns handler with noisy in this' lists, except for those in other's lists
912 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
913 for (UInt_t module=0; module<240; module++) {
914 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
915 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
916 UInt_t eqId = GetEqIdFromKey(key);
917 UInt_t hs = GetHSFromKey(key);
918 UInt_t chip = GetChipFromKey(key);
919 UInt_t col = GetColFromKey(key);
920 UInt_t row = GetRowFromKey(key);
921 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
922 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
929 void AliITSOnlineCalibrationSPDhandler::InitModuleMaps() {
930 // initializes the module mapping arrays needed for the methods below (GetEqIdFromOffline etc.)
931 for (UInt_t iDDL=0; iDDL<20; iDDL++) {
932 for (UInt_t iModule=0; iModule<12; iModule++) {
933 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(iDDL,iModule);
934 fiDDL[module] = iDDL;
935 fiModule[module] = iModule;
940 void AliITSOnlineCalibrationSPDhandler::GenerateDCSConfigFile(const Char_t* fileName) {
941 // generates an ascii file in the format as the one produced by online da (but with dummy runNr=0)
943 dcsfile.open(fileName);
944 dcsfile << "[SPD SCAN]\n";
945 dcsfile << "RunNumber=" << "0" << "\n"; // dummy value
946 dcsfile << "Type=" << "4" << "\n";
947 dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values
948 dcsfile << "[NOISY]\n";
949 for (UInt_t module=0; module<240; module++) {
950 UInt_t headkey=20*10*6;
951 for (UInt_t ind=0; ind<fNrNoisy[module]; ind++) {
952 UInt_t newkey = GetNoisyEqIdAt(module,ind)*10*6 +
953 GetNoisyHSAt(module,ind)*10 +
954 GetNoisyChipAt(module,ind);
955 if (newkey!=headkey) { // print eqId,hs,chip header
957 dcsfile << "-" << newkey/(6*10) << "," << (newkey%(6*10))/10 << "," << (newkey%(6*10))%10 << "\n";
959 dcsfile << GetNoisyColAt(module,ind) << "," << GetNoisyRowAt(module,ind) << "\n";
965 UInt_t AliITSOnlineCalibrationSPDhandler::GetEqIdFromOffline(UInt_t module) {
966 // module to eqId mapping
967 if (!fModuleMapInited) InitModuleMaps();
968 return fiDDL[module];
970 UInt_t AliITSOnlineCalibrationSPDhandler::GetHSFromOffline(UInt_t module) {
971 // module to hs mapping
972 if (!fModuleMapInited) InitModuleMaps();
973 return fiModule[module]/2;
975 UInt_t AliITSOnlineCalibrationSPDhandler::GetChipFromOffline(UInt_t module, UInt_t colM) {
976 // module,colM to chip mapping
977 if (!fModuleMapInited) InitModuleMaps();
978 return colM/32 + 5*(fiModule[module]%2);
980 UInt_t AliITSOnlineCalibrationSPDhandler::GetColFromOffline(UInt_t colM) const {
981 // colM to col mapping