00001 #include "CheckMySQL.h"
00002 #include "TH1F.h"
00003 #include "TBufferFile.h"
00004 CheckMYSQL::CheckMYSQL( const std::string& name,
00005 ISvcLocator* pSvcLocator )
00006 : Algorithm ( name, pSvcLocator )
00007 {
00008
00009
00010 }
00011
00012
00013 StatusCode CheckMYSQL::initialize() {
00014 StatusCode sc;
00015 MsgStream log(msgSvc(), name());
00016 log << MSG::INFO << "Initialize()" << endreq;
00017
00018
00019 return StatusCode::SUCCESS;
00020
00021 }
00022
00023
00024 StatusCode CheckMYSQL::execute( ) {
00025 MsgStream log(msgSvc(), name());
00026
00027 char *opt_host_name = "bes3db2.ihep.ac.cn";
00028
00029 char *opt_user_name = "maqm";
00030 char *opt_password = "maqm_offline";
00031 unsigned int opt_port_num = 3306;
00032 char *opt_socket_name = NULL;
00033 char *opt_db_name = "offlinedb";
00034 unsigned int opt_flags = 0;
00035 MYSQL *conn;
00036
00037
00038
00039
00040 conn = mysql_init(NULL);
00041
00042 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
00043 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
00044 printf("connect the database ok\n");
00045
00046
00047 time_t now;
00048 struct tm *timenow;
00049 timenow = localtime(&now);
00050 printf("Local time is %s\n",asctime(timenow));
00051
00052 TFile *f = new TFile("/ihepbatch/besd12/max/bBhabha_EsTime_run6018.root");
00053 cout<<"step11111111"<<endl;
00054
00055 TTree *Level0 = (TTree*)f-> Get("h2");
00056 TBufferFile Level0_buf(TBuffer::kWrite);
00057 Level0->Streamer(Level0_buf);
00058
00059 cout<<"step22222222"<<endl;
00060
00061 TTree *Level1 = (TTree*)f-> Get("calibconst");
00062 TBufferFile Level1_buf(TBuffer::kWrite);
00063 Level1->Streamer(Level1_buf);
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 char query[5024000],buf[1024*1000],buf1[1024*1000],*p,*p1;
00137 unsigned int from_len,from_len1;
00138
00139 int status;
00140 int id =60034;
00141
00142
00143 sprintf(query,"INSERT INTO EsTimeCalConst(SerNo,RunFrom,RunTo,EsTimeH2,EsTimeH9) VALUES(%d,'100','1000','",id);
00144
00145 printf("%s\n",query);
00146 p= query + strlen(query);
00147 p += mysql_escape_string(p,Level0_buf.Buffer(),Level0_buf.BufferSize());
00148
00149 strcat(p,"','");
00150 cout<<"strlen(query)22222222222="<<strlen(query)<<endl;
00151
00152 p= query + strlen(query);
00153 p +=mysql_escape_string(p,Level1_buf.Buffer(),Level1_buf.BufferSize());
00154 strcat(p,"')");
00155 status = mysql_query(conn,query);
00156 printf("%d\n",status);
00157
00158
00159
00160
00161
00162
00163 unsigned long *lengths;
00164
00165 MYSQL_RES *res_set;
00166 MYSQL_ROW row;
00167
00168
00169 char stmt1[200];
00170 int serno =1;
00171
00172 sprintf(stmt1,"select EsTimeH2,EsTimeH9,RunFrom,RunTo from TofCalConst where SerNo=%d",serno);
00173
00174
00175 printf("%s\n",stmt1);
00176 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
00177 printf("query error\n");
00178 res_set = mysql_store_result (conn);
00179 mysql_field_seek (res_set, 0);
00180
00181 row = mysql_fetch_row (res_set);
00182 lengths = mysql_fetch_lengths(res_set);
00183 for(int i=0;i<8;i++){
00184
00185 cout<<"lengths["<<i<<"]="<<lengths[i]<<endl;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 return StatusCode::SUCCESS;
00226 }
00227 StatusCode CheckMYSQL::finalize( ) {
00228
00229 MsgStream log(msgSvc(), name());
00230 log << MSG::INFO
00231 << " CheckMYSQL FINALIZE!! "
00232 << endreq;
00233
00234 return StatusCode::SUCCESS;
00235 }
00236
00237