00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/ODEcalCycle.h"
00006 #include "OnlineDB/EcalCondDB/interface/ODCCSCycle.h"
00007 #include "OnlineDB/EcalCondDB/interface/ODDCCCycle.h"
00008 #include "OnlineDB/EcalCondDB/interface/ODJBH4Cycle.h"
00009 #include "OnlineDB/EcalCondDB/interface/ODLaserCycle.h"
00010 #include "OnlineDB/EcalCondDB/interface/ODLTCCycle.h"
00011 #include "OnlineDB/EcalCondDB/interface/ODLTSCycle.h"
00012 #include "OnlineDB/EcalCondDB/interface/ODDCUCycle.h"
00013 #include "OnlineDB/EcalCondDB/interface/ODRunConfigCycleInfo.h"
00014 #include "OnlineDB/EcalCondDB/interface/ODScanCycle.h"
00015 #include "OnlineDB/EcalCondDB/interface/ODTCCCycle.h"
00016 #include "OnlineDB/EcalCondDB/interface/ODTTCciCycle.h"
00017 #include "OnlineDB/EcalCondDB/interface/ODTTCFCycle.h"
00018 #include "OnlineDB/EcalCondDB/interface/ODSRPCycle.h"
00019
00020 using namespace std;
00021 using namespace oracle::occi;
00022
00023 ODEcalCycle::ODEcalCycle()
00024 {
00025 m_env = NULL;
00026 m_conn = NULL;
00027 m_writeStmt = NULL;
00028 m_readStmt = NULL;
00029
00030 m_ID=0;
00031 clear();
00032 }
00033
00034
00035
00036 ODEcalCycle::~ODEcalCycle()
00037 {
00038 }
00039
00040
00041
00042 void ODEcalCycle::prepareWrite()
00043 throw(runtime_error)
00044 {
00045
00046 std::cout<< "ODEcalCycle::prepareWrite(): this is a view writing specific tables "<< endl;
00047
00048 }
00049
00050
00051
00052 void ODEcalCycle::writeDB()
00053 throw(runtime_error)
00054 {
00055
00056 ODRunConfigCycleInfo cyc;
00057 cyc.setTag(this->getCycleTag());
00058 cyc.setDescription(this->getCycleDescription());
00059 cyc.setCycleNumber(this->getCycleNum());
00060 cyc.setSequenceID(this->getSequenceId());
00061
00062 cyc.setConnection(m_env, m_conn);
00063 cyc.insertConfig();
00064 int cyc_id=cyc.getId();
00065 cout << "Cycle inserted with ID "<< cyc_id<< endl;
00066 m_ID=cyc_id;
00067
00068 if(getCCSId()!=0){
00069 ODCCSCycle ccs_cycle;
00070 ccs_cycle.setId(cyc_id);
00071 ccs_cycle.setCCSConfigurationID(getCCSId());
00072 ccs_cycle.setConnection(m_env, m_conn);
00073 ccs_cycle.insertConfig();
00074 cout << "Inserting CCS-cycle in DB..." << flush;
00075 }
00076 if(getDCCId()!=0){
00077 ODDCCCycle dcc_cycle;
00078 dcc_cycle.setId(cyc_id);
00079 dcc_cycle.setDCCConfigurationID(getDCCId());
00080 dcc_cycle.setConnection(m_env, m_conn);
00081 dcc_cycle.insertConfig();
00082 cout << "Inserting DCC-cycle in DB..." << flush;
00083 }
00084 if(getLaserId()!=0){
00085 ODLaserCycle laser_cycle;
00086 laser_cycle.setId(cyc_id);
00087 laser_cycle.setLaserConfigurationID(getLaserId());
00088 laser_cycle.setConnection(m_env, m_conn);
00089 laser_cycle.insertConfig();
00090 cout << "Inserting LASER-cycle in DB..." << flush;
00091 }
00092 if(getLTCId()!=0){
00093 ODLTCCycle ltc_cycle;
00094 ltc_cycle.setId(cyc_id);
00095 ltc_cycle.setLTCConfigurationID(getLTCId());
00096 ltc_cycle.setConnection(m_env, m_conn);
00097 ltc_cycle.insertConfig();
00098 cout << "Inserting LTC-cycle in DB..." << flush;
00099 }
00100 if(getLTSId()!=0){
00101 ODLTSCycle lts_cycle;
00102 lts_cycle.setId(cyc_id);
00103 lts_cycle.setLTSConfigurationID(getLTSId());
00104 lts_cycle.setConnection(m_env, m_conn);
00105 lts_cycle.insertConfig();
00106 cout << "Inserting LTS-cycle in DB..." << flush;
00107 }
00108 if(getDCUId()!=0){
00109 ODDCUCycle dcu_cycle;
00110 dcu_cycle.setId(cyc_id);
00111 dcu_cycle.setDCUConfigurationID(getDCUId());
00112 dcu_cycle.setConnection(m_env, m_conn);
00113 dcu_cycle.insertConfig();
00114 cout << "Inserting DCU-cycle in DB..." << flush;
00115 }
00116 if(getTCCId()!=0){
00117 ODTCCCycle tcc_cycle;
00118 tcc_cycle.setId(cyc_id);
00119 tcc_cycle.setTCCConfigurationID(getTCCId());
00120 tcc_cycle.setConnection(m_env, m_conn);
00121 tcc_cycle.insertConfig();
00122 cout << "Inserting TCC-cycle in DB..." << flush;
00123 }
00124 if(getTTCCIId()!=0){
00125 ODTTCciCycle ttcci_cycle;
00126 ttcci_cycle.setId(cyc_id);
00127 ttcci_cycle.setTTCciConfigurationID(getTTCCIId());
00128 ttcci_cycle.setConnection(m_env, m_conn);
00129 ttcci_cycle.insertConfig();
00130 cout << "Inserting TTCCI-cycle in DB..." << flush;
00131 }
00132 if(getTTCFId()!=0){
00133 ODTTCFCycle ttcf_cycle;
00134 ttcf_cycle.setId(cyc_id);
00135 ttcf_cycle.setTTCFConfigurationID(getTTCFId());
00136 ttcf_cycle.setConnection(m_env, m_conn);
00137 ttcf_cycle.insertConfig();
00138 cout << "Inserting TTCF-cycle in DB..." << flush;
00139 }
00140 if(getSRPId()!=0){
00141 ODSRPCycle srp_cycle;
00142 srp_cycle.setId(cyc_id);
00143 srp_cycle.setSRPConfigurationID(getSRPId());
00144 srp_cycle.setConnection(m_env, m_conn);
00145 srp_cycle.insertConfig();
00146 cout << "Inserting SRP-cycle in DB..." << flush;
00147 }
00148 if(getJBH4Id()!=0){
00149 ODJBH4Cycle jbh4_cycle;
00150 jbh4_cycle.setId(cyc_id);
00151 jbh4_cycle.setJBH4ConfigurationID(getJBH4Id());
00152 jbh4_cycle.setConnection(m_env, m_conn);
00153 jbh4_cycle.insertConfig();
00154 cout << "Inserting JBH4-cycle in DB..." << flush;
00155 }
00156 if(getScanId()!=0){
00157 ODScanCycle scan_cycle;
00158 scan_cycle.setId(cyc_id);
00159 scan_cycle.setScanConfigurationID(getScanId());
00160 scan_cycle.setConnection(m_env, m_conn);
00161 scan_cycle.insertConfig();
00162 cout << "Inserting SCAN-cycle in DB..." << flush;
00163 }
00164
00165
00166 }
00167
00168
00169 void ODEcalCycle::clear(){
00170 m_tag="";
00171 m_version=0;
00172 m_seq_num=0;
00173 m_cycle_num=0;
00174 m_cycle_tag="";
00175 m_cycle_description="";
00176 m_ccs=0;
00177 m_dcc=0;
00178 m_laser=0;
00179 m_ltc=0;
00180 m_lts=0;
00181 m_dcu=0;
00182 m_tcc=0;
00183 m_ttcci=0;
00184 m_jbh4=0;
00185 m_scan=0;
00186 m_seq_id=0;
00187 m_ttcf=0;
00188 m_srp=0;
00189 }
00190
00191 void ODEcalCycle::printout(){
00192
00193 std::cout << "**** ODEcalCycle ****"<< std::endl;
00194 std::cout << "**** id: "<< m_ID << std::endl;
00195 std::cout << "**** tag: "<< m_tag << std::endl;
00196 std::cout << "**** version: "<< m_version << std::endl;
00197 std::cout << "**** seq_num: "<< m_seq_num << std::endl;
00198 std::cout << "**** cycle num: "<< m_cycle_num << std::endl;
00199 std::cout << "**** cycle tag: "<< m_cycle_tag << std::endl;
00200 std::cout << "**** cycle description: "<< m_cycle_description<< std::endl;
00201 std::cout << "**** ccs_id: "<< m_ccs <<std::endl;
00202 std::cout << "**** dcc_id: "<< m_dcc <<std::endl;
00203 std::cout << "**** laser: "<< m_laser << std::endl;
00204 std::cout << "**** ttcf_id: "<< m_ttcf << std::endl;
00205 std::cout << "**** srp_id: "<< m_srp << std::endl;
00206 std::cout << "**** scan_id: "<< m_scan << std::endl;
00207 std::cout << "**** ODEcalCycle ****"<< std::endl;
00208
00209
00210 }
00211
00212
00213 void ODEcalCycle::fetchData(ODEcalCycle * result)
00214 throw(runtime_error)
00215 {
00216 this->checkConnection();
00217 result->clear();
00218 if(result->getId()==0){
00219 throw(runtime_error("ODEcalCycle::fetchData(): no Id defined for this ODEcalCycle "));
00220 }
00221
00222 try {
00223
00224 m_readStmt->setSQL("SELECT d.tag, d.version, d.sequence_num, d.cycle_num, d.cycle_tag, d.description, d.ccs_configuration_id, "
00225 " d.dcc_configuration_id, d.laser_configuration_id, d.ltc_configuration_id, d.lts_configuration_id, d.tcc_configuration_id,"
00226 " d.\"TTCci_CONFIGURATION_ID\" , d.jbh4_configuration_id, d.scan_id, d.TTCF_configuration_id, d.srp_configuration_id, d.dcu_configuration_id "
00227 "FROM ECAL_CYCLE d "
00228 " where d.cycle_id = :1 " );
00229 m_readStmt->setInt(1, result->getId());
00230 ResultSet* rset = m_readStmt->executeQuery();
00231
00232 rset->next();
00233
00234 result->setTag( rset->getString(1) );
00235 result->setVersion( rset->getInt(2) );
00236 result->setSeqNum( rset->getInt(3) );
00237 result->setCycleNum( rset->getInt(4) );
00238 result->setCycleTag( rset->getString(5) );
00239 result->setCycleDescription( rset->getString(6) );
00240 result->setCCSId( rset->getInt(7) );
00241 result->setDCCId( rset->getInt(8) );
00242 result->setLaserId( rset->getInt(9) );
00243 result->setLTCId( rset->getInt(10) );
00244 result->setLTSId( rset->getInt(11) );
00245 result->setTCCId( rset->getInt(12) );
00246 result->setTTCCIId( rset->getInt(13) );
00247
00248
00249 result->setJBH4Id( rset->getInt(14) );
00250 result->setScanId( rset->getInt(15) );
00251
00252 result->setTTCFId( rset->getInt(16) );
00253 result->setSRPId( rset->getInt(17) );
00254 result->setDCUId( rset->getInt(18) );
00255
00256 } catch (SQLException &e) {
00257 throw(runtime_error("ODEcalCycle::fetchData(): "+e.getMessage()));
00258 }
00259 }
00260