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();
363 spdEntry->Add(calObj);
365 for(UInt_t module=0; module<240; module++){
366 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrDead( GetNrDead(module) );
367 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetDeadList( GetDeadArray(module) );
368 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNrNoisy( GetNrNoisy(module) );
369 ((AliITSCalibrationSPD*) spdEntry->At(module)) -> SetNoisyList( GetNoisyArray(module) );
371 AliCDBEntry* cdbEntry = new AliCDBEntry((TObject*)spdEntry,idCalSPD,metaData);
380 void AliITSOnlineCalibrationSPDhandler::WriteToFiles() {
381 // write the lists of dead and noisy to files (only if there are >0 dead or noisy pixels)
382 for (UInt_t module=0; module<240; module++) {
383 if (fNrDead[module]+fNrNoisy[module] > 0) {
388 void AliITSOnlineCalibrationSPDhandler::WriteToFile(UInt_t module) {
389 // write the lists of dead and noisy for module to file
390 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
391 calib->SetModuleNr(module);
392 calib->SetDeadList(GetDeadArray(module));
393 calib->SetNoisyList(GetNoisyArray(module));
394 calib->SetNrDead(GetNrDead(module));
395 calib->SetNrNoisy(GetNrNoisy(module));
396 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
397 TFile file(fileName.Data(), "RECREATE");
398 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
402 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFiles() {
403 // write the lists of dead to files (only if there are >0 dead pixels)
404 for (UInt_t module=0; module<240; module++) {
405 if (fNrDead[module] > 0) {
406 WriteDeadToFile(module);
410 void AliITSOnlineCalibrationSPDhandler::WriteDeadToFile(UInt_t module) {
411 // write the lists of dead for module to file
412 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
413 calib->SetModuleNr(module);
414 calib->SetDeadList(GetDeadArray(module));
415 calib->SetNrDead(GetNrDead(module));
416 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
417 TFile file(fileName.Data(), "RECREATE");
418 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
422 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFiles() {
423 // write the lists of noisy to files (only if there are >0 dead pixels)
424 for (UInt_t module=0; module<240; module++) {
425 if (fNrNoisy[module] > 0) {
426 printf("writing noisy to file for module %d\n",module);
427 WriteNoisyToFile(module);
431 void AliITSOnlineCalibrationSPDhandler::WriteNoisyToFile(UInt_t module) {
432 // write the lists of noisy for module to file
433 AliITSOnlineCalibrationSPD* calib = new AliITSOnlineCalibrationSPD();
434 calib->SetModuleNr(module);
435 calib->SetNoisyList(GetNoisyArray(module));
436 calib->SetNrNoisy(GetNrNoisy(module));
437 TString fileName = Form("%s/SPD_DeadNoisy_%d.root",fFileLocation.Data(),module);
438 TFile file(fileName.Data(), "RECREATE");
439 file.WriteTObject(calib, "AliITSOnlineCalibrationSPD");
444 TArrayI AliITSOnlineCalibrationSPDhandler::GetDeadArray(UInt_t module) {
445 // get a TArrayI of the dead pixels (format for the AliITSCalibrationSPD object)
447 returnArray.Set(GetNrDead(module)*2);
448 fDeadPixelMap[module]->PrepareSerialize(); // for tree ordered values
449 for (UInt_t index=0; index<GetNrDead(module); index++) {
450 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
451 Int_t colM = GetColMFromKey(key);
452 Int_t row = GetRowFromKey(key);
453 returnArray.AddAt(colM,index*2);
454 returnArray.AddAt(row,index*2+1);
458 TArrayI AliITSOnlineCalibrationSPDhandler::GetNoisyArray(UInt_t module) {
459 // get a TArrayI of the noisy pixels (format for the AliITSCalibrationSPD object)
461 returnArray.Set(GetNrNoisy(module)*2);
462 fNoisyPixelMap[module]->PrepareSerialize(); // for tree ordered values
463 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
464 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
465 Int_t colM = GetColMFromKey(key);
466 Int_t row = GetRowFromKey(key);
467 returnArray.AddAt(colM,index*2);
468 returnArray.AddAt(row,index*2+1);
473 void AliITSOnlineCalibrationSPDhandler::ResetDead() {
474 // reset the dead pixel map
475 for (UInt_t module=0; module<240; module++) {
477 fDeadPixelMap[module]->Clear();
481 void AliITSOnlineCalibrationSPDhandler::ResetDeadForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
482 // clear the noisy pixels for this chip
483 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
484 for (UInt_t col=0; col<32; col++) {
485 for (UInt_t row=0; row<256; row++) {
486 Int_t key = GetKey(eqId,hs,chip,col,row);
487 if (fDeadPixelMap[module]->Remove(key)) {
494 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
495 // set a dead pixel, returns false if pixel is already dead
496 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
497 Int_t key = GetKey(eqId,hs,chip,col,row);
498 //!!! // if noisy we dont want to add it...
499 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
500 if (fDeadPixelMap[module]->Insert(key,module)) {
507 Bool_t AliITSOnlineCalibrationSPDhandler::SetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row) {
508 // set a dead pixel, returns false if pixel is already dead
509 UInt_t eqId = GetEqIdFromOffline(module);
510 UInt_t hs = GetHSFromOffline(module);
511 UInt_t chip = GetChipFromOffline(module,colM);
512 UInt_t col = GetColFromOffline(colM);
513 Int_t key = GetKey(eqId,hs,chip,col,row);
514 //!!! // if noisy we dont want to add it...
515 //!!! if (fNoisyPixelMap[module]->Find(key) != NULL) return kFALSE;
516 if (fDeadPixelMap[module]->Insert(key,module)) {
523 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadKey(Int_t key) const {
524 // is this pixel noisy?
525 UInt_t eqId = GetEqIdFromKey(key);
526 UInt_t hs = GetHSFromKey(key);
527 UInt_t chip = GetChipFromKey(key);
528 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
529 return IsPixelDeadMKey(module,key);
532 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadMKey(UInt_t module, Int_t key) const {
533 // is this pixel dead?
534 if ( fDeadPixelMap[module]->Find(key) != NULL ) {
542 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDead(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
543 // is the pixel dead?
544 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
545 Int_t key = GetKey(eqId,hs,chip,col,row);
546 return IsPixelDeadMKey(module,key);
549 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelDeadM(UInt_t module, UInt_t colM, UInt_t row) {
550 // is the pixel dead?
551 UInt_t eqId = GetEqIdFromOffline(module);
552 UInt_t hs = GetHSFromOffline(module);
553 UInt_t chip = GetChipFromOffline(module,colM);
554 UInt_t col = GetColFromOffline(colM);
555 Int_t key = GetKey(eqId,hs,chip,col,row);
556 return IsPixelDeadMKey(module,key);
559 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead() const {
560 // returns the total nr of dead pixels
562 for (UInt_t module=0; module<240; module++) {
563 nrDead+=fNrDead[module];
568 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDead(UInt_t module) const {
569 // returns the number of dead pixels for a certain module
571 return fNrDead[module];
578 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt(UInt_t module, UInt_t index) {
579 // get eqId for the dead pixel at position index in list of dead
580 if (index<GetNrDead(module)) {
581 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
582 return GetEqIdFromKey(key);
585 Error("AliITSOnlineCalibrationSPDhandler::GetDeadEqIdAt", "Index %d out of bounds.", index);
589 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadHSAt(UInt_t module, UInt_t index) {
590 // get hs for the dead pixel at position index in list of dead
591 if (index<GetNrDead(module)) {
592 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
593 return GetHSFromKey(key);
596 Error("AliITSOnlineCalibrationSPDhandler::GetDeadHSAt", "Index %d out of bounds.", index);
600 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadChipAt(UInt_t module, UInt_t index) {
601 // get chip for the dead pixel at position index in list of dead
602 if (index<GetNrDead(module)) {
603 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
604 return GetChipFromKey(key);
607 Error("AliITSOnlineCalibrationSPDhandler::GetDeadChipAt", "Index %d out of bounds.", index);
611 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadColAt(UInt_t module, UInt_t index) {
612 // get column for the dead pixel at position index in list of dead
613 if (index<GetNrDead(module)) {
614 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
615 return GetColFromKey(key);
618 Error("AliITSOnlineCalibrationSPDhandler::GetDeadColAt", "Index %d out of bounds.", index);
622 UInt_t AliITSOnlineCalibrationSPDhandler::GetDeadRowAt(UInt_t module, UInt_t index) {
623 // get row for the dead pixel at position index in list of dead
624 if (index<GetNrDead(module)) {
625 Int_t key = fDeadPixelMap[module]->GetKeyIndex(index);
626 return GetRowFromKey(key);
629 Error("AliITSOnlineCalibrationSPDhandler::GetDeadRowAt", "Index %d out of bounds.", index);
634 void AliITSOnlineCalibrationSPDhandler::ResetNoisy() {
635 // clear the list of noisy pixels
636 for (UInt_t module=0; module<240; module++) {
638 fNoisyPixelMap[module]->Clear();
641 void AliITSOnlineCalibrationSPDhandler::ResetNoisyForChip(UInt_t eqId, UInt_t hs, UInt_t chip) {
642 // clear the noisy pixels for this chip
643 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
644 for (UInt_t col=0; col<32; col++) {
645 for (UInt_t row=0; row<256; row++) {
646 Int_t key = GetKey(eqId,hs,chip,col,row);
647 if (fNoisyPixelMap[module]->Remove(key)) {
655 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixel(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) {
656 // set a noisy pixel, returns false if already there
657 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
658 Int_t key = GetKey(eqId,hs,chip,col,row);
659 //!!! // if dead before - remove from the dead list
660 //!!! UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
661 //!!! if (fDeadPixelMap.Remove(key)) {
662 //!!! fNrDead[module]--;
664 if (fNoisyPixelMap[module]->Insert(key,col)) {
671 Bool_t AliITSOnlineCalibrationSPDhandler::SetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row) {
672 // set a noisy pixel, returns false if already there
673 UInt_t eqId = GetEqIdFromOffline(module);
674 UInt_t hs = GetHSFromOffline(module);
675 UInt_t chip = GetChipFromOffline(module,colM);
676 UInt_t col = GetColFromOffline(colM);
677 Int_t key = GetKey(eqId,hs,chip,col,row);
678 //!!! // if dead before - remove from the dead list
679 //!!! if (fDeadPixelMap[module]->Remove(key)) {
680 //!!! fNrDead[module]--;
682 if (fNoisyPixelMap[module]->Insert(key,col)) {
689 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyKey(Int_t key) const {
690 // is this pixel noisy?
691 UInt_t eqId = GetEqIdFromKey(key);
692 UInt_t hs = GetHSFromKey(key);
693 UInt_t chip = GetChipFromKey(key);
694 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
695 return IsPixelNoisyMKey(module,key);
698 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyMKey(UInt_t module, Int_t key) const {
699 // is this pixel noisy?
700 if ( fNoisyPixelMap[module]->Find(key) != NULL ) {
708 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisy(UInt_t eqId, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const {
709 // is this pixel noisy?
710 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,hs,chip);
711 Int_t key = GetKey(eqId,hs,chip,col,row);
712 return IsPixelNoisyMKey(module,key);
715 Bool_t AliITSOnlineCalibrationSPDhandler::IsPixelNoisyM(UInt_t module, UInt_t colM, UInt_t row) {
716 // is this pixel noisy?
717 UInt_t eqId = GetEqIdFromOffline(module);
718 UInt_t hs = GetHSFromOffline(module);
719 UInt_t chip = GetChipFromOffline(module,colM);
720 UInt_t col = GetColFromOffline(colM);
721 Int_t key = GetKey(eqId,hs,chip,col,row);
722 return IsPixelNoisyMKey(module,key);
725 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy() const {
726 // returns the total nr of noisy pixels
728 for (UInt_t module=0; module<240; module++) {
729 nrNoisy+=fNrNoisy[module];
734 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisy(UInt_t module) const {
735 // returns the number of noisy pixels for a certain module
737 return fNrNoisy[module];
744 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt(UInt_t module, UInt_t index) {
745 // get chip for the noisy pixel at position index in list of noisy
746 if (index<GetNrNoisy(module)) {
747 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
748 return GetEqIdFromKey(key);
751 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyEqIdAt", "Index %d out of bounds.", index);
755 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt(UInt_t module, UInt_t index) {
756 // get chip for the noisy pixel at position index in list of noisy
757 if (index<GetNrNoisy(module)) {
758 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
759 return GetHSFromKey(key);
762 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyHSAt", "Index %d out of bounds.", index);
766 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt(UInt_t module, UInt_t index) {
767 // get chip for the noisy pixel at position index in list of noisy
768 if (index<GetNrNoisy(module)) {
769 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
770 return GetChipFromKey(key);
773 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyChipAt", "Index %d out of bounds.", index);
777 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyColAt(UInt_t module, UInt_t index) {
778 // get column for the noisy pixel at position index in list of noisy
779 if (index<GetNrNoisy(module)) {
780 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
781 return GetColFromKey(key);
784 Warning("AliITSOnlineCalibrationSPDhandler::GetNoisyColAt", "Index %d out of bounds.", index);
788 UInt_t AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt(UInt_t module, UInt_t index) {
789 // get row for the noisy pixel at position index in list of noisy
790 if (index<GetNrNoisy(module)) {
791 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
792 return GetRowFromKey(key);
795 Error("AliITSOnlineCalibrationSPDhandler::GetNoisyRowAt", "Index %d out of bounds.", index);
800 void AliITSOnlineCalibrationSPDhandler::PrintDead() const {
801 // print the dead pixels to screen
802 printf("-----------------------------------\n");
803 printf("Dead 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<GetNrDead(module); index++) {
807 Int_t key = fDeadPixelMap[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 void AliITSOnlineCalibrationSPDhandler::PrintNoisy() const {
819 // print the dead pixels to screen
820 printf("-----------------------------------\n");
821 printf("Noisy Pixels: (eqId,hs,chip,col,row)\n");
822 printf("-----------------------------------\n");
823 for (UInt_t module=0; module<240; module++) {
824 for (UInt_t index=0; index<GetNrNoisy(module); index++) {
825 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(index);
826 UInt_t eqId = GetEqIdFromKey(key);
827 UInt_t hs = GetHSFromKey(key);
828 UInt_t chip = GetChipFromKey(key);
829 UInt_t col = GetColFromKey(key);
830 UInt_t row = GetRowFromKey(key);
831 printf("%d,%d,%d,%d,%d\n",eqId,hs,chip,col,row);
836 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
837 // returns nr of dead in this' lists and not in other's lists
839 for (UInt_t module=0; module<240; module++) {
840 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
841 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
842 UInt_t eqId = GetEqIdFromKey(key);
843 UInt_t hs = GetHSFromKey(key);
844 UInt_t chip = GetChipFromKey(key);
845 UInt_t col = GetColFromKey(key);
846 UInt_t row = GetRowFromKey(key);
847 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
855 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
856 // returns nr of noisy in this' lists and not in other's lists
858 for (UInt_t module=0; module<240; module++) {
859 for (UInt_t ind1=0; ind1<fNrNoisy[module]; ind1++) {
860 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind1);
861 UInt_t eqId = GetEqIdFromKey(key);
862 UInt_t hs = GetHSFromKey(key);
863 UInt_t chip = GetChipFromKey(key);
864 UInt_t col = GetColFromKey(key);
865 UInt_t row = GetRowFromKey(key);
866 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
874 UInt_t AliITSOnlineCalibrationSPDhandler::GetNrDiff(AliITSOnlineCalibrationSPDhandler* other) const {
875 // returns nr of dead/noisy in this' lists and not in other's lists
876 return GetNrDeadDiff(other) + GetNrNoisyDiff(other);
879 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDiff(AliITSOnlineCalibrationSPDhandler* other) const {
880 // returns handler with dead/noisy in this' lists, except for those in other's lists
881 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
882 for (UInt_t module=0; module<240; module++) {
883 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
884 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
885 UInt_t eqId = GetEqIdFromKey(key);
886 UInt_t hs = GetHSFromKey(key);
887 UInt_t chip = GetChipFromKey(key);
888 UInt_t col = GetColFromKey(key);
889 UInt_t row = GetRowFromKey(key);
890 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
891 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
894 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
895 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
896 UInt_t eqId = GetEqIdFromKey(key);
897 UInt_t hs = GetHSFromKey(key);
898 UInt_t chip = GetChipFromKey(key);
899 UInt_t col = GetColFromKey(key);
900 UInt_t row = GetRowFromKey(key);
901 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
902 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
909 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetDeadDiff(AliITSOnlineCalibrationSPDhandler* other) const {
910 // returns handler with dead in this' lists, except for those in other's lists
911 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
912 for (UInt_t module=0; module<240; module++) {
913 for (UInt_t ind1=0; ind1<fNrDead[module]; ind1++) {
914 Int_t key = fDeadPixelMap[module]->GetKeyIndex(ind1);
915 UInt_t eqId = GetEqIdFromKey(key);
916 UInt_t hs = GetHSFromKey(key);
917 UInt_t chip = GetChipFromKey(key);
918 UInt_t col = GetColFromKey(key);
919 UInt_t row = GetRowFromKey(key);
920 if (!(other->IsPixelDead(eqId,hs,chip,col,row))) {
921 newHandler->SetDeadPixel(eqId,hs,chip,col,row);
928 AliITSOnlineCalibrationSPDhandler* AliITSOnlineCalibrationSPDhandler::GetNoisyDiff(AliITSOnlineCalibrationSPDhandler* other) const {
929 // returns handler with noisy in this' lists, except for those in other's lists
930 AliITSOnlineCalibrationSPDhandler* newHandler = new AliITSOnlineCalibrationSPDhandler();
931 for (UInt_t module=0; module<240; module++) {
932 for (UInt_t ind2=0; ind2<fNrNoisy[module]; ind2++) {
933 Int_t key = fNoisyPixelMap[module]->GetKeyIndex(ind2);
934 UInt_t eqId = GetEqIdFromKey(key);
935 UInt_t hs = GetHSFromKey(key);
936 UInt_t chip = GetChipFromKey(key);
937 UInt_t col = GetColFromKey(key);
938 UInt_t row = GetRowFromKey(key);
939 if (!(other->IsPixelNoisy(eqId,hs,chip,col,row))) {
940 newHandler->SetNoisyPixel(eqId,hs,chip,col,row);
947 void AliITSOnlineCalibrationSPDhandler::InitModuleMaps() {
948 // initializes the module mapping arrays needed for the methods below (GetEqIdFromOffline etc.)
949 for (UInt_t iDDL=0; iDDL<20; iDDL++) {
950 for (UInt_t iModule=0; iModule<12; iModule++) {
951 UInt_t module = AliITSRawStreamSPD::GetModuleNumber(iDDL,iModule);
952 fiDDL[module] = iDDL;
953 fiModule[module] = iModule;
958 void AliITSOnlineCalibrationSPDhandler::GenerateDCSConfigFile(const Char_t* fileName) {
959 // generates an ascii file in the format as the one produced by online da (but with dummy runNr=0)
961 dcsfile.open(fileName);
962 dcsfile << "[SPD SCAN]\n";
963 dcsfile << "RunNumber=" << "0" << "\n"; // dummy value
964 dcsfile << "Type=" << "4" << "\n";
965 dcsfile << "Router=" << "0" << "\n"; // dummy value
966 dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values
967 dcsfile << "[NOISY]\n";
968 for (UInt_t module=0; module<240; module++) {
969 UInt_t headkey=20*10*6;
970 for (UInt_t ind=0; ind<fNrNoisy[module]; ind++) {
971 UInt_t newkey = GetNoisyEqIdAt(module,ind)*10*6 +
972 GetNoisyHSAt(module,ind)*10 +
973 GetNoisyChipAt(module,ind);
974 if (newkey!=headkey) { // print eqId,hs,chip header
976 dcsfile << "-" << newkey/(6*10) << "," << (newkey%(6*10))/10 << "," << (newkey%(6*10))%10 << "\n";
978 dcsfile << GetNoisyColAt(module,ind) << "," << GetNoisyRowAt(module,ind) << "\n";
984 UInt_t AliITSOnlineCalibrationSPDhandler::GetEqIdFromOffline(UInt_t module) {
985 // module to eqId mapping
986 if (!fModuleMapInited) InitModuleMaps();
987 return fiDDL[module];
989 UInt_t AliITSOnlineCalibrationSPDhandler::GetHSFromOffline(UInt_t module) {
990 // module to hs mapping
991 if (!fModuleMapInited) InitModuleMaps();
992 return fiModule[module]/2;
994 UInt_t AliITSOnlineCalibrationSPDhandler::GetChipFromOffline(UInt_t module, UInt_t colM) {
995 // module,colM to chip mapping
996 if (!fModuleMapInited) InitModuleMaps();
997 return colM/32 + 5*(fiModule[module]%2);
999 UInt_t AliITSOnlineCalibrationSPDhandler::GetColFromOffline(UInt_t colM) const {
1000 // colM to col mapping