/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/DQA/DQA_TO_DB/DQA_TO_DB-00-00-16/src/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

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

Definition at line 25 of file DQA_TO_DB.cxx.

References db_mysql::Close(), db_mysql::Connect(), file, db_mysql::Init(), ISNeedReFit, LumTau_txt, offline_passwd, offline_user, ParVer, ReadFromDB(), ReWriteBeamParToDb(), runNo, db_mysql::SelectDB(), server_ip, sqloffline, WriteBeamParToDb(), WriteLumDB(), and WriteLumTauDB().

00025                                 {
00026         //define:
00027         int WriteLumDB();
00028         int WriteBeamParToDb();
00029         int ReWriteBeamParToDb();       
00030         int ReadFromDB();
00031         int WriteLumTauDB();
00032         //Execute:
00033         offline_user=argv[1];
00034         offline_passwd=argv[2];
00035         char* runNo_temp=argv[3];
00036         runNo=atoi(runNo_temp);
00037         ParVer=argv[4];
00038         file=argv[5];
00039         LumTau_txt = argv[6];
00040         std::cout<<"-----------------------------------"<<runNo<<"-------------------------"<<std::endl;
00041         sqloffline.Init(server_ip,offline_user,offline_passwd);
00042         sqloffline.Connect();
00043         sqloffline.SelectDB("offlinedb");
00044 
00045         WriteLumDB();
00046         WriteBeamParToDb();
00047         if(ISNeedReFit){ReWriteBeamParToDb();}
00048         ReadFromDB();
00049         WriteLumTauDB();
00050 
00051         sqloffline.Close();
00052 
00053         return 1;
00054 }

int ReadFromDB (  ) 

Definition at line 215 of file DQA_TO_DB.cxx.

References db_mysql::Execute(), db_mysql::GetField(), db_mysql::GetRow(), ParVer, runNo, SftVer, and sqloffline.

Referenced by main().

00215                 {
00216         std::cout<<"--------------check RUN LUM and Vertex info -----------------------------------"<<std::endl;
00217         char sql_input[550];
00218         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);
00219         sqloffline.Execute(sql_input);
00220         std::cout<<"LUM is:"<<"SerNo,RunNo,IntLumEndcapEE,OfflineTwoGam,SftVer,ParVer,Creator,CreateTime,Notes"<<std::endl;
00221         if(sqloffline.GetRow(0)){
00222                 std::cout<<sqloffline.GetField(0)<<","<<sqloffline.GetField(1)<<","<<sqloffline.GetField(2)<<","<<sqloffline.GetField(3)<<","
00223                         <<sqloffline.GetField(4)<<","<<sqloffline.GetField(5)<<","<<sqloffline.GetField(6)<<","<<sqloffline.GetField(7)<<","
00224                         <<sqloffline.GetField(8)<<std::endl;
00225                 std::cout<<"---------------------------------------------------------------LUM is OK!"<<std::endl;
00226         }
00227         else std::cout<<"-----------------------------------------ERROR to read LUM from OfflineLum db"<<std::endl;
00228 
00229         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);
00230         sqloffline.Execute(sql_input);
00231         std::cout<<"BeamPar is:"<<"BeamParSerNo,RunNo,Vx,Vy,Vz,SigmaVx,SigmaVy,SigmaVz,VerFitFunc,DistFitFunc,SftVer,Creator,AcSigmaVx,AcSigmaVy,ParVer"<<std::endl;
00232         if(sqloffline.GetRow(0)){
00233                 std::cout<<sqloffline.GetField(0)<<","<<sqloffline.GetField(1)<<","<<sqloffline.GetField(2)<<","<<sqloffline.GetField(3)<<","
00234                         <<sqloffline.GetField(4)<<","<<sqloffline.GetField(5)<<","<<sqloffline.GetField(6)<<","<<sqloffline.GetField(7)<<","
00235                         <<sqloffline.GetField(8)<<","<<sqloffline.GetField(9)<<","<<sqloffline.GetField(10)<<","<<sqloffline.GetField(11)<<","
00236                         <<sqloffline.GetField(12)<<","<<sqloffline.GetField(13)<<","<<sqloffline.GetField(14)<<std::endl;
00237                 std::cout<<"-------------------------------------------------------BeamPar is OK!"<<std::endl;
00238         }
00239         else std::cout<<"-----------------------------------------ERROR to read Vertex  from BeamPar db"<<std::endl;
00240         return 1;
00241 }

