File indexing completed on 2024-04-06 12:22:52
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef ECALCONDDBINTERFACE_HH
0009 #define ECALCONDDBINTERFACE_HH
0010
0011 #include <iostream>
0012 #include <string>
0013 #include <vector>
0014 #include <map>
0015 #include <stdexcept>
0016 #include "OnlineDB/Oracle/interface/Oracle.h"
0017
0018 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
0019 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0020 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0021 #include "OnlineDB/EcalCondDB/interface/IIOV.h"
0022 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0023 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0024 #include "OnlineDB/EcalCondDB/interface/DCUIOV.h"
0025 #include "OnlineDB/EcalCondDB/interface/CaliIOV.h"
0026 #include "OnlineDB/EcalCondDB/interface/RunList.h"
0027 #include "OnlineDB/EcalCondDB/interface/MonRunList.h"
0028 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0029 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
0030 #include "OnlineDB/EcalCondDB/interface/all_fe_config_types.h"
0031 #include "OnlineDB/EcalCondDB/interface/all_lmf_types.h"
0032 #include "OnlineDB/EcalCondDB/interface/all_od_types.h"
0033
0034 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0035 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0036
0037 class EcalCondDBInterface : public EcalDBConnection {
0038 public:
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 EcalCondDBInterface(std::string host, std::string sid, std::string user, std::string pass, int port = 1521)
0053 : EcalDBConnection(host, sid, user, pass, port) {
0054
0055
0056
0057 dh = new DateHandler(env, conn);
0058 }
0059
0060
0061
0062
0063
0064
0065
0066
0067 EcalCondDBInterface(std::string sid, std::string user, std::string pass) : EcalDBConnection(sid, user, pass) {
0068
0069
0070
0071 dh = new DateHandler(env, conn);
0072 }
0073
0074
0075
0076
0077 ~EcalCondDBInterface() noexcept(false) override {
0078
0079
0080
0081 delete (dh);
0082 }
0083
0084
0085
0086
0087 inline DateHandler* getDateHandler() { return dh; }
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 EcalLogicID getEcalLogicID(std::string name,
0098 int id1 = EcalLogicID::NULLID,
0099 int id2 = EcalLogicID::NULLID,
0100 int id3 = EcalLogicID::NULLID,
0101 std::string mapsTo = "") noexcept(false);
0102
0103
0104
0105
0106
0107
0108 std::vector<EcalLogicID> getEcalLogicIDMappedTo(int logic_id, std::string maps_to);
0109
0110 std::vector<EcalLogicID> getEcalLogicIDForLMR(int lmr_logic_id);
0111 std::vector<EcalLogicID> getEcalLogicIDForLMR(const EcalLogicID& lmr_logic_id);
0112 std::vector<EcalLogicID> getEcalLogicIDForLMPN(int lmr_logic_id);
0113 std::vector<EcalLogicID> getEcalLogicIDForLMPN(const EcalLogicID& lmr_logic_id);
0114
0115
0116
0117
0118
0119
0120
0121 EcalLogicID getEcalLogicID(int logicID) noexcept(false);
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 std::vector<EcalLogicID> getEcalLogicIDSet(std::string name,
0133 int fromId1 = EcalLogicID::NULLID,
0134 int toId1 = EcalLogicID::NULLID,
0135 int fromId2 = EcalLogicID::NULLID,
0136 int toId2 = EcalLogicID::NULLID,
0137 int fromId3 = EcalLogicID::NULLID,
0138 int toId3 = EcalLogicID::NULLID,
0139 std::string mapsTo = "") noexcept(false);
0140
0141 std::map<int, int> getEcalLogicID2LmrMap();
0142 std::vector<EcalLogicID> getEcalLogicIDSetOrdered(std::string name,
0143 int fromId1,
0144 int toId1,
0145 int fromId2 = EcalLogicID::NULLID,
0146 int toId2 = EcalLogicID::NULLID,
0147 int fromId3 = EcalLogicID::NULLID,
0148 int toId3 = EcalLogicID::NULLID,
0149 std::string mapsTo = "",
0150 int orderedBy = EcalLogicID::NULLID) noexcept(false);
0151
0152
0153
0154
0155 void insertRunIOV(RunIOV* iov) noexcept(false);
0156
0157 void updateRunIOV(RunIOV* iov) noexcept(false);
0158 void updateRunIOVStartTime(RunIOV* iov) noexcept(false);
0159 void updateRunIOVEndTime(RunIOV* iov) noexcept(false);
0160
0161 void updateRunConfig(ODRunConfigInfo* od) noexcept(false);
0162
0163 void insertLmfIOV(LMFIOV* iov) noexcept(false);
0164 void insertLmfLmrSubIOV(LMFLmrSubIOV* iov) noexcept(false);
0165 void insertLmfSeq(LMFSeqDat* iov) noexcept(false);
0166 void insertLmfRunIOV(LMFRunIOV* iov) noexcept(false);
0167 void insertLmfDat(LMFDat* dat) noexcept(false);
0168 void insertLmfDat(std::list<LMFDat*> dat) noexcept(false);
0169
0170
0171
0172
0173
0174 std::list<ODDelaysDat> fetchFEDelaysForRun(RunIOV* iov) noexcept(false);
0175
0176
0177
0178
0179 RunIOV fetchRunIOV(RunTag* tag, run_t run) noexcept(false);
0180
0181
0182
0183
0184
0185
0186 RunIOV fetchRunIOV(std::string location, run_t run) noexcept(false);
0187
0188 RunIOV fetchRunIOV(std::string location, const Tm& t) noexcept(false);
0189
0190
0191
0192
0193 void insertMonRunIOV(MonRunIOV* iov) noexcept(false);
0194
0195
0196
0197
0198 void insertDCUIOV(DCUIOV* iov) noexcept(false);
0199
0200
0201
0202
0203 MonRunIOV fetchMonRunIOV(RunTag* runtag, MonRunTag* montag, run_t run, subrun_t monrun) noexcept(false);
0204
0205
0206
0207
0208 DCUIOV fetchDCUIOV(DCUTag* tag, const Tm& evenTm) noexcept(false);
0209
0210
0211
0212
0213 LMFRunIOV fetchLMFRunIOV(RunTag* runtag, LMFRunTag* lmftag, run_t run, subrun_t lmfrun) noexcept(false);
0214 bool fetchLMFRunIOV(const LMFSeqDat&, LMFRunIOV&, int lmr, int type, int color) const;
0215 RunIOV fetchLMFLastRun() const;
0216
0217
0218
0219
0220 CaliIOV fetchCaliIOV(CaliTag* tag, const Tm& evenTm) noexcept(false);
0221
0222
0223
0224
0225 RunList fetchRunList(const RunTag& tag) noexcept(false);
0226 RunList fetchRunList(const RunTag& tag, int min_run, int max_run) noexcept(false);
0227 RunList fetchNonEmptyRunList(const RunTag& tag, int min_run, int max_run) noexcept(false);
0228 RunList fetchNonEmptyGlobalRunList(const RunTag& tag, int min_run, int max_run) noexcept(false);
0229 RunList fetchRunListByLocation(const RunTag& tag, int min_run, int max_run, const LocationDef& locDef) noexcept(false);
0230 RunList fetchGlobalRunListByLocation(const RunTag& tag,
0231 int min_run,
0232 int max_run,
0233 const LocationDef& locDef) noexcept(false);
0234 RunList fetchRunListLastNRuns(const RunTag& tag, int max_run, int n_runs) noexcept(false);
0235
0236
0237
0238
0239
0240 DCSPTMTempList fetchDCSPTMTempList(const EcalLogicID& ecid) noexcept(false);
0241 DCSPTMTempList fetchDCSPTMTempList(const EcalLogicID& ecid, const Tm& start, const Tm& end) noexcept(false);
0242
0243 MonRunList fetchMonRunList(const RunTag& tag, const MonRunTag& monruntag) noexcept(false);
0244 MonRunList fetchMonRunList(const RunTag& tag, const MonRunTag& monruntag, int min_run, int max_run) noexcept(false);
0245 MonRunList fetchMonRunListLastNRuns(const RunTag& tag,
0246 const MonRunTag& monruntag,
0247 int max_run,
0248 int n_runs) noexcept(false);
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259 template <class DATT, class IOVT>
0260 void insertDataSet(const std::map<EcalLogicID, DATT>* data, IOVT* iov) noexcept(false) {
0261 try {
0262 iov->setConnection(env, conn);
0263
0264 if (iov->getID() == 0) {
0265 std::cout << "IOV was not set we retrieve it from DB" << std::endl;
0266 iov->fetchID();
0267 }
0268 if (iov->getID() == 0) {
0269 std::cout << "IOV was not written we write it" << std::endl;
0270 iov->writeDB();
0271 }
0272
0273 DATT dataIface;
0274 dataIface.setConnection(env, conn);
0275 dataIface.prepareWrite();
0276
0277 const EcalLogicID* channel;
0278 const DATT* dataitem;
0279 typedef typename std::map<EcalLogicID, DATT>::const_iterator CI;
0280 for (CI p = data->begin(); p != data->end(); ++p) {
0281 channel = &(p->first);
0282 dataitem = &(p->second);
0283 dataIface.writeDB(channel, dataitem, iov);
0284 }
0285 conn->commit();
0286 dataIface.terminateWriteStatement();
0287 } catch (std::runtime_error& e) {
0288 conn->rollback();
0289 throw(e);
0290 } catch (...) {
0291 conn->rollback();
0292 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
0293 }
0294 }
0295
0296
0297 template <class DATT, class IOVT>
0298 void insertDataArraySet(const std::map<EcalLogicID, DATT>* data, IOVT* iov) noexcept(false) {
0299 try {
0300 iov->setConnection(env, conn);
0301 if (iov->getID() == 0) {
0302 std::cout << "IOV was not set we retrieve it from DB" << std::endl;
0303 iov->fetchID();
0304 }
0305 if (iov->getID() == 0) {
0306 std::cout << "IOV was not written we write it" << std::endl;
0307 iov->writeDB();
0308 }
0309
0310 std::cout << "id=" << iov->getID() << std::endl;
0311
0312 DATT dataIface;
0313 dataIface.setConnection(env, conn);
0314 dataIface.prepareWrite();
0315
0316 dataIface.writeArrayDB(data, iov);
0317 conn->commit();
0318
0319 dataIface.terminateWriteStatement();
0320
0321 } catch (std::runtime_error& e) {
0322 conn->rollback();
0323 throw(e);
0324 } catch (...) {
0325 conn->rollback();
0326 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
0327 }
0328 }
0329
0330 template <class DATT, class IOVT>
0331 void insertDataSetVector(const std::vector<EcalLogicID>& ecid,
0332 const std::vector<IOVT>& run_iov,
0333 const std::vector<DATT>& data) noexcept(false) {
0334 int nruns = run_iov.size();
0335
0336 if (run_iov.size() != ecid.size() && ecid.size() != data.size()) {
0337 throw(std::runtime_error("EcalCondDBInterface::insertDataSetVector: vector sizes are different.."));
0338 }
0339
0340 try {
0341 DATT dataIface;
0342 dataIface.setConnection(env, conn);
0343 dataIface.prepareWrite();
0344
0345 for (int i = 0; i < nruns; i++) {
0346 run_iov[i].setConnection(env, conn);
0347 run_iov[i].writeDB();
0348
0349 dataIface.writeDB(&ecid[i], &data[i], &run_iov[i]);
0350
0351 conn->commit();
0352 }
0353 } catch (std::runtime_error& e) {
0354 conn->rollback();
0355 throw(e);
0356 } catch (...) {
0357 conn->rollback();
0358 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
0359 }
0360 }
0361
0362
0363
0364 template <class ICONF>
0365 void insertConfigSet(ICONF* iconf) noexcept(false) {
0366 try {
0367 iconf->setConnection(env, conn);
0368 iconf->prepareWrite();
0369
0370 iconf->writeDB();
0371 std::cout << "iconf inserted with ID=" << iconf->getId() << std::endl;
0372 conn->commit();
0373 iconf->terminateWriteStatement();
0374 } catch (std::runtime_error& e) {
0375 conn->rollback();
0376 throw(e);
0377 } catch (...) {
0378 conn->rollback();
0379 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
0380 }
0381 }
0382
0383
0384
0385
0386 template <class ICONF>
0387 void fetchConfigSet(ICONF* iconf) noexcept(false) {
0388 iconf->clear();
0389 iconf->setConnection(env, conn);
0390 iconf->createReadStatement();
0391 iconf->fetchData(iconf);
0392 iconf->terminateReadStatement();
0393 }
0394
0395
0396
0397
0398 template <class ICONF>
0399 void fetchLastConfigSet(ICONF* iconf) noexcept(false) {
0400 iconf->clear();
0401 iconf->setConnection(env, conn);
0402 iconf->createReadStatement();
0403 iconf->fetchLastData(iconf);
0404 iconf->terminateReadStatement();
0405 }
0406
0407
0408
0409
0410 template <class DATT, class ICONF>
0411 void insertConfigDataSet(const std::vector<DATT> data, ICONF* iconf) noexcept(false) {
0412 try {
0413 iconf->setConnection(env, conn);
0414
0415 if (iconf->getId() == 0) {
0416 std::cout << "EcalCondDBInterface>> config_id was not set we retrieve it from DB" << std::endl;
0417 iconf->fetchID();
0418 }
0419 if (iconf->getId() == 0) {
0420 std::cout << "EcalCondDBInterface>> configuration info was not written we write it" << std::endl;
0421 iconf->writeDB();
0422 }
0423
0424 DATT dataIface;
0425 dataIface.setConnection(env, conn);
0426 dataIface.prepareWrite();
0427
0428 const DATT* dataitem;
0429
0430 for (int p = 0; p != data->size(); ++p) {
0431 dataitem = data[p];
0432 dataIface.writeDB(dataitem, iconf);
0433 }
0434 conn->commit();
0435 dataIface.terminateWriteStatement();
0436 } catch (std::runtime_error& e) {
0437 conn->rollback();
0438 throw(e);
0439 } catch (...) {
0440 conn->rollback();
0441 throw(std::runtime_error("EcalCondDBInterface::insertConfigDataSet: Unknown exception caught"));
0442 }
0443 }
0444
0445
0446
0447 template <class DATT, class ICONF>
0448 void insertConfigDataArraySet(const std::vector<DATT>& data, ICONF* iconf) noexcept(false) {
0449 try {
0450 iconf->setConnection(env, conn);
0451
0452 if (iconf->getId() == 0) {
0453 std::cout << "EcalCondDBInterface>> config_id was not set we retrieve it from DB" << std::endl;
0454 iconf->fetchID();
0455 }
0456 if (iconf->getId() == 0) {
0457 std::cout << "EcalCondDBInterface>> configuration info was not written we write it" << std::endl;
0458 iconf->writeDB();
0459 }
0460
0461 DATT dataIface;
0462 dataIface.setConnection(env, conn);
0463 dataIface.prepareWrite();
0464
0465 dataIface.writeArrayDB(data, iconf);
0466 conn->commit();
0467
0468 dataIface.terminateWriteStatement();
0469
0470 } catch (std::runtime_error& e) {
0471 conn->rollback();
0472 throw(e);
0473 } catch (...) {
0474 conn->rollback();
0475 throw(std::runtime_error("EcalCondDBInterface::insertConfigDataArraySet: Unknown exception caught"));
0476 }
0477 }
0478
0479
0480
0481 template <class DATT, class ICONF>
0482 void fetchConfigDataSet(std::vector<DATT>* fillMap, ICONF* iconf) noexcept(false) {
0483 DATT datiface;
0484 datiface.setConnection(env, conn);
0485 datiface.createReadStatement();
0486 datiface.setPrefetchRowCount(1024);
0487 datiface.fetchData(fillMap, iconf);
0488 datiface.terminateReadStatement();
0489 }
0490
0491
0492
0493
0494 template <class DATT, class IOVT>
0495 void fetchDataSet(std::map<EcalLogicID, DATT>* fillMap, IOVT* iov) noexcept(false) {
0496 fillMap->clear();
0497
0498 DATT datiface;
0499 datiface.setConnection(env, conn);
0500 datiface.createReadStatement();
0501 datiface.setPrefetchRowCount(1024);
0502 datiface.fetchData(fillMap, iov);
0503 datiface.terminateReadStatement();
0504 }
0505
0506
0507
0508
0509 template <class DATT>
0510 void fetchDCSDataSet(std::list<std::pair<Tm, std::map<EcalLogicID, DATT> > >* fillMap, const Tm& t) noexcept(false) {
0511 fillMap->clear();
0512
0513 DATT datiface;
0514 datiface.setConnection(env, conn);
0515 datiface.createReadStatement();
0516 datiface.setPrefetchRowCount(1024);
0517 datiface.fetchHistoricalData(fillMap, t);
0518 datiface.terminateReadStatement();
0519 }
0520
0521
0522
0523
0524
0525 template <class DATT, class IOVT>
0526 void fetchDataSetWithMap(std::map<EcalLogicID, DATT>* fillMap, IOVT* iov, std::string mapping_name) noexcept(false) {
0527 fillMap->clear();
0528
0529 DATT datiface;
0530 datiface.setConnection(env, conn);
0531 datiface.createReadStatement();
0532 datiface.setPrefetchRowCount(1024);
0533 datiface.fetchData(fillMap, iov, mapping_name);
0534 datiface.terminateReadStatement();
0535 }
0536
0537
0538
0539
0540
0541
0542
0543
0544 template <class DATT, class IOVT>
0545 void fetchValidDataSet(std::map<EcalLogicID, DATT>* fillMap,
0546 IOVT* fillIOV,
0547 RunTag* tag,
0548 run_t run = (unsigned int)-1) noexcept(false) {
0549 fillMap->clear();
0550 DATT datiface;
0551 fillIOV->setConnection(env, conn);
0552 fillIOV->setByRecentData(datiface.getTable(), tag, run);
0553 datiface.setConnection(env, conn);
0554 datiface.createReadStatement();
0555 datiface.setPrefetchRowCount(1024);
0556 datiface.fetchData(fillMap, fillIOV);
0557 datiface.terminateReadStatement();
0558 }
0559
0560
0561
0562
0563
0564
0565
0566
0567 template <class DATT, class IOVT>
0568 void fetchValidDataSet(std::map<EcalLogicID, DATT>* fillMap,
0569 IOVT* fillIOV,
0570 std::string location,
0571 run_t run = (unsigned int)-1) noexcept(false) {
0572 fillMap->clear();
0573 DATT datiface;
0574 fillIOV->setConnection(env, conn);
0575 fillIOV->setByRecentData(datiface.getTable(), location, run);
0576 datiface.setConnection(env, conn);
0577 datiface.createReadStatement();
0578 datiface.setPrefetchRowCount(1024);
0579 datiface.fetchData(fillMap, fillIOV);
0580 datiface.terminateReadStatement();
0581 }
0582
0583 inline int getDetIdFromLogicId(int logic_id) {
0584 int detid = -1;
0585 if (_logicId2DetId.empty()) {
0586 fillLogicId2DetIdMaps();
0587 }
0588 if (_logicId2DetId.find(logic_id) != _logicId2DetId.end()) {
0589 detid = _logicId2DetId[logic_id];
0590 }
0591 return detid;
0592 }
0593
0594 inline int getLogicIdFromDetId(int det_id) {
0595 int logic_id = -1;
0596 if (_logicId2DetId.empty()) {
0597 fillLogicId2DetIdMaps();
0598 }
0599 if (_detId2LogicId.find(det_id) != _detId2LogicId.end()) {
0600 logic_id = _detId2LogicId[det_id];
0601 }
0602 return logic_id;
0603 }
0604
0605 inline std::map<int, int> getLogicId2DetIdMap() {
0606 if (_logicId2DetId.empty()) {
0607 fillLogicId2DetIdMaps();
0608 }
0609 return _logicId2DetId;
0610 }
0611
0612 inline std::map<int, int> getDetId2LogicIdMap() {
0613 if (_logicId2DetId.empty()) {
0614 fillLogicId2DetIdMaps();
0615 }
0616 return _detId2LogicId;
0617 }
0618
0619 void dummy();
0620
0621 private:
0622
0623
0624
0625 void fillLogicId2DetIdMaps();
0626
0627
0628
0629
0630
0631 DateHandler* dh;
0632
0633 std::map<int, int> _logicId2DetId;
0634 std::map<int, int> _detId2LogicId;
0635
0636 public:
0637 EcalCondDBInterface() = delete;
0638 EcalCondDBInterface(const EcalCondDBInterface& copy) = delete;
0639 };
0640
0641 #endif