Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:07

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/ODJBH4Config.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 ODJBH4Config::ODJBH4Config() {
0011   m_env = nullptr;
0012   m_conn = nullptr;
0013   m_writeStmt = nullptr;
0014   m_readStmt = nullptr;
0015   m_config_tag = "";
0016   m_ID = 0;
0017   clear();
0018 }
0019 
0020 ODJBH4Config::~ODJBH4Config() {}
0021 
0022 void ODJBH4Config::clear() {
0023   m_use_buffer = 0;
0024   m_hal_mod_file = "";
0025   m_hal_add_file = "";
0026   m_hal_tab_file = "";
0027   m_serial = "";
0028   m_caen1 = "";
0029   m_caen2 = 0;
0030   m_caen3 = 0;
0031 }
0032 
0033 int ODJBH4Config::fetchNextId() noexcept(false) {
0034   int result = 0;
0035   try {
0036     this->checkConnection();
0037 
0038     m_readStmt = m_conn->createStatement();
0039     m_readStmt->setSQL("select ecal_JBH4_config_sq.NextVal from dual");
0040     ResultSet *rset = m_readStmt->executeQuery();
0041     while (rset->next()) {
0042       result = rset->getInt(1);
0043     }
0044     m_conn->terminateStatement(m_readStmt);
0045     return result;
0046 
0047   } catch (SQLException &e) {
0048     throw(std::runtime_error("ODJBH4Config::fetchNextId():  " + e.getMessage()));
0049   }
0050 }
0051 
0052 void ODJBH4Config::prepareWrite() noexcept(false) {
0053   this->checkConnection();
0054   int next_id = fetchNextId();
0055 
0056   try {
0057     m_writeStmt = m_conn->createStatement();
0058     m_writeStmt->setSQL(
0059         "INSERT INTO ECAL_Jbh4_CONFIGURATION ( jbh4_configuration_id, jbh4_tag, "
0060         " useBuffer, halModuleFile, halAddressTableFile, halStaticTableFile, halcbd8210serialnumber, "
0061         " caenbridgetype, caenlinknumber, caenboardnumber) "
0062         " VALUES ( :1, :2, :3, :4, :5, :6, :7, :8 , :9, :10 )");
0063 
0064     m_writeStmt->setInt(1, next_id);
0065     m_ID = next_id;
0066   } catch (SQLException &e) {
0067     throw(std::runtime_error("ODJBH4Config::prepareWrite():  " + e.getMessage()));
0068   }
0069 }
0070 
0071 void ODJBH4Config::writeDB() noexcept(false) {
0072   this->checkConnection();
0073   this->checkPrepare();
0074 
0075   try {
0076     // number 1 is the id number 2 is the tag
0077     m_writeStmt->setString(2, this->getConfigTag());
0078 
0079     m_writeStmt->setInt(3, this->getUseBuffer());
0080     m_writeStmt->setString(4, this->getHalModuleFile());
0081     m_writeStmt->setString(5, this->getHalAddressTableFile());
0082     m_writeStmt->setString(6, this->getHalStaticTableFile());
0083     m_writeStmt->setString(7, this->getCbd8210SerialNumber());
0084     m_writeStmt->setString(8, this->getCaenBridgeType());
0085     m_writeStmt->setInt(9, this->getCaenLinkNumber());
0086     m_writeStmt->setInt(10, this->getCaenBoardNumber());
0087 
0088     m_writeStmt->executeUpdate();
0089 
0090   } catch (SQLException &e) {
0091     throw(std::runtime_error("ODJBH4Config::writeDB():  " + e.getMessage()));
0092   }
0093   // Now get the ID
0094   if (!this->fetchID()) {
0095     throw(std::runtime_error("ODJBH4Config::writeDB:  Failed to write"));
0096   }
0097 }
0098 
0099 void ODJBH4Config::fetchData(ODJBH4Config *result) noexcept(false) {
0100   this->checkConnection();
0101   result->clear();
0102   if (result->getId() == 0) {
0103     throw(std::runtime_error("ODJBH4Config::fetchData(): no Id defined for this ODJBH4Config "));
0104   }
0105 
0106   try {
0107     m_readStmt->setSQL(
0108         "SELECT * FROM ECAL_Jbh4_CONFIGURATION  "
0109         " where ( jbh4_configuration_id = :1 or jbh4_tag=:2 )");
0110     m_readStmt->setInt(1, result->getId());
0111     m_readStmt->setString(2, result->getConfigTag());
0112     ResultSet *rset = m_readStmt->executeQuery();
0113 
0114     rset->next();
0115 
0116     result->setId(rset->getInt(1));
0117     result->setConfigTag(rset->getString(2));
0118 
0119     result->setUseBuffer(rset->getInt(3));
0120     result->setHalModuleFile(rset->getString(4));
0121     result->setHalAddressTableFile(rset->getString(5));
0122     result->setHalStaticTableFile(rset->getString(6));
0123     result->setCbd8210SerialNumber(rset->getString(7));
0124     result->setCaenBridgeType(rset->getString(8));
0125     result->setCaenLinkNumber(rset->getInt(9));
0126     result->setCaenBoardNumber(rset->getInt(10));
0127 
0128   } catch (SQLException &e) {
0129     throw(std::runtime_error("ODJBH4Config::fetchData():  " + e.getMessage()));
0130   }
0131 }
0132 
0133 int ODJBH4Config::fetchID() noexcept(false) {
0134   // Return from memory if available
0135   if (m_ID != 0) {
0136     return m_ID;
0137   }
0138 
0139   this->checkConnection();
0140 
0141   try {
0142     Statement *stmt = m_conn->createStatement();
0143     stmt->setSQL(
0144         "SELECT jbh4_configuration_id FROM ecal_jbh4_configuration "
0145         "WHERE  jbh4_tag=:jbh4_tag ");
0146 
0147     stmt->setString(1, getConfigTag());
0148 
0149     ResultSet *rset = stmt->executeQuery();
0150 
0151     if (rset->next()) {
0152       m_ID = rset->getInt(1);
0153     } else {
0154       m_ID = 0;
0155     }
0156     m_conn->terminateStatement(stmt);
0157   } catch (SQLException &e) {
0158     throw(std::runtime_error("ODJBH4Config::fetchID:  " + e.getMessage()));
0159   }
0160 
0161   return m_ID;
0162 }