int ReWriteBeamParToDb (  ) 

Definition at line 168 of file DQA_TO_DB.cxx.

References db_mysql::Execute(), db_mysql::GetField(), db_mysql::GetRow(), ISNeedReFitX, ISNeedReFitY, ISNeedReFitZ, ParVer, runNo, SftVer, sqloffline, and deljobs::string.

Referenced by main().

00168                         {
00169         char query[1024*100];
00170         int irun=1;
00171         std::string Vx;
00172         std::string Vy;
00173         std::string Vz;
00174         std::string SigmaVx;
00175         std::string SigmaVy;
00176         std::string SigmaVz;
00177         bool Runloop=0;
00178         do{
00179                 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);
00180                 sqloffline.Execute(query);
00181                 if(sqloffline.GetRow(0)){
00182                         Vx=sqloffline.GetField(0);
00183                         Vy=sqloffline.GetField(1);
00184                         Vz=sqloffline.GetField(2);
00185                         SigmaVx=sqloffline.GetField(3);
00186                         SigmaVy=sqloffline.GetField(4);
00187                         SigmaVz=sqloffline.GetField(5);
00188                         Runloop=0;
00189                 }
00190                 else Runloop=1;
00191                 irun++;
00192         }while(Runloop);
00193         if(ISNeedReFitX){
00194                 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);
00195                 sqloffline.Execute(query);
00196                 //   std::cout<<query<<std::endl;
00197                 std::cout<<"------------------update Vx,SigmaVx successful!--------"<<std::endl;
00198         }
00199         if(ISNeedReFitY){
00200                 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);
00201                 sqloffline.Execute(query);
00202                 // std::cout<<query<<std::endl;
00203                 std::cout<<"------------------update Vy,SigmaVy successful!---------"<<std::endl;
00204         }
00205         if(ISNeedReFitZ){
00206                 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);
00207                 sqloffline.Execute(query);
00208                 //std::cout<<query<<std::endl;
00209                 std::cout<<"------------------update Vz,SigmaVz successful!---------"<<std::endl;
00210         }
00211 
00212 
00213         return 1;
00214 }

int WriteBeamParToDb (  ) 

Definition at line 86 of file DQA_TO_DB.cxx.

References Creator, db_mysql::Execute(), file, ISNeedReFit, ISNeedReFitX, ISNeedReFitY, ISNeedReFitZ, ParVer, runNo, SftVer, and sqloffline.

Referenced by main().

