Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:02

0001 
0002 #include <iostream>
0003 #include <string>
0004 #include <vector>
0005 #include <sstream>
0006 #include <cstdlib>
0007 #include <cstdlib>
0008 #include <ctime>
0009 #include <stdexcept>
0010 #include "OnlineDB/Oracle/interface/Oracle.h"
0011 
0012 #include "OnlineDB/EcalCondDB/interface/IDBObject.h"
0013 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
0014 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
0015 #include "OnlineDB/EcalCondDB/interface/EcalLogicID.h"
0016 #include "OnlineDB/EcalCondDB/interface/DCSPTMTempList.h"
0017 
0018 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0019 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0020 #include "OnlineDB/EcalCondDB/interface/RunList.h"
0021 #include "OnlineDB/EcalCondDB/interface/MonRunList.h"
0022 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0023 #include "OnlineDB/EcalCondDB/interface/LMFRunTag.h"
0024 
0025 using namespace std;
0026 using namespace oracle::occi;
0027 
0028 void EcalCondDBInterface::fillLogicId2DetIdMaps() {
0029   // retrieve the lists of logic_ids, to build the detids
0030   std::vector<EcalLogicID> crystals_EB = getEcalLogicIDSetOrdered(
0031       "EB_crystal_angle", -85, 85, 1, 360, EcalLogicID::NULLID, EcalLogicID::NULLID, "EB_crystal_number", 4);
0032   std::vector<EcalLogicID> crystals_EE =
0033       getEcalLogicIDSetOrdered("EE_crystal_number", -1, 1, 1, 100, 1, 100, "EE_crystal_number", 4);
0034   // fill the barrel map
0035   std::vector<EcalLogicID>::const_iterator ieb = crystals_EB.begin();
0036   std::vector<EcalLogicID>::const_iterator eeb = crystals_EB.end();
0037   while (ieb != eeb) {
0038     int iEta = ieb->getID1();
0039     int iPhi = ieb->getID2();
0040     EBDetId ebdetid(iEta, iPhi);
0041     _logicId2DetId[ieb->getLogicID()] = ebdetid;
0042     _detId2LogicId[ebdetid] = ieb->getLogicID();
0043     ieb++;
0044   }
0045 
0046   // fill the endcap map
0047   std::vector<EcalLogicID>::const_iterator iee = crystals_EE.begin();
0048   std::vector<EcalLogicID>::const_iterator eee = crystals_EE.end();
0049 
0050   while (iee != eee) {
0051     int iSide = iee->getID1();
0052     int iX = iee->getID2();
0053     int iY = iee->getID3();
0054     EEDetId eedetidpos(iX, iY, iSide);
0055     _logicId2DetId[iee->getLogicID()] = eedetidpos;
0056     _detId2LogicId[eedetidpos] = iee->getLogicID();
0057     iee++;
0058   }
0059 }
0060 
0061 EcalLogicID EcalCondDBInterface::getEcalLogicID(int logicID) noexcept(false) {
0062   string sql =
0063       "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE logic_id = :logicID AND name=maps_to";
0064 
0065   int id1, id2, id3;
0066   string name, mapsTo;
0067 
0068   try {
0069     stmt->setSQL(sql);
0070     stmt->setInt(1, logicID);
0071     ResultSet* rset = stmt->executeQuery();
0072 
0073     if (rset->next()) {
0074       name = rset->getString(1);
0075       logicID = rset->getInt(2);
0076       id1 = rset->getInt(3);
0077       if (rset->isNull(3)) {
0078         id1 = EcalLogicID::NULLID;
0079       }
0080       id2 = rset->getInt(4);
0081       if (rset->isNull(4)) {
0082         id2 = EcalLogicID::NULLID;
0083       }
0084       id3 = rset->getInt(5);
0085       if (rset->isNull(5)) {
0086         id3 = EcalLogicID::NULLID;
0087       }
0088       mapsTo = rset->getString(6);
0089     } else {
0090       stringstream msg;
0091       msg << "ERROR:  Cannot build EcalLogicID for logic_id " << logicID;
0092       throw(std::runtime_error(msg.str()));
0093     }
0094 
0095   } catch (SQLException& e) {
0096     throw(std::runtime_error(std::string("ERROR:  Failed to retrive ids:  ") + e.getMessage()));
0097   }
0098 
0099   return EcalLogicID(name, logicID, id1, id2, id3, mapsTo);
0100 }
0101 
0102 std::list<ODDelaysDat> EcalCondDBInterface::fetchFEDelaysForRun(RunIOV* iov) noexcept(false) {
0103   std::list<ODDelaysDat> ret;
0104   RunFEConfigDat d;
0105   std::map<EcalLogicID, RunFEConfigDat> fillMap;
0106   try {
0107     d.setConnection(env, conn);
0108     d.fetchData(&fillMap, iov);
0109   } catch (std::runtime_error& e) {
0110     throw e;
0111   }
0112   std::map<EcalLogicID, RunFEConfigDat>::const_iterator i = fillMap.begin();
0113   std::map<EcalLogicID, RunFEConfigDat>::const_iterator e = fillMap.end();
0114   while (i != e) {
0115     ODFEDAQConfig feDaqConfig;
0116     ODFEDAQConfig temp;
0117     temp.setId(i->second.getConfigId());
0118     feDaqConfig.setConnection(env, conn);
0119     feDaqConfig.fetchData(&temp);
0120     std::vector<ODDelaysDat> delays;
0121     ODDelaysDat temp2;
0122     temp2.setConnection(env, conn);
0123     temp2.fetchData(&delays, temp.getDelayId());
0124     std::vector<ODDelaysDat>::const_iterator di = delays.begin();
0125     std::vector<ODDelaysDat>::const_iterator de = delays.end();
0126     while (di != de) {
0127       ret.push_back(*di++);
0128     }
0129     i++;
0130   }
0131   return ret;
0132 }
0133 
0134 EcalLogicID EcalCondDBInterface::getEcalLogicID(string name, int id1, int id2, int id3, string mapsTo) noexcept(false) {
0135   if (mapsTo.empty()) {
0136     mapsTo = name;
0137   }
0138 
0139   // build the sql string
0140   stringstream ss;
0141   ss << "SELECT logic_id FROM channelView WHERE name = :n AND";
0142   int idarray[] = {id1, id2, id3};
0143   for (int i = 1; i <= 3; i++) {
0144     if (idarray[i - 1] == EcalLogicID::NULLID) {
0145       ss << " id" << i << " IS NULL AND";
0146     } else {
0147       ss << " id" << i << " = :id" << i << " AND";
0148     }
0149   }
0150   ss << " maps_to = :m";
0151 
0152   // cout << "SQL:  " << ss.str() << endl;
0153 
0154   int logic_id;
0155   try {
0156     stmt->setSQL(ss.str());
0157 
0158     // bind the parameters
0159     int j = 1;  // parameter number counter
0160     stmt->setString(j, name);
0161     j++;
0162     for (int i = 0; i < 3; i++) {
0163       if (idarray[i] != EcalLogicID::NULLID) {
0164         stmt->setInt(j, idarray[i]);
0165         j++;
0166       }
0167     }
0168     stmt->setString(j, mapsTo);
0169 
0170     // execute the statement and retrieve the logic_id
0171     ResultSet* rset = stmt->executeQuery();
0172     if (rset->next()) {
0173       logic_id = rset->getInt(1);
0174     } else {
0175       stringstream msg;
0176       msg << "ERROR:  Query for EcalLogicID failed for parameters ["
0177           << "name=" << name << ",maps_to=" << mapsTo << ",id1=" << id1 << ",id2=" << id2 << ",id3=" << id3 << "]";
0178       throw(std::runtime_error(msg.str()));
0179     }
0180   } catch (SQLException& e) {
0181     throw(std::runtime_error(std::string("ERROR:  Failed to retrive logic_id:  ") + e.getMessage()));
0182   }
0183 
0184   // create and return the EcalLogicID object
0185   return EcalLogicID(name, logic_id, id1, id2, id3, mapsTo);
0186 }
0187 
0188 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDSet(
0189     string name, int fromId1, int toId1, int fromId2, int toId2, int fromId3, int toId3, string mapsTo) noexcept(false) {
0190   if (mapsTo.empty()) {
0191     mapsTo = name;
0192   }
0193 
0194   int idArray[] = {fromId1, toId1, fromId2, toId2, fromId3, toId3};
0195   int from, to;
0196 
0197   stringstream ss;
0198   ss << "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE name = :name AND ";
0199 
0200   // loop through the three ids
0201   for (int i = 1; i <= 3; i++) {
0202     from = idArray[2 * (i - 1)];
0203     to = idArray[2 * (i - 1) + 1];
0204 
0205     // check the id arguments in pairs
0206     if ((from == EcalLogicID::NULLID && to != EcalLogicID::NULLID) ||  // one is null
0207         (from != EcalLogicID::NULLID && to == EcalLogicID::NULLID) ||  //   but not the other
0208         (from > to)) {                                                 // negative interval
0209       throw(std::runtime_error("ERROR:  Bad arguments for getEcalLogicIDSet"));
0210     }
0211 
0212     // build the sql
0213     if (from == EcalLogicID::NULLID && to == EcalLogicID::NULLID) {
0214       ss << "id" << i << " IS NULL AND ";
0215     } else {
0216       ss << "id" << i << " >= :id" << i << "from AND "
0217          << "id" << i << " <= :id" << i << "to AND ";
0218     }
0219   }
0220   ss << "maps_to = :maps_to ORDER BY id1, id2, id3";
0221 
0222   std::vector<EcalLogicID> result;
0223 
0224   try {
0225     stmt->setSQL(ss.str());
0226 
0227     // bind the parameters
0228     int j = 1;  // parameter number counter
0229     stmt->setString(j, name);
0230     j++;
0231 
0232     for (int i = 0; i < 3; i++) {
0233       from = idArray[2 * i];
0234       to = idArray[2 * i + 1];
0235       if (from != EcalLogicID::NULLID) {
0236         stmt->setInt(j, from);
0237         j++;
0238         stmt->setInt(j, to);
0239         j++;
0240       }
0241     }
0242 
0243     stmt->setString(j, mapsTo);
0244 
0245     stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
0246 
0247     ResultSet* rset = stmt->executeQuery();
0248 
0249     int id1, id2, id3, logicId;
0250 
0251     while (rset->next()) {
0252       name = rset->getString(1);
0253       logicId = rset->getInt(2);
0254       id1 = rset->getInt(3);
0255       if (rset->isNull(3)) {
0256         id1 = EcalLogicID::NULLID;
0257       }
0258       id2 = rset->getInt(4);
0259       if (rset->isNull(4)) {
0260         id2 = EcalLogicID::NULLID;
0261       }
0262       id3 = rset->getInt(5);
0263       if (rset->isNull(5)) {
0264         id3 = EcalLogicID::NULLID;
0265       }
0266       mapsTo = rset->getString(6);
0267 
0268       EcalLogicID ecid = EcalLogicID(name, logicId, id1, id2, id3, mapsTo);
0269       result.push_back(ecid);
0270     }
0271     stmt->setPrefetchRowCount(0);
0272 
0273   } catch (SQLException& e) {
0274     throw(std::runtime_error(std::string("ERROR:  Failure while getting EcalLogicID set:  ") + e.getMessage()));
0275   }
0276 
0277   return result;
0278 }
0279 
0280 std::map<int, int> EcalCondDBInterface::getEcalLogicID2LmrMap() {
0281   std::map<int, int> ret;
0282   std::vector<EcalLogicID> crystals_EB = getEcalLogicIDSetOrdered("EB_crystal_number",
0283                                                                   1,
0284                                                                   36,
0285                                                                   1,
0286                                                                   1700,
0287                                                                   EcalLogicID::NULLID,
0288                                                                   EcalLogicID::NULLID,
0289                                                                   "EB_crystal_number",
0290                                                                   EcalLogicID::NULLID);
0291   std::vector<EcalLogicID> crystals_EE =
0292       getEcalLogicIDSetOrdered("EE_crystal_number", -1, 1, 1, 100, 1, 100, "EE_crystal_number", EcalLogicID::NULLID);
0293   std::vector<EcalLogicID> EB_lmr = getEcalLogicIDSetOrdered(
0294       "EB_crystal_number", 1, 36, 1, 1700, EcalLogicID::NULLID, EcalLogicID::NULLID, "ECAL_LMR", EcalLogicID::NULLID);
0295   std::vector<EcalLogicID> EE_lmr =
0296       getEcalLogicIDSetOrdered("EE_crystal_number", -1, 1, 1, 100, 1, 100, "ECAL_LMR", EcalLogicID::NULLID);
0297   unsigned int neb = crystals_EB.size();
0298   unsigned int nee = crystals_EE.size();
0299   if (neb != EB_lmr.size()) {
0300     throw(std::runtime_error("ERROR: EB Vectors size do not agree"));
0301   }
0302   if (nee != EE_lmr.size()) {
0303     throw(std::runtime_error("ERROR: EE Vectors size do not agree"));
0304   }
0305   for (unsigned int i = 0; i < neb; i++) {
0306     ret[crystals_EB[i].getLogicID()] = EB_lmr[i].getLogicID() % 100;
0307   }
0308   for (unsigned int i = 0; i < nee; i++) {
0309     ret[crystals_EE[i].getLogicID()] = EE_lmr[i].getLogicID() % 100;
0310   }
0311   return ret;
0312 }
0313 
0314 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDMappedTo(int lmr_logic_id, std::string maps_to) {
0315   std::string name = "EB_crystal_angle";
0316   std::string sql =
0317       "SELECT LOGIC_ID, ID1, ID2, ID3 "
0318       "FROM CHANNELVIEW WHERE NAME = 'EB_crystal_angle' AND LOGIC_ID IN "
0319       "(SELECT LOGIC_ID FROM CHANNELVIEW WHERE NAME = 'EB_crystal_number' AND "
0320       "ID1*10000+ID2 IN (SELECT DISTINCT ID1*10000+ID2 FROM CHANNELVIEW "
0321       "WHERE LOGIC_ID = :1 AND NAME = 'EB_crystal_number' AND MAPS_TO = :2) "
0322       "AND NAME = MAPS_TO)";
0323   if ((lmr_logic_id / 1000000000) == 2) {
0324     name = "EE_crystal_number";
0325     sql =
0326         "SELECT LOGIC_ID, ID1, ID2, ID3 "
0327         "FROM CHANNELVIEW WHERE NAME = 'EE_crystal_number' AND LOGIC_ID IN "
0328         "(SELECT LOGIC_ID FROM CHANNELVIEW WHERE NAME = 'EE_crystal_number' AND "
0329         "ID1*10000000+ID2*10000+ID3 IN (SELECT DISTINCT "
0330         "ID1*10000000+ID2*10000+ID3 FROM CHANNELVIEW "
0331         "WHERE LOGIC_ID = :1 AND NAME = 'EE_crystal_number' AND MAPS_TO = :2) "
0332         "AND NAME = MAPS_TO) AND NAME = MAPS_TO";
0333   }
0334   std::vector<EcalLogicID> ret;
0335   try {
0336     stmt->setSQL(sql);
0337     stmt->setInt(1, lmr_logic_id);
0338     stmt->setString(2, maps_to);
0339     stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
0340 
0341     ResultSet* rset = stmt->executeQuery();
0342 
0343     while (rset->next()) {
0344       int logic_id = rset->getInt(1);
0345       int id1 = rset->getInt(2);
0346       if (rset->isNull(2)) {
0347         id1 = EcalLogicID::NULLID;
0348       }
0349       int id2 = rset->getInt(3);
0350       if (rset->isNull(3)) {
0351         id2 = EcalLogicID::NULLID;
0352       }
0353       int id3 = rset->getInt(4);
0354       if (rset->isNull(4)) {
0355         id3 = EcalLogicID::NULLID;
0356       }
0357 
0358       EcalLogicID ecid = EcalLogicID(name, logic_id, id1, id2, id3, maps_to);
0359       ret.push_back(ecid);
0360     }
0361     stmt->setPrefetchRowCount(0);
0362   } catch (SQLException& e) {
0363     throw(std::runtime_error(std::string("ERROR:  Failure while getting EcalLogicID set:  ") + e.getMessage()));
0364   }
0365   return ret;
0366 }
0367 
0368 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMR(int lmr) {
0369   return getEcalLogicIDMappedTo(lmr, "ECAL_LMR");
0370 }
0371 
0372 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMR(const EcalLogicID& lmr) {
0373   return getEcalLogicIDForLMR(lmr.getLogicID());
0374 }
0375 
0376 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMPN(int lmr) {
0377   if ((lmr / 1000000000) == 2) {
0378     return getEcalLogicIDMappedTo(lmr, "EE_LM_PN");
0379   } else {
0380     return getEcalLogicIDMappedTo(lmr, "EB_LM_PN");
0381   }
0382 }
0383 
0384 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDForLMPN(const EcalLogicID& lmr) {
0385   return getEcalLogicIDForLMR(lmr.getLogicID());
0386 }
0387 
0388 std::vector<EcalLogicID> EcalCondDBInterface::getEcalLogicIDSetOrdered(
0389     string name, int fromId1, int toId1, int fromId2, int toId2, int fromId3, int toId3, string mapsTo, int orderedBy)
0390     // the orderedBy can be 1, 2, 3, 4
0391     // corresponding to id1 id2 id3 or logic_id
0392     noexcept(false) {
0393   if (mapsTo.empty()) {
0394     mapsTo = name;
0395   }
0396 
0397   int idArray[] = {fromId1, toId1, fromId2, toId2, fromId3, toId3};
0398   int from, to;
0399 
0400   stringstream ss;
0401   ss << "SELECT name, logic_id, id1, id2, id3, maps_to FROM channelView WHERE name = :name AND ";
0402 
0403   // loop through the three ids
0404   for (int i = 1; i <= 3; i++) {
0405     from = idArray[2 * (i - 1)];
0406     to = idArray[2 * (i - 1) + 1];
0407 
0408     // check the id arguments in pairs
0409     if ((from == EcalLogicID::NULLID && to != EcalLogicID::NULLID) ||  // one is null
0410         (from != EcalLogicID::NULLID && to == EcalLogicID::NULLID) ||  //   but not the other
0411         (from > to)) {                                                 // negative interval
0412       throw(std::runtime_error("ERROR:  Bad arguments for getEcalLogicIDSet"));
0413     }
0414 
0415     // build the sql
0416     if (from == EcalLogicID::NULLID && to == EcalLogicID::NULLID) {
0417       ss << "id" << i << " IS NULL AND ";
0418     } else {
0419       ss << "id" << i << " >= :id" << i << "from AND "
0420          << "id" << i << " <= :id" << i << "to AND ";
0421     }
0422   }
0423   ss << "maps_to = :maps_to ";
0424 
0425   if (orderedBy == EcalLogicID::NULLID) {
0426     ss << "  ORDER BY id1, id2, id3";
0427   } else if (orderedBy == 1 || orderedBy == 12 || orderedBy == 123) {
0428     ss << "  ORDER BY id1, id2, id3 ";
0429   } else if (orderedBy == 213 || orderedBy == 21) {
0430     ss << "  ORDER BY id2, id1, id3 ";
0431   } else if (orderedBy == 231 || orderedBy == 23) {
0432     ss << "  ORDER BY id2, id3, id1 ";
0433   } else if (orderedBy == 321 || orderedBy == 32) {
0434     ss << "  ORDER BY id3, id2, id1 ";
0435   } else if (orderedBy == 312 || orderedBy == 31) {
0436     ss << "  ORDER BY id3, id1, id2 ";
0437   } else if (orderedBy == 132 || orderedBy == 13) {
0438     ss << "  ORDER BY id1, id3, id2 ";
0439   } else if (orderedBy == 1234) {
0440     ss << "  ORDER BY id1, id2, id3, logic_id ";
0441   } else if (orderedBy == 4) {
0442     ss << "  ORDER BY logic_id ";
0443   } else {
0444     ss << "  ORDER BY id1, id2, id3";
0445   }
0446 
0447   std::vector<EcalLogicID> result;
0448 
0449   try {
0450     stmt->setSQL(ss.str());
0451 
0452     // bind the parameters
0453     int j = 1;  // parameter number counter
0454     stmt->setString(j, name);
0455     j++;
0456 
0457     for (int i = 0; i < 3; i++) {
0458       from = idArray[2 * i];
0459       to = idArray[2 * i + 1];
0460       if (from != EcalLogicID::NULLID) {
0461         stmt->setInt(j, from);
0462         j++;
0463         stmt->setInt(j, to);
0464         j++;
0465       }
0466     }
0467 
0468     stmt->setString(j, mapsTo);
0469 
0470     stmt->setPrefetchRowCount(IDBObject::ECALDB_NROWS);
0471 
0472     ResultSet* rset = stmt->executeQuery();
0473 
0474     int id1, id2, id3, logicId;
0475 
0476     while (rset->next()) {
0477       name = rset->getString(1);
0478       logicId = rset->getInt(2);
0479       id1 = rset->getInt(3);
0480       if (rset->isNull(3)) {
0481         id1 = EcalLogicID::NULLID;
0482       }
0483       id2 = rset->getInt(4);
0484       if (rset->isNull(4)) {
0485         id2 = EcalLogicID::NULLID;
0486       }
0487       id3 = rset->getInt(5);
0488       if (rset->isNull(5)) {
0489         id3 = EcalLogicID::NULLID;
0490       }
0491       mapsTo = rset->getString(6);
0492 
0493       EcalLogicID ecid = EcalLogicID(name, logicId, id1, id2, id3, mapsTo);
0494       result.push_back(ecid);
0495     }
0496     stmt->setPrefetchRowCount(0);
0497 
0498   } catch (SQLException& e) {
0499     throw(std::runtime_error(std::string("ERROR:  Failure while getting EcalLogicID set:  ") + e.getMessage()));
0500   }
0501 
0502   return result;
0503 }
0504 
0505 void EcalCondDBInterface::insertRunIOV(RunIOV* iov) noexcept(false) {
0506   try {
0507     iov->setConnection(env, conn);
0508     iov->writeDB();
0509   } catch (std::runtime_error& e) {
0510     conn->rollback();
0511     throw(e);
0512   }
0513   conn->commit();
0514 }
0515 
0516 void EcalCondDBInterface::insertLmfSeq(LMFSeqDat* iov) noexcept(false) {
0517   try {
0518     iov->setConnection(env, conn);
0519     iov->writeDB();
0520   } catch (std::runtime_error& e) {
0521     conn->rollback();
0522     throw(e);
0523   }
0524   conn->commit();
0525 }
0526 
0527 void EcalCondDBInterface::insertLmfLmrSubIOV(LMFLmrSubIOV* iov) noexcept(false) {
0528   try {
0529     iov->setConnection(env, conn);
0530     iov->writeDB();
0531   } catch (std::runtime_error& e) {
0532     conn->rollback();
0533     throw(e);
0534   }
0535   conn->commit();
0536 }
0537 
0538 void EcalCondDBInterface::insertLmfIOV(LMFIOV* iov) noexcept(false) {
0539   try {
0540     iov->setConnection(env, conn);
0541     iov->writeDB();
0542   } catch (std::runtime_error& e) {
0543     conn->rollback();
0544     throw(e);
0545   }
0546   conn->commit();
0547 }
0548 
0549 void EcalCondDBInterface::insertLmfDat(LMFDat* dat) noexcept(false) {
0550   try {
0551     dat->setConnection(env, conn);
0552     dat->writeDB();
0553   } catch (std::runtime_error& e) {
0554     conn->rollback();
0555     throw(e);
0556   }
0557   conn->commit();
0558 }
0559 
0560 void EcalCondDBInterface::insertLmfDat(std::list<LMFDat*> dat) noexcept(false) {
0561   try {
0562     std::list<LMFDat*>::iterator i = dat.begin();
0563     std::list<LMFDat*>::iterator e = dat.end();
0564     while (i != e) {
0565       (*i)->setConnection(env, conn);
0566       (*i)->writeDB();
0567       i++;
0568     }
0569   } catch (std::runtime_error& e) {
0570     conn->rollback();
0571     throw(e);
0572   }
0573   conn->commit();
0574 }
0575 
0576 void EcalCondDBInterface::insertLmfRunIOV(LMFRunIOV* iov) noexcept(false) {
0577   try {
0578     iov->setConnection(env, conn);
0579     iov->writeDB();
0580   } catch (std::runtime_error& e) {
0581     conn->rollback();
0582     throw(e);
0583   }
0584   conn->commit();
0585 }
0586 
0587 void EcalCondDBInterface::updateRunIOV(RunIOV* iov) noexcept(false) {
0588   try {
0589     iov->setConnection(env, conn);
0590     iov->updateEndTimeDB();
0591   } catch (std::runtime_error& e) {
0592     conn->rollback();
0593     throw(e);
0594   }
0595   conn->commit();
0596 }
0597 
0598 void EcalCondDBInterface::updateRunIOVEndTime(RunIOV* iov) noexcept(false) {
0599   try {
0600     iov->setConnection(env, conn);
0601     iov->updateEndTimeDB();
0602   } catch (std::runtime_error& e) {
0603     conn->rollback();
0604     throw(e);
0605   }
0606   conn->commit();
0607 }
0608 
0609 void EcalCondDBInterface::updateRunIOVStartTime(RunIOV* iov) noexcept(false) {
0610   try {
0611     iov->setConnection(env, conn);
0612     iov->updateStartTimeDB();
0613   } catch (std::runtime_error& e) {
0614     conn->rollback();
0615     throw(e);
0616   }
0617   conn->commit();
0618 }
0619 
0620 void EcalCondDBInterface::updateRunConfig(ODRunConfigInfo* od) noexcept(false) {
0621   try {
0622     od->setConnection(env, conn);
0623     od->updateDefaultCycle();
0624   } catch (std::runtime_error& e) {
0625     conn->rollback();
0626     throw(e);
0627   }
0628   conn->commit();
0629 }
0630 
0631 RunIOV EcalCondDBInterface::fetchRunIOV(RunTag* tag, run_t run) noexcept(false) {
0632   RunIOV iov;
0633   iov.setConnection(env, conn);
0634   iov.setByRun(tag, run);
0635   return iov;
0636 }
0637 
0638 RunIOV EcalCondDBInterface::fetchRunIOV(std::string location, run_t run) noexcept(false) {
0639   RunIOV iov;
0640   iov.setConnection(env, conn);
0641   iov.setByRun(location, run);
0642   return iov;
0643 }
0644 
0645 RunIOV EcalCondDBInterface::fetchRunIOV(std::string location, const Tm& t) noexcept(false) {
0646   RunIOV iov;
0647   iov.setConnection(env, conn);
0648   iov.setByTime(location, t);
0649   return iov;
0650 }
0651 
0652 void EcalCondDBInterface::insertMonRunIOV(MonRunIOV* iov) noexcept(false) {
0653   try {
0654     iov->setConnection(env, conn);
0655     iov->writeDB();
0656   } catch (std::runtime_error& e) {
0657     conn->rollback();
0658     throw(e);
0659   }
0660   conn->commit();
0661 }
0662 
0663 void EcalCondDBInterface::insertDCUIOV(DCUIOV* iov) noexcept(false) {
0664   try {
0665     iov->setConnection(env, conn);
0666     iov->writeDB();
0667   } catch (std::runtime_error& e) {
0668     conn->rollback();
0669     throw(e);
0670   }
0671   conn->commit();
0672 }
0673 
0674 MonRunIOV EcalCondDBInterface::fetchMonRunIOV(RunTag* runtag,
0675                                               MonRunTag* montag,
0676                                               run_t run,
0677                                               subrun_t subrun) noexcept(false) {
0678   RunIOV runiov = fetchRunIOV(runtag, run);
0679   MonRunIOV moniov;
0680   moniov.setConnection(env, conn);
0681   moniov.setByRun(montag, &runiov, subrun);
0682   return moniov;
0683 }
0684 
0685 DCUIOV EcalCondDBInterface::fetchDCUIOV(DCUTag* tag, const Tm& eventTm) noexcept(false) {
0686   DCUIOV dcuiov;
0687   dcuiov.setConnection(env, conn);
0688   dcuiov.setByTm(tag, eventTm);
0689   return dcuiov;
0690 }
0691 
0692 RunIOV EcalCondDBInterface::fetchLMFLastRun() const {
0693   LMFSeqDat seq(env, conn);
0694   return seq.fetchLastRun();
0695 }
0696 
0697 LMFRunIOV EcalCondDBInterface::fetchLMFRunIOV(RunTag* runtag,
0698                                               LMFRunTag* lmftag,
0699                                               run_t run,
0700                                               subrun_t subrun) noexcept(false) {
0701   RunIOV runiov = fetchRunIOV(runtag, run);
0702   LMFRunIOV lmfiov;
0703   lmfiov.setConnection(env, conn);
0704   //  lmfiov.setByRun(lmftag, &runiov, subrun);
0705   return lmfiov;
0706 }
0707 
0708 bool EcalCondDBInterface::fetchLMFRunIOV(const LMFSeqDat& seq, LMFRunIOV& iov, int lmr, int type, int color) const {
0709   bool ret = false;
0710   iov.setConnection(env, conn);
0711   std::list<LMFRunIOV> iovlist = iov.fetchBySequence(seq, lmr, type, color);
0712   int s = iovlist.size();
0713   if (s > 0) {
0714     iov = iovlist.front();
0715     ret = true;
0716     if (s > 1) {
0717       // should not happen
0718       std::cout << "################################" << std::endl;
0719       std::cout << "################################" << std::endl;
0720       std::cout << "WARNING: More than one LMFRUNIOV" << std::endl;
0721       std::cout << "         Found for seq " << seq.getID() << std::endl;
0722       std::cout << "         lmr " << lmr << " type " << type << std::endl;
0723       std::cout << "         and color " << color << std::endl;
0724       std::cout << "################################" << std::endl;
0725       std::cout << "################################" << std::endl;
0726     }
0727   } else {
0728     // find the most recent data
0729     iovlist = iov.fetchLastBeforeSequence(seq, lmr, type, color);
0730     s = iovlist.size();
0731     if (s == 1) {
0732       iov = iovlist.front();
0733     }
0734   }
0735   return ret;
0736 }
0737 
0738 CaliIOV EcalCondDBInterface::fetchCaliIOV(CaliTag* tag, const Tm& eventTm) noexcept(false) {
0739   CaliIOV caliiov;
0740   caliiov.setConnection(env, conn);
0741   caliiov.setByTm(tag, eventTm);
0742   return caliiov;
0743 }
0744 
0745 DCSPTMTempList EcalCondDBInterface::fetchDCSPTMTempList(const EcalLogicID& ecid) noexcept(false) {
0746   DCSPTMTempList r;
0747   r.setConnection(env, conn);
0748   r.fetchValuesForECID(ecid);
0749   return r;
0750 }
0751 
0752 DCSPTMTempList EcalCondDBInterface::fetchDCSPTMTempList(const EcalLogicID& ecid,
0753                                                         const Tm& start,
0754                                                         const Tm& end) noexcept(false) {
0755   DCSPTMTempList r;
0756   r.setConnection(env, conn);
0757   r.fetchValuesForECIDAndTime(ecid, start, end);
0758   return r;
0759 }
0760 
0761 RunList EcalCondDBInterface::fetchRunList(const RunTag& tag) noexcept(false) {
0762   RunList r;
0763   r.setConnection(env, conn);
0764   r.setRunTag(tag);
0765   r.fetchRuns();
0766   return r;
0767 }
0768 
0769 RunList EcalCondDBInterface::fetchRunList(const RunTag& tag, int min_run, int max_run) noexcept(false) {
0770   RunList r;
0771   r.setConnection(env, conn);
0772   r.setRunTag(tag);
0773   r.fetchRuns(min_run, max_run);
0774   return r;
0775 }
0776 
0777 RunList EcalCondDBInterface::fetchNonEmptyRunList(const RunTag& tag, int min_run, int max_run) noexcept(false) {
0778   RunList r;
0779   r.setConnection(env, conn);
0780   r.setRunTag(tag);
0781   r.fetchNonEmptyRuns(min_run, max_run);
0782   return r;
0783 }
0784 
0785 RunList EcalCondDBInterface::fetchNonEmptyGlobalRunList(const RunTag& tag, int min_run, int max_run) noexcept(false) {
0786   RunList r;
0787   r.setConnection(env, conn);
0788   r.setRunTag(tag);
0789   r.fetchNonEmptyGlobalRuns(min_run, max_run);
0790   return r;
0791 }
0792 
0793 RunList EcalCondDBInterface::fetchRunListByLocation(const RunTag& tag,
0794                                                     int min_run,
0795                                                     int max_run,
0796                                                     const LocationDef& locDef) noexcept(false) {
0797   RunList r;
0798   r.setConnection(env, conn);
0799   r.setRunTag(tag);
0800   r.fetchRunsByLocation(min_run, max_run, locDef);
0801   return r;
0802 }
0803 
0804 RunList EcalCondDBInterface::fetchGlobalRunListByLocation(const RunTag& tag,
0805                                                           int min_run,
0806                                                           int max_run,
0807                                                           const LocationDef& locDef) noexcept(false) {
0808   RunList r;
0809   r.setConnection(env, conn);
0810   r.setRunTag(tag);
0811   r.fetchGlobalRunsByLocation(min_run, max_run, locDef);
0812   return r;
0813 }
0814 
0815 RunList EcalCondDBInterface::fetchRunListLastNRuns(const RunTag& tag, int max_run, int n_runs) noexcept(false) {
0816   RunList r;
0817   r.setConnection(env, conn);
0818   r.setRunTag(tag);
0819   r.fetchLastNRuns(max_run, n_runs);
0820   return r;
0821 }
0822 
0823 // from here it is for the MonRunList
0824 
0825 MonRunList EcalCondDBInterface::fetchMonRunList(const RunTag& tag, const MonRunTag& monrunTag) noexcept(false) {
0826   MonRunList r;
0827   r.setConnection(env, conn);
0828   r.setRunTag(tag);
0829   r.setMonRunTag(monrunTag);
0830   r.fetchRuns();
0831   return r;
0832 }
0833 
0834 MonRunList EcalCondDBInterface::fetchMonRunList(const RunTag& tag,
0835                                                 const MonRunTag& monrunTag,
0836                                                 int min_run,
0837                                                 int max_run) noexcept(false) {
0838   MonRunList r;
0839   r.setConnection(env, conn);
0840   r.setRunTag(tag);
0841   r.setMonRunTag(monrunTag);
0842   r.fetchRuns(min_run, max_run);
0843   return r;
0844 }
0845 
0846 MonRunList EcalCondDBInterface::fetchMonRunListLastNRuns(const RunTag& tag,
0847                                                          const MonRunTag& monrunTag,
0848                                                          int max_run,
0849                                                          int n_runs) noexcept(false) {
0850   MonRunList r;
0851   r.setConnection(env, conn);
0852   r.setRunTag(tag);
0853   r.setMonRunTag(monrunTag);
0854   r.fetchLastNRuns(max_run, n_runs);
0855   return r;
0856 }
0857 
0858 void EcalCondDBInterface::dummy() {}