00001 #ifndef BEAN
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/SvcFactory.h"
00004 #include "GaudiKernel/ISvcLocator.h"
00005 #include "GaudiKernel/SmartDataPtr.h"
00006 #include "GaudiKernel/Bootstrap.h"
00007
00008 #include "facilities/Util.h"
00009 #else
00010 #include "DatabaseSvc/DatabaseSvc.h"
00011 #endif
00012
00013 #include <iostream>
00014 #include <cstdio>
00015 #include <cstdlib>
00016
00017 #include "MagneticField/ConnectionDB.h"
00018
00019 using namespace std;
00020
00021 namespace FieldDBUtil {
00022
00023 #ifndef BEAN
00024 ConnectionDB::ConnectionDB() {
00025 StatusCode sc = Gaudi::svcLocator()->service("DatabaseSvc", m_dbsvc, true);
00026 if (sc .isFailure() ) {
00027 std::cout << "ERROR: In ConnectionDB()--> Unable to find DatabaseSvc " << std::endl;
00028 }
00029 }
00030 #endif
00031
00032 ConnectionDB::eRet ConnectionDB::getReadSC_MagnetInfo( std::vector<double>& current, int runNo) {
00033
00034 #ifdef BEAN
00035 static DatabaseSvc* m_dbsvc = 0;
00036
00037 if( !m_dbsvc ) {
00038 m_dbsvc = DatabaseSvc::instance();
00039 }
00040 #endif
00041
00042
00043 char stmt1[200];
00044 int run_No = std::abs(runNo);
00045
00046 sprintf(stmt1,"select Magnet_Current,SCQL,SCQR from SC_magnet where run_number = %d ",run_No);
00047
00048 DatabaseRecordVector results;
00049 results.clear();
00050 int status = m_dbsvc->query("run",stmt1,results);
00051
00052 if(status<0){
00053 std::cout << "ERROR Read the SSM and SCQ current from the Database" << endl;
00054 exit(1);
00055 }
00056
00057 int RowNumber = results.size();
00058 if(RowNumber!=1){
00059 std::cout<<"ERROR:error searching SC_Magnet Data in the database, check your selection criterions"<<std::endl;
00060 return RETMySQLError;
00061 }
00062
00063 DatabaseRecord& rec = *results[0];
00064 double ssm_curr = rec.GetDouble("Magnet_Current");
00065 double scql_curr = rec.GetDouble("SCQL");
00066 double scqr_curr = rec.GetDouble("SCQR");
00067
00068
00069 current.resize(3);
00070 current[0] = ssm_curr;
00071 current[1] = scql_curr;
00072 current[2] = scqr_curr;
00073
00074 return RETOk;
00075 }
00076
00077 ConnectionDB::eRet ConnectionDB::getBeamEnergy( std::vector<double>& beamE, int runNo) {
00078
00079 char stmt1[200];
00080 int run_No = std::abs(runNo);
00081
00082 sprintf(stmt1,"select BPR_PRB,BER_PRB from RunParams where run_number = %d ",run_No);
00083
00084 DatabaseRecordVector results;
00085 results.clear();
00086 int status = m_dbsvc->query("run",stmt1,results);
00087 if(status<0){
00088 std::cout << "ERROR Read the beam energy from the Database" << endreq;
00089 exit(1);
00090 }
00091
00092 int RowNumber = results.size();
00093
00094 if(RowNumber == 0) {
00095 beamE.push_back(1.843);
00096 beamE.push_back(1.843);
00097
00098 return RETOk;
00099 }
00100
00101 if(RowNumber!=1){
00102 std::cout<<"ERROR:error searching beam energy in the database, check your selection criterions"<<std::endl;
00103 return RETMySQLError;
00104 }
00105
00106 beamE.push_back(atof((*results[0])["BPR_PRB"]));
00107 beamE.push_back(atof((*results[0])["BER_PRB"]));
00108
00109 return RETOk;
00110 }
00111
00112 }