BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
DQA_TO_DB.cxx
Go to the documentation of this file.
1#include <stdlib.h>
2#include <string.h>
3#include <iostream>
4#include <fstream>
5#include "TH1F.h"
6#include "TFile.h"
7#include "db_mysql.h"
8#include "TF1.h"
9using namespace std;
15char* file;
16const char* server_ip = "bes3db1.ihep.ac.cn";
17char* Creator=getenv("USER"); // TODO: set the current creator
18char* SftVer=getenv("BES_RELEASE"); // TODO: set the current boss version
19char* ParVer; // //set soft version for Boss Version
20char* LumTau_txt; // FOR LumTau
25int main(int argc, char* argv[]){
26 //define:
27 int WriteLumDB();
28 int WriteBeamParToDb();
29 int ReWriteBeamParToDb();
30 int ReadFromDB();
31 int WriteLumTauDB();
32 //Execute:
33 offline_user=argv[1];
34 offline_passwd=argv[2];
35 char* runNo_temp=argv[3];
36 runNo=atoi(runNo_temp);
37 ParVer=argv[4];
38 file=argv[5];
39 LumTau_txt = argv[6];
40 std::cout<<"-----------------------------------"<<runNo<<"-------------------------"<<std::endl;
43 sqloffline.SelectDB("offlinedb");
44
45 WriteLumDB();
48 ReadFromDB();
50
52
53 return 1;
54}
55
57 char Notes[]="";
58 TFile f(file);
59 double LumValue;
60 TH1F* lum;
61 f.GetObject("/zhsLUM/lum",lum);
62 LumValue=lum->GetBinContent(3);
63 char sql_input[350];
64 sqlonline.Init("202.122.33.123","guest","guestpass");
66 sqlonline.SelectDB("RunInfo");
67 sprintf(sql_input,"select IntLumEndcapEE from OnlineLum where run_number='%d'",runNo);
68 sqlonline.Execute(sql_input);
69 std::string intLumEndcapEE;
70 if(sqlonline.GetRow(0)){
71 intLumEndcapEE=sqlonline.GetField(0);
72 }
73 else intLumEndcapEE="-0";
75
76 //LumValue ,intLumEndCapEE write to database;
77
78 sprintf(sql_input,"delete from OfflineLum where RunNo=%d && SftVer='%s' && ParVer='%s'",runNo,SftVer,ParVer);
79 sqloffline.Execute(sql_input);
80
81 sprintf(sql_input,"insert into OfflineLum(SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes) values(0,'%d','%s','%f','%s','%s','%s',now(),'%s')",runNo,intLumEndcapEE.c_str(),LumValue,SftVer,ParVer,Creator,Notes);
82 sqloffline.Execute(sql_input);
83 return 1;
84}
85
87 TFile f(file);
88 TH1D* x_of_vertex_in_kal;
89 TH1D* y_of_vertex_in_kal;
90 TH1D* z_of_vertex_in_kal;
91 f.GetObject("/zhsVER/x_of_vertex_in_kal",x_of_vertex_in_kal);
92 f.GetObject("/zhsVER/y_of_vertex_in_kal",y_of_vertex_in_kal);
93 f.GetObject("/zhsVER/z_of_vertex_in_kal",z_of_vertex_in_kal);
94 TF1 *func;
95 TF1 *funcY;
96 TF1 *funcZ;
97 if(runNo<=10878 || runNo>20433){ //jpsi,psip
98 func = new TF1("func", "gaus", -0.6, 0.6);
99 funcY = new TF1("funcY", "gaus", -0.6, 0.2);
100 funcZ = new TF1("funcZ", "gaus", -6, 6);
101 }
102 else if(runNo >10878 && runNo<= 20433){//psipp
103 func = new TF1("func", "gaus", 0., 1.8);
104 funcY = new TF1("funcY", "gaus", -1., 1.);
105 funcZ = new TF1("funcZ", "gaus", -6, 6);
106 }
107 x_of_vertex_in_kal->Fit("func", "RQ");
108 Double_t MeanXKal = func->GetParameter(1);
109 Double_t SigmaXKal = func->GetParameter(2);
110
111 y_of_vertex_in_kal->Fit("funcY", "RQ");
112 Double_t MeanYKal = funcY->GetParameter(1);
113 Double_t SigmaYKal = funcY->GetParameter(2);
114
115 z_of_vertex_in_kal->Fit("funcZ", "RQ");
116 Double_t MeanZKal = funcZ->GetParameter(1);
117 Double_t SigmaZKal = funcZ->GetParameter(2);
118 if(runNo<=10878 || runNo>20433){
119 if(MeanXKal<-0.05 || MeanXKal>0.25 || SigmaXKal>0.12 || SigmaXKal<0.){
120 std::cout<<"--------------x_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
122 }
123 if(MeanYKal<-0.4 || MeanYKal>0 || SigmaYKal>0.12 || SigmaYKal<0)
124 {
125 std::cout<<"--------------y_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
127 }
128 if(MeanZKal<-1 || MeanZKal>1.0 || SigmaZKal>1.5 || SigmaZKal<0)
129 {
130 std::cout<<"--------------z_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
132 }
133 }
134 else{
135 if(MeanXKal<0.6 || MeanXKal>1.2 || SigmaXKal>0.18 || SigmaXKal<0.){
136 std::cout<<"--------------x_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
138 }
139 if(MeanYKal<-0.4 || MeanYKal>0 || SigmaYKal>0.12 || SigmaYKal<0.)
140 {
141 std::cout<<"--------------y_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
143 }
144 if(MeanZKal<-0.8 || MeanZKal>0.8 || SigmaZKal>1.5 || SigmaZKal<0.)
145 {
146 std::cout<<"--------------z_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
148 }
149
150 }
151 char VerFitFunc[] = "Kalman";
152 char DistFitFunc[] = "single Gaussian";
153
154 double AcSigmaVx, AcSigmaVy;
155
156 AcSigmaVx = 0.038;
157 AcSigmaVy = 0.00057;
158 char query[1024*100];
159
160 sprintf(query, "DELETE FROM BeamPar where RunNo = '%d' && SftVer='%s' && ParVer='%s'", runNo,SftVer,ParVer);
161 sqloffline.Execute(query);
162 sprintf(query,"INSERT INTO BeamPar(BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer) values(0,'%d','%f','%f','%f','%f','%f','%f','%s','%s','%s','%s','%f','%f','%s')",runNo,MeanXKal,MeanYKal,MeanZKal,SigmaXKal,SigmaYKal,SigmaZKal,VerFitFunc,DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer);
163 sqloffline.Execute(query);
164
165 return 1;
166
167}
169 char query[1024*100];
170 int irun=1;
171 std::string Vx;
172 std::string Vy;
173 std::string Vz;
174 std::string SigmaVx;
175 std::string SigmaVy;
176 std::string SigmaVz;
177 bool Runloop=0;
178 do{
179 sprintf(query,"select Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,RunNo,SftVer,ParVer from BeamPar where RunNo='%d' && SftVer='%s' && ParVer='%s'",runNo-irun,SftVer,ParVer);
180 sqloffline.Execute(query);
181 if(sqloffline.GetRow(0)){
182 Vx=sqloffline.GetField(0);
183 Vy=sqloffline.GetField(1);
184 Vz=sqloffline.GetField(2);
185 SigmaVx=sqloffline.GetField(3);
186 SigmaVy=sqloffline.GetField(4);
187 SigmaVz=sqloffline.GetField(5);
188 Runloop=0;
189 }
190 else Runloop=1;
191 irun++;
192 }while(Runloop);
193 if(ISNeedReFitX){
194 sprintf(query,"update BeamPar set Vx='%s',SigmaVx='%s' where RunNo='%d' && SftVer='%s' && ParVer='%s'",Vx.c_str(),SigmaVx.c_str(),runNo,SftVer,ParVer);
195 sqloffline.Execute(query);
196 // std::cout<<query<<std::endl;
197 std::cout<<"------------------update Vx,SigmaVx successful!--------"<<std::endl;
198 }
199 if(ISNeedReFitY){
200 sprintf(query,"update BeamPar set Vy='%s',SigmaVy='%s' where RunNo='%d' && SftVer='%s' && ParVer='%s'",Vy.c_str(),SigmaVy.c_str(),runNo,SftVer,ParVer);
201 sqloffline.Execute(query);
202 // std::cout<<query<<std::endl;
203 std::cout<<"------------------update Vy,SigmaVy successful!---------"<<std::endl;
204 }
205 if(ISNeedReFitZ){
206 sprintf(query,"update BeamPar set Vz='%s',SigmaVz='%s' where RunNo='%d' && SftVer='%s' && ParVer='%s'",Vz.c_str(),SigmaVz.c_str(),runNo,SftVer,ParVer);
207 sqloffline.Execute(query);
208 //std::cout<<query<<std::endl;
209 std::cout<<"------------------update Vz,SigmaVz successful!---------"<<std::endl;
210 }
211
212
213 return 1;
214}
216 std::cout<<"--------------check RUN LUM and Vertex info -----------------------------------"<<std::endl;
217 char sql_input[550];
218 sprintf(sql_input,"select SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes from OfflineLum where RunNo=%d && SftVer='%s' && ParVer='%s'",runNo,SftVer,ParVer);
219 sqloffline.Execute(sql_input);
220 std::cout<<"LUM is:"<<"SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes"<<std::endl;
221 if(sqloffline.GetRow(0)){
222 std::cout<<sqloffline.GetField(0)<<","<<sqloffline.GetField(1)<<","<<sqloffline.GetField(2)<<","<<sqloffline.GetField(3)<<","
223 <<sqloffline.GetField(4)<<","<<sqloffline.GetField(5)<<","<<sqloffline.GetField(6)<<","<<sqloffline.GetField(7)<<","
224 <<sqloffline.GetField(8)<<std::endl;
225 std::cout<<"---------------------------------------------------------------LUM is OK!"<<std::endl;
226 }
227 else std::cout<<"-----------------------------------------ERROR to read LUM from OfflineLum db"<<std::endl;
228
229 sprintf(sql_input, "select BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer FROM BeamPar where RunNo ='%d' && SftVer='%s' && ParVer='%s'", runNo,SftVer,ParVer);
230 sqloffline.Execute(sql_input);
231 std::cout<<"BeamPar is:"<<"BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer"<<std::endl;
232 if(sqloffline.GetRow(0)){
233 std::cout<<sqloffline.GetField(0)<<","<<sqloffline.GetField(1)<<","<<sqloffline.GetField(2)<<","<<sqloffline.GetField(3)<<","
234 <<sqloffline.GetField(4)<<","<<sqloffline.GetField(5)<<","<<sqloffline.GetField(6)<<","<<sqloffline.GetField(7)<<","
235 <<sqloffline.GetField(8)<<","<<sqloffline.GetField(9)<<","<<sqloffline.GetField(10)<<","<<sqloffline.GetField(11)<<","
236 <<sqloffline.GetField(12)<<","<<sqloffline.GetField(13)<<","<<sqloffline.GetField(14)<<std::endl;
237 std::cout<<"-------------------------------------------------------BeamPar is OK!"<<std::endl;
238 }
239 else std::cout<<"-----------------------------------------ERROR to read Vertex from BeamPar db"<<std::endl;
240 return 1;
241}
242
244 ifstream rwite;
245 rwite.open(LumTau_txt);
246 bool file_open = 1;
247 if(!rwite){
248 cout<<"************************************"<<endl;
249 cout<<LumTau_txt<<" not exist!"<<endl;
250 cout<<"************************************"<<endl;
251 file_open = 0;
252 }
253 if(!file_open) return -1;
254
255 int m_runNo = -1;
256 double runTime = -1;
257 double Lum_start = -1;
258 double Lum_end = -1;
259 double Tau_Value = -1;
260
261 while(!rwite.eof()){
262 rwite>>m_runNo>>runTime>>Lum_start>>Lum_end>>Tau_Value;
263 if( Tau_Value<0 )
264 Tau_Value = 99999;
265 char sql_input[350];
266 sprintf(sql_input,"update OfflineLum set runTime=%f, Lum_start=%f, Lum_end=%f, Tau_Value=%f where runNo=%d && SftVer='%s' && ParVer='%s' ",runTime,Lum_start,Lum_end,Tau_Value,m_runNo,SftVer,ParVer);
267 sqloffline.Execute(sql_input);
268
269 cout<<"************************************"<<endl;
270 cout<<"LumTau FOR RUN "<<m_runNo<<" is OK!"<<endl;
271 cout<<"************************************"<<endl;
272
273 // cout<<endl<<m_runNo<<" "<<runTime<<" "<<Lum_start<<" "<<Lum_end<<" "<<Tau_Value<<" "<<SftVer<<" "<<ParVer<<endl;
274 return 1;
275 }
276}
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)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
char * LumTau_txt
Definition: DQA_TO_DB.cxx:20
char * SftVer
Definition: DQA_TO_DB.cxx:18
char * Creator
Definition: DQA_TO_DB.cxx:17
const char * server_ip
Definition: DQA_TO_DB.cxx:16
db_mysql sqloffline
Definition: DQA_TO_DB.cxx:11
bool ISNeedReFitX
Definition: DQA_TO_DB.cxx:22
char * offline_user
Definition: DQA_TO_DB.cxx:13
int WriteBeamParToDb()
Definition: DQA_TO_DB.cxx:86
int runNo
Definition: DQA_TO_DB.cxx:12
int WriteLumTauDB()
Definition: DQA_TO_DB.cxx:243
bool ISNeedReFitZ
Definition: DQA_TO_DB.cxx:24
int ReadFromDB()
Definition: DQA_TO_DB.cxx:215
int WriteLumDB()
Definition: DQA_TO_DB.cxx:56
bool ISNeedReFitY
Definition: DQA_TO_DB.cxx:23
char * offline_passwd
Definition: DQA_TO_DB.cxx:14
db_mysql sqlonline
Definition: DQA_TO_DB.cxx:10
char * ParVer
Definition: DQA_TO_DB.cxx:19
int ReWriteBeamParToDb()
Definition: DQA_TO_DB.cxx:168
char * file
Definition: DQA_TO_DB.cxx:15
bool ISNeedReFit
Definition: DQA_TO_DB.cxx:21
Double_t lum[10]
bool SelectDB(string db)
Definition: db_mysql.cpp:79
bool GetRow(my_ulonglong row=NEXT_ROW)
Definition: db_mysql.cpp:133
void Close(void)
Definition: db_mysql.cpp:223
void Init(string host, string user, string passwd, string db="")
Definition: db_mysql.cpp:25
bool Connect(void)
Definition: db_mysql.cpp:41
bool Execute(string query="")
Definition: db_mysql.cpp:96
string GetField(unsigned int n)
Definition: db_mysql.cpp:160
int main()
Definition: test_IFile.cxx:11