BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
FieldDBUtil::ConnectionDB Class Reference

#include <ConnectionDB.h>

Public Types

enum  eRet {
  RETOk = 0 , RETBadCnfFile = 1 , RETBadHost = 2 , RETNoConnect = 3 ,
  RETWrongState = 4 , RETBadValue = 5 , RETMySQLError = 6 , RETNoSchemaMatch = 7
}
 
enum  eLevel { LEVELProd = 1 , LEVELDev = 2 , LEVELTest = 4 , LEVELSuperseded = 8 }
 Used to form bit masks for dbs queries. More...
 

Public Member Functions

 ConnectionDB ()
 Constructor keeps track of table of interest.
 
 ~ConnectionDB ()
 
ConnectionDB::eRet getReadSC_MagnetInfo (std::vector< double > &current, int runNo)
 
ConnectionDB::eRet getBeamEnergy (std::vector< double > &beamE, int runNo)
 
bool getReadSC_MagnetInfo (std::map< int, std::vector< double > > &m_mapMagnetInfo, int runFrom, int runTo)
 
bool getBeamEnergy (std::map< int, std::vector< double > > &m_mapBeamEnergy, int runFrom, int runTo)
 

Detailed Description

Definition at line 13 of file ConnectionDB.h.

Member Enumeration Documentation

◆ eLevel

Used to form bit masks for dbs queries.

Enumerator
LEVELProd 
LEVELDev 
LEVELTest 
LEVELSuperseded 

Definition at line 36 of file ConnectionDB.h.

◆ eRet

Enumerator
RETOk 
RETBadCnfFile 
RETBadHost 
RETNoConnect 
RETWrongState 
RETBadValue 
RETMySQLError 
RETNoSchemaMatch 

Definition at line 25 of file ConnectionDB.h.

Constructor & Destructor Documentation

◆ ConnectionDB()

FieldDBUtil::ConnectionDB::ConnectionDB ( )

Constructor keeps track of table of interest.

Definition at line 24 of file ConnectionDB.cxx.

24 {
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 }

◆ ~ConnectionDB()

FieldDBUtil::ConnectionDB::~ConnectionDB ( )
inline

Definition at line 23 of file ConnectionDB.h.

23{}

Member Function Documentation

◆ getBeamEnergy() [1/2]

bool FieldDBUtil::ConnectionDB::getBeamEnergy ( std::map< int, std::vector< double > > & m_mapBeamEnergy,
int runFrom,
int runTo )

Definition at line 77 of file ConnectionDB.cxx.