00086                       {
00087         TFile f(file);
00088         TH1D* x_of_vertex_in_kal;
00089         TH1D* y_of_vertex_in_kal;
00090         TH1D* z_of_vertex_in_kal;
00091         f.GetObject("/zhsVER/x_of_vertex_in_kal",x_of_vertex_in_kal);
00092         f.GetObject("/zhsVER/y_of_vertex_in_kal",y_of_vertex_in_kal);
00093         f.GetObject("/zhsVER/z_of_vertex_in_kal",z_of_vertex_in_kal);
00094         TF1 *func;
00095         TF1 *funcY;
00096         TF1 *funcZ;
00097         if(runNo<=10878 || runNo>20433){ //jpsi,psip
00098                 func = new TF1("func", "gaus", -0.6, 0.6);
00099                 funcY = new TF1("funcY", "gaus", -0.6, 0.2);
00100                 funcZ = new TF1("funcZ", "gaus", -6, 6);
00101         }
00102         else if(runNo >10878 && runNo<= 20433){//psipp
00103                 func = new TF1("func", "gaus", 0., 1.8);
00104                 funcY = new TF1("funcY", "gaus", -1., 1.);
00105                 funcZ = new TF1("funcZ", "gaus", -6, 6);
00106         }
00107         x_of_vertex_in_kal->Fit("func", "RQ");
00108         Double_t MeanXKal = func->GetParameter(1);
00109         Double_t SigmaXKal = func->GetParameter(2);
00110 
00111         y_of_vertex_in_kal->Fit("funcY", "RQ");
00112         Double_t MeanYKal = funcY->GetParameter(1);
00113         Double_t SigmaYKal = funcY->GetParameter(2);
00114 
00115         z_of_vertex_in_kal->Fit("funcZ", "RQ");
00116         Double_t MeanZKal = funcZ->GetParameter(1);
00117         Double_t SigmaZKal = funcZ->GetParameter(2); 
00118         if(runNo<=10878 || runNo>20433){
00119                 if(MeanXKal<-0.05 || MeanXKal>0.25 || SigmaXKal>0.12 || SigmaXKal<0.){
00120                         std::cout<<"--------------x_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00121                         ISNeedReFitX=1;ISNeedReFit=1;
00122                 }
00123                 if(MeanYKal<-0.4 || MeanYKal>0 || SigmaYKal>0.12 || SigmaYKal<0)
00124                 {
00125                         std::cout<<"--------------y_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00126                         ISNeedReFitY=1;ISNeedReFit=1;
00127                 }
00128                 if(MeanZKal<-1 || MeanZKal>1.0 || SigmaZKal>1.5 || SigmaZKal<0)
00129                 {
00130                         std::cout<<"--------------z_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00131                         ISNeedReFitZ=1;ISNeedReFit=1;
00132                 }
00133         }
00134         else{
00135                 if(MeanXKal<0.6 || MeanXKal>1.2 || SigmaXKal>0.18 || SigmaXKal<0.){
00136                         std::cout<<"--------------x_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00137                         ISNeedReFitX=1;ISNeedReFit=1;
00138                 }
00139                 if(MeanYKal<-0.4 || MeanYKal>0 || SigmaYKal>0.12 || SigmaYKal<0.)
00140                 {
00141                         std::cout<<"--------------y_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00142                         ISNeedReFitY=1;ISNeedReFit=1;
00143                 }
00144                 if(MeanZKal<-0.8 || MeanZKal>0.8 || SigmaZKal>1.5 || SigmaZKal<0.)
00145                 {
00146                         std::cout<<"--------------z_of_vertex_in_kal-------out of range--runID is:"<<runNo<<std::endl;
00147                         ISNeedReFitZ=1;ISNeedReFit=1;
00148                 }
00149 
00150         }
00151         char VerFitFunc[] = "Kalman"; 
00152         char DistFitFunc[] = "single Gaussian";
00153 
00154         double AcSigmaVx, AcSigmaVy;
00155 
00156         AcSigmaVx = 0.038;
00157         AcSigmaVy = 0.00057;
00158         char query[1024*100];
00159         
00160         sprintf(query, "DELETE FROM BeamPar where RunNo = '%d' && SftVer='%s' && ParVer='%s'", runNo,SftVer,ParVer);
00161         sqloffline.Execute(query);
00162         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);        
00163         sqloffline.Execute(query);
00164         
00165         return 1;
00166 
00167 }

int WriteLumDB (  ) 

Definition at line 56 of file DQA_TO_DB.cxx.

References db_mysql::Close(), db_mysql::Connect(), Creator, db_mysql::Execute(), file, db_mysql::GetField(), db_mysql::GetRow(), db_mysql::Init(), ParVer, runNo, db_mysql::SelectDB(), SftVer, sqloffline, sqlonline, and deljobs::string.

Referenced by main().

00056                 {
00057         char Notes[]="";
00058         TFile f(file);
00059         double LumValue;
00060         TH1F* lum;
00061         f.GetObject("/zhsLUM/lum",lum);
00062         LumValue=lum->GetBinContent(3);
00063         char sql_input[350];
00064         sqlonline.Init("202.122.33.123","guest","guestpass");
00065         sqlonline.Connect();
00066         sqlonline.SelectDB("RunInfo");
00067         sprintf(sql_input,"select IntLumEndcapEE from OnlineLum where run_number='%d'",runNo);
00068         sqlonline.Execute(sql_input);
00069         std::string intLumEndcapEE;
00070         if(sqlonline.GetRow(0)){
00071                 intLumEndcapEE=sqlonline.GetField(0);
00072         }
00073         else intLumEndcapEE="-0";
00074         sqlonline.Close();
00075 
00076         //LumValue ,intLumEndCapEE write to database;
00077 
00078         sprintf(sql_input,"delete from OfflineLum where RunNo=%d && SftVer='%s' && ParVer='%s'",runNo,SftVer,ParVer);
00079         sqloffline.Execute(sql_input);
00080 
00081         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);
00082         sqloffline.Execute(sql_input);
00083         return 1;
00084 }

int WriteLumTauDB (  ) 

Definition at line 243 of file DQA_TO_DB.cxx.

References db_mysql::Execute(), LumTau_txt, ParVer, SftVer, and sqloffline.

Referenced by main().

00243                    {
00244         ifstream rwite;
00245         rwite.open(LumTau_txt);
00246         bool file_open = 1;
00247         if(!rwite){
00248                 cout<<"************************************"<<endl;
00249                 cout<<LumTau_txt<<" not exist!"<<endl;
00250                 cout<<"************************************"<<endl;
00251                 file_open = 0;
00252         }
00253         if(!file_open) return -1;
00254 
00255         int m_runNo = -1;
00256         double runTime = -1;
00257         double Lum_start = -1;
00258         double Lum_end = -1;
00259         double Tau_Value = -1;
00260 
00261         while(!rwite.eof()){
00262                 rwite>>m_runNo>>runTime>>Lum_start>>Lum_end>>Tau_Value;
00263                 if( Tau_Value<0 )
00264                     Tau_Value = 99999;  
00265                 char sql_input[350];
00266                 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);
00267                 sqloffline.Execute(sql_input);
00268 
00269                 cout<<"************************************"<<endl;
00270                 cout<<"LumTau FOR RUN "<<m_runNo<<" is OK!"<<endl;
00271                 cout<<"************************************"<<endl;
00272 
00273                 //              cout<<endl<<m_runNo<<"  "<<runTime<<"   "<<Lum_start<<" "<<Lum_end<<"   "<<Tau_Value<<" "<<SftVer<<"    "<<ParVer<<endl;
00274                 return 1;
00275         }
00276 }


Variable Documentation

char* Creator = getenv("USER")

Definition at line 17 of file DQA_TO_DB.cxx.

Referenced by WriteBeamParToDb(), and WriteLumDB().

char* file

Definition at line 15 of file DQA_TO_DB.cxx.

Referenced by calib_conv2root(), UseMdcCalibData::execute(), DetVerSvcPack::getRunFromFileList(), main(), BesVisAlg::producer(), parityC::readParityC(), readTree(), sim_conv2root(), WriteBeamParToDb(), WriteLumDB(), and writeTree().

bool ISNeedReFit = 0

Definition at line 21 of file DQA_TO_DB.cxx.

Referenced by main(), and WriteBeamParToDb().

bool ISNeedReFitX = 0

Definition at line 22 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

bool ISNeedReFitY = 0

Definition at line 23 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

bool ISNeedReFitZ = 0

Definition at line 24 of file DQA_TO_DB.cxx.

Referenced by ReWriteBeamParToDb(), and WriteBeamParToDb().

char* LumTau_txt

Definition at line 20 of file DQA_TO_DB.cxx.

