CMS 3D CMS Logo

ODLaserConfig.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 
00005 #include "OnlineDB/EcalCondDB/interface/ODLaserConfig.h"
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 ODLaserConfig::ODLaserConfig()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_writeStmt = NULL;
00015   m_readStmt = NULL;
00016   m_config_tag="";
00017 
00018    m_ID=0;
00019    clear();
00020 }
00021 
00022 void ODLaserConfig::clear(){
00023 
00024 
00025   m_debug=0;
00026   m_dummy=0;
00027 
00028   // emtc 
00029    m_emtc_1=0;
00030    m_emtc_2=0;
00031    m_emtc_3=0;
00032    m_emtc_4=0;
00033    m_emtc_5=0;
00034 
00035   // laser
00036   m_wave=0;
00037   m_power=0;
00038   m_switch=0;
00039   m_filter=0;
00040   m_on=0;
00041   m_laserhost="";
00042   m_laserport=0;
00043 
00044   // mataq
00045    m_mq_base=0;
00046    m_mq_none=0;
00047    m_mode="" ;
00048    m_chan_mask=0;
00049    m_samples="";
00050    m_ped_file="";
00051    m_use_buffer=0;
00052    m_post_trig=0;
00053    m_fp_mode=0;
00054    m_hal_mod_file="";
00055    m_hal_add_file="";
00056    m_hal_tab_file="";
00057    m_serial="";
00058    m_ped_count=0;
00059    m_raw_mode=0;
00060    m_aqmode="";
00061    m_mq_file="";
00062    m_laser_tag="";
00063 
00064 }
00065 
00066 ODLaserConfig::~ODLaserConfig()
00067 {
00068 }
00069 
00070 
00071 
00072 void ODLaserConfig::setParameters(std::map<string,string> my_keys_map){
00073   
00074   // parses the result of the XML parser that is a map of 
00075   // string string with variable name variable value 
00076   
00077   for( std::map<std::string, std::string >::iterator ci=
00078          my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
00079     
00080     if(ci->first==  "LASER_CONFIGURATION_ID") setConfigTag(ci->second);
00081     if(ci->first==  "DEBUG") setDebug(atoi(ci->second.c_str()) );
00082     if(ci->first==  "DUMMY") setDummy(atoi(ci->second.c_str() ));
00083     if(ci->first==  "MATACQ_BASE_ADDRESS") setMatacqBaseAddress(atoi(ci->second.c_str() ));
00084     if(ci->first==  "MATACQ_NONE") setMatacqNone(atoi(ci->second.c_str() ));
00085     if(ci->first==  "MATACQ_MODE") setMatacqMode(ci->second);
00086     if(ci->first==  "CHANNEL_MASK") setChannelMask(atoi(ci->second.c_str() ));
00087     if(ci->first==  "MAX_SAMPLES_FOR_DAQ") setMaxSamplesForDaq(ci->second );
00088     if(ci->first==  "MATACQ_FED_ID") setMatacqFedId(atoi(ci->second.c_str()) );
00089     if(ci->first==  "PEDESTAL_FILE") setPedestalFile(ci->second );
00090     if(ci->first==  "USE_BUFFER") setUseBuffer(atoi(ci->second.c_str())) ;
00091     if(ci->first==  "POSTTRIG") setPostTrig(atoi(ci->second.c_str()) );
00092     if(ci->first==  "FP_MODE") setFPMode(atoi(ci->second.c_str() ));
00093     if(ci->first==  "HAL_MODULE_FILE") setHalModuleFile(ci->second );
00094     if(ci->first==  "HAL_ADDRESS_TABLE_FILE" || ci->first==  "HAL_ADDRESST_ABLE_FILE") setHalAddressTableFile(ci->second);
00095     if(ci->first==  "HAL_STATIC_TABLE_FILE") setHalStaticTableFile(ci->second );
00096     if(ci->first==  "MATACQ_SERIAL_NUMBER") setMatacqSerialNumber(ci->second );
00097     if(ci->first==  "PEDESTAL_RUN_EVENT_COUNT") setPedestalRunEventCount(atoi(ci->second.c_str()) );
00098     if(ci->first==  "RAW_DATA_MODE") setRawDataMode(atoi(ci->second.c_str()) );
00099     if(ci->first==  "ACQUISITION_MODE") setMatacqAcquisitionMode(ci->second );
00100     if(ci->first==  "LOCAL_OUTPUT_FILE") setLocalOutputFile(ci->second );
00101     if(ci->first==  "EMTC_NONE") setEMTCNone(atoi(ci->second.c_str()) );
00102     if(ci->first==  "WTE2_LASER_DELAY") setWTE2LaserDelay(atoi(ci->second.c_str()) );
00103     if(ci->first==  "LASER_PHASE") setLaserPhase(atoi(ci->second.c_str()) );
00104     if(ci->first==  "EMTC_TTC_IN") setEMTCTTCIn(atoi(ci->second.c_str()) );
00105     if(ci->first==  "EMTC_SLOT_ID") setEMTCSlotId(atoi(ci->second.c_str()) );
00106     if(ci->first==  "WAVELENGTH") setWaveLength(atoi(ci->second.c_str()) );
00107     if(ci->first==  "OPTICAL_SWITCH") setOpticalSwitch(atoi(ci->second.c_str()) );
00108     if(ci->first==  "POWER_SETTING") setPower(atoi(ci->second.c_str()) );
00109     if(ci->first==  "FILTER") setFilter(atoi(ci->second.c_str()) );
00110     if(ci->first==  "LASER_CONTROL_ON") setLaserControlOn(atoi(ci->second.c_str()) );
00111     if(ci->first==  "LASER_CONTROL_HOST") setLaserControlHost(ci->second );
00112     if(ci->first==  "LASER_CONTROL_PORT") setLaserControlPort(atoi(ci->second.c_str()) );
00113 
00114   }
00115   
00116 }
00117 
00118 int ODLaserConfig::fetchNextId()  throw(std::runtime_error) {
00119 
00120   int result=0;
00121   try {
00122     this->checkConnection();
00123 
00124     m_readStmt = m_conn->createStatement(); 
00125     m_readStmt->setSQL("select ecal_laser_config_sq.NextVal from dual");
00126     ResultSet* rset = m_readStmt->executeQuery();
00127     while (rset->next ()){
00128       result= rset->getInt(1);
00129     }
00130     m_conn->terminateStatement(m_readStmt);
00131     return result; 
00132 
00133   } catch (SQLException &e) {
00134     throw(runtime_error("ODLaserConfig::fetchNextId():  "+e.getMessage()));
00135   }
00136 
00137 }
00138 
00139 
00140 void ODLaserConfig::prepareWrite()
00141   throw(runtime_error)
00142 {
00143   this->checkConnection();
00144   int next_id=fetchNextId();
00145 
00146 
00147   try {
00148     m_writeStmt = m_conn->createStatement();
00149     m_writeStmt->setSQL("INSERT INTO ECAL_Laser_CONFIGURATION ( laser_configuration_id, laser_tag "
00150                         ", laser_DEBUG "
00151                         ", DUMMY "
00152                         ", MATACQ_BASE_ADDRESS " 
00153                         ", MATACQ_NONE "
00154                         ", matacq_mode "
00155                         ", channel_Mask "
00156                         ", max_Samples_For_Daq "
00157                         ", maTACQ_FED_ID "
00158                         ", pedestal_File "
00159                         ", use_Buffer "
00160                         ", postTrig "
00161                         ", fp_Mode "
00162                         ", hal_Module_File " 
00163                         ", hal_Address_Table_File "
00164                         ", hal_Static_Table_File "
00165                         ", matacq_Serial_Number "
00166                         ", pedestal_Run_Event_Count " 
00167                         ", raw_Data_Mode "
00168                         ", ACQUISITION_MODE " 
00169                         ", LOCAL_OUTPUT_FILE " 
00170                         ", emtc_none "
00171                         ", wte2_laser_delay " 
00172                         ", laser_phase "
00173                         ", emtc_ttc_in "
00174                         ", emtc_slot_id " 
00175                         ", WAVELENGTH "
00176                         ", POWER_SETTING "
00177                         ", OPTICAL_SWITCH "
00178                         ", FILTER "
00179                         ", LASER_CONTROL_ON " 
00180                         ", LASER_CONTROL_HOST " 
00181                         ", LASER_CONTROL_PORT "
00182                         ", LASER_TAG2 ) "
00183                         "VALUES (  :1, :2, :3, :4, :5, :6, :7, :8, :9, :10, "
00184                         ":11, :12, :13, :14, :15, :16, :17, :18, :19, :20,  "
00185                         ":21, :22, :23, :24, :25, :26, :27, :28, :29, :30,  "
00186                         ":31, :32, :33, :34, :35 )");
00187     m_writeStmt->setInt(1, next_id);
00188     m_ID=next_id;
00189   } catch (SQLException &e) {
00190     throw(runtime_error("ODLaserConfig::prepareWrite():  "+e.getMessage()));
00191   }
00192 }
00193 
00194 
00195 
00196 void ODLaserConfig::writeDB()
00197   throw(runtime_error)
00198 {
00199   this->checkConnection();
00200   this->checkPrepare();
00201 
00202   try {
00203     
00204     // 1 is the id 2 is the tag
00205     m_writeStmt->setString(2, this->getConfigTag());
00206 
00207     m_writeStmt->setInt(   3, this->getDebug());
00208     m_writeStmt->setInt(   4, this->getDummy());
00209     m_writeStmt->setInt(   5, this->getMatacqBaseAddress());
00210     m_writeStmt->setInt(   6, this->getMatacqNone());
00211     m_writeStmt->setString(7, this->getMatacqMode());
00212     m_writeStmt->setInt(   8, this->getChannelMask());
00213     m_writeStmt->setString(9, this->getMaxSamplesForDaq());
00214     m_writeStmt->setInt(  10, this->getMatacqFedId());
00215     m_writeStmt->setString(11, this->getPedestalFile());
00216     m_writeStmt->setInt(  12, this->getUseBuffer());
00217     m_writeStmt->setInt(  13, this->getPostTrig());
00218     m_writeStmt->setInt(  14, this->getFPMode());
00219     m_writeStmt->setString(15,  this->getHalModuleFile() );
00220     m_writeStmt->setString(16, this->getHalAddressTableFile() );
00221     m_writeStmt->setString(17, this->getHalStaticTableFile() );
00222     m_writeStmt->setString(18, this->getMatacqSerialNumber() );
00223     m_writeStmt->setInt(   19, this->getPedestalRunEventCount() );
00224     m_writeStmt->setInt(   20, this->getRawDataMode());
00225     m_writeStmt->setString(21, this->getMatacqAcquisitionMode());
00226     m_writeStmt->setString(22, this->getLocalOutputFile());
00227     m_writeStmt->setInt(   23, this->getEMTCNone());
00228     m_writeStmt->setInt(   24, this->getWTE2LaserDelay());
00229     m_writeStmt->setInt(   25, this->getLaserPhase());
00230     m_writeStmt->setInt(   26, this->getEMTCTTCIn());
00231     m_writeStmt->setInt(   27, this->getEMTCSlotId());
00232     // laser
00233     m_writeStmt->setInt(28, this->getWaveLength());
00234     m_writeStmt->setInt(29, this->getPower());
00235     m_writeStmt->setInt(30, this->getOpticalSwitch());
00236     m_writeStmt->setInt(31, this->getFilter());
00237     m_writeStmt->setInt(32, this->getLaserControlOn());
00238     m_writeStmt->setString(33, this->getLaserControlHost() );
00239     m_writeStmt->setInt(   34, this->getLaserControlPort());
00240     m_writeStmt->setString(   35, this->getLaserTag());
00241 
00242     m_writeStmt->executeUpdate();
00243 
00244 
00245   } catch (SQLException &e) {
00246     throw(runtime_error("ODLaserConfig::writeDB():  "+e.getMessage()));
00247   }
00248   // Now get the ID
00249   if (!this->fetchID()) {
00250     throw(runtime_error("ODLaserConfig::writeDB:  Failed to write"));
00251   }
00252 
00253 
00254 }
00255 
00256 
00257 
00258 void ODLaserConfig::fetchData(ODLaserConfig * result)
00259   throw(runtime_error)
00260 {
00261   this->checkConnection();
00262   result->clear();
00263   if(result->getId()==0 && (result->getConfigTag()=="") ){
00264     throw(runtime_error("ODLaserConfig::fetchData(): no Id defined for this ODLaserConfig "));
00265   }
00266 
00267   try {
00268 
00269     m_readStmt->setSQL("SELECT * "
00270                        "FROM ECAL_Laser_CONFIGURATION d "
00271                        " where ( laser_configuration_id = :1  or laser_tag=:2 )" );
00272     m_readStmt->setInt(1, result->getId());
00273     m_readStmt->setString(2, result->getConfigTag());
00274    ResultSet* rset = m_readStmt->executeQuery();
00275 
00276     rset->next();
00277 
00278     
00279     // start from 3 because of select * 
00280 
00281     result->setId(rset->getInt(1));
00282     result->setConfigTag(rset->getString(2));
00283 
00284     result->setDebug(rset->getInt(  3  ));
00285     result->setDummy(rset->getInt(  4  ));
00286     result->setMatacqBaseAddress(rset->getInt( 5   ));
00287     result->setMatacqNone(rset->getInt(  6  ));
00288     result->setMatacqMode(rset->getString(7    ));
00289     result->setChannelMask(rset->getInt(  8  ));
00290     result->setMaxSamplesForDaq(rset->getString( 9   ));
00291     result->setMatacqFedId(rset->getInt( 10   ));
00292     result->setPedestalFile(rset->getString( 11   ));
00293     result->setUseBuffer(rset->getInt(   12 ));
00294     result->setPostTrig(rset->getInt(   13 ));
00295     result->setFPMode(rset->getInt(   14 ));
00296     result->setHalModuleFile(rset->getString( 15   ));
00297     result->setHalAddressTableFile(rset->getString( 16   ));
00298     result->setHalStaticTableFile(rset->getString(  17  ));
00299     result->setMatacqSerialNumber(rset->getString(  18  ));
00300     result->setPedestalRunEventCount(rset->getInt(  19  ));
00301     result->setRawDataMode(rset->getInt( 20   ));
00302     result->setMatacqAcquisitionMode(rset->getString( 21   ));
00303     result->setLocalOutputFile(rset->getString(  22  ));
00304     result->setEMTCNone(rset->getInt(  23  ));
00305     result->setWTE2LaserDelay(rset->getInt( 24   ));
00306     result->setLaserPhase(rset->getInt(  25  ));
00307     result->setEMTCTTCIn(rset->getInt(  26  ));
00308     result->setEMTCSlotId(rset->getInt( 27   ));
00309     // laser
00310     result->setWaveLength(rset->getInt( 28   ));
00311     result->setPower(rset->getInt(  29  ));
00312     result->setOpticalSwitch(rset->getInt( 30   ));
00313     result->setFilter(rset->getInt(  31  ));
00314     result->setLaserControlOn(rset->getInt( 32   ));
00315     result->setLaserControlHost(rset->getString( 33   ));
00316     result->setLaserControlPort(rset->getInt( 34   ));
00317     result->setLaserTag(rset->getString( 35   ));
00318   
00319   } catch (SQLException &e) {
00320     throw(runtime_error("ODLaserConfig::fetchData():  "+e.getMessage()));
00321   }
00322 }
00323 
00324 int ODLaserConfig::fetchID()    throw(std::runtime_error)
00325 {
00326   // Return from memory if available
00327   if (m_ID!=0) {
00328     return m_ID;
00329   }
00330 
00331   this->checkConnection();
00332 
00333   try {
00334     Statement* stmt = m_conn->createStatement();
00335     stmt->setSQL("SELECT laser_configuration_id FROM ecal_laser_configuration "
00336                  "WHERE laser_tag=:laser_tag ");
00337     stmt->setString(1, getLaserTag());
00338 
00339     ResultSet* rset = stmt->executeQuery();
00340 
00341     if (rset->next()) {
00342       m_ID = rset->getInt(1);
00343     } else {
00344       m_ID = 0;
00345     }
00346     m_conn->terminateStatement(stmt);
00347   } catch (SQLException &e) {
00348     throw(runtime_error("ODLaserConfig::fetchID:  "+e.getMessage()));
00349   }
00350 
00351   fetchData(this);
00352 
00353   return m_ID;
00354 }

Generated on Tue Jun 9 17:40:49 2009 for CMSSW by  doxygen 1.5.4