|
| 1 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 2 | +#include "CCDB/BasicCCDBManager.h" |
| 3 | +#include "TH2I.h" |
| 4 | +#include "TCanvas.h" |
| 5 | +#include "CCDB/CCDBTimeStampUtils.h" |
| 6 | +#include "CPVBase/Geometry.h" |
| 7 | +#include "DataFormatsCPV/BadChannelMap.h" |
| 8 | +#endif |
| 9 | + |
| 10 | +void makeBadMapFromPedestalRun(const char* ccdbURI = "http://ccdb-test.cern.ch:8080", long timeStamp = 0) |
| 11 | +{ |
| 12 | + // ccdbURI -> CCDB instance |
| 13 | + // timeStamp -> time in milliseconds (wow!) (starting at 00:00 on 1.1.1970) |
| 14 | + // timeStamp == 0 -> current time |
| 15 | + auto& ccdbMgr = o2::ccdb::BasicCCDBManager::instance(); |
| 16 | + ccdbMgr.setURL(ccdbURI); |
| 17 | + if (!ccdbMgr.isHostReachable()) { |
| 18 | + std::cerr << ccdbURI << " is not reachable!" << std::endl; |
| 19 | + return; |
| 20 | + } |
| 21 | + if (timeStamp == 0) { |
| 22 | + timeStamp = o2::ccdb::getCurrentTimestamp(); |
| 23 | + } |
| 24 | + ccdbMgr.setTimestamp(timeStamp); |
| 25 | + std::vector<float>* effs = ccdbMgr.get<std::vector<float>>("CPV/PedestalRun/ChannelEfficiencies"); |
| 26 | + if (!effs) { |
| 27 | + std::cerr << "Cannot get Efficiencies from CCDB/CPV/PedestalRun/ChannelEfficiencies!" << std::endl; |
| 28 | + } |
| 29 | + |
| 30 | + std::vector<int>* dead = ccdbMgr.get<std::vector<int>>("CPV/PedestalRun/DeadChannels"); |
| 31 | + if (!dead) { |
| 32 | + std::cerr << "Cannot get dead channels from CCDB/CPV/PedestalRun/DeadChannels!" << std::endl; |
| 33 | + } |
| 34 | + |
| 35 | + std::vector<int>* highPed = ccdbMgr.get<std::vector<int>>("CPV/PedestalRun/HighPedChannels"); |
| 36 | + if (!highPed) { |
| 37 | + std::cerr << "Cannot get high ped channels from CCDB/CPV/PedestalRun/HighPedChannels!" << std::endl; |
| 38 | + } |
| 39 | + |
| 40 | + bool badMapBool[23040] = {false}; |
| 41 | + for (int i = 0; i < 23040; i++) { |
| 42 | + badMapBool[i] = false; |
| 43 | + if (effs->at(i) > 1.1) { |
| 44 | + badMapBool[i] = true; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + for (int i = 0; i < dead->size(); i++) { |
| 49 | + badMapBool[dead->at(i)] = true; |
| 50 | + } |
| 51 | + |
| 52 | + for (int i = 0; i < highPed->size(); i++) { |
| 53 | + badMapBool[highPed->at(i)] = true; |
| 54 | + } |
| 55 | + |
| 56 | + o2::cpv::Geometry geo; |
| 57 | + short relId[3]; |
| 58 | + o2::cpv::BadChannelMap badMap(1); |
| 59 | + TH2I* hBadMap[3]; |
| 60 | + for (int iMod = 0; iMod < 3; iMod++) { |
| 61 | + hBadMap[iMod] = new TH2I(Form("hBadMapM%d", iMod + 2), |
| 62 | + Form("Bad channels in M%d", iMod + 2), |
| 63 | + 128, 0., 128., 60, 0., 60); |
| 64 | + for (int iCh = iMod * 7680; iCh < (iMod + 1) * 7680; iCh++) { |
| 65 | + if (badMapBool[iCh]) { |
| 66 | + geo.absToRelNumbering(iCh, relId); |
| 67 | + hBadMap[iMod]->SetBinContent(relId[1] + 1, relId[2] + 1, 1); |
| 68 | + badMap.addBadChannel(iCh); |
| 69 | + } |
| 70 | + } |
| 71 | + TCanvas* can = new TCanvas(Form("canM%d", iMod + 2), Form("module M%d", iMod + 2), 10 * iMod, 0, 1000 + 10 * iMod, 1000); |
| 72 | + can->Divide(1, 1); |
| 73 | + can->cd(1); |
| 74 | + hBadMap[iMod]->Draw("colz"); |
| 75 | + } |
| 76 | + |
| 77 | + o2::ccdb::CcdbApi api; |
| 78 | + map<string, string> metadata; // can be empty |
| 79 | + api.init(ccdbURI); // or http://localhost:8080 for a local installation |
| 80 | + api.storeAsTFileAny(&badMap, "CPV/Calib/BadChannelMap", metadata, timeStamp, timeStamp + 31536000000); |
| 81 | +} |
0 commit comments