BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DQA_TO_DB.cxx
Go to the documentation of this file.
1#include "TF1.h"
2#include "TFile.h"
3#include "TH1F.h"
4#include "db_mysql.h"
5#include <cstdlib>
6#include <fstream>
7#include <iostream>
8#include <stdlib.h>
9#include <string.h>
10using namespace std;
16char* file;
17const char* server_ip = "bes3db1.ihep.ac.cn";
18char* Creator = getenv( "USER" ); // TODO: set the current creator
19char* SftVer = getenv( "BES_RELEASE" ); // TODO: set the current boss version
20char* ParVer; // //set soft version for Boss Version
21char* LumTau_txt; // FOR LumTau
22bool ISNeedReFit = 0;
23bool ISNeedReFitX = 0;
24bool ISNeedReFitY = 0;
25bool ISNeedReFitZ = 0;
26
27// define:
28int WriteLumDB();
31int ReadFromDB();
32int WriteLumTauDB();
33
34int main( int argc, char* argv[] ) {
35 // Execute:
36 offline_user = argv[1];
37 offline_passwd = argv[2];
38 char* runNo_temp = argv[3];
39 runNo = atoi( runNo_temp );
40 ParVer = argv[4];
41 file = argv[5];
42 LumTau_txt = argv[6];
43 std::cout << "-----------------------------------" << runNo << "-------------------------"
44 << std::endl;
46 sqloffline.Connect();
47 sqloffline.SelectDB( "offlinedb" );
48
49 WriteLumDB();
52 ReadFromDB();
54
55 sqloffline.Close();
56
57 return 1;
58}
59
61 char Notes[] = "";
62 TFile f( file );
63 double LumValue;
64 TH1F* lum;
65 f.GetObject( "/zhsLUM/lum", lum );
66 LumValue = lum->GetBinContent( 3 );
67 char sql_input[350];
68 sqlonline.Init( "202.122.33.123", "guest", "guestpass" );
69 sqlonline.Connect();
70 sqlonline.SelectDB( "RunInfo" );
71 sprintf( sql_input, "select IntLumEndcapEE from OnlineLum where run_number='%d'", runNo );
72 sqlonline.Execute( sql_input );
73 std::string intLumEndcapEE;
74 if ( sqlonline.GetRow( 0 ) ) { intLumEndcapEE = sqlonline.GetField( 0 ); }
75 else intLumEndcapEE = "-0";
76 sqlonline.Close();
77
78 // LumValue ,intLumEndCapEE write to database;
79
80 sprintf( sql_input, "delete from OfflineLum where RunNo=%d && SftVer='%s' && ParVer='%s'",
82 sqloffline.Execute( sql_input );
83
84 sprintf( sql_input,
85 "insert into "
86 "OfflineLum(SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,"
87 "CreateTime,Notes) values(0,'%d','%s','%f','%s','%s','%s',now(),'%s')",
88 runNo, intLumEndcapEE.c_str(), LumValue, SftVer, ParVer, Creator, Notes );
89 sqloffline.Execute( sql_input );
90 return 1;
91}
92
94 TFile f( file );
95 TH1D* x_of_vertex_in_kal;
96 TH1D* y_of_vertex_in_kal;
97 TH1D* z_of_vertex_in_kal;
98 f.GetObject( "/zhsVER/x_of_vertex_in_kal", x_of_vertex_in_kal );
99 f.GetObject( "/zhsVER/y_of_vertex_in_kal", y_of_vertex_in_kal );
100 f.GetObject( "/zhsVER/z_of_vertex_in_kal", z_of_vertex_in_kal );
101 TF1* func;
102 TF1* funcY;
103 TF1* funcZ;
104 if ( runNo <= 10878 || runNo > 20433 )
105 { // jpsi,psip
106 func = new TF1( "func", "gaus", -0.6, 0.6 );
107 funcY = new TF1( "funcY", "gaus", -0.6, 0.2 );
108 funcZ = new TF1( "funcZ", "gaus", -6, 6 );
109 }
110 else if ( runNo > 10878 && runNo <= 20433 )
111 { // psipp
112 func = new TF1( "func", "gaus", 0., 1.8 );
113 funcY = new TF1( "funcY", "gaus", -1., 1. );
114 funcZ = new TF1( "funcZ", "gaus", -6, 6 );
115 }
116 x_of_vertex_in_kal->Fit( "func", "RQ" );
117 Double_t MeanXKal = func->GetParameter( 1 );
118 Double_t SigmaXKal = func->GetParameter( 2 );
119
120 y_of_vertex_in_kal->Fit( "funcY", "RQ" );
121 Double_t MeanYKal = funcY->GetParameter( 1 );
122 Double_t SigmaYKal = funcY->GetParameter( 2 );
123
124 z_of_vertex_in_kal->Fit( "funcZ", "RQ" );
125 Double_t MeanZKal = funcZ->GetParameter( 1 );
126 Double_t SigmaZKal = funcZ->GetParameter( 2 );
127 if ( runNo <= 10878 || runNo > 20433 )
128 {
129 if ( MeanXKal < -0.3 || MeanXKal > 0.3 || SigmaXKal > 0.12 || SigmaXKal < 0. )
130 {
131 std::cout << "--------------x_of_vertex_in_kal-------out of range--" << MeanXKal << " " << SigmaXKal << " runID is:" << runNo
132 << std::endl;
133 ISNeedReFitX = 1;
134 ISNeedReFit = 1;
135 }
136 if ( MeanYKal < -0.4 || MeanYKal > 0.4 || SigmaYKal > 0.12 || SigmaYKal < 0 )
137 {
138 std::cout << "--------------y_of_vertex_in_kal-------out of range--" << MeanYKal << " " << SigmaYKal << " runID is:" << runNo
139 << std::endl;
140 ISNeedReFitY = 1;
141 ISNeedReFit = 1;
142 }
143 if ( MeanZKal < -2.0 || MeanZKal > 2.0 || SigmaZKal > 1.5 || SigmaZKal < 0 )
144 {
145 std::cout << "--------------z_of_vertex_in_kal-------out of range--" << MeanZKal << " " << SigmaZKal << " runID is:" << runNo
146 << std::endl;
147 ISNeedReFitZ = 1;
148 ISNeedReFit = 1;
149 }
150 }
151 else
152 {
153 if ( MeanXKal < 0.6 || MeanXKal > 1.2 || SigmaXKal > 0.18 || SigmaXKal < 0. )
154 {
155 std::cout << "--------------x_of_vertex_in_kal-------out of range--" << MeanXKal << " " << SigmaXKal << " runID is:" << runNo
156 << std::endl;
157 ISNeedReFitX = 1;
158 ISNeedReFit = 1;
159 }
160 if ( MeanYKal < -0.4 || MeanYKal > 0 || SigmaYKal > 0.12 || SigmaYKal < 0. )
161 {
162 std::cout << "--------------y_of_vertex_in_kal-------out of range--" << MeanYKal << " " << SigmaYKal << " runID is:" << runNo
163 << std::endl;
164 ISNeedReFitY = 1;
165 ISNeedReFit = 1;
166 }
167 if ( MeanZKal < -0.8 || MeanZKal > 0.8 || SigmaZKal > 1.5 || SigmaZKal < 0. )
168 {
169 std::cout << "--------------z_of_vertex_in_kal-------out of range--" << MeanZKal << " " << SigmaZKal << " runID is:" << runNo
170 << std::endl;
171 ISNeedReFitZ = 1;
172 ISNeedReFit = 1;
173 }
174 }
175 char VerFitFunc[] = "Kalman";
176 char DistFitFunc[] = "single Gaussian";
177
178 double AcSigmaVx, AcSigmaVy;
179
180 AcSigmaVx = 0.038;
181 AcSigmaVy = 0.00057;
182 char query[1024 * 100];
183
184 sprintf( query, "DELETE FROM BeamPar where RunNo = '%d' && SftVer='%s' && ParVer='%s'",
185 runNo, SftVer, ParVer );
186 sqloffline.Execute( query );
187 sprintf( query,
188 "INSERT INTO "
189 "BeamPar(BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,"
190 "DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer) "
191 "values(0,'%d','%f','%f','%f','%f','%f','%f','%s','%s','%s','%s','%f','%f','%s')",
192 runNo, MeanXKal, MeanYKal, MeanZKal, SigmaXKal, SigmaYKal, SigmaZKal, VerFitFunc,
193 DistFitFunc, SftVer, Creator, AcSigmaVx, AcSigmaVy, ParVer );
194 sqloffline.Execute( query );
195
196 return 1;
197}
199 char query[1024 * 100];
200 int irun = 1;
201 std::string Vx;
202 std::string Vy;
203 std::string Vz;
204 std::string SigmaVx;
205 std::string SigmaVy;
206 std::string SigmaVz;
207 bool Runloop = 0;
208 do {
209 sprintf( query,
210 "select Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,RunNo,SftVer,ParVer from BeamPar where "
211 "RunNo='%d' && SftVer='%s' && ParVer='%s'",
212 runNo - irun, SftVer, ParVer );
213 sqloffline.Execute( query );
214 if ( sqloffline.GetRow( 0 ) )
215 {
216 Vx = sqloffline.GetField( 0 );
217 Vy = sqloffline.GetField( 1 );
218 Vz = sqloffline.GetField( 2 );
219 SigmaVx = sqloffline.GetField( 3 );
220 SigmaVy = sqloffline.GetField( 4 );
221 SigmaVz = sqloffline.GetField( 5 );
222 Runloop = 0;
223 }
224 else Runloop = 1;
225 irun++;
226 } while ( Runloop );
227 if ( ISNeedReFitX )
228 {
229 sprintf( query,
230 "update BeamPar set Vx='%s',SigmaVx='%s' where RunNo='%d' && SftVer='%s' && "
231 "ParVer='%s'",
232 Vx.c_str(), SigmaVx.c_str(), runNo, SftVer, ParVer );
233 sqloffline.Execute( query );
234 // std::cout<<query<<std::endl;
235 std::cout << "------------------update Vx,SigmaVx successful!--------" << std::endl;
236 }
237 if ( ISNeedReFitY )
238 {
239 sprintf( query,
240 "update BeamPar set Vy='%s',SigmaVy='%s' where RunNo='%d' && SftVer='%s' && "
241 "ParVer='%s'",
242 Vy.c_str(), SigmaVy.c_str(), runNo, SftVer, ParVer );
243 sqloffline.Execute( query );
244 // std::cout<<query<<std::endl;
245 std::cout << "------------------update Vy,SigmaVy successful!---------" << std::endl;
246 }
247 if ( ISNeedReFitZ )
248 {
249 sprintf( query,
250 "update BeamPar set Vz='%s',SigmaVz='%s' where RunNo='%d' && SftVer='%s' && "
251 "ParVer='%s'",
252 Vz.c_str(), SigmaVz.c_str(), runNo, SftVer, ParVer );
253 sqloffline.Execute( query );
254 // std::cout<<query<<std::endl;
255 std::cout << "------------------update Vz,SigmaVz successful!---------" << std::endl;
256 }
257
258 return 1;
259}
261 std::cout
262 << "--------------check RUN LUM and Vertex info -----------------------------------"
263 << std::endl;
264 char sql_input[550];
265 sprintf(
266 sql_input,
267 "select SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes "
268 "from OfflineLum where RunNo=%d && SftVer='%s' && ParVer='%s'",
269 runNo, SftVer, ParVer );
270 sqloffline.Execute( sql_input );
271 std::cout
272 << "LUM is:"
273 << "SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes"
274 << std::endl;
275 if ( sqloffline.GetRow( 0 ) )
276 {
277 std::cout << sqloffline.GetField( 0 ) << "," << sqloffline.GetField( 1 ) << ","
278 << sqloffline.GetField( 2 ) << "," << sqloffline.GetField( 3 ) << ","
279 << sqloffline.GetField( 4 ) << "," << sqloffline.GetField( 5 ) << ","
280 << sqloffline.GetField( 6 ) << "," << sqloffline.GetField( 7 ) << ","
281 << sqloffline.GetField( 8 ) << std::endl;
282 std::cout << "---------------------------------------------------------------LUM is OK!"
283 << std::endl;
284 }
285 else
286 std::cout
287 << "-----------------------------------------ERROR to read LUM from OfflineLum db"
288 << std::endl;
289
290 sprintf( sql_input,
291 "select "
292 "BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,SftVer,"
293 "Creator,AcSigmaVx,AcSigmaVy,ParVer FROM BeamPar where RunNo ='%d' && SftVer='%s' "
294 "&& ParVer='%s'",
295 runNo, SftVer, ParVer );
296 sqloffline.Execute( sql_input );
297 std::cout << "BeamPar is:"
298 << "BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,"
299 "SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer"
300 << std::endl;
301 if ( sqloffline.GetRow( 0 ) )
302 {
303 std::cout << sqloffline.GetField( 0 ) << "," << sqloffline.GetField( 1 ) << ","
304 << sqloffline.GetField( 2 ) << "," << sqloffline.GetField( 3 ) << ","
305 << sqloffline.GetField( 4 ) << "," << sqloffline.GetField( 5 ) << ","
306 << sqloffline.GetField( 6 ) << "," << sqloffline.GetField( 7 ) << ","
307 << sqloffline.GetField( 8 ) << "," << sqloffline.GetField( 9 ) << ","
308 << sqloffline.GetField( 10 ) << "," << sqloffline.GetField( 11 ) << ","
309 << sqloffline.GetField( 12 ) << "," << sqloffline.GetField( 13 ) << ","
310 << sqloffline.GetField( 14 ) << std::endl;
311 std::cout << "-------------------------------------------------------BeamPar is OK!"
312 << std::endl;
313 }
314 else
315 std::cout
316 << "-----------------------------------------ERROR to read Vertex from BeamPar db"
317 << std::endl;
318 return 1;
319}
320
322 ifstream rwite;
323 rwite.open( LumTau_txt );
324 bool file_open = 1;
325 if ( !rwite )
326 {
327 cout << "************************************" << endl;
328 cout << LumTau_txt << " not exist!" << endl;
329 cout << "************************************" << endl;
330 file_open = 0;
331 }
332 if ( !file_open ) return -1;
333
334 int m_runNo = -1;
335 double runTime = -1;
336 double Lum_start = -1;
337 double Lum_end = -1;
338 double Tau_Value = -1;
339
340 while ( !rwite.eof() )
341 {
342 rwite >> m_runNo >> runTime >> Lum_start >> Lum_end >> Tau_Value;
343 if ( Tau_Value < 0 ) Tau_Value = 99999;
344 char sql_input[350];
345 sprintf( sql_input,
346 "update OfflineLum set runTime=%f, Lum_start=%f, Lum_end=%f, Tau_Value=%f where "
347 "runNo=%d && SftVer='%s' && ParVer='%s' ",
348 runTime, Lum_start, Lum_end, Tau_Value, m_runNo, SftVer, ParVer );
349 sqloffline.Execute( sql_input );
350
351 cout << "************************************" << endl;
352 cout << "LumTau FOR RUN " << m_runNo << " is OK!" << endl;
353 cout << "************************************" << endl;
354
355 // cout<<endl<<m_runNo<<" "<<runTime<<" "<<Lum_start<<" "<<Lum_end<<"
356 // "<<Tau_Value<<" "<<SftVer<<" "<<ParVer<<endl;
357 return 1;
358 }
359
360 cerr << __FILE__ << " : " << __LINE__ << ": Should not reach here!" << endl;
361 abort();
362}
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:21
char * SftVer
Definition DQA_TO_DB.cxx:19
char * Creator
Definition DQA_TO_DB.cxx:18
const char * server_ip
Definition DQA_TO_DB.cxx:17
db_mysql sqloffline
Definition DQA_TO_DB.cxx:12
bool ISNeedReFitX
Definition DQA_TO_DB.cxx:23
char * offline_user
Definition DQA_TO_DB.cxx:14
int WriteBeamParToDb()
Definition DQA_TO_DB.cxx:93
int runNo
Definition DQA_TO_DB.cxx:13
int WriteLumTauDB()
bool ISNeedReFitZ
Definition DQA_TO_DB.cxx:25
int ReadFromDB()
int WriteLumDB()
Definition DQA_TO_DB.cxx:60
bool ISNeedReFitY
Definition DQA_TO_DB.cxx:24
char * offline_passwd
Definition DQA_TO_DB.cxx:15
db_mysql sqlonline
Definition DQA_TO_DB.cxx:11
char * ParVer
Definition DQA_TO_DB.cxx:20
int ReWriteBeamParToDb()
char * file
Definition DQA_TO_DB.cxx:16
bool ISNeedReFit
Definition DQA_TO_DB.cxx:22
Double_t lum[10]
int main()
Definition phokhara.cc:42