Referenced by main(), and WriteLumTauDB().

char* offline_passwd

Definition at line 14 of file DQA_TO_DB.cxx.

Referenced by main().

char* offline_user

Definition at line 13 of file DQA_TO_DB.cxx.

Referenced by main().

char* ParVer

Definition at line 19 of file DQA_TO_DB.cxx.

Referenced by main(), ReadFromDB(), ReWriteBeamParToDb(), WriteBeamParToDb(), WriteLumDB(), and WriteLumTauDB().

int runNo

Definition at line 12 of file DQA_TO_DB.cxx.

Referenced by DedxCalibRunByRun::AnalyseHists(), DedxCalibRunByRun::BookHists(), PackedRawDataCnvSvc::connectOutput(), CalibMySQLCnvSvc::createCalib(), ValidRecMdcTrackAlg::execute(), PrintMcInfo::execute(), MixerAlg::execute(), T0Dummy::execute(), SD0Tag::execute(), QCMCFilter::execute(), KalFitAlg::execute(), EsTimeAlg::execute(), KKMC::execute(), EvtDecay::execute(), ReadRawData::execute(), TwoGamma::execute(), DQA_TOF::execute(), DSemilepAlg::execute(), DDecay::execute(), Rhopi::execute(), AbsCor::execute(), Ppjrhopi::execute(), OfflineEventLoopMgr::executeEvent(), DedxCalibRunByRun::FillHists(), FillValidRecMdcTrackHisto(), BesClient::GetRecEvent(), TofQCorrSvc::getTofQCorrInfo(), RealizationSvc::handle(), MagneticFieldSvc::init_params(), main(), Pipipi0::MTotal(), Pipi::MTotal(), Kpipi0pi0::MTotal(), Kpipi0::MTotal(), Kpi::MTotal(), Kkpipi::MTotal(), Kkpi0::MTotal(), Kk::MTotal(), K3pipi0::MTotal(), K3pi::MTotal(), K0pipipi0::MTotal(), K0pipi::MTotal(), K0pi0::MTotal(), K0kpi::MTotal(), K0kk::MTotal(), ReadFromDB(), CalibDataSvc::retrieveObject(), ReWriteBeamParToDb(), CalibMySQLCnvSvc::updateCalib(), WriteBeamParToDb(), DedxCalibRunByRun::WriteHists(), and WriteLumDB().

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

Definition at line 16 of file DQA_TO_DB.cxx.

Referenced by main().

char* SftVer = getenv("BES_RELEASE")

Definition at line 18 of file DQA_TO_DB.cxx.

Referenced by calibUtil::Metadata::getReadDedxInfo(), calibUtil::Metadata::getReadDedxSimInfo(), calibUtil::Metadata::getReadEMCInfo(), calibUtil::Metadata::getReadEsTimeInfo(), calibUtil::Metadata::getReadEstTofInfo(), calibUtil::Metadata::getReadMdcAlignInfo(), calibUtil::Metadata::getReadMdcDataConstInfo(), calibUtil::Metadata::getReadMDCInfo(), calibUtil::Metadata::getReadMUCInfo(), calibUtil::Metadata::getReadTOFInfo(), calibUtil::Metadata::getReadTofQElecInfo(), calibUtil::Metadata::getReadTofSimInfo(), ReadFromDB(), ReWriteBeamParToDb(), WriteBeamParToDb(), WriteLumDB(), and WriteLumTauDB().

db_mysql sqloffline

Definition at line 11 of file DQA_TO_DB.cxx.

Referenced by main(), ReadFromDB(), ReWriteBeamParToDb(), WriteBeamParToDb(), WriteLumDB(), and WriteLumTauDB().

db_mysql sqlonline

Definition at line 10 of file DQA_TO_DB.cxx.

Referenced by WriteLumDB().


Generated on Tue Nov 29 23:14:58 2016 for BOSS_7.0.2 by  doxygen 1.4.7