00001
00002
00003 #include <iostream>
00004 #include <string>
00005 #include <vector>
00006 #include <sstream>
00007 #include <stdlib.h>
00008 #include <cstdlib>
00009 #include <time.h>
00010 #include <stdexcept>
00011 #include "OnlineDB/Oracle/interface/Oracle.h"
00012
00013 #include "OnlineDB/EcalCondDB/interface/IDBObject.h"
00014 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00015 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
00016 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
00017 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
00018
00019 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00020 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00021 #include "OnlineDB/EcalCondDB/interface/RunList.h"
00022 #include "OnlineDB/EcalCondDB/interface/MonRunList.h"
00023 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
00024 #include "OnlineDB/EcalCondDB/interface/LMFRunTag.h"
00025
00026 using namespace std;
00027 using namespace oracle::occi;
00028
00029 void EcalCondDBInterface::fillLogicId2DetIdMaps() {
00030
00031 std::vector<EcalLogicID> crystals_EB =
00032 getEcalLogicIDSetOrdered( "EB_crystal_angle",
00033 -85,85,1,360,
00034 EcalLogicID::NULLID,EcalLogicID::NULLID,
00035 "EB_crystal_number", 4 );
00036 std::vector<EcalLogicID> crystals_EE =
00037 getEcalLogicIDSetOrdered( "EE_crystal_number",
00038 -1,1,1,100,
00039 1,100,
00040 "EE_crystal_number", 4 );
00041
00042 std::vector<EcalLogicID>::const_iterator ieb = crystals_EB.begin();
00043 std::vector<EcalLogicID>::const_iterator eeb = crystals_EB.end();
00044 while (ieb != eeb) {
00045 int iEta = ieb->getID1();
00046 int iPhi = ieb->getID2();
00047 EBDetId ebdetid(iEta,iPhi);
00048 _logicId2DetId[ieb->getLogicID()] = ebdetid;
00049 _detId2LogicId[ebdetid] = ieb->getLogicID();
00050 ieb++;
00051 }
00052
00053
00054 std::vector<EcalLogicID>::const_iterator iee = crystals_EE.begin();
00055 std::vector<EcalLogicID>::const_iterator eee = crystals_EE.end();
00056
00057 while (iee != eee) {
00058 int iSide = iee->getID1();
00059 int iX = iee->getID2();
00060 int iY = iee->getID3();
00061 EEDetId eedetidpos(iX,iY,iSide);
00062 _logicId2DetId[iee->getLogicID()] = eedetidpos;
00063 _detId2LogicId[eedetidpos] = iee->getLogicID();
00064 iee++;
00065 }
00066
00067 }
00068
00069
00070 EcalLogicID EcalCondDBInterface::getEcalLogicID( int logicID )
00071 throw(std::runtime_error)
00072 {
00073
00074 string sql = "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE logic_id = :logicID AND name=maps_to";
00075
00076 int id1, id2, id3;
00077 string name, mapsTo;
00078
00079 try {
00080 stmt->setSQL(sql);
00081 stmt->setInt(1, logicID);
00082 ResultSet* rset = stmt->executeQuery();
00083
00084 if (rset->next()) {
00085 name = rset->getString(1);
00086 logicID = rset->getInt(2);
00087 id1 = rset->getInt(3);
00088 if (rset->isNull(3)) { id1 = EcalLogicID::NULLID; }
00089 id2 = rset->getInt(4);
00090 if (rset->isNull(4)) { id2 = EcalLogicID::NULLID; }
00091 id3 = rset->getInt(5);
00092 if (rset->isNull(5)) { id3 = EcalLogicID::NULLID; }
00093 mapsTo = rset->getString(6);
00094 } else {
00095 stringstream msg;
00096 msg << "ERROR: Cannot build EcalLogicID for logic_id " << logicID;
00097 throw(std::runtime_error(msg.str()));
00098 }
00099
00100 } catch (SQLException &e) {
00101 throw(std::runtime_error("ERROR: Failed to retrive ids: " + e.getMessage() ));
00102 }
00103
00104 return EcalLogicID( name, logicID, id1, id2, id3, mapsTo );
00105 }
00106
00107 std::list<ODDelaysDat> EcalCondDBInterface::fetchFEDelaysForRun(RunIOV *iov)
00108 throw(std::runtime_error)
00109 {
00110 std::list<ODDelaysDat> ret;
00111 RunFEConfigDat d;
00112 std::map<EcalLogicID, RunFEConfigDat > fillMap;
00113 try {
00114 d.setConnection(env, conn);
00115 d.fetchData(&fillMap, iov);
00116 } catch (std::runtime_error &e) {
00117 throw e;
00118 }
00119 std::map<EcalLogicID, RunFEConfigDat >::const_iterator i = fillMap.begin();
00120 std::map<EcalLogicID, RunFEConfigDat >::const_iterator e = fillMap.end();
00121 while (i != e) {
00122 ODFEDAQConfig feDaqConfig;
00123 ODFEDAQConfig temp;
00124 temp.setId(i->second.getConfigId());
00125 feDaqConfig.setConnection(env, conn);
00126 feDaqConfig.fetchData(&temp);
00127 std::vector<ODDelaysDat> delays;
00128 ODDelaysDat temp2;
00129 temp2.setConnection(env, conn);
00130 temp2.fetchData(&delays, temp.getDelayId());
00131 std::vector<ODDelaysDat>::const_iterator di = delays.begin();
00132 std::vector<ODDelaysDat>::const_iterator de = delays.end();
00133 while (di != de) {
00134 ret.push_back(*di++);
00135 }
00136 i++;
00137 }
00138 return ret;
00139 }
00140
00141 EcalLogicID EcalCondDBInterface::getEcalLogicID( string name,
00142 int id1,
00143 int id2,
00144 int id3,
00145 string mapsTo )
00146 throw(std::runtime_error)
00147 {
00148
00149 if (mapsTo == "") {
00150 mapsTo = name;
00151 }
00152
00153
00154 stringstream ss;
00155 ss << "SELECT logic_id FROM channelView WHERE name = :n AND";
00156 int idarray[] = {id1, id2, id3};
00157 for (int i=1; i<=3; i++) {
00158 if (idarray[i-1] == EcalLogicID::NULLID) {
00159 ss << " id"<<i<<" IS NULL AND";
00160 } else {
00161 ss << " id"<<i<<" = :id"<<i<<" AND";
00162 }
00163 }
00164 ss <<" maps_to = :m";
00165
00166
00167
00168 int logic_id;
00169 try {
00170 stmt->setSQL(ss.str());
00171
00172
00173 int j = 1;
00174 stmt->setString(j, name);
00175 j++;
00176 for (int i=0; i<3; i++) {
00177 if (idarray[i] != EcalLogicID::NULLID) {
00178 stmt->setInt(j, idarray[i]);
00179 j++;
00180 }
00181 }
00182 stmt->setString(j, mapsTo);
00183
00184
00185 ResultSet* rset = stmt->executeQuery();
00186 if ( rset->next() ) {
00187 logic_id = rset->getInt(1);
00188 } else {
00189 stringstream msg;
00190 msg << "ERROR: Query for EcalLogicID failed for parameters [" <<
00191 "name=" << name << ",maps_to=" << mapsTo <<
00192 ",id1=" << id1 << ",id2=" << id2 << ",id3=" << id3 << "]";
00193 throw(std::runtime_error(msg.str()));
00194 }
00195 } catch (SQLException &e) {
00196 throw(std::runtime_error("ERROR: Failed to retrive logic_id: " + e.getMessage() ));
00197 }
00198
00199
00200 return EcalLogicID(name, logic_id, id1, id2, id3, mapsTo);
00201 }
00202
00203 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDSet( string name,
00204 int fromId1, int toId1,
00205 int fromId2, int toId2,
00206 int fromId3, int toId3,
00207 string mapsTo )
00208 throw(std::runtime_error)
00209 {
00210 if (mapsTo == "") {
00211 mapsTo = name;
00212 }
00213
00214 int idArray[] = { fromId1, toId1, fromId2, toId2, fromId3, toId3 };
00215 int from, to;
00216
00217 stringstream ss;
00218 ss << "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE name = :name AND ";
00219
00220
00221 for (int i=1; i<=3; i++) {
00222 from = idArray[2*(i-1)];
00223 to = idArray[2*(i-1) + 1];
00224
00225
00226 if ((from == EcalLogicID::NULLID && to != EcalLogicID::NULLID) ||
00227 (from != EcalLogicID::NULLID && to == EcalLogicID::NULLID) ||
00228 (from > to)) {
00229 throw(std::runtime_error("ERROR: Bad arguments for getEcalLogicIDSet"));
00230 }
00231
00232
00233 if (from == EcalLogicID::NULLID && to == EcalLogicID::NULLID) {
00234 ss << "id" << i << " IS NULL AND ";
00235 } else {
00236 ss << "id" << i << " >= :id" << i << "from AND " <<
00237 "id" << i << " <= :id" << i << "to AND ";
00238 }
00239 }
00240 ss << "maps_to = :maps_to ORDER BY id1, id2, id3";
00241
00242 std::vector<EcalLogicID> result;
00243
00244 try {
00245 stmt->setSQL(ss.str());
00246
00247
00248 int j = 1;
00249 stmt->setString(j, name);
00250 j++;
00251
00252 for (int i=0; i<3; i++) {
00253 from = idArray[2*i];
00254 to = idArray[2*i + 1];
00255 if (from != EcalLogicID::NULLID) {
00256 stmt->setInt(j, from);
00257 j++;
00258 stmt->setInt(j, to);
00259 j++;
00260 }
00261 }
00262
00263 stmt->setString(j, mapsTo);
00264
00265
00266 stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
00267
00268 ResultSet* rset = stmt->executeQuery();
00269
00270 int id1, id2, id3, logicId;
00271
00272 while (rset->next()) {
00273 name = rset->getString(1);
00274 logicId = rset->getInt(2);
00275 id1 = rset->getInt(3);
00276 if (rset->isNull(3)) { id1 = EcalLogicID::NULLID; }
00277 id2 = rset->getInt(4);
00278 if (rset->isNull(4)) { id2 = EcalLogicID::NULLID; }
00279 id3 = rset->getInt(5);
00280 if (rset->isNull(5)) { id3 = EcalLogicID::NULLID; }
00281 mapsTo = rset->getString(6);
00282
00283 EcalLogicID ecid = EcalLogicID( name, logicId, id1, id2, id3, mapsTo );
00284 result.push_back(ecid);
00285 }
00286 stmt->setPrefetchRowCount(0);
00287
00288 } catch (SQLException &e) {
00289 throw(std::runtime_error("ERROR: Failure while getting EcalLogicID set: " + e.getMessage() ));
00290 }
00291
00292 return result;
00293 }
00294
00295 std::map<int, int> EcalCondDBInterface::getEcalLogicID2LmrMap() {
00296 std::map<int, int> ret;
00297 std::vector<EcalLogicID> crystals_EB =
00298 getEcalLogicIDSetOrdered( "EB_crystal_number",
00299 1,36,1,1700,
00300 EcalLogicID::NULLID,EcalLogicID::NULLID,
00301 "EB_crystal_number", EcalLogicID::NULLID);
00302 std::vector<EcalLogicID> crystals_EE =
00303 getEcalLogicIDSetOrdered( "EE_crystal_number",
00304 -1,1,1,100,
00305 1,100,
00306 "EE_crystal_number", EcalLogicID::NULLID);
00307 std::vector<EcalLogicID> EB_lmr =
00308 getEcalLogicIDSetOrdered( "EB_crystal_number",
00309 1,36,1,1700,
00310 EcalLogicID::NULLID,EcalLogicID::NULLID,
00311 "ECAL_LMR", EcalLogicID::NULLID);
00312 std::vector<EcalLogicID> EE_lmr =
00313 getEcalLogicIDSetOrdered( "EE_crystal_number",
00314 -1,1,1,100,
00315 1,100,
00316 "ECAL_LMR", EcalLogicID::NULLID);
00317 unsigned int neb = crystals_EB.size();
00318 unsigned int nee = crystals_EE.size();
00319 if (neb != EB_lmr.size()) {
00320 throw(std::runtime_error("ERROR: EB Vectors size do not agree"));
00321 }
00322 if (nee != EE_lmr.size()) {
00323 throw(std::runtime_error("ERROR: EE Vectors size do not agree"));
00324 }
00325 for (unsigned int i = 0; i < neb; i++) {
00326 ret[crystals_EB[i].getLogicID()] = EB_lmr[i].getLogicID() % 100;
00327 }
00328 for (unsigned int i = 0; i < nee; i++) {
00329 ret[crystals_EE[i].getLogicID()] = EE_lmr[i].getLogicID() % 100;
00330 }
00331 return ret;
00332 }
00333
00334 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDMappedTo(int lmr_logic_id, std::string maps_to) {
00335 std::string name = "EB_crystal_angle";
00336 std::string sql = "SELECT LOGIC_ID, ID1, ID2, ID3 "
00337 "FROM CHANNELVIEW WHERE NAME = 'EB_crystal_angle' AND LOGIC_ID IN "
00338 "(SELECT LOGIC_ID FROM CHANNELVIEW WHERE NAME = 'EB_crystal_number' AND "
00339 "ID1*10000+ID2 IN (SELECT DISTINCT ID1*10000+ID2 FROM CHANNELVIEW "
00340 "WHERE LOGIC_ID = :1 AND NAME = 'EB_crystal_number' AND MAPS_TO = :2) "
00341 "AND NAME = MAPS_TO)";
00342 if ((lmr_logic_id / 1000000000) == 2) {
00343 name = "EE_crystal_number";
00344 sql = "SELECT LOGIC_ID, ID1, ID2, ID3 "
00345 "FROM CHANNELVIEW WHERE NAME = 'EE_crystal_number' AND LOGIC_ID IN "
00346 "(SELECT LOGIC_ID FROM CHANNELVIEW WHERE NAME = 'EE_crystal_number' AND "
00347 "ID1*10000000+ID2*10000+ID3 IN (SELECT DISTINCT "
00348 "ID1*10000000+ID2*10000+ID3 FROM CHANNELVIEW "
00349 "WHERE LOGIC_ID = :1 AND NAME = 'EE_crystal_number' AND MAPS_TO = :2) "
00350 "AND NAME = MAPS_TO) AND NAME = MAPS_TO";
00351 }
00352 std::vector<EcalLogicID> ret;
00353 try {
00354 stmt->setSQL(sql.c_str());
00355 stmt->setInt(1, lmr_logic_id);
00356 stmt->setString(2, maps_to);
00357 stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
00358
00359 ResultSet* rset = stmt->executeQuery();
00360
00361 while (rset->next()) {
00362 int logic_id = rset->getInt(1);
00363 int id1 = rset->getInt(2);
00364 if (rset->isNull(2)) { id1 = EcalLogicID::NULLID; }
00365 int id2 = rset->getInt(3);
00366 if (rset->isNull(3)) { id2 = EcalLogicID::NULLID; }
00367 int id3 = rset->getInt(4);
00368 if (rset->isNull(4)) { id3 = EcalLogicID::NULLID; }
00369
00370 EcalLogicID ecid = EcalLogicID( name, logic_id, id1, id2, id3, maps_to );
00371 ret.push_back(ecid);
00372 }
00373 stmt->setPrefetchRowCount(0);
00374 }
00375 catch (SQLException &e) {
00376 throw(std::runtime_error("ERROR: Failure while getting EcalLogicID set: " + e.getMessage() ));
00377 }
00378 return ret;
00379 }
00380
00381 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMR(int lmr) {
00382 return getEcalLogicIDMappedTo(lmr, "ECAL_LMR");
00383 }
00384
00385 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMR(const EcalLogicID &lmr) {
00386 return getEcalLogicIDForLMR(lmr.getLogicID());
00387 }
00388
00389 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMPN(int lmr) {
00390 if ((lmr / 1000000000) == 2) {
00391 return getEcalLogicIDMappedTo(lmr, "EE_LM_PN");
00392 } else {
00393 return getEcalLogicIDMappedTo(lmr, "EB_LM_PN");
00394 }
00395 }
00396
00397 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMPN(const EcalLogicID &lmr) {
00398 return getEcalLogicIDForLMR(lmr.getLogicID());
00399 }
00400
00401 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDSetOrdered( string name,
00402 int fromId1, int toId1,
00403 int fromId2, int toId2,
00404 int fromId3, int toId3,
00405 string mapsTo, int orderedBy )
00406
00407
00408 throw(std::runtime_error)
00409 {
00410 if (mapsTo == "") {
00411 mapsTo = name;
00412 }
00413
00414 int idArray[] = { fromId1, toId1, fromId2, toId2, fromId3, toId3 };
00415 int from, to;
00416
00417 stringstream ss;
00418 ss << "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE name = :name AND ";
00419
00420
00421 for (int i=1; i<=3; i++) {
00422 from = idArray[2*(i-1)];
00423 to = idArray[2*(i-1) + 1];
00424
00425
00426 if ((from == EcalLogicID::NULLID && to != EcalLogicID::NULLID) ||
00427 (from != EcalLogicID::NULLID && to == EcalLogicID::NULLID) ||
00428 (from > to)) {
00429 throw(std::runtime_error("ERROR: Bad arguments for getEcalLogicIDSet"));
00430 }
00431
00432
00433 if (from == EcalLogicID::NULLID && to == EcalLogicID::NULLID) {
00434 ss << "id" << i << " IS NULL AND ";
00435 } else {
00436 ss << "id" << i << " >= :id" << i << "from AND " <<
00437 "id" << i << " <= :id" << i << "to AND ";
00438 }
00439 }
00440 ss << "maps_to = :maps_to ";
00441
00442 if(orderedBy==EcalLogicID::NULLID){
00443 ss<<" ORDER BY id1, id2, id3";
00444 } else if(orderedBy==1 || orderedBy==12 || orderedBy==123){
00445 ss<<" ORDER BY id1, id2, id3 ";
00446 } else if (orderedBy==213 || orderedBy==21 ){
00447 ss<<" ORDER BY id2, id1, id3 ";
00448 } else if (orderedBy==231|| orderedBy==23){
00449 ss<<" ORDER BY id2, id3, id1 ";
00450 } else if (orderedBy==321|| orderedBy==32){
00451 ss<<" ORDER BY id3, id2, id1 ";
00452 } else if (orderedBy==312|| orderedBy==31){
00453 ss<<" ORDER BY id3, id1, id2 ";
00454 } else if (orderedBy==132|| orderedBy==13){
00455 ss<<" ORDER BY id1, id3, id2 ";
00456 } else if (orderedBy==1234 ){
00457 ss<<" ORDER BY id1, id2, id3, logic_id ";
00458 } else if (orderedBy==4) {
00459 ss<<" ORDER BY logic_id ";
00460 } else {
00461 ss<<" ORDER BY id1, id2, id3";
00462 }
00463
00464 std::vector<EcalLogicID> result;
00465
00466 try {
00467 stmt->setSQL(ss.str());
00468
00469
00470 int j = 1;
00471 stmt->setString(j, name);
00472 j++;
00473
00474 for (int i=0; i<3; i++) {
00475 from = idArray[2*i];
00476 to = idArray[2*i + 1];
00477 if (from != EcalLogicID::NULLID) {
00478 stmt->setInt(j, from);
00479 j++;
00480 stmt->setInt(j, to);
00481 j++;
00482 }
00483 }
00484
00485 stmt->setString(j, mapsTo);
00486
00487
00488 stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
00489
00490 ResultSet* rset = stmt->executeQuery();
00491
00492 int id1, id2, id3, logicId;
00493
00494 while (rset->next()) {
00495 name = rset->getString(1);
00496 logicId = rset->getInt(2);
00497 id1 = rset->getInt(3);
00498 if (rset->isNull(3)) { id1 = EcalLogicID::NULLID; }
00499 id2 = rset->getInt(4);
00500 if (rset->isNull(4)) { id2 = EcalLogicID::NULLID; }
00501 id3 = rset->getInt(5);
00502 if (rset->isNull(5)) { id3 = EcalLogicID::NULLID; }
00503 mapsTo = rset->getString(6);
00504
00505 EcalLogicID ecid = EcalLogicID( name, logicId, id1, id2, id3, mapsTo );
00506 result.push_back(ecid);
00507 }
00508 stmt->setPrefetchRowCount(0);
00509
00510 } catch (SQLException &e) {
00511 throw(std::runtime_error("ERROR: Failure while getting EcalLogicID set: " + e.getMessage() ));
00512 }
00513
00514 return result;
00515 }
00516
00517
00518
00519 void EcalCondDBInterface::insertRunIOV(RunIOV* iov)
00520 throw(std::runtime_error)
00521 {
00522 try {
00523 iov->setConnection(env, conn);
00524 iov->writeDB();
00525 } catch(std::runtime_error &e) {
00526 conn->rollback();
00527 throw(e);
00528 }
00529 conn->commit();
00530 }
00531
00532 void EcalCondDBInterface::insertLmfSeq(LMFSeqDat *iov)
00533 throw(std::runtime_error)
00534 {
00535 try {
00536 iov->setConnection(env, conn);
00537 iov->writeDB();
00538 } catch(std::runtime_error &e) {
00539 conn->rollback();
00540 throw(e);
00541 }
00542 conn->commit();
00543 }
00544
00545 void EcalCondDBInterface::insertLmfLmrSubIOV(LMFLmrSubIOV *iov)
00546 throw(std::runtime_error)
00547 {
00548 try {
00549 iov->setConnection(env, conn);
00550 iov->writeDB();
00551 } catch(std::runtime_error &e) {
00552 conn->rollback();
00553 throw(e);
00554 }
00555 conn->commit();
00556 }
00557
00558 void EcalCondDBInterface::insertLmfIOV(LMFIOV *iov)
00559 throw(std::runtime_error)
00560 {
00561 try {
00562 iov->setConnection(env, conn);
00563 iov->writeDB();
00564 } catch(std::runtime_error &e) {
00565 conn->rollback();
00566 throw(e);
00567 }
00568 conn->commit();
00569 }
00570
00571 void EcalCondDBInterface::insertLmfDat(LMFDat *dat)
00572 throw(std::runtime_error)
00573 {
00574 try {
00575 dat->setConnection(env, conn);
00576 dat->writeDB();
00577 } catch(std::runtime_error &e) {
00578 conn->rollback();
00579 throw(e);
00580 }
00581 conn->commit();
00582 }
00583
00584 void EcalCondDBInterface::insertLmfDat(std::list<LMFDat *> dat)
00585 throw(std::runtime_error)
00586 {
00587 try {
00588 std::list<LMFDat *>::iterator i = dat.begin();
00589 std::list<LMFDat *>::iterator e = dat.end();
00590 while (i != e) {
00591 (*i)->setConnection(env, conn);
00592 (*i)->writeDB();
00593 i++;
00594 }
00595 } catch(std::runtime_error &e) {
00596 conn->rollback();
00597 throw(e);
00598 }
00599 conn->commit();
00600 }
00601
00602 void EcalCondDBInterface::insertLmfRunIOV(LMFRunIOV *iov)
00603 throw(std::runtime_error)
00604 {
00605 try {
00606 iov->setConnection(env, conn);
00607 iov->writeDB();
00608 } catch(std::runtime_error &e) {
00609 conn->rollback();
00610 throw(e);
00611 }
00612 conn->commit();
00613 }
00614
00615 void EcalCondDBInterface::updateRunIOV(RunIOV* iov)
00616 throw(std::runtime_error)
00617 {
00618 try {
00619 iov->setConnection(env, conn);
00620 iov->updateEndTimeDB();
00621 } catch(std::runtime_error &e) {
00622 conn->rollback();
00623 throw(e);
00624 }
00625 conn->commit();
00626 }
00627
00628 void EcalCondDBInterface::updateRunIOVEndTime(RunIOV* iov)
00629 throw(std::runtime_error)
00630 {
00631 try {
00632 iov->setConnection(env, conn);
00633 iov->updateEndTimeDB();
00634 } catch(std::runtime_error &e) {
00635 conn->rollback();
00636 throw(e);
00637 }
00638 conn->commit();
00639 }
00640
00641 void EcalCondDBInterface::updateRunIOVStartTime(RunIOV* iov)
00642 throw(std::runtime_error)
00643 {
00644 try {
00645 iov->setConnection(env, conn);
00646 iov->updateStartTimeDB();
00647 } catch(std::runtime_error &e) {
00648 conn->rollback();
00649 throw(e);
00650 }
00651 conn->commit();
00652 }
00653
00654 void EcalCondDBInterface::updateRunConfig(ODRunConfigInfo* od)
00655 throw(std::runtime_error)
00656 {
00657 try {
00658 od->setConnection(env, conn);
00659 od->updateDefaultCycle();
00660 } catch(std::runtime_error &e) {
00661 conn->rollback();
00662 throw(e);
00663 }
00664 conn->commit();
00665 }
00666
00667 RunIOV EcalCondDBInterface::fetchRunIOV(RunTag* tag, run_t run)
00668 throw(std::runtime_error)
00669 {
00670 RunIOV iov;
00671 iov.setConnection(env, conn);
00672 iov.setByRun(tag, run);
00673 return iov;
00674 }
00675
00676
00677
00678 RunIOV EcalCondDBInterface::fetchRunIOV(std::string location, run_t run)
00679 throw(std::runtime_error)
00680 {
00681 RunIOV iov;
00682 iov.setConnection(env, conn);
00683 iov.setByRun(location, run);
00684 return iov;
00685 }
00686
00687 RunIOV EcalCondDBInterface::fetchRunIOV(std::string location, const Tm &t)
00688 throw(std::runtime_error)
00689 {
00690 RunIOV iov;
00691 iov.setConnection(env, conn);
00692 iov.setByTime(location, t);
00693 return iov;
00694 }
00695
00696 void EcalCondDBInterface::insertMonRunIOV(MonRunIOV* iov)
00697 throw(std::runtime_error)
00698 {
00699 try {
00700 iov->setConnection(env, conn);
00701 iov->writeDB();
00702 } catch(std::runtime_error &e) {
00703 conn->rollback();
00704 throw(e);
00705 }
00706 conn->commit();
00707 }
00708
00709 void EcalCondDBInterface::insertDCUIOV(DCUIOV* iov)
00710 throw(std::runtime_error)
00711 {
00712 try {
00713 iov->setConnection(env, conn);
00714 iov->writeDB();
00715 } catch(std::runtime_error &e) {
00716 conn->rollback();
00717 throw(e);
00718 }
00719 conn->commit();
00720 }
00721
00722
00723
00724
00725 MonRunIOV EcalCondDBInterface::fetchMonRunIOV(RunTag* runtag, MonRunTag* montag, run_t run, subrun_t subrun)
00726 throw(std::runtime_error)
00727 {
00728 RunIOV runiov = fetchRunIOV(runtag, run);
00729 MonRunIOV moniov;
00730 moniov.setConnection(env, conn);
00731 moniov.setByRun(montag, &runiov, subrun);
00732 return moniov;
00733 }
00734
00735
00736
00737 DCUIOV EcalCondDBInterface::fetchDCUIOV(DCUTag* tag, Tm eventTm)
00738 throw(std::runtime_error)
00739 {
00740 DCUIOV dcuiov;
00741 dcuiov.setConnection(env, conn);
00742 dcuiov.setByTm(tag, eventTm);
00743 return dcuiov;
00744 }
00745
00746 RunIOV EcalCondDBInterface::fetchLMFLastRun() const {
00747 LMFSeqDat seq(env, conn);
00748 return seq.fetchLastRun();
00749 }
00750
00751 LMFRunIOV EcalCondDBInterface::fetchLMFRunIOV(RunTag* runtag, LMFRunTag* lmftag, run_t run, subrun_t subrun)
00752 throw(std::runtime_error)
00753 {
00754 RunIOV runiov = fetchRunIOV(runtag, run);
00755 LMFRunIOV lmfiov;
00756 lmfiov.setConnection(env, conn);
00757
00758 return lmfiov;
00759 }
00760
00761 bool EcalCondDBInterface::fetchLMFRunIOV(const LMFSeqDat &seq, LMFRunIOV& iov,
00762 int lmr, int type, int color ) const {
00763 bool ret = false;
00764 iov.setConnection(env, conn);
00765 std::list<LMFRunIOV> iovlist = iov.fetchBySequence(seq, lmr, type, color);
00766 int s = iovlist.size();
00767 if (s > 0) {
00768 iov = iovlist.front();
00769 ret = true;
00770 if (s > 1) {
00771
00772 std::cout << "################################" << std::endl;
00773 std::cout << "################################" << std::endl;
00774 std::cout << "WARNING: More than one LMFRUNIOV" << std::endl;
00775 std::cout << " Found for seq " << seq.getID() << std::endl;
00776 std::cout << " lmr " << lmr << " type " << type << std::endl;
00777 std::cout << " and color " << color << std::endl;
00778 std::cout << "################################" << std::endl;
00779 std::cout << "################################" << std::endl;
00780 }
00781 } else {
00782
00783 iovlist = iov.fetchLastBeforeSequence(seq, lmr, type, color);
00784 s = iovlist.size();
00785 if (s == 1) {
00786 iov = iovlist.front();
00787 }
00788 }
00789 return ret;
00790 }
00791
00792 CaliIOV EcalCondDBInterface::fetchCaliIOV(CaliTag* tag, Tm eventTm)
00793 throw(std::runtime_error)
00794 {
00795 CaliIOV caliiov;
00796 caliiov.setConnection(env, conn);
00797 caliiov.setByTm(tag, eventTm);
00798 return caliiov;
00799 }
00800
00801 DCSPTMTempList EcalCondDBInterface::fetchDCSPTMTempList(EcalLogicID ecid)
00802 throw(std::runtime_error)
00803 {
00804 DCSPTMTempList r;
00805 r.setConnection(env, conn);
00806 r.fetchValuesForECID(ecid);
00807 return r;
00808 }
00809
00810 DCSPTMTempList EcalCondDBInterface::fetchDCSPTMTempList(EcalLogicID ecid, Tm start, Tm end)
00811 throw(std::runtime_error)
00812 {
00813 DCSPTMTempList r;
00814 r.setConnection(env, conn);
00815 r.fetchValuesForECIDAndTime(ecid, start, end);
00816 return r;
00817 }
00818
00819 RunList EcalCondDBInterface::fetchRunList(RunTag tag)
00820 throw(std::runtime_error)
00821 {
00822 RunList r;
00823 r.setConnection(env, conn);
00824 r.setRunTag(tag);
00825 r.fetchRuns();
00826 return r;
00827 }
00828
00829 RunList EcalCondDBInterface::fetchRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error){
00830 RunList r;
00831 r.setConnection(env, conn);
00832 r.setRunTag(tag);
00833 r.fetchRuns( min_run, max_run);
00834 return r;
00835 }
00836
00837 RunList EcalCondDBInterface::fetchNonEmptyRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error){
00838 RunList r;
00839 r.setConnection(env, conn);
00840 r.setRunTag(tag);
00841 r.fetchNonEmptyRuns( min_run, max_run);
00842 return r;
00843 }
00844
00845 RunList EcalCondDBInterface::fetchNonEmptyGlobalRunList(RunTag tag, int min_run, int max_run) throw(std::runtime_error){
00846 RunList r;
00847 r.setConnection(env, conn);
00848 r.setRunTag(tag);
00849 r.fetchNonEmptyGlobalRuns( min_run, max_run);
00850 return r;
00851 }
00852
00853 RunList EcalCondDBInterface::fetchRunListByLocation(RunTag tag, int min_run, int max_run , const LocationDef locDef)
00854 throw(std::runtime_error) {
00855 RunList r;
00856 r.setConnection(env, conn);
00857 r.setRunTag(tag);
00858 r.fetchRunsByLocation( min_run, max_run, locDef);
00859 return r;
00860 }
00861
00862 RunList EcalCondDBInterface::fetchGlobalRunListByLocation(RunTag tag, int min_run, int max_run , const LocationDef locDef)
00863 throw(std::runtime_error) {
00864 RunList r;
00865 r.setConnection(env, conn);
00866 r.setRunTag(tag);
00867 r.fetchGlobalRunsByLocation( min_run, max_run, locDef);
00868 return r;
00869 }
00870
00871 RunList EcalCondDBInterface::fetchRunListLastNRuns(RunTag tag, int max_run, int n_runs)
00872 throw(std::runtime_error){
00873 RunList r;
00874 r.setConnection(env, conn);
00875 r.setRunTag(tag);
00876 r.fetchLastNRuns( max_run, n_runs);
00877 return r;
00878 }
00879
00880
00881
00882
00883
00884
00885 MonRunList EcalCondDBInterface::fetchMonRunList(RunTag tag, MonRunTag monrunTag)
00886 throw(std::runtime_error)
00887 {
00888 MonRunList r;
00889 r.setConnection(env, conn);
00890 r.setRunTag(tag);
00891 r.setMonRunTag(monrunTag);
00892 r.fetchRuns();
00893 return r;
00894 }
00895
00896 MonRunList EcalCondDBInterface::fetchMonRunList(RunTag tag, MonRunTag monrunTag,int min_run, int max_run)
00897 throw(std::runtime_error)
00898 {
00899 MonRunList r;
00900 r.setConnection(env, conn);
00901 r.setRunTag(tag);
00902 r.setMonRunTag(monrunTag);
00903 r.fetchRuns(min_run, max_run);
00904 return r;
00905 }
00906
00907 MonRunList EcalCondDBInterface::fetchMonRunListLastNRuns(RunTag tag, MonRunTag monrunTag,int max_run, int n_runs )
00908 throw(std::runtime_error)
00909 {
00910 MonRunList r;
00911 r.setConnection(env, conn);
00912 r.setRunTag(tag);
00913 r.setMonRunTag(monrunTag);
00914 r.fetchLastNRuns(max_run, n_runs );
00915 return r;
00916 }
00917
00918
00919
00920 void EcalCondDBInterface::dummy()
00921 {
00922 }