00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ECALCONDDBINTERFACE_HH
00010 #define ECALCONDDBINTERFACE_HH
00011
00012 #include <iostream>
00013 #include <string>
00014 #include <vector>
00015 #include <map>
00016 #include <stdexcept>
00017 #include "OnlineDB/Oracle/interface/Oracle.h"
00018
00019
00020 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
00021 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00022 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
00023 #include "OnlineDB/EcalCondDB/interface/IIOV.h"
00024 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00025 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
00026 #include "OnlineDB/EcalCondDB/interface/DCUIOV.h"
00027 #include "OnlineDB/EcalCondDB/interface/CaliIOV.h"
00028 #include "OnlineDB/EcalCondDB/interface/RunList.h"
00029 #include "OnlineDB/EcalCondDB/interface/MonRunList.h"
00030 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
00031 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
00032 #include "OnlineDB/EcalCondDB/interface/all_fe_config_types.h"
00033 #include "OnlineDB/EcalCondDB/interface/all_lmf_types.h"
00034 #include "OnlineDB/EcalCondDB/interface/all_od_types.h"
00035
00036 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00037 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00038
00039 class EcalCondDBInterface : public EcalDBConnection {
00040 public:
00041
00042
00043
00044
00045
00055 EcalCondDBInterface( std::string host,
00056 std::string sid,
00057 std::string user,
00058 std::string pass,
00059 int port=1521 )
00060 : EcalDBConnection( host, sid, user, pass, port )
00061 {
00062
00063
00064
00065 dh = new DateHandler(env, conn);
00066 }
00067
00068
00069
00077 EcalCondDBInterface( std::string sid,
00078 std::string user,
00079 std::string pass )
00080 : EcalDBConnection( sid, user, pass )
00081 {
00082
00083
00084
00085 dh = new DateHandler(env, conn);
00086 }
00087
00088
00092 virtual ~EcalCondDBInterface()
00093 throw(std::runtime_error)
00094 {
00095
00096
00097
00098 delete(dh);
00099 }
00100
00101
00105 inline DateHandler* getDateHandler()
00106 {
00107 return dh;
00108 }
00109
00110
00119 EcalLogicID getEcalLogicID( std::string name,
00120 int id1 = EcalLogicID::NULLID,
00121 int id2 = EcalLogicID::NULLID,
00122 int id3 = EcalLogicID::NULLID,
00123 std::string mapsTo = "" )
00124 throw(std::runtime_error);
00125
00131 std::vector<EcalLogicID> getEcalLogicIDMappedTo(int logic_id, std::string maps_to);
00132
00133 std::vector<EcalLogicID> getEcalLogicIDForLMR(int lmr_logic_id);
00134 std::vector<EcalLogicID> getEcalLogicIDForLMR(const EcalLogicID &lmr_logic_id);
00135 std::vector<EcalLogicID> getEcalLogicIDForLMPN(int lmr_logic_id);
00136 std::vector<EcalLogicID> getEcalLogicIDForLMPN(const EcalLogicID &lmr_logic_id);
00137
00138
00145 EcalLogicID getEcalLogicID( int logicID )
00146 throw(std::runtime_error);
00147
00157 std::vector<EcalLogicID> getEcalLogicIDSet( std::string name,
00158 int fromId1 = EcalLogicID::NULLID, int toId1 = EcalLogicID::NULLID,
00159 int fromId2 = EcalLogicID::NULLID, int toId2 = EcalLogicID::NULLID,
00160 int fromId3 = EcalLogicID::NULLID, int toId3 = EcalLogicID::NULLID,
00161 std::string mapsTo = "" )
00162 throw(std::runtime_error);
00163
00164 std::map<int, int> getEcalLogicID2LmrMap();
00165 std::vector<EcalLogicID> getEcalLogicIDSetOrdered( std::string name,
00166 int fromId1, int toId1,
00167 int fromId2 = EcalLogicID::NULLID, int toId2 = EcalLogicID::NULLID,
00168 int fromId3 = EcalLogicID::NULLID, int toId3 = EcalLogicID::NULLID,
00169 std::string mapsTo = "", int orderedBy= EcalLogicID::NULLID ) throw(std::runtime_error);
00170
00171
00175 void insertRunIOV(RunIOV* iov)
00176 throw(std::runtime_error);
00177
00178 void updateRunIOV(RunIOV* iov)
00179 throw(std::runtime_error);
00180 void updateRunIOVStartTime(RunIOV* iov)
00181 throw(std::runtime_error);
00182 void updateRunIOVEndTime(RunIOV* iov)
00183 throw(std::runtime_error);
00184
00185 void updateRunConfig(ODRunConfigInfo* od) throw(std::runtime_error);
00186
00187 void insertLmfIOV(LMFIOV* iov)
00188 throw(std::runtime_error);
00189 void insertLmfLmrSubIOV(LMFLmrSubIOV* iov)
00190 throw(std::runtime_error);
00191 void insertLmfSeq(LMFSeqDat* iov)
00192 throw(std::runtime_error);
00193 void insertLmfRunIOV(LMFRunIOV* iov)
00194 throw(std::runtime_error);
00195 void insertLmfDat(LMFDat* dat)
00196 throw(std::runtime_error);
00197 void insertLmfDat(std::list<LMFDat*> dat)
00198 throw(std::runtime_error);
00199
00204 std::list<ODDelaysDat> fetchFEDelaysForRun(RunIOV *iov)
00205 throw(std::runtime_error);
00206
00210 RunIOV fetchRunIOV(RunTag* tag, run_t run)
00211 throw(std::runtime_error);
00212
00213
00214
00220 RunIOV fetchRunIOV(std::string location, run_t run)
00221 throw(std::runtime_error);
00222
00223 RunIOV fetchRunIOV(std::string location, const Tm &t)
00224 throw(std::runtime_error);
00225
00226
00227
00231 void insertMonRunIOV(MonRunIOV* iov)
00232 throw(std::runtime_error);
00233
00234
00238 void insertDCUIOV(DCUIOV* iov)
00239 throw(std::runtime_error);
00240
00241
00245 MonRunIOV fetchMonRunIOV(RunTag* runtag, MonRunTag* montag, run_t run, subrun_t monrun)
00246 throw(std::runtime_error);
00247
00248
00252 DCUIOV fetchDCUIOV(DCUTag* tag, Tm evenTm)
00253 throw(std::runtime_error);
00254
00255
00256
00260 LMFRunIOV fetchLMFRunIOV(RunTag* runtag, LMFRunTag* lmftag, run_t run, subrun_t lmfrun)
00261 throw(std::runtime_error);
00262 bool fetchLMFRunIOV(const LMFSeqDat&, LMFRunIOV&, int lmr, int type,
00263 int color) const;
00264 RunIOV fetchLMFLastRun() const;
00265
00269 CaliIOV fetchCaliIOV(CaliTag* tag, Tm evenTm)
00270 throw(std::runtime_error);
00271
00272
00276 RunList fetchRunList(RunTag tag) throw(std::runtime_error);
00277 RunList fetchRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error);
00278 RunList fetchNonEmptyRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error);
00279 RunList fetchNonEmptyGlobalRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error);
00280 RunList fetchRunListByLocation(RunTag tag, int min_run, int max_run , const LocationDef locDef) throw(std::runtime_error);
00281 RunList fetchGlobalRunListByLocation(RunTag tag, int min_run, int max_run , const LocationDef locDef) throw(std::runtime_error);
00282 RunList fetchRunListLastNRuns(RunTag tag, int max_run, int n_runs) throw(std::runtime_error);
00283
00288 DCSPTMTempList fetchDCSPTMTempList(EcalLogicID ecid) throw(std::runtime_error);
00289 DCSPTMTempList fetchDCSPTMTempList(EcalLogicID ecid, Tm start, Tm end) throw(std::runtime_error);
00290
00291 MonRunList fetchMonRunList(RunTag tag, MonRunTag monruntag) throw(std::runtime_error);
00292 MonRunList fetchMonRunList(RunTag tag, MonRunTag monruntag,int min_run, int max_run) throw(std::runtime_error);
00293 MonRunList fetchMonRunListLastNRuns(RunTag tag, MonRunTag monruntag, int max_run, int n_runs) throw(std::runtime_error);
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 template<class DATT, class IOVT>
00308 void insertDataSet(const std::map< EcalLogicID, DATT >* data, IOVT* iov)
00309 throw(std::runtime_error)
00310 {
00311 try {
00312 iov->setConnection(env, conn);
00313
00314 if(iov->getID()==0){
00315 std::cout<<"IOV was not set we retrieve it from DB"<<std::endl;
00316 iov->fetchID();
00317 }
00318 if(iov->getID()==0){
00319 std::cout<<"IOV was not written we write it"<<std::endl;
00320 iov->writeDB();
00321 }
00322
00323 DATT dataIface;
00324 dataIface.setConnection(env, conn);
00325 dataIface.prepareWrite();
00326
00327 const EcalLogicID* channel;
00328 const DATT* dataitem;
00329 typedef typename std::map< EcalLogicID, DATT >::const_iterator CI;
00330 for (CI p = data->begin(); p != data->end(); ++p) {
00331 channel = &(p->first);
00332 dataitem = &(p->second);
00333 dataIface.writeDB( channel, dataitem, iov);
00334 }
00335 conn->commit();
00336 dataIface.terminateWriteStatement();
00337 } catch (std::runtime_error &e) {
00338 conn->rollback();
00339 throw(e);
00340 } catch (...) {
00341 conn->rollback();
00342 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
00343 }
00344 }
00345
00346
00347 template<class DATT, class IOVT>
00348 void insertDataArraySet(const std::map< EcalLogicID, DATT >* data, IOVT* iov)
00349 throw(std::runtime_error)
00350 {
00351 try {
00352 iov->setConnection(env, conn);
00353 if(iov->getID()==0){
00354 std::cout<<"IOV was not set we retrieve it from DB"<<std::endl;
00355 iov->fetchID();
00356 }
00357 if(iov->getID()==0){
00358 std::cout<<"IOV was not written we write it"<<std::endl;
00359 iov->writeDB();
00360 }
00361
00362 std::cout<<"id="<<iov->getID()<<std::endl;
00363
00364 DATT dataIface;
00365 dataIface.setConnection(env, conn);
00366 dataIface.prepareWrite();
00367
00368 dataIface.writeArrayDB(data, iov);
00369 conn->commit();
00370
00371 dataIface.terminateWriteStatement();
00372
00373 } catch (std::runtime_error &e) {
00374 conn->rollback();
00375 throw(e);
00376 } catch (...) {
00377 conn->rollback();
00378 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
00379 }
00380 }
00381
00382 template<class DATT, class IOVT>
00383 void insertDataSetVector( std::vector<EcalLogicID> ecid, std::vector<IOVT> run_iov, std::vector<DATT> data )
00384 throw(std::runtime_error)
00385 {
00386
00387 int nruns= run_iov.size();
00388
00389 if(run_iov.size()!=ecid.size() &&ecid.size()!=data.size()){
00390 throw(std::runtime_error("EcalCondDBInterface::insertDataSetVector: vector sizes are different.."));
00391 }
00392
00393
00394 try {
00395
00396 DATT dataIface;
00397 dataIface.setConnection(env, conn);
00398 dataIface.prepareWrite();
00399
00400 for (int i=0; i<nruns; i++){
00401
00402 run_iov[i].setConnection(env, conn);
00403 run_iov[i].writeDB();
00404
00405 dataIface.writeDB( &ecid[i], &data[i], &run_iov[i]);
00406
00407 conn->commit();
00408 }
00409 } catch (std::runtime_error &e) {
00410 conn->rollback();
00411 throw(e);
00412 } catch (...) {
00413 conn->rollback();
00414 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
00415 }
00416 }
00417
00418
00419
00420
00421
00422
00423
00424 template<class ICONF >
00425 void insertConfigSet( ICONF* iconf)
00426 throw(std::runtime_error)
00427 {
00428 try {
00429 iconf->setConnection(env, conn);
00430 iconf->prepareWrite();
00431
00432 iconf->writeDB();
00433 std::cout<< "iconf inserted with ID="<<iconf->getId()<<std::endl;
00434 conn->commit();
00435 iconf->terminateWriteStatement();
00436 } catch (std::runtime_error &e) {
00437 conn->rollback();
00438 throw(e);
00439 } catch (...) {
00440 conn->rollback();
00441 throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
00442 }
00443 }
00444
00445
00446
00447
00448 template<class ICONF>
00449 void fetchConfigSet( ICONF* iconf)
00450 throw(std::runtime_error)
00451 {
00452
00453 iconf->clear();
00454 iconf->setConnection(env, conn);
00455 iconf->createReadStatement();
00456 iconf->fetchData(iconf);
00457 iconf->terminateReadStatement();
00458
00459 }
00460
00461
00462
00463
00464 template<class ICONF>
00465 void fetchLastConfigSet( ICONF* iconf)
00466 throw(std::runtime_error)
00467 {
00468
00469 iconf->clear();
00470 iconf->setConnection(env, conn);
00471 iconf->createReadStatement();
00472 iconf->fetchLastData(iconf);
00473 iconf->terminateReadStatement();
00474
00475 }
00476
00477
00478
00479
00480
00481
00482 template<class DATT, class ICONF>
00483 void insertConfigDataSet(const std::vector< DATT > data, ICONF* iconf)
00484 throw(std::runtime_error)
00485 {
00486 try {
00487 iconf->setConnection(env, conn);
00488
00489 if(iconf->getId()==0){
00490 std::cout<<"EcalCondDBInterface>> config_id was not set we retrieve it from DB"<<std::endl;
00491 iconf->fetchID();
00492 }
00493 if(iconf->getId()==0){
00494 std::cout<<"EcalCondDBInterface>> configuration info was not written we write it"<<std::endl;
00495 iconf->writeDB();
00496 }
00497
00498 DATT dataIface;
00499 dataIface.setConnection(env, conn);
00500 dataIface.prepareWrite();
00501
00502 const DATT* dataitem;
00503
00504 for (int p = 0; p != data->size(); ++p) {
00505 dataitem = data[p];
00506 dataIface.writeDB( dataitem, iconf);
00507 }
00508 conn->commit();
00509 dataIface.terminateWriteStatement();
00510 } catch (std::runtime_error &e) {
00511 conn->rollback();
00512 throw(e);
00513 } catch (...) {
00514 conn->rollback();
00515 throw(std::runtime_error("EcalCondDBInterface::insertConfigDataSet: Unknown exception caught"));
00516 }
00517 }
00518
00519
00520
00521 template<class DATT, class ICONF>
00522 void insertConfigDataArraySet(const std::vector< DATT > data, ICONF* iconf)
00523 throw(std::runtime_error)
00524 {
00525 try {
00526 iconf->setConnection(env, conn);
00527
00528 if(iconf->getId()==0){
00529 std::cout<<"EcalCondDBInterface>> config_id was not set we retrieve it from DB"<<std::endl;
00530 iconf->fetchID();
00531 }
00532 if(iconf->getId()==0){
00533 std::cout<<"EcalCondDBInterface>> configuration info was not written we write it"<<std::endl;
00534 iconf->writeDB();
00535 }
00536
00537 DATT dataIface;
00538 dataIface.setConnection(env, conn);
00539 dataIface.prepareWrite();
00540
00541 dataIface.writeArrayDB(data, iconf);
00542 conn->commit();
00543
00544 dataIface.terminateWriteStatement();
00545
00546 } catch (std::runtime_error &e) {
00547 conn->rollback();
00548 throw(e);
00549 } catch (...) {
00550 conn->rollback();
00551 throw(std::runtime_error("EcalCondDBInterface::insertConfigDataArraySet: Unknown exception caught"));
00552 }
00553 }
00554
00555
00556
00557 template<class DATT, class ICONF>
00558 void fetchConfigDataSet(std::vector< DATT >* fillMap, ICONF* iconf)
00559 throw(std::runtime_error)
00560 {
00561
00562 DATT datiface;
00563 datiface.setConnection(env, conn);
00564 datiface.createReadStatement();
00565 datiface.setPrefetchRowCount(1024);
00566 datiface.fetchData( fillMap, iconf );
00567 datiface.terminateReadStatement();
00568
00569 }
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 template<class DATT, class IOVT>
00581 void fetchDataSet(std::map< EcalLogicID, DATT >* fillMap, IOVT* iov)
00582 throw(std::runtime_error)
00583 {
00584 fillMap->clear();
00585
00586 DATT datiface;
00587 datiface.setConnection(env, conn);
00588 datiface.createReadStatement();
00589 datiface.setPrefetchRowCount(1024);
00590 datiface.fetchData( fillMap, iov );
00591 datiface.terminateReadStatement();
00592
00593 }
00594
00595
00596
00597
00598
00599
00600
00601 template<class DATT>
00602 void fetchDCSDataSet(std::list< std::pair< Tm, std::map< EcalLogicID, DATT > > >* fillMap, Tm t)
00603 throw(std::runtime_error)
00604 {
00605 fillMap->clear();
00606
00607 DATT datiface;
00608 datiface.setConnection(env, conn);
00609 datiface.createReadStatement();
00610 datiface.setPrefetchRowCount(1024);
00611 datiface.fetchHistoricalData( fillMap, t );
00612 datiface.terminateReadStatement();
00613
00614 }
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624 template<class DATT, class IOVT>
00625 void fetchDataSetWithMap(std::map< EcalLogicID, DATT >* fillMap, IOVT* iov, std::string mapping_name )
00626 throw(std::runtime_error)
00627 {
00628 fillMap->clear();
00629
00630 DATT datiface;
00631 datiface.setConnection(env, conn);
00632 datiface.createReadStatement();
00633 datiface.setPrefetchRowCount(1024);
00634 datiface.fetchData( fillMap, iov , mapping_name);
00635 datiface.terminateReadStatement();
00636
00637 }
00638
00639
00640
00641
00642
00643
00644
00645
00646 template<class DATT, class IOVT>
00647 void fetchValidDataSet(std::map< EcalLogicID, DATT >* fillMap,
00648 IOVT* fillIOV,
00649 RunTag* tag, run_t run = (unsigned int)-1)
00650 throw(std::runtime_error)
00651 {
00652 fillMap->clear();
00653 DATT datiface;
00654 fillIOV->setConnection(env, conn);
00655 fillIOV->setByRecentData(datiface.getTable(), tag, run);
00656 datiface.setConnection(env, conn);
00657 datiface.createReadStatement();
00658 datiface.setPrefetchRowCount(1024);
00659 datiface.fetchData( fillMap, fillIOV );
00660 datiface.terminateReadStatement();
00661 }
00662
00663
00664
00665
00666
00667
00668
00669
00670 template<class DATT, class IOVT>
00671 void fetchValidDataSet(std::map< EcalLogicID, DATT >* fillMap,
00672 IOVT* fillIOV,
00673 std::string location, run_t run = (unsigned int)-1)
00674 throw(std::runtime_error)
00675 {
00676 fillMap->clear();
00677 DATT datiface;
00678 fillIOV->setConnection(env, conn);
00679 fillIOV->setByRecentData(datiface.getTable(), location, run);
00680 datiface.setConnection(env, conn);
00681 datiface.createReadStatement();
00682 datiface.setPrefetchRowCount(1024);
00683 datiface.fetchData( fillMap, fillIOV );
00684 datiface.terminateReadStatement();
00685 }
00686
00687 inline int getDetIdFromLogicId(int logic_id) {
00688 int detid = -1;
00689 if (_logicId2DetId.size() == 0) {
00690 fillLogicId2DetIdMaps();
00691 }
00692 if (_logicId2DetId.find(logic_id) != _logicId2DetId.end()) {
00693 detid = _logicId2DetId[logic_id];
00694 }
00695 return detid;
00696 }
00697
00698 inline int getLogicIdFromDetId(int det_id) {
00699 int logic_id = -1;
00700 if (_logicId2DetId.size() == 0) {
00701 fillLogicId2DetIdMaps();
00702 }
00703 if (_detId2LogicId.find(det_id) != _detId2LogicId.end()) {
00704 logic_id = _detId2LogicId[det_id];
00705 }
00706 return logic_id;
00707 }
00708
00709 inline std::map<int, int> getLogicId2DetIdMap() {
00710 if (_logicId2DetId.size() == 0) {
00711 fillLogicId2DetIdMaps();
00712 }
00713 return _logicId2DetId;
00714 }
00715
00716 inline std::map<int, int> getDetId2LogicIdMap() {
00717 if (_logicId2DetId.size() == 0) {
00718 fillLogicId2DetIdMaps();
00719 }
00720 return _detId2LogicId;
00721 }
00722
00723 void dummy();
00724
00725 private:
00726
00730 void fillLogicId2DetIdMaps();
00731
00732
00733
00734
00735
00736
00737 DateHandler* dh;
00738
00739 EcalCondDBInterface();
00740 EcalCondDBInterface(const EcalCondDBInterface& copy);
00741
00742 std::map<int, int> _logicId2DetId;
00743 std::map<int, int> _detId2LogicId;
00744 };
00745
00746 #endif