CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/OnlineDB/EcalCondDB/src/ODEcalCycle.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00005 
00006 #include "OnlineDB/EcalCondDB/interface/ODEcalCycle.h"
00007 #include "OnlineDB/EcalCondDB/interface/ODCCSCycle.h"
00008 #include "OnlineDB/EcalCondDB/interface/ODDCCCycle.h"
00009 #include "OnlineDB/EcalCondDB/interface/ODJBH4Cycle.h"
00010 #include "OnlineDB/EcalCondDB/interface/ODLaserCycle.h"
00011 #include "OnlineDB/EcalCondDB/interface/ODLTCCycle.h"
00012 #include "OnlineDB/EcalCondDB/interface/ODLTSCycle.h"
00013 #include "OnlineDB/EcalCondDB/interface/ODDCUCycle.h"
00014 #include "OnlineDB/EcalCondDB/interface/ODRunConfigCycleInfo.h"
00015 #include "OnlineDB/EcalCondDB/interface/ODScanCycle.h"
00016 #include "OnlineDB/EcalCondDB/interface/ODTCCCycle.h"
00017 #include "OnlineDB/EcalCondDB/interface/ODTCCEECycle.h"
00018 #include "OnlineDB/EcalCondDB/interface/ODTTCciCycle.h"
00019 #include "OnlineDB/EcalCondDB/interface/ODTTCFCycle.h"
00020 #include "OnlineDB/EcalCondDB/interface/ODSRPCycle.h"
00021 
00022 using namespace std;
00023 using namespace oracle::occi;
00024 
00025 ODEcalCycle::ODEcalCycle()
00026 {
00027   m_env = NULL;
00028   m_conn = NULL;
00029   m_writeStmt = NULL;
00030   m_readStmt = NULL;
00031 
00032    m_ID=0;
00033    clear();
00034 }
00035 
00036 
00037 
00038 ODEcalCycle::~ODEcalCycle()
00039 {
00040 }
00041 
00042 
00043 
00044 void ODEcalCycle::prepareWrite()
00045   throw(std::runtime_error)
00046 {
00047 
00048   std::cout<< "ODEcalCycle::prepareWrite(): this is a view writing specific tables  "<< endl;
00049 
00050 }
00051 
00052 
00053 
00054 void ODEcalCycle::writeDB()
00055   throw(std::runtime_error)
00056 {
00057 
00058   ODRunConfigCycleInfo cyc;
00059   cyc.setTag(this->getCycleTag());
00060   cyc.setDescription(this->getCycleDescription());
00061   cyc.setCycleNumber(this->getCycleNum());
00062   cyc.setSequenceID(this->getSequenceId());
00063   // here we insert the cycle and get back the id
00064   cyc.setConnection(m_env, m_conn);
00065   cyc.insertConfig();
00066   int cyc_id=cyc.getId();
00067   cout << "Cycle inserted with ID "<< cyc_id<< endl;
00068   m_ID=cyc_id;
00069 
00070   if(getCCSId()!=0){ 
00071     ODCCSCycle ccs_cycle;
00072     ccs_cycle.setId(cyc_id);
00073     ccs_cycle.setCCSConfigurationID(getCCSId());
00074     ccs_cycle.setConnection(m_env, m_conn);
00075     ccs_cycle.insertConfig();
00076     cout << "Inserting CCS-cycle in DB..." << flush;
00077   } 
00078   if(getDCCId()!=0){
00079     ODDCCCycle dcc_cycle;
00080     dcc_cycle.setId(cyc_id);
00081     dcc_cycle.setDCCConfigurationID(getDCCId());
00082     dcc_cycle.setConnection(m_env, m_conn);
00083     dcc_cycle.insertConfig();
00084     cout << "Inserting DCC-cycle in DB..." << flush;
00085   }
00086   if(getLaserId()!=0){
00087     ODLaserCycle laser_cycle;
00088     laser_cycle.setId(cyc_id);
00089     laser_cycle.setLaserConfigurationID(getLaserId());
00090     laser_cycle.setConnection(m_env, m_conn);
00091     laser_cycle.insertConfig();
00092     cout << "Inserting LASER-cycle in DB..." << flush;
00093   }
00094   if(getLTCId()!=0){
00095     ODLTCCycle ltc_cycle;
00096     ltc_cycle.setId(cyc_id);
00097     ltc_cycle.setLTCConfigurationID(getLTCId());
00098     ltc_cycle.setConnection(m_env, m_conn);
00099     ltc_cycle.insertConfig();
00100     cout << "Inserting LTC-cycle in DB..." << flush;
00101   }
00102   if(getLTSId()!=0){
00103     ODLTSCycle lts_cycle;
00104     lts_cycle.setId(cyc_id);
00105     lts_cycle.setLTSConfigurationID(getLTSId());
00106     lts_cycle.setConnection(m_env, m_conn);
00107     lts_cycle.insertConfig();
00108     cout << "Inserting LTS-cycle in DB..." << flush;
00109   }
00110   if(getDCUId()!=0){
00111     ODDCUCycle dcu_cycle;
00112     dcu_cycle.setId(cyc_id);
00113     dcu_cycle.setDCUConfigurationID(getDCUId());
00114     dcu_cycle.setConnection(m_env, m_conn);
00115     dcu_cycle.insertConfig();
00116     cout << "Inserting DCU-cycle in DB..." << flush;
00117   }
00118   if(getTCCId()!=0){
00119     ODTCCCycle tcc_cycle;
00120     tcc_cycle.setId(cyc_id);
00121     tcc_cycle.setTCCConfigurationID(getTCCId());
00122     tcc_cycle.setConnection(m_env, m_conn);
00123     tcc_cycle.insertConfig();
00124     cout << "Inserting TCC-cycle in DB..." << flush;
00125   }
00126   if(getTCCEEId()!=0){
00127     ODTCCEECycle tcc_ee_cycle;
00128     tcc_ee_cycle.setId(cyc_id);
00129     tcc_ee_cycle.setTCCConfigurationID(getTCCEEId());
00130     tcc_ee_cycle.setConnection(m_env, m_conn);
00131     tcc_ee_cycle.insertConfig();
00132     cout << "Inserting TCCEE-cycle in DB..." << flush;
00133   }
00134   if(getTTCCIId()!=0){
00135     ODTTCciCycle ttcci_cycle;
00136     ttcci_cycle.setId(cyc_id);
00137     ttcci_cycle.setTTCciConfigurationID(getTTCCIId());
00138     ttcci_cycle.setConnection(m_env, m_conn);
00139     ttcci_cycle.insertConfig();
00140     cout << "Inserting TTCCI-cycle in DB..." << flush;
00141   }
00142   if(getTTCFId()!=0){
00143     ODTTCFCycle ttcf_cycle;
00144     ttcf_cycle.setId(cyc_id);
00145     ttcf_cycle.setTTCFConfigurationID(getTTCFId());
00146     ttcf_cycle.setConnection(m_env, m_conn);
00147     ttcf_cycle.insertConfig();
00148     cout << "Inserting TTCF-cycle in DB..." << flush;
00149   }
00150   if(getSRPId()!=0){
00151     ODSRPCycle srp_cycle;
00152     srp_cycle.setId(cyc_id);
00153     srp_cycle.setSRPConfigurationID(getSRPId());
00154     srp_cycle.setConnection(m_env, m_conn);
00155     srp_cycle.insertConfig();
00156     cout << "Inserting SRP-cycle in DB..." << flush;
00157   }
00158   if(getJBH4Id()!=0){
00159     ODJBH4Cycle jbh4_cycle;
00160     jbh4_cycle.setId(cyc_id);
00161     jbh4_cycle.setJBH4ConfigurationID(getJBH4Id());
00162     jbh4_cycle.setConnection(m_env, m_conn);
00163     jbh4_cycle.insertConfig();
00164     cout << "Inserting JBH4-cycle in DB..." << flush;
00165   }
00166   if(getScanId()!=0){
00167     ODScanCycle scan_cycle;
00168     scan_cycle.setId(cyc_id);
00169     scan_cycle.setScanConfigurationID(getScanId());
00170     scan_cycle.setConnection(m_env, m_conn);
00171     scan_cycle.insertConfig();
00172     cout << "Inserting SCAN-cycle in DB..." << flush;
00173   }
00174 
00175 
00176 }
00177 
00178 
00179 void ODEcalCycle::clear(){
00180    m_tag="";
00181    m_version=0;
00182    m_seq_num=0;
00183    m_cycle_num=0;
00184    m_cycle_tag="";
00185    m_cycle_description="";
00186    m_ccs=0;
00187    m_dcc=0;
00188    m_laser=0;
00189    m_ltc=0;
00190    m_lts=0;
00191    m_dcu=0;
00192    m_tcc=0;
00193    m_tcc_ee=0;
00194    m_ttcci=0;
00195    m_jbh4=0;
00196    m_scan=0;
00197    //   m_seq_id=0;
00198    m_ttcf=0;
00199    m_srp=0;
00200 }
00201 
00202 int ODEcalCycle::fetchID()
00203   throw(std::runtime_error)
00204 {
00205   // Return from memory if available
00206   if (m_ID>0) {
00207     return m_ID;
00208   }
00209 
00210   this->checkConnection();
00211 
00212 
00213   DateHandler dh(m_env, m_conn);
00214 
00215   try {
00216     Statement* stmt = m_conn->createStatement();
00217     stmt->setSQL("SELECT cycle_id from ECAL_CYCLE_DAT "
00218                "WHERE sequence_id = :1 ");
00219     stmt->setInt(1, m_seq_id);
00220 
00221     ResultSet* rset = stmt->executeQuery();
00222 
00223     if (rset->next()) {
00224       m_ID = rset->getInt(1);
00225     } else {
00226       m_ID = 0;
00227     }
00228     m_conn->terminateStatement(stmt);
00229   } catch (SQLException &e) {
00230     throw(std::runtime_error("ODEcalCycle::fetchID:  "+e.getMessage()));
00231   }
00232   setByID(m_ID);
00233   return m_ID;
00234 }
00235 
00236 void ODEcalCycle::setByID(int id)
00237   throw(std::runtime_error)
00238 {
00239    this->checkConnection();
00240 
00241    DateHandler dh(m_env, m_conn);
00242 
00243    try {
00244      Statement* stmt = m_conn->createStatement();
00245 
00246      stmt->setSQL("SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
00247                      "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
00248                      "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
00249                      "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
00250                      "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
00251                      "FROM ECAL_CYCLE where cycle_id = :1 " );
00252      stmt->setInt(1, id);
00253 
00254      ResultSet* rset = stmt->executeQuery();
00255      if (rset->next()) {
00256        m_tag = rset->getString(1);
00257        m_version = rset->getInt(2);
00258        m_seq_num = rset->getInt(3);
00259        m_cycle_num = rset->getInt(4);
00260        m_cycle_tag = rset->getString(5);
00261        m_cycle_description = rset->getString(6);
00262        m_ccs = rset->getInt(7);
00263        m_dcc = rset->getInt(8);
00264        m_laser = rset->getInt(9);
00265        m_ltc = rset->getInt(10);
00266        m_lts = rset->getInt(11);
00267        m_tcc = rset->getInt(12);
00268        m_ttcci = rset->getInt(13);
00269        m_jbh4 = rset->getInt(14);
00270        m_scan = rset->getInt(15);
00271        m_ttcf = rset->getInt(16);
00272        m_srp = rset->getInt(17);
00273        m_dcu = rset->getInt(18);
00274        m_tcc_ee = rset->getInt(19);
00275 
00276      } else {
00277        throw(std::runtime_error("ODEcalCycle::setByID:  Given config_id is not in the database"));
00278      }
00279      m_conn->terminateStatement(stmt);
00280    } catch (SQLException &e) {
00281      throw(std::runtime_error("ODEcalCycle::setByID:  "+e.getMessage()));
00282    }
00283 }
00284 
00285 
00286 void ODEcalCycle::printout(){
00287 
00288   std::cout << "**** ODEcalCycle ****"<< std::endl;
00289   std::cout << "**** id: "<< m_ID << std::endl;
00290   std::cout << "**** tag: "<< m_tag << std::endl;
00291   std::cout << "**** version: "<< m_version << std::endl;
00292   std::cout << "**** seq_num: "<< m_seq_num << std::endl;
00293   std::cout << "**** cycle num: "<< m_cycle_num << std::endl;
00294   std::cout << "**** cycle tag: "<< m_cycle_tag << std::endl;
00295   std::cout << "**** cycle description: "<< m_cycle_description<< std::endl;
00296   std::cout << "**** ccs_id: "<< m_ccs <<std::endl;
00297   std::cout << "**** dcc_id: "<< m_dcc <<std::endl;
00298   std::cout << "**** laser: "<< m_laser << std::endl;
00299   std::cout << "**** ttcf_id: "<< m_ttcf << std::endl;
00300   std::cout << "**** srp_id: "<< m_srp << std::endl;
00301   std::cout << "**** scan_id: "<< m_scan << std::endl;
00302   std::cout << "**** ODEcalCycle ****"<< std::endl;
00303  
00304  
00305 }
00306 
00307 
00308 void ODEcalCycle::fetchData(ODEcalCycle * result)
00309   throw(std::runtime_error)
00310 {
00311   this->checkConnection();
00312   //  result->clear();
00313   if(result->getId()==0){
00314     //    throw(std::runtime_error("ODEcalCycle::fetchData(): no Id defined for this ODEcalCycle "));
00315     result->fetchID();
00316   }
00317 
00318   try {
00319 
00320     m_readStmt->setSQL("SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
00321                      "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
00322                      "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
00323                      "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
00324                      "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
00325                      "FROM ECAL_CYCLE where cycle_id = :1 " );
00326     m_readStmt->setInt(1, result->getId());
00327     ResultSet* rset = m_readStmt->executeQuery();
00328 
00329     rset->next();
00330 
00331     result->setTag(          rset->getString(1) );
00332     result->setVersion(      rset->getInt(2) );
00333     result->setSeqNum(       rset->getInt(3) );
00334     result->setCycleNum(     rset->getInt(4) );
00335     result->setCycleTag(     rset->getString(5) );
00336     result->setCycleDescription( rset->getString(6) );
00337     result->setCCSId(        rset->getInt(7) );
00338     result->setDCCId(        rset->getInt(8) );
00339     result->setLaserId(      rset->getInt(9) );
00340     result->setLTCId(        rset->getInt(10) );
00341     result->setLTSId(        rset->getInt(11) );
00342     result->setTCCId(        rset->getInt(12) );
00343     result->setTTCCIId(        rset->getInt(13) );
00344 
00345    
00346     result->setJBH4Id(        rset->getInt(14) );
00347     result->setScanId(        rset->getInt(15) );
00348 
00349     result->setTTCFId(        rset->getInt(16) );
00350     result->setSRPId(        rset->getInt(17) );
00351     result->setDCUId(        rset->getInt(18) );
00352     result->setTCCEEId(      rset->getInt(19) );
00353 
00354   } catch (SQLException &e) {
00355     throw(std::runtime_error("ODEcalCycle::fetchData():  "+e.getMessage()));
00356   }
00357 }
00358