File indexing completed on 2024-09-07 04:35:43
0001 #include "CondTools/Ecal/interface/EcalDCSHandler.h"
0002 #include "CondFormats/EcalObjects/interface/EcalDCSTowerStatusHelper.h"
0003 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0004
0005 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007
0008 #include <iostream>
0009
0010 popcon::EcalDCSHandler::EcalDCSHandler(const edm::ParameterSet& ps)
0011 : m_name(ps.getUntrackedParameter<std::string>("name", "EcalDCSHandler")) {
0012 std::cout << "EcalDCS Source handler constructor\n" << std::endl;
0013 m_firstRun = (unsigned long)atoi(ps.getParameter<std::string>("firstRun").c_str());
0014 m_lastRun = (unsigned long)atoi(ps.getParameter<std::string>("lastRun").c_str());
0015 m_sid = ps.getParameter<std::string>("OnlineDBSID");
0016 m_user = ps.getParameter<std::string>("OnlineDBUser");
0017 m_pass = ps.getParameter<std::string>("OnlineDBPassword");
0018
0019 std::cout << m_sid << "/" << m_user << std::endl;
0020 }
0021
0022 popcon::EcalDCSHandler::~EcalDCSHandler() {}
0023
0024 void popcon::EcalDCSHandler::printHVDataSet(const std::map<EcalLogicID, RunDCSHVDat>* dataset, int limit = 0) const {
0025 std::cout << "==========printDataSet()" << std::endl;
0026 if (dataset->empty()) {
0027 std::cout << "No data in map!" << std::endl;
0028 }
0029 EcalLogicID ecid;
0030 RunDCSHVDat hv;
0031
0032 int count = 0;
0033 typedef std::map<EcalLogicID, RunDCSHVDat>::const_iterator CI;
0034 for (CI p = dataset->begin(); p != dataset->end(); ++p) {
0035 count++;
0036 if (limit && count > limit) {
0037 return;
0038 }
0039 ecid = p->first;
0040 hv = p->second;
0041
0042 std::cout << "SM: " << ecid.getID1() << std::endl;
0043 std::cout << "Channel: " << ecid.getID2() << std::endl;
0044 std::cout << "HV: " << hv.getHV() << std::endl;
0045 std::cout << "HV nominal: " << hv.getHVNominal() << std::endl;
0046 std::cout << "HV status: " << hv.getStatus() << std::endl;
0047 std::cout << "========================" << std::endl;
0048 }
0049 std::cout << std::endl;
0050 }
0051
0052 void popcon::EcalDCSHandler::printLVDataSet(const std::map<EcalLogicID, RunDCSLVDat>* dataset, int limit = 0) const {
0053 std::cout << "==========printDataSet()" << std::endl;
0054 if (dataset->empty()) {
0055 std::cout << "No data in map!" << std::endl;
0056 }
0057 EcalLogicID ecid;
0058 RunDCSLVDat lv;
0059
0060 int count = 0;
0061 typedef std::map<EcalLogicID, RunDCSLVDat>::const_iterator CI;
0062 for (CI p = dataset->begin(); p != dataset->end(); ++p) {
0063 count++;
0064 if (limit && count > limit) {
0065 return;
0066 }
0067 ecid = p->first;
0068 lv = p->second;
0069
0070 std::cout << "SM: " << ecid.getID1() << std::endl;
0071 std::cout << "Channel: " << ecid.getID2() << std::endl;
0072 std::cout << "LV: " << lv.getLV() << std::endl;
0073 std::cout << "LV nominal: " << lv.getLVNominal() << std::endl;
0074 std::cout << "LV status: " << lv.getStatus() << std::endl;
0075 std::cout << "========================" << std::endl;
0076 }
0077 std::cout << std::endl;
0078 }
0079
0080 uint16_t popcon::EcalDCSHandler::OffDBStatus(uint16_t dbStatus, int pos) {
0081 uint16_t hv_off_dbstatus = (dbStatus & (1 << pos));
0082 if (hv_off_dbstatus > 0)
0083 hv_off_dbstatus = 1;
0084 return hv_off_dbstatus;
0085 }
0086
0087 uint16_t popcon::EcalDCSHandler::updateHV(RunDCSHVDat* hv, uint16_t dbStatus, int mode) const {
0088
0089
0090 uint16_t result = 0;
0091 uint16_t hv_on_dbstatus = 0;
0092 uint16_t hv_nomi_on_dbstatus = 0;
0093
0094 if (hv->getStatus() == RunDCSHVDat::HVNOTNOMINAL)
0095 hv_nomi_on_dbstatus = 1;
0096 if (hv->getStatus() == RunDCSHVDat::HVOFF)
0097 hv_on_dbstatus = 1;
0098
0099 uint16_t temp = 0;
0100
0101 if (mode == 0 || mode == 1) {
0102 for (int i = 0; i < 16; i++) {
0103 if (i != EcalDCSTowerStatusHelper::HVSTATUS && i != EcalDCSTowerStatusHelper::HVNOMINALSTATUS) {
0104 temp = temp | (1 << i);
0105 } else {
0106 temp = temp | (0 << i);
0107 }
0108 }
0109 result = dbStatus & temp;
0110 result = (result | (hv_on_dbstatus << EcalDCSTowerStatusHelper::HVSTATUS)) |
0111 (hv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::HVNOMINALSTATUS);
0112 } else {
0113 for (int i = 0; i < 16; i++) {
0114 if (i != EcalDCSTowerStatusHelper::HVEEDNOMINALSTATUS && i != EcalDCSTowerStatusHelper::HVEEDSTATUS) {
0115 temp = temp | (1 << i);
0116 } else {
0117 temp = temp | (0 << i);
0118 }
0119 }
0120 result = dbStatus & temp;
0121 result = (result | (hv_on_dbstatus << EcalDCSTowerStatusHelper::HVEEDSTATUS)) |
0122 (hv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::HVEEDNOMINALSTATUS);
0123 }
0124
0125 return result;
0126 }
0127
0128 uint16_t popcon::EcalDCSHandler::updateLV(RunDCSLVDat* lv, uint16_t dbStatus) const {
0129 uint16_t result = 0;
0130 uint16_t lv_on_dbstatus = 0;
0131 uint16_t lv_nomi_on_dbstatus = 0;
0132 if (lv->getStatus() == RunDCSLVDat::LVNOTNOMINAL)
0133 lv_nomi_on_dbstatus = 1;
0134 if (lv->getStatus() == RunDCSLVDat::LVOFF)
0135 lv_on_dbstatus = 1;
0136
0137 uint16_t temp = 0;
0138 for (int i = 0; i < 16; i++) {
0139 if (i != EcalDCSTowerStatusHelper::LVSTATUS && i != EcalDCSTowerStatusHelper::LVNOMINALSTATUS) {
0140 temp = temp | (1 << i);
0141 } else {
0142 temp = temp | (0 << i);
0143 }
0144 }
0145
0146 result = dbStatus & temp;
0147 result = (result | (lv_on_dbstatus << EcalDCSTowerStatusHelper::LVSTATUS)) |
0148 (lv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::LVNOMINALSTATUS);
0149
0150 return result;
0151 }
0152
0153 bool popcon::EcalDCSHandler::insertHVDataSetToOffline(const std::map<EcalLogicID, RunDCSHVDat>* dataset,
0154 EcalDCSTowerStatus* dcs_temp) const {
0155 bool result = false;
0156 if (dataset->empty()) {
0157 std::cout << "No data in std::map!" << std::endl;
0158 }
0159 EcalLogicID ecid;
0160 RunDCSHVDat hv;
0161
0162 typedef std::map<EcalLogicID, RunDCSHVDat>::const_iterator CI;
0163
0164 for (CI p = dataset->begin(); p != dataset->end(); ++p) {
0165 ecid = p->first;
0166 hv = p->second;
0167
0168 if (ecid.getName() == "EB_HV_channel") {
0169 int sm = ecid.getID1();
0170 int chan = ecid.getID2();
0171
0172 int* limits = nullptr;
0173 limits = HVLogicIDToDetID(sm, chan);
0174 int iz = limits[0];
0175 int i1 = limits[1];
0176 int i2 = limits[2];
0177 int j = limits[3];
0178
0179 for (int ik = i1; ik <= i2; ik++) {
0180 if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, ik)) {
0181 EcalTrigTowerDetId ebid(iz, EcalBarrel, j, ik);
0182 EcalDCSTowerStatus::const_iterator it = dcs_temp->find(ebid.rawId());
0183
0184 uint16_t dbStatus = 0;
0185 if (it != dcs_temp->end()) {
0186 dbStatus = it->getStatusCode();
0187 }
0188 int modo = 0;
0189 uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
0190 if (new_dbStatus != dbStatus)
0191 result = true;
0192
0193 dcs_temp->setValue(ebid, new_dbStatus);
0194
0195 if (new_dbStatus != dbStatus) {
0196 std::cout << "SM/chan:" << sm << "/" << chan << " new db status =" << new_dbStatus << " old " << dbStatus
0197 << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
0198 }
0199 }
0200 }
0201 delete[] limits;
0202 } else {
0203
0204 int dee = ecid.getID1();
0205 int chan = ecid.getID2();
0206
0207 int* limits = nullptr;
0208 limits = HVEELogicIDToDetID(dee, chan);
0209 int iz = limits[0];
0210 int i1 = limits[1];
0211 int i2 = limits[2];
0212 int j1 = limits[3];
0213 int j2 = limits[4];
0214
0215 int ex_x[6];
0216 int ex_y[6];
0217 if (dee == 1) {
0218 ex_x[0] = 4;
0219 ex_y[0] = 8;
0220 ex_x[1] = 4;
0221 ex_y[1] = 9;
0222 ex_x[2] = 4;
0223 ex_y[2] = 10;
0224 ex_x[3] = 5;
0225 ex_y[3] = 9;
0226 ex_x[4] = 5;
0227 ex_y[4] = 10;
0228 ex_x[5] = 6;
0229 ex_y[5] = 10;
0230 } else if (dee == 2) {
0231 ex_x[0] = 17;
0232 ex_y[0] = 11;
0233 ex_x[1] = 17;
0234 ex_y[1] = 12;
0235 ex_x[2] = 17;
0236 ex_y[2] = 13;
0237 ex_x[3] = 16;
0238 ex_y[3] = 11;
0239 ex_x[4] = 16;
0240 ex_y[4] = 12;
0241 ex_x[5] = 15;
0242 ex_y[5] = 11;
0243 } else if (dee == 3) {
0244 ex_x[0] = 17;
0245 ex_y[0] = 8;
0246 ex_x[1] = 17;
0247 ex_y[1] = 9;
0248 ex_x[2] = 17;
0249 ex_y[2] = 10;
0250 ex_x[3] = 16;
0251 ex_y[3] = 9;
0252 ex_x[4] = 16;
0253 ex_y[4] = 10;
0254 ex_x[5] = 15;
0255 ex_y[5] = 10;
0256 } else if (dee == 4) {
0257 ex_x[0] = 4;
0258 ex_y[0] = 11;
0259 ex_x[1] = 4;
0260 ex_y[1] = 12;
0261 ex_x[2] = 4;
0262 ex_y[2] = 13;
0263 ex_x[3] = 5;
0264 ex_y[3] = 11;
0265 ex_x[4] = 5;
0266 ex_y[4] = 12;
0267 ex_x[5] = 6;
0268 ex_y[5] = 11;
0269 } else {
0270 throw cms::Exception("Invalid EcalLogicID") << "Unknown ECAL Endcap Dee number " << dee;
0271 }
0272
0273 int modo = 1;
0274 if (ecid.getName() == "EE_HVD_channel")
0275 modo = 2;
0276
0277 for (int ik = i1; ik <= i2; ik++) {
0278 for (int ip = j1; ip <= j2; ip++) {
0279 bool not_excluded = true;
0280 if (chan == 2) {
0281 for (int l = 0; l < 6; l++) {
0282 if (ik == ex_x[l] && ip == ex_y[l])
0283 not_excluded = false;
0284 }
0285 }
0286 if (not_excluded) {
0287 if (EcalScDetId::validDetId(ik, ip, iz)) {
0288 EcalScDetId eeid(ik, ip, iz);
0289 EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
0290
0291 uint16_t dbStatus = 0;
0292 if (it != dcs_temp->end()) {
0293 dbStatus = it->getStatusCode();
0294 }
0295
0296 uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
0297 if (new_dbStatus != dbStatus)
0298 result = true;
0299
0300 dcs_temp->setValue(eeid, new_dbStatus);
0301
0302 if (new_dbStatus != dbStatus) {
0303 std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
0304 << dbStatus << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
0305 }
0306 }
0307 }
0308 }
0309 }
0310 if (chan == 1) {
0311 for (int l = 0; l < 6; l++) {
0312 int ik = ex_x[l];
0313 int ip = ex_y[l];
0314 if (EcalScDetId::validDetId(ik, ip, iz)) {
0315 EcalScDetId eeid(ik, ip, iz);
0316 EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
0317
0318 uint16_t dbStatus = 0;
0319 if (it != dcs_temp->end()) {
0320 dbStatus = it->getStatusCode();
0321 }
0322 uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
0323 if (new_dbStatus != dbStatus)
0324 result = true;
0325
0326 dcs_temp->setValue(eeid, new_dbStatus);
0327
0328 if (new_dbStatus != dbStatus) {
0329 std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
0330 << dbStatus << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
0331 }
0332 }
0333 }
0334 }
0335
0336 delete[] limits;
0337 }
0338 }
0339 return result;
0340 }
0341
0342 int popcon::EcalDCSHandler::detIDToLogicID(int iz, int i, int j) {
0343
0344
0345 int sm = 0;
0346 int hv_chan = 0;
0347
0348 sm = (i - 1) / 4;
0349 if (iz < 0)
0350 sm = sm + 18;
0351
0352 int ilocal = (i - 1) - sm * 4;
0353 if (iz < 0) {
0354 if (ilocal == 0 || ilocal == 1)
0355 hv_chan = 1;
0356 if (ilocal == 2 || ilocal == 3)
0357 hv_chan = 2;
0358 } else {
0359 if (ilocal == 0 || ilocal == 1)
0360 hv_chan = 2;
0361 if (ilocal == 2 || ilocal == 3)
0362 hv_chan = 1;
0363 }
0364
0365 sm = sm + 1;
0366
0367 hv_chan = (j - 1) * 2 + hv_chan;
0368
0369 hv_chan = (sm - 1) * 34 + hv_chan - 1;
0370
0371 return hv_chan;
0372 }
0373
0374 int* popcon::EcalDCSHandler::HVEELogicIDToDetID(int dee, int chan) const {
0375 int iz = -1;
0376 if (dee == 1 || dee == 2)
0377 iz = 1;
0378 int ix1 = 1;
0379 int ix2 = 1;
0380 int iy1 = 1;
0381 int iy2 = 1;
0382
0383 if (dee == 1 && chan == 1) {
0384 ix1 = 1;
0385 ix2 = 10;
0386 iy1 = 11;
0387 iy2 = 20;
0388 } else if (dee == 2 && chan == 1) {
0389 ix1 = 11;
0390 ix2 = 20;
0391 iy1 = 1;
0392 iy2 = 10;
0393 } else if (dee == 3 && chan == 1) {
0394 ix1 = 11;
0395 ix2 = 20;
0396 iy1 = 11;
0397 iy2 = 20;
0398 } else if (dee == 4 && chan == 1) {
0399 ix1 = 1;
0400 ix2 = 10;
0401 iy1 = 1;
0402 iy2 = 10;
0403 } else if (dee == 1 && chan == 2) {
0404 ix1 = 1;
0405 ix2 = 10;
0406 iy1 = 1;
0407 iy2 = 10;
0408 } else if (dee == 2 && chan == 2) {
0409 ix1 = 11;
0410 ix2 = 20;
0411 iy1 = 11;
0412 iy2 = 20;
0413 } else if (dee == 3 && chan == 2) {
0414 ix1 = 11;
0415 ix2 = 20;
0416 iy1 = 1;
0417 iy2 = 10;
0418 } else if (dee == 4 && chan == 2) {
0419 ix1 = 1;
0420 ix2 = 10;
0421 iy1 = 11;
0422 iy2 = 20;
0423 }
0424
0425 int* result = new int[5];
0426
0427 result[0] = iz;
0428 result[1] = ix1;
0429 result[2] = ix2;
0430 result[3] = iy1;
0431 result[4] = iy2;
0432 return result;
0433 }
0434
0435 int* popcon::EcalDCSHandler::HVLogicIDToDetID(int sm, int chan) const {
0436
0437
0438 int iz = -1;
0439 if (sm > 0 && sm <= 18)
0440 iz = 1;
0441 int j = (chan - 1) / 2 + 1;
0442 int i_local_hv = (chan - 1) - (j - 1) * 2 + 1;
0443 int i1 = 0;
0444 int i2 = 0;
0445 if (iz > 0) {
0446 if (i_local_hv == 1) {
0447 i1 = 3;
0448 i2 = 4;
0449 } else {
0450 i1 = 1;
0451 i2 = 2;
0452 }
0453 } else {
0454 if (i_local_hv == 1) {
0455 i1 = 1;
0456 i2 = 2;
0457 } else {
0458 i1 = 3;
0459 i2 = 4;
0460 }
0461 }
0462 int ioffset = 0;
0463 if (iz == 1)
0464 ioffset = (sm - 1) * 4;
0465 if (iz == -1)
0466 ioffset = (sm - 18 - 1) * 4;
0467 i1 = i1 + ioffset;
0468 i2 = i2 + ioffset;
0469
0470 int* result = new int[5];
0471
0472 result[0] = iz;
0473 result[1] = i1;
0474 result[2] = i2;
0475 result[3] = j;
0476 result[4] = j;
0477
0478 return result;
0479 }
0480
0481 int* popcon::EcalDCSHandler::LVLogicIDToDetID(int sm, int chan) const {
0482
0483
0484 int iz = -1;
0485 if (sm > 0 && sm <= 18)
0486 iz = 1;
0487
0488 int j1 = 0;
0489 int j2 = 0;
0490 int i1 = 0;
0491 int i2 = 0;
0492
0493 if (chan == 1) {
0494 i1 = 1;
0495 i2 = 4;
0496 j1 = 1;
0497 j2 = 1;
0498 } else {
0499 int ch2 = (chan / 2) * 2;
0500 if (ch2 == chan) {
0501 j1 = chan;
0502 } else {
0503 j1 = chan - 1;
0504 }
0505 j2 = j1 + 1;
0506 if (iz > 0) {
0507 if (ch2 == chan) {
0508 i1 = 3;
0509 i2 = 4;
0510 } else {
0511 i1 = 1;
0512 i2 = 2;
0513 }
0514 } else {
0515 if (ch2 == chan) {
0516 i1 = 1;
0517 i2 = 2;
0518 } else {
0519 i1 = 3;
0520 i2 = 4;
0521 }
0522 }
0523 }
0524 int ioffset = 0;
0525 if (iz == 1)
0526 ioffset = (sm - 1) * 4;
0527 if (iz == -1)
0528 ioffset = (sm - 18 - 1) * 4;
0529 i1 = i1 + ioffset;
0530 i2 = i2 + ioffset;
0531
0532 int* result = new int[5];
0533 result[0] = iz;
0534 result[1] = i1;
0535 result[2] = i2;
0536 result[3] = j1;
0537 result[4] = j2;
0538
0539 return result;
0540 }
0541
0542 bool popcon::EcalDCSHandler::insertLVDataSetToOffline(const std::map<EcalLogicID, RunDCSLVDat>* dataset,
0543 EcalDCSTowerStatus* dcs_temp,
0544 const std::vector<EcalLogicID>& my_EELVchan) const {
0545 bool result = false;
0546 if (dataset->empty()) {
0547 std::cout << "No data in map!" << std::endl;
0548 }
0549 EcalLogicID ecid;
0550 RunDCSLVDat lv;
0551
0552 typedef std::map<EcalLogicID, RunDCSLVDat>::const_iterator CI;
0553 for (CI p = dataset->begin(); p != dataset->end(); ++p) {
0554 ecid = p->first;
0555 lv = p->second;
0556
0557 if (ecid.getName() == "EB_LV_channel") {
0558 int sm = ecid.getID1();
0559 int chan = ecid.getID2();
0560
0561 int* limits = nullptr;
0562 limits = LVLogicIDToDetID(sm, chan);
0563 int iz = limits[0];
0564 int i1 = limits[1];
0565 int i2 = limits[2];
0566 int j1 = limits[3];
0567 int j2 = limits[4];
0568
0569 for (int ik = i1; ik <= i2; ik++) {
0570 for (int j = j1; j <= j2; j++) {
0571 if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, ik)) {
0572 EcalTrigTowerDetId ebid(iz, EcalBarrel, j, ik);
0573 EcalDCSTowerStatus::const_iterator it = dcs_temp->find(ebid.rawId());
0574 uint16_t dbStatus = 0;
0575 if (it != dcs_temp->end()) {
0576 dbStatus = it->getStatusCode();
0577 }
0578 uint16_t new_dbStatus = updateLV(&lv, dbStatus);
0579 if (new_dbStatus != dbStatus)
0580 result = true;
0581 dcs_temp->setValue(ebid, new_dbStatus);
0582
0583 if (new_dbStatus != dbStatus) {
0584 std::cout << "SM/chan:" << sm << "/" << chan << " new db status =" << new_dbStatus << " old " << dbStatus
0585 << " LV: " << lv.getLV() << "/" << lv.getLVNominal() << std::endl;
0586 }
0587 }
0588 }
0589 }
0590 delete[] limits;
0591
0592 } else {
0593
0594 int dee = ecid.getID1();
0595 int chan = ecid.getID2();
0596 int n = my_EELVchan.size();
0597
0598 for (int ixt = 0; ixt < n; ixt++) {
0599 if (my_EELVchan[ixt].getID1() == dee && my_EELVchan[ixt].getID2() == chan) {
0600 int ilogic = my_EELVchan[ixt].getLogicID();
0601
0602 if (ilogic == 2012058060 || ilogic == 2010060058 || ilogic == 2012043041 || ilogic == 2010041043) {
0603 std::cout << "crystal " << ilogic << " in the corner ignored" << std::endl;
0604 } else {
0605 int iz = (ilogic / 1000000) - 2010;
0606 if (iz == 0)
0607 iz = -1;
0608 if (iz == 2)
0609 iz = 1;
0610 if (iz != 1 && iz != -1)
0611 std::cout << "BAD z" << std::endl;
0612
0613 int iy = ilogic - int(ilogic / 1000) * 1000;
0614
0615 int ix = (ilogic - int(ilogic / 1000000) * 1000000 - iy) / 1000;
0616
0617 int ixtower = ((ix - 1) / 5) + 1;
0618 int iytower = ((iy - 1) / 5) + 1;
0619
0620 if (ixtower < 1 || ixtower > 20 || iytower < 1 || iytower > 20)
0621 std::cout << "BAD x/y" << ilogic << "/" << ixtower << "/" << iytower << std::endl;
0622
0623 if (EcalScDetId::validDetId(ixtower, iytower, iz)) {
0624 EcalScDetId eeid(ixtower, iytower, iz);
0625 EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
0626 uint16_t dbStatus = 0;
0627 if (it != dcs_temp->end()) {
0628 dbStatus = it->getStatusCode();
0629 }
0630
0631 uint16_t new_dbStatus = updateLV(&lv, dbStatus);
0632 if (new_dbStatus != dbStatus)
0633 result = true;
0634 dcs_temp->setValue(eeid, new_dbStatus);
0635
0636
0637
0638 if (new_dbStatus != dbStatus) {
0639 std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
0640 << dbStatus << " LV: " << lv.getLV() << "/" << lv.getLVNominal() << std::endl;
0641 }
0642 }
0643 }
0644 }
0645 }
0646
0647 }
0648 }
0649 return result;
0650 }
0651
0652 void popcon::EcalDCSHandler::getNewObjects() {
0653 bool lot_of_printout = false;
0654 std::cout << "------- Ecal DCS - > getNewObjects\n";
0655
0656 std::ostringstream ss;
0657 ss << "ECAL ";
0658
0659 unsigned long long max_since = 1;
0660
0661
0662 EcalDCSTowerStatus* dcs_temp = new EcalDCSTowerStatus();
0663 if (tagInfo().size) {
0664 max_since = tagInfo().lastInterval.since;
0665 Ref dcs_db = lastPayload();
0666 std::cout << "retrieved last payload " << std::endl;
0667
0668
0669 int iz = 0;
0670 for (int k = 0; k < 2; k++) {
0671 if (k == 0)
0672 iz = -1;
0673 if (k == 1)
0674 iz = 1;
0675 for (int i = 1; i < 73; i++) {
0676 for (int j = 1; j < 18; j++) {
0677 if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, i)) {
0678 EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
0679
0680 uint16_t dbStatus = 0;
0681 dbStatus = (dcs_db->barrel(ebid.hashedIndex())).getStatusCode();
0682
0683 EcalDCSTowerStatus::const_iterator it = dcs_db->find(ebid.rawId());
0684 if (it != dcs_db->end()) {
0685 } else {
0686 std::cout << "*** error channel not found: j/i=" << j << "/" << i << std::endl;
0687 }
0688 dcs_temp->setValue(ebid, dbStatus);
0689 }
0690 }
0691 }
0692 }
0693
0694
0695 for (int k = 0; k < 2; k++) {
0696 if (k == 0)
0697 iz = -1;
0698 if (k == 1)
0699 iz = +1;
0700 for (int i = 1; i < 21; i++) {
0701 for (int j = 1; j < 21; j++) {
0702 if (EcalScDetId::validDetId(i, j, iz)) {
0703 EcalScDetId eeid(i, j, iz);
0704
0705 EcalDCSTowerStatus::const_iterator it = dcs_db->find(eeid.rawId());
0706
0707 uint16_t dbStatus = 0;
0708 if (it != dcs_db->end()) {
0709 dbStatus = it->getStatusCode();
0710 }
0711 dcs_temp->setValue(eeid, dbStatus);
0712 }
0713 }
0714 }
0715 }
0716 }
0717 else {
0718 int iz = -1;
0719 for (int k = 0; k < 2; k++) {
0720 if (k == 1)
0721 iz = 1;
0722
0723 for (int i = 1; i < 73; i++) {
0724 for (int j = 1; j < 18; j++) {
0725 if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, i)) {
0726 EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
0727 dcs_temp->setValue(ebid, 0);
0728 }
0729 }
0730 }
0731
0732 for (int i = 1; i < 21; i++) {
0733 for (int j = 1; j < 21; j++) {
0734 if (EcalScDetId::validDetId(i, j, iz)) {
0735 EcalScDetId eeid(i, j, iz);
0736 dcs_temp->setValue(eeid, 0);
0737 }
0738 }
0739 }
0740 }
0741 }
0742 std::cout << "max_since : " << max_since << std::endl;
0743
0744
0745 econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
0746 std::cout << "Connection done" << std::endl;
0747
0748 if (!econn) {
0749 std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << std::endl;
0750 throw cms::Exception("OMDS not available");
0751 }
0752
0753 std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
0754 std::map<EcalLogicID, RunDat> rundat;
0755 RunIOV rp;
0756 run_t runmax = 10000000;
0757 std::string location_p5 = "P5_Co";
0758 econn->fetchValidDataSet(&rundat, &rp, location_p5, runmax);
0759
0760 unsigned long long irun = (unsigned long long)rp.getRunNumber();
0761
0762
0763
0764
0765 if (max_since < irun) {
0766
0767
0768 std::cout << "Retrieving endcap channel list from ONLINE DB ... " << std::endl;
0769
0770 std::vector<EcalLogicID> my_EELVchan = econn->getEcalLogicIDSetOrdered(
0771 "EE_crystal_number", 1, 4, 1, 200, EcalLogicID::NULLID, EcalLogicID::NULLID, "EE_LV_channel", 12);
0772
0773 std::cout << "done endcap channel list ... " << std::endl;
0774
0775
0776
0777
0778 std::map<EcalLogicID, RunDCSHVDat> dataset;
0779 RunIOV* r = nullptr;
0780 econn->fetchDataSet(&dataset, r);
0781
0782 if (dataset.empty()) {
0783 throw(std::runtime_error("Zero rows read back"));
0784 }
0785
0786 if (lot_of_printout)
0787 std::cout << "read OK" << std::endl;
0788 if (lot_of_printout)
0789 printHVDataSet(&dataset, 10);
0790
0791 std::map<EcalLogicID, RunDCSLVDat> dataset_lv;
0792 econn->fetchDataSet(&dataset_lv, r);
0793
0794 if (dataset_lv.empty()) {
0795 throw(std::runtime_error("Zero rows read back"));
0796 }
0797 if (lot_of_printout)
0798 std::cout << "read OK" << std::endl;
0799 if (lot_of_printout)
0800 printLVDataSet(&dataset_lv);
0801
0802 bool somediff_hv = insertHVDataSetToOffline(&dataset, dcs_temp);
0803 bool somediff_lv = insertLVDataSetToOffline(&dataset_lv, dcs_temp, my_EELVchan);
0804
0805 if (somediff_hv || somediff_lv) {
0806
0807
0808
0809
0810
0811
0812
0813
0814 std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
0815
0816
0817
0818
0819
0820
0821 m_to_transfer.push_back(std::make_pair((EcalDCSTowerStatus*)dcs_temp, irun));
0822 ss << "Run=" << irun << "_DCSchanged_" << std::endl;
0823
0824 m_userTextLog = ss.str() + ";";
0825
0826 } else {
0827
0828
0829
0830 std::cout << "Run " << irun << " DCS record was the same as previous run " << std::endl;
0831 ss << "Run=" << irun << "_DCSchanged_" << std::endl;
0832 m_userTextLog = ss.str() + ";";
0833
0834 delete dcs_temp;
0835 }
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854
0855
0856
0857
0858
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878
0879
0880
0881
0882
0883
0884
0885
0886
0887
0888
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913
0914
0915
0916
0917
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944 }
0945
0946 delete econn;
0947 std::cout << "Ecal - > end of getNewObjects -----------\n";
0948 }