Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonRunDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0007 #include "OnlineDB/EcalCondDB/interface/MonRunOutcomeDef.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 MonRunDat::MonRunDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_numEvents = 0;
0019   m_outcomeDef = MonRunOutcomeDef();
0020   m_rootfileName = "";
0021   m_taskList = 0;
0022   m_taskOutcome = 0;
0023 }
0024 
0025 MonRunDat::~MonRunDat() {}
0026 
0027 void MonRunDat::prepareWrite() noexcept(false) {
0028   this->checkConnection();
0029 
0030   try {
0031     m_writeStmt = m_conn->createStatement();
0032     m_writeStmt->setSQL(
0033         "INSERT INTO mon_run_dat (iov_id, logic_id, "
0034         "num_events, run_outcome_id, rootfile_name, task_list, task_outcome) "
0035         "VALUES (:iov_id, :logic_id, "
0036         ":num_events, :run_outcome_id, :rootfile_name, :task_list, :task_outcome) ");
0037   } catch (SQLException& e) {
0038     throw(std::runtime_error("MonRunDat::prepareWrite():  " + e.getMessage()));
0039   }
0040 }
0041 
0042 void MonRunDat::writeDB(const EcalLogicID* ecid, const MonRunDat* item, MonRunIOV* iov) noexcept(false) {
0043   this->checkConnection();
0044   this->checkPrepare();
0045 
0046   int iovID = iov->fetchID();
0047   if (!iovID) {
0048     throw(std::runtime_error("MonRunDat::writeDB:  IOV not in DB"));
0049   }
0050 
0051   MonRunOutcomeDef monRunOutcomeDef = item->getMonRunOutcomeDef();  // XXX object copy every row!
0052   monRunOutcomeDef.setConnection(m_env, m_conn);
0053   int outcomeID = monRunOutcomeDef.fetchID();
0054   if (!outcomeID) {
0055     throw(std::runtime_error("MonRunDat::writeDB:  Outcome Definition not in DB"));
0056   }
0057 
0058   int logicID = ecid->getLogicID();
0059   if (!logicID) {
0060     throw(std::runtime_error("MonRunDat::writeDB:  Bad EcalLogicID"));
0061   }
0062 
0063   try {
0064     m_writeStmt->setInt(1, iovID);
0065     m_writeStmt->setInt(2, logicID);
0066     m_writeStmt->setInt(3, item->getNumEvents());
0067     m_writeStmt->setInt(4, outcomeID);
0068     m_writeStmt->setString(5, item->getRootfileName());
0069     m_writeStmt->setInt(6, item->getTaskList());
0070     m_writeStmt->setInt(7, item->getTaskOutcome());
0071 
0072     m_writeStmt->executeUpdate();
0073   } catch (SQLException& e) {
0074     throw(std::runtime_error("MonRunDat::writeDB():  " + e.getMessage()));
0075   }
0076 }
0077 
0078 void MonRunDat::fetchData(map<EcalLogicID, MonRunDat>* fillMap, MonRunIOV* iov) noexcept(false) {
0079   this->checkConnection();
0080   fillMap->clear();
0081 
0082   iov->setConnection(m_env, m_conn);
0083   int iovID = iov->fetchID();
0084   if (!iovID) {
0085     //  throw(std::runtime_error("MonRunDat::writeDB:  IOV not in DB"));
0086     return;
0087   }
0088 
0089   try {
0090     m_readStmt->setSQL(
0091         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0092         "d.num_events, d.run_outcome_id, d.rootfile_name, d.task_list, d.task_outcome "
0093         "FROM channelview cv JOIN mon_run_dat d "
0094         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0095         "WHERE d.iov_id = :iov_id");
0096     m_readStmt->setInt(1, iovID);
0097     ResultSet* rset = m_readStmt->executeQuery();
0098 
0099     std::pair<EcalLogicID, MonRunDat> p;
0100     MonRunDat dat;
0101     MonRunOutcomeDef outcomeDef;
0102     outcomeDef.setConnection(m_env, m_conn);
0103     while (rset->next()) {
0104       p.first = EcalLogicID(rset->getString(1),   // name
0105                             rset->getInt(2),      // logic_id
0106                             rset->getInt(3),      // id1
0107                             rset->getInt(4),      // id2
0108                             rset->getInt(5),      // id3
0109                             rset->getString(6));  // maps_to
0110 
0111       dat.setNumEvents(rset->getInt(7));
0112       outcomeDef.setByID(rset->getInt(8));
0113       dat.setMonRunOutcomeDef(outcomeDef);
0114       dat.setRootfileName(rset->getString(9));
0115       dat.setTaskList(rset->getInt(10));
0116       dat.setTaskOutcome(rset->getInt(11));
0117 
0118       p.second = dat;
0119       fillMap->insert(p);
0120     }
0121   } catch (SQLException& e) {
0122     throw(std::runtime_error("MonRunDat::fetchData():  " + e.getMessage()));
0123   }
0124 }