78{
79 char stmt1[200];
80 int run_From = std::abs(runFrom);
81 int run_To = std::abs(runTo);
83 results.clear();
84
85 IDatabaseSvc* m_dbsvc;
86 StatusCode sc = Gaudi::svcLocator()->service("DatabaseSvc",m_dbsvc,true);
87 if (sc .isFailure() ) {
88 std::cout<< "MSG::ERROR " << "Unable to find DatabaseSvc " << std::endl;
89 exit(1) ;
90 }
91
92 sprintf(stmt1,"select run_number,BPR_PRB,BER_PRB from RunParams where run_number >= %d and run_number <= %d ",run_From,run_To);
93 //cout<<stmt1<<endl;
94 int row_no = m_dbsvc->query("run",stmt1,results);
95 if(row_no<=0){
96 std::cout <<"ERROR:"<< "Run:"<<run_From<<" Can not read the beam energy from the Database" << endl;
97 exit(1); }
98
99 /*int RowNumber = results.size();
100 if(RowNumber == 0) {
101 beamE.push_back(1.843); // for positron
102 beamE.push_back(1.843); // for electron
103 std::cout << "No beam energy, so set BPR_PRB=1.843, BER_PRB=1.843"<<std::endl;
104 exit(1);
105 }*/
106 if( row_no > 0 )
107 {
108 for(int i=0;i<row_no;i++)
109 {
110 DatabaseRecord& dbrec = *results[i];
111 int run_No = dbrec.GetInt("run_number");
112 std::vector<double> beamEnergy;
113 beamEnergy.push_back(dbrec.GetDouble("BPR_PRB"));
114 beamEnergy.push_back(dbrec.GetDouble("BER_PRB"));
115 m_mapBeamEnergy[run_No] = beamEnergy;
116 float beam1,beam2;
117 beam1=beamEnergy[0];
118 beam2=beamEnergy[1];
119 //cout<<"map of run:"<<run_No<<"BPR_PRB:"<<beam1<<"BER_PRB:"<<beam2<<endl;
120
121 }
122 return true;
123 }
124}
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
double GetDouble(std::string key)
int GetInt(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0

◆ getBeamEnergy() [2/2]

ConnectionDB::eRet FieldDBUtil::ConnectionDB::getBeamEnergy ( std::vector< double > & beamE,
int runNo )

Definition at line 164 of file ConnectionDB.cxx.

164 {
165 //Read magnetic field map
166 char stmt1[200];
167 int run_No = std::abs(runNo);
168
169 sprintf(stmt1,"select BPR_PRB,BER_PRB from RunParams where run_number = %d ",run_No);
170 //cout<<stmt1<<endl;
171 DatabaseRecordVector results;
172 results.clear();
173 int status = m_dbsvc->query("run",stmt1,results);
174 if(status<0){
175 std::cout << "ERROR Read the beam energy from the Database" << endreq;
176 exit(1);
177 }
178
179 int RowNumber = results.size();
180
181 if(RowNumber == 0) {
182 beamE.push_back(1.843); // for positron
183 beamE.push_back(1.843); // for electron
184
185 return RETOk;
186 }
187
188 if(RowNumber!=1){
189 std::cout<<"ERROR:error searching beam energy in the database, check your selection criterions"<<std::endl;
190 return RETMySQLError;
191 }
192
193 beamE.push_back(atof((*results[0])["BPR_PRB"])); // for positron
194 beamE.push_back(atof((*results[0])["BER_PRB"])); // for electron
195 float beam1,beam2;
196 beam1=atof((*results[0])["BPR_PRB"]);
197 beam2=atof((*results[0])["BER_PRB"]);
198 //cout<<"map of run:"<<run_No<<"BPR_PRB:"<<beam1<<"BER_PRB:"<<beam2<<endl;
199 return RETOk;
200 }
int runNo
Definition DQA_TO_DB.cxx:12

Referenced by MagneticFieldSvc::handle(), and MagneticFieldSvc::initialize().

◆ getReadSC_MagnetInfo() [1/2]

bool FieldDBUtil::ConnectionDB::getReadSC_MagnetInfo ( std::map< int, std::vector< double > > & m_mapMagnetInfo,
int runFrom,
int runTo )

Definition at line 127 of file ConnectionDB.cxx.

128 {
129 char stmt1[200];
130 int run_From = std::abs(runFrom);
131 int run_To = std::abs(runTo);
132 DatabaseRecordVector results;
133 results.clear();
134
135 IDatabaseSvc* m_dbsvc;
136 StatusCode sc = Gaudi::svcLocator()->service("DatabaseSvc",m_dbsvc,true);
137 if (sc .isFailure() ) {
138 std::cout<< "MSG::ERROR " << "Unable to find DatabaseSvc " << std::endl;
139 exit(1) ;
140 }
141 sprintf(stmt1,"select run_number,Magnet_Current,SCQL,SCQR from SC_magnet where run_number >= %d and run_number<=%d ",run_From,run_To);
142 //cout<<stmt1<<endl;
143 int row_no = m_dbsvc->query("run",stmt1,results);
144 if(row_no<=0){
145 std::cout << "ERROR Read the SSM and SCQ current from the Database"<< " Run:"<<run_From << endl; exit(1); }
146 if( row_no > 0 )
147 {
148 for(int i=0;i<row_no;i++)
149 {
150 DatabaseRecord& dbrec = *results[i];
151 int run_No = dbrec.GetInt("run_number");
152 std::vector<double> SCMagnet;
153 SCMagnet.push_back(dbrec.GetDouble("Magnet_Current"));
154 SCMagnet.push_back(dbrec.GetDouble("SCQL"));
155 SCMagnet.push_back(dbrec.GetDouble("SCQR"));
156 m_mapMagnetInfo[run_No] = SCMagnet;
157 //cout<<"map of run:"<<run_No<<"Magnet_Current:"<<(m_mapMagnetInfo[run_No])[0]<<"SCQL:"<<(m_mapMagnetInfo[run_No])[1]<<"SCQR:"<<(m_mapMagnetInfo[run_No])[2]<<endl;
158 }
159
160 }
161 return true;
162
163 }

◆ getReadSC_MagnetInfo() [2/2]

ConnectionDB::eRet FieldDBUtil::ConnectionDB::getReadSC_MagnetInfo ( std::vector< double > & current,
int runNo )

Definition at line 32 of file ConnectionDB.cxx.

32 {
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 //cout<<stmt1<<endl;
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 //cout<<"run:"<<run_No<<"Magnet_Current:"<<current[0]<<"SCQL:"<<current[1]<<"SCQR:"<<current[2]<<endl;
74 return RETOk;
75 }
int query(const std::string &dbName, const std::string &sql)

Referenced by MagneticFieldSvc::handle(), and MagneticFieldSvc::initialize().


The documentation for this class was generated from the following files: