BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
DQA_TO_DB.cxx File Reference
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include "TH1F.h"
#include "TFile.h"
#include "db_mysql.h"
#include "TF1.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 
int WriteLumDB ()
 
int WriteBeamParToDb ()
 
int ReWriteBeamParToDb ()
 
int ReadFromDB ()
 
int WriteLumTauDB ()
 

Variables

db_mysql sqlonline
 
db_mysql sqloffline
 
int runNo
 
char * offline_user
 
char * offline_passwd
 
char * file
 
const char * server_ip = "bes3db1.ihep.ac.cn"
 
char * Creator =getenv("USER")
 
char * SftVer =getenv("BES_RELEASE")
 
char * ParVer
 
char * LumTau_txt
 
bool ISNeedReFit =0
 
bool ISNeedReFitX =0
 
bool ISNeedReFitY =0
 
bool ISNeedReFitZ =0
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file DQA_TO_DB.cxx.

25 {
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}
char * LumTau_txt
Definition: DQA_TO_DB.cxx:20
const char * server_ip
Definition: DQA_TO_DB.cxx:16
db_mysql sqloffline
Definition: DQA_TO_DB.cxx:11
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
int ReadFromDB()
Definition: DQA_TO_DB.cxx:215
int WriteLumDB()
Definition: DQA_TO_DB.cxx:56
char * offline_passwd
Definition: DQA_TO_DB.cxx:14
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
bool SelectDB(string db)
Definition: db_mysql.cpp:67
void Close(void)
Definition: db_mysql.cpp:211
void Init(string host, string user, string passwd, string db="")
Definition: db_mysql.cpp:25
bool Connect(void)
Definition: db_mysql.cpp:41

◆ ReadFromDB()

int ReadFromDB ( )

Definition at line 215 of file DQA_TO_DB.cxx.

215 {
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}
char * SftVer
Definition: DQA_TO_DB.cxx:18
bool GetRow(my_ulonglong row=NEXT_ROW)
Definition: db_mysql.cpp:121
bool Execute(string query="")
Definition: db_mysql.cpp:84
string GetField(unsigned int n)
Definition: db_mysql.cpp:148
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)

Referenced by main().

◆ ReWriteBeamParToDb()

int ReWriteBeamParToDb ( )

Definition at line 168 of file DQA_TO_DB.cxx.

168 {
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}
bool ISNeedReFitX
Definition: DQA_TO_DB.cxx:22
bool ISNeedReFitZ
Definition: DQA_TO_DB.cxx:24
bool ISNeedReFitY
Definition: DQA_TO_DB.cxx:23

Referenced by main().

◆ WriteBeamParToDb()

int WriteBeamParToDb ( )

Definition at line 86 of file DQA_TO_DB.cxx.

86 {
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('','%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}
char * Creator
Definition: DQA_TO_DB.cxx:17
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")

Referenced by main().

◆ WriteLumDB()

int WriteLumDB ( )

Definition at line 56 of file DQA_TO_DB.cxx.

56 {
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('','%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}
db_mysql sqlonline
Definition: DQA_TO_DB.cxx:10
Double_t lum[10]

Referenced by main().

◆ WriteLumTauDB()

int WriteLumTauDB ( )

Definition at line 243 of file DQA_TO_DB.cxx.

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

Referenced by main().

Variable Documentation

◆ Creator

char* Creator =getenv("USER")

Definition at line 17 of file DQA_TO_DB.cxx.

Referenced by WriteBeamParToDb(), and WriteLumDB().

◆ file

◆ ISNeedReFit

bool ISNeedReFit =0

Definition at line 21 of file DQA_TO_DB.cxx.

Referenced by main(), and WriteBeamParToDb().

◆ ISNeedReFitX

bool ISNeedReFitX =0

Definition at line 22 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

◆ ISNeedReFitY

bool ISNeedReFitY =0

Definition at line 23 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

◆ ISNeedReFitZ

bool ISNeedReFitZ =0

Definition at line 24 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

◆ LumTau_txt

char* LumTau_txt

Definition at line 20 of file DQA_TO_DB.cxx.

Referenced by main(), and WriteLumTauDB().

◆ offline_passwd

char* offline_passwd

Definition at line 14 of file DQA_TO_DB.cxx.

Referenced by main().

◆ offline_user

char* offline_user

Definition at line 13 of file DQA_TO_DB.cxx.

Referenced by main().

◆ ParVer

◆ runNo

int runNo

Definition at line 12 of file DQA_TO_DB.cxx.

Referenced by DedxCalibRunByRun::AnalyseHists(), DedxCalibRunByRun::BookHists(), PackedRawDataCnvSvc::connectOutput(), CalibMySQLCnvSvc::createCalib(), Ppjrhopi::execute(), AbsCor::execute(), Rhopi::execute(), DDecay::execute(), DSemilepAlg::execute(), DQA_TOF::execute(), DQAPi2p2::execute(), TwoGamma::execute(), ReadRawData::execute(), EvtDecay::execute(), KKMC::execute(), MixerAlg::execute(), EsTimeAlg::execute(), KalFitAlg::execute(), PrintMcInfo::execute(), QCMCFilter::execute(), SD0Tag::execute(), T0Dummy::execute(), ValidRecMdcTrackAlg::execute(), OfflineEventLoopMgr::executeEvent(), DedxCalibRunByRun::FillHists(), FillValidRecMdcTrackHisto(), MeasuredEcmsSvc::getAveEcms(), MeasuredEcmsSvc::getAveEcmsErr(), FieldDBUtil::ConnectionDB::getBeamEnergy(), RealDBUtil::ConnectionProvider::getcal(), MeasuredEcmsSvc::getEcms(), MeasuredEcmsSvc::getEcmsErr(), RealDBUtil::ConnectionProvider::getEmcGain(), MeasuredEcmsSvc::getInfo(), RealDBUtil::ConnectionProvider::getLumCurvePar(), RealizationSvc::getLuminosity(), MeasuredEcmsSvc::getPx(), MeasuredEcmsSvc::getPy(), MeasuredEcmsSvc::getPz(), RealDBUtil::ConnectionProvider::getReadBackgroundInfo(), RealDBUtil::ConnectionProvider::getReadBunchInfo(), calibUtil::Metadata::getReadDedxInfo(), calibUtil::Metadata::getReadDedxSimInfo(), calibUtil::Metadata::getReadEMCInfo(), calibUtil::Metadata::getReadEsTimeInfo(), calibUtil::Metadata::getReadEstTofInfo(), RealDBUtil::ConnectionProvider::getReadLumInfo(), calibUtil::Metadata::getReadMdcAlignInfo(), calibUtil::Metadata::getReadMdcDataConstInfo(), calibUtil::Metadata::getReadMDCInfo(), calibUtil::Metadata::getReadMUCInfo(), FieldDBUtil::ConnectionDB::getReadSC_MagnetInfo(), calibUtil::Metadata::getReadTOFInfo(), calibUtil::Metadata::getReadTofQElecInfo(), calibUtil::Metadata::getReadTofSimInfo(), RealDBUtil::ConnectionProvider::getReadTofThreshInfo(), RealDBUtil::ConnectionProvider::getReadTrgTableInfo(), BesClient::GetRecEvent(), MeasuredEcmsSvc::getRecord(), MeasuredEcmsSvc::getRunFrom(), RealDBUtil::ConnectionProvider::getRunInfo(), MeasuredEcmsSvc::getRunTo(), MeasuredEcmsSvc::getSampleName(), TofQCorrSvc::getTofQCorrInfo(), RealDBUtil::ConnectionProvider::getTrgConfigInfo(), MeasuredEcmsSvc::handle(), RealizationSvc::handle(), MagneticFieldSvc::init_params(), MeasuredEcmsSvc::isGetEcmsValid(), MeasuredEcmsSvc::isGetInfoValid(), MeasuredEcmsSvc::isGetRecordValid(), MeasuredEcmsSvc::isRunNoValid(), main(), K0kk::MTotal(), K0kpi::MTotal(), K0pi0::MTotal(), K0pipi::MTotal(), K0pipipi0::MTotal(), K3pi::MTotal(), K3pipi0::MTotal(), Kk::MTotal(), Kkpi0::MTotal(), Kkpipi::MTotal(), Kpi::MTotal(), Kpipi0::MTotal(), Kpipi0pi0::MTotal(), Pipi::MTotal(), Pipipi0::MTotal(), MdcUtilitySvc::p_cms(), CalibEventSelect::readbeamEfromDb(), ReadME::readDB(), MeasuredEcmsSvc::readDB(), RealizationSvc::readDB(), ReadFromDB(), MeasuredEcmsSvc::readInfo(), ReadME::ReadME(), ReadME::readMeasuredEcms(), MeasuredEcmsSvc::readMeasuredEcms(), MeasuredEcmsSvc::readMeasuredEcms2(), MeasuredEcmsSvc::readRecord(), ReadME::readRunParams(), MeasuredEcmsSvc::readRunParams(), MeasuredEcmsSvc::readRunParams2(), CalibDataSvc::retrieveObject(), ReWriteBeamParToDb(), McContext::setRunNumber(), McIterator::setRunNumber(), CalibMySQLCnvSvc::updateCalib(), WriteBeamParToDb(), DedxCalibRunByRun::WriteHists(), and WriteLumDB().

◆ server_ip

const char* server_ip = "bes3db1.ihep.ac.cn"

Definition at line 16 of file DQA_TO_DB.cxx.

Referenced by main().

◆ SftVer

◆ sqloffline

db_mysql sqloffline

◆ sqlonline

db_mysql sqlonline

Definition at line 10 of file DQA_TO_DB.cxx.

Referenced by WriteLumDB().