Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0005 
0006 #include "OnlineDB/EcalCondDB/interface/ODEcalCycle.h"
0007 #include "OnlineDB/EcalCondDB/interface/ODCCSCycle.h"
0008 #include "OnlineDB/EcalCondDB/interface/ODDCCCycle.h"
0009 #include "OnlineDB/EcalCondDB/interface/ODJBH4Cycle.h"
0010 #include "OnlineDB/EcalCondDB/interface/ODLaserCycle.h"
0011 #include "OnlineDB/EcalCondDB/interface/ODLTCCycle.h"
0012 #include "OnlineDB/EcalCondDB/interface/ODLTSCycle.h"
0013 #include "OnlineDB/EcalCondDB/interface/ODDCUCycle.h"
0014 #include "OnlineDB/EcalCondDB/interface/ODRunConfigCycleInfo.h"
0015 #include "OnlineDB/EcalCondDB/interface/ODScanCycle.h"
0016 #include "OnlineDB/EcalCondDB/interface/ODTCCCycle.h"
0017 #include "OnlineDB/EcalCondDB/interface/ODTCCEECycle.h"
0018 #include "OnlineDB/EcalCondDB/interface/ODTTCciCycle.h"
0019 #include "OnlineDB/EcalCondDB/interface/ODTTCFCycle.h"
0020 #include "OnlineDB/EcalCondDB/interface/ODSRPCycle.h"
0021 
0022 using namespace std;
0023 using namespace oracle::occi;
0024 
0025 ODEcalCycle::ODEcalCycle() {
0026   m_env = nullptr;
0027   m_conn = nullptr;
0028   m_writeStmt = nullptr;
0029   m_readStmt = nullptr;
0030 
0031   m_ID = 0;
0032   clear();
0033 }
0034 
0035 ODEcalCycle::~ODEcalCycle() {}
0036 
0037 void ODEcalCycle::prepareWrite() noexcept(false) {
0038   std::cout << "ODEcalCycle::prepareWrite(): this is a view writing specific tables  " << endl;
0039 }
0040 
0041 void ODEcalCycle::writeDB() noexcept(false) {
0042   ODRunConfigCycleInfo cyc;
0043   cyc.setTag(this->getCycleTag());
0044   cyc.setDescription(this->getCycleDescription());
0045   cyc.setCycleNumber(this->getCycleNum());
0046   cyc.setSequenceID(this->getSequenceId());
0047   // here we insert the cycle and get back the id
0048   cyc.setConnection(m_env, m_conn);
0049   cyc.insertConfig();
0050   int cyc_id = cyc.getId();
0051   cout << "Cycle inserted with ID " << cyc_id << endl;
0052   m_ID = cyc_id;
0053 
0054   if (getCCSId() != 0) {
0055     ODCCSCycle ccs_cycle;
0056     ccs_cycle.setId(cyc_id);
0057     ccs_cycle.setCCSConfigurationID(getCCSId());
0058     ccs_cycle.setConnection(m_env, m_conn);
0059     ccs_cycle.insertConfig();
0060     cout << "Inserting CCS-cycle in DB..." << flush;
0061   }
0062   if (getDCCId() != 0) {
0063     ODDCCCycle dcc_cycle;
0064     dcc_cycle.setId(cyc_id);
0065     dcc_cycle.setDCCConfigurationID(getDCCId());
0066     dcc_cycle.setConnection(m_env, m_conn);
0067     dcc_cycle.insertConfig();
0068     cout << "Inserting DCC-cycle in DB..." << flush;
0069   }
0070   if (getLaserId() != 0) {
0071     ODLaserCycle laser_cycle;
0072     laser_cycle.setId(cyc_id);
0073     laser_cycle.setLaserConfigurationID(getLaserId());
0074     laser_cycle.setConnection(m_env, m_conn);
0075     laser_cycle.insertConfig();
0076     cout << "Inserting LASER-cycle in DB..." << flush;
0077   }
0078   if (getLTCId() != 0) {
0079     ODLTCCycle ltc_cycle;
0080     ltc_cycle.setId(cyc_id);
0081     ltc_cycle.setLTCConfigurationID(getLTCId());
0082     ltc_cycle.setConnection(m_env, m_conn);
0083     ltc_cycle.insertConfig();
0084     cout << "Inserting LTC-cycle in DB..." << flush;
0085   }
0086   if (getLTSId() != 0) {
0087     ODLTSCycle lts_cycle;
0088     lts_cycle.setId(cyc_id);
0089     lts_cycle.setLTSConfigurationID(getLTSId());
0090     lts_cycle.setConnection(m_env, m_conn);
0091     lts_cycle.insertConfig();
0092     cout << "Inserting LTS-cycle in DB..." << flush;
0093   }
0094   if (getDCUId() != 0) {
0095     ODDCUCycle dcu_cycle;
0096     dcu_cycle.setId(cyc_id);
0097     dcu_cycle.setDCUConfigurationID(getDCUId());
0098     dcu_cycle.setConnection(m_env, m_conn);
0099     dcu_cycle.insertConfig();
0100     cout << "Inserting DCU-cycle in DB..." << flush;
0101   }
0102   if (getTCCId() != 0) {
0103     ODTCCCycle tcc_cycle;
0104     tcc_cycle.setId(cyc_id);
0105     tcc_cycle.setTCCConfigurationID(getTCCId());
0106     tcc_cycle.setConnection(m_env, m_conn);
0107     tcc_cycle.insertConfig();
0108     cout << "Inserting TCC-cycle in DB..." << flush;
0109   }
0110   if (getTCCEEId() != 0) {
0111     ODTCCEECycle tcc_ee_cycle;
0112     tcc_ee_cycle.setId(cyc_id);
0113     tcc_ee_cycle.setTCCConfigurationID(getTCCEEId());
0114     tcc_ee_cycle.setConnection(m_env, m_conn);
0115     tcc_ee_cycle.insertConfig();
0116     cout << "Inserting TCCEE-cycle in DB..." << flush;
0117   }
0118   if (getTTCCIId() != 0) {
0119     ODTTCciCycle ttcci_cycle;
0120     ttcci_cycle.setId(cyc_id);
0121     ttcci_cycle.setTTCciConfigurationID(getTTCCIId());
0122     ttcci_cycle.setConnection(m_env, m_conn);
0123     ttcci_cycle.insertConfig();
0124     cout << "Inserting TTCCI-cycle in DB..." << flush;
0125   }
0126   if (getTTCFId() != 0) {
0127     ODTTCFCycle ttcf_cycle;
0128     ttcf_cycle.setId(cyc_id);
0129     ttcf_cycle.setTTCFConfigurationID(getTTCFId());
0130     ttcf_cycle.setConnection(m_env, m_conn);
0131     ttcf_cycle.insertConfig();
0132     cout << "Inserting TTCF-cycle in DB..." << flush;
0133   }
0134   if (getSRPId() != 0) {
0135     ODSRPCycle srp_cycle;
0136     srp_cycle.setId(cyc_id);
0137     srp_cycle.setSRPConfigurationID(getSRPId());
0138     srp_cycle.setConnection(m_env, m_conn);
0139     srp_cycle.insertConfig();
0140     cout << "Inserting SRP-cycle in DB..." << flush;
0141   }
0142   if (getJBH4Id() != 0) {
0143     ODJBH4Cycle jbh4_cycle;
0144     jbh4_cycle.setId(cyc_id);
0145     jbh4_cycle.setJBH4ConfigurationID(getJBH4Id());
0146     jbh4_cycle.setConnection(m_env, m_conn);
0147     jbh4_cycle.insertConfig();
0148     cout << "Inserting JBH4-cycle in DB..." << flush;
0149   }
0150   if (getScanId() != 0) {
0151     ODScanCycle scan_cycle;
0152     scan_cycle.setId(cyc_id);
0153     scan_cycle.setScanConfigurationID(getScanId());
0154     scan_cycle.setConnection(m_env, m_conn);
0155     scan_cycle.insertConfig();
0156     cout << "Inserting SCAN-cycle in DB..." << flush;
0157   }
0158 }
0159 
0160 void ODEcalCycle::clear() {
0161   m_tag = "";
0162   m_version = 0;
0163   m_seq_num = 0;
0164   m_cycle_num = 0;
0165   m_cycle_tag = "";
0166   m_cycle_description = "";
0167   m_ccs = 0;
0168   m_dcc = 0;
0169   m_laser = 0;
0170   m_ltc = 0;
0171   m_lts = 0;
0172   m_dcu = 0;
0173   m_tcc = 0;
0174   m_tcc_ee = 0;
0175   m_ttcci = 0;
0176   m_jbh4 = 0;
0177   m_scan = 0;
0178   //   m_seq_id=0;
0179   m_ttcf = 0;
0180   m_srp = 0;
0181 }
0182 
0183 int ODEcalCycle::fetchID() noexcept(false) {
0184   // Return from memory if available
0185   if (m_ID > 0) {
0186     return m_ID;
0187   }
0188 
0189   this->checkConnection();
0190 
0191   DateHandler dh(m_env, m_conn);
0192 
0193   try {
0194     Statement* stmt = m_conn->createStatement();
0195     stmt->setSQL(
0196         "SELECT cycle_id from ECAL_CYCLE_DAT "
0197         "WHERE sequence_id = :1 ");
0198     stmt->setInt(1, m_seq_id);
0199 
0200     ResultSet* rset = stmt->executeQuery();
0201 
0202     if (rset->next()) {
0203       m_ID = rset->getInt(1);
0204     } else {
0205       m_ID = 0;
0206     }
0207     m_conn->terminateStatement(stmt);
0208   } catch (SQLException& e) {
0209     throw(std::runtime_error("ODEcalCycle::fetchID:  " + e.getMessage()));
0210   }
0211   setByID(m_ID);
0212   return m_ID;
0213 }
0214 
0215 void ODEcalCycle::setByID(int id) noexcept(false) {
0216   this->checkConnection();
0217 
0218   DateHandler dh(m_env, m_conn);
0219 
0220   try {
0221     Statement* stmt = m_conn->createStatement();
0222 
0223     stmt->setSQL(
0224         "SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
0225         "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
0226         "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
0227         "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
0228         "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
0229         "FROM ECAL_CYCLE where cycle_id = :1 ");
0230     stmt->setInt(1, id);
0231 
0232     ResultSet* rset = stmt->executeQuery();
0233     if (rset->next()) {
0234       m_tag = rset->getString(1);
0235       m_version = rset->getInt(2);
0236       m_seq_num = rset->getInt(3);
0237       m_cycle_num = rset->getInt(4);
0238       m_cycle_tag = rset->getString(5);
0239       m_cycle_description = rset->getString(6);
0240       m_ccs = rset->getInt(7);
0241       m_dcc = rset->getInt(8);
0242       m_laser = rset->getInt(9);
0243       m_ltc = rset->getInt(10);
0244       m_lts = rset->getInt(11);
0245       m_tcc = rset->getInt(12);
0246       m_ttcci = rset->getInt(13);
0247       m_jbh4 = rset->getInt(14);
0248       m_scan = rset->getInt(15);
0249       m_ttcf = rset->getInt(16);
0250       m_srp = rset->getInt(17);
0251       m_dcu = rset->getInt(18);
0252       m_tcc_ee = rset->getInt(19);
0253 
0254     } else {
0255       throw(std::runtime_error("ODEcalCycle::setByID:  Given config_id is not in the database"));
0256     }
0257     m_conn->terminateStatement(stmt);
0258   } catch (SQLException& e) {
0259     throw(std::runtime_error("ODEcalCycle::setByID:  " + e.getMessage()));
0260   }
0261 }
0262 
0263 void ODEcalCycle::printout() {
0264   std::cout << "**** ODEcalCycle ****" << std::endl;
0265   std::cout << "**** id: " << m_ID << std::endl;
0266   std::cout << "**** tag: " << m_tag << std::endl;
0267   std::cout << "**** version: " << m_version << std::endl;
0268   std::cout << "**** seq_num: " << m_seq_num << std::endl;
0269   std::cout << "**** cycle num: " << m_cycle_num << std::endl;
0270   std::cout << "**** cycle tag: " << m_cycle_tag << std::endl;
0271   std::cout << "**** cycle description: " << m_cycle_description << std::endl;
0272   std::cout << "**** ccs_id: " << m_ccs << std::endl;
0273   std::cout << "**** dcc_id: " << m_dcc << std::endl;
0274   std::cout << "**** laser: " << m_laser << std::endl;
0275   std::cout << "**** ttcf_id: " << m_ttcf << std::endl;
0276   std::cout << "**** srp_id: " << m_srp << std::endl;
0277   std::cout << "**** scan_id: " << m_scan << std::endl;
0278   std::cout << "**** ODEcalCycle ****" << std::endl;
0279 }
0280 
0281 void ODEcalCycle::fetchData(ODEcalCycle* result) noexcept(false) {
0282   this->checkConnection();
0283   //  result->clear();
0284   if (result->getId() == 0) {
0285     //    throw(std::runtime_error("ODEcalCycle::fetchData(): no Id defined for this ODEcalCycle "));
0286     result->fetchID();
0287   }
0288 
0289   try {
0290     m_readStmt->setSQL(
0291         "SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
0292         "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
0293         "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
0294         "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
0295         "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
0296         "FROM ECAL_CYCLE where cycle_id = :1 ");
0297     m_readStmt->setInt(1, result->getId());
0298     ResultSet* rset = m_readStmt->executeQuery();
0299 
0300     rset->next();
0301 
0302     result->setTag(rset->getString(1));
0303     result->setVersion(rset->getInt(2));
0304     result->setSeqNum(rset->getInt(3));
0305     result->setCycleNum(rset->getInt(4));
0306     result->setCycleTag(rset->getString(5));
0307     result->setCycleDescription(rset->getString(6));
0308     result->setCCSId(rset->getInt(7));
0309     result->setDCCId(rset->getInt(8));
0310     result->setLaserId(rset->getInt(9));
0311     result->setLTCId(rset->getInt(10));
0312     result->setLTSId(rset->getInt(11));
0313     result->setTCCId(rset->getInt(12));
0314     result->setTTCCIId(rset->getInt(13));
0315 
0316     result->setJBH4Id(rset->getInt(14));
0317     result->setScanId(rset->getInt(15));
0318 
0319     result->setTTCFId(rset->getInt(16));
0320     result->setSRPId(rset->getInt(17));
0321     result->setDCUId(rset->getInt(18));
0322     result->setTCCEEId(rset->getInt(19));
0323 
0324   } catch (SQLException& e) {
0325     throw(std::runtime_error("ODEcalCycle::fetchData():  " + e.getMessage()));
0326   }
0327 }