CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
ConnectionDB.cxx
Go to the documentation of this file.
1#ifndef BEAN
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/SvcFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/Bootstrap.h"
7
8#include "facilities/Util.h"
9#else
10#include "DatabaseSvc/DatabaseSvc.h"
11#endif
12
13#include <iostream>
14#include <cstdio>
15#include <cstdlib>
16
17#include "MagneticField/ConnectionDB.h"
18
19using namespace std;
20
21namespace FieldDBUtil {
22
23#ifndef BEAN
25 StatusCode sc = Gaudi::svcLocator()->service("DatabaseSvc", m_dbsvc, true);
26 if (sc .isFailure() ) {
27 std::cout << "ERROR: In ConnectionDB()--> Unable to find DatabaseSvc " << std::endl;
28 }
29 }
30#endif
31
32 ConnectionDB::eRet ConnectionDB::getReadSC_MagnetInfo( std::vector<double>& current, int runNo) {
33
34#ifdef BEAN
35 static DatabaseSvc* m_dbsvc = 0;
36
37 if( !m_dbsvc ) {
38 m_dbsvc = DatabaseSvc::instance();
39 }
40#endif
41
42 //Read magnetic field map
43 char stmt1[200];
44 int run_No = std::abs(runNo);
45
46 sprintf(stmt1,"select Magnet_Current,SCQL,SCQR from SC_magnet where run_number = %d ",run_No);
47
48 DatabaseRecordVector results;
49 results.clear();
50 int status = m_dbsvc->query("run",stmt1,results);
51
52 if(status<0){
53 std::cout << "ERROR Read the SSM and SCQ current from the Database" << endl;
54 exit(1);
55 }
56
57 int RowNumber = results.size();
58 if(RowNumber!=1){
59 std::cout<<"ERROR:error searching SC_Magnet Data in the database, check your selection criterions"<<std::endl;
60 return RETMySQLError;
61 }
62
63 DatabaseRecord& rec = *results[0];
64 double ssm_curr = rec.GetDouble("Magnet_Current");
65 double scql_curr = rec.GetDouble("SCQL");
66 double scqr_curr = rec.GetDouble("SCQR");
67
68 // save results in vector
69 current.resize(3);
70 current[0] = ssm_curr;
71 current[1] = scql_curr;
72 current[2] = scqr_curr;
73
74 return RETOk;
75 }
76
77 ConnectionDB::eRet ConnectionDB::getBeamEnergy( std::vector<double>& beamE, int runNo) {
78 //Read magnetic field map
79 char stmt1[200];
80 int run_No = std::abs(runNo);
81
82 sprintf(stmt1,"select BPR_PRB,BER_PRB from RunParams where run_number = %d ",run_No);
83
85 results.clear();
86 int status = m_dbsvc->query("run",stmt1,results);
87 if(status<0){
88 std::cout << "ERROR Read the beam energy from the Database" << endreq;
89 exit(1);
90 }
91
92 int RowNumber = results.size();
93
94 if(RowNumber == 0) {
95 beamE.push_back(1.843); // for positron
96 beamE.push_back(1.843); // for electron
97
98 return RETOk;
99 }
100
101 if(RowNumber!=1){
102 std::cout<<"ERROR:error searching beam energy in the database, check your selection criterions"<<std::endl;
103 return RETMySQLError;
104 }
105
106 beamE.push_back(atof((*results[0])["BPR_PRB"])); // for positron
107 beamE.push_back(atof((*results[0])["BER_PRB"])); // for electron
108
109 return RETOk;
110 }
111
112}
int runNo
int query(const std::string &dbName, const std::string &sql)
ConnectionDB()
Constructor keeps track of table of interest.
ConnectionDB::eRet getReadSC_MagnetInfo(std::vector< double > &current, int runNo)
ConnectionDB::eRet getBeamEnergy(std::vector< double > &beamE, int runNo)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0