14#include "GaudiKernel/Bootstrap.h"
15#include "GaudiKernel/ISvcLocator.h"
40 const std::string& dbName)
41 : m_readCxt(0), m_writeCxt(0),
42 m_host(host), m_table(table), m_dbName(dbName), m_man(0), m_rdb(0),
44 if (table.compare(
"*") == 0) m_table = std::string(
"$(MYSQL_METATABLE)");
45 if (host.compare(
"*") == 0) m_host = std::string(
"$(MYSQL_HOST)");
49 if (nsub < 0) m_table = std::string(
"metadata");
50 StatusCode sc=Gaudi::svcLocator()->service(
"DatabaseSvc", m_dbsvc,
true);
51 if ( !sc.isSuccess() ) {
52 std::cout <<
"Metadata ERROR ::Could not retrieve the DataBaseSvc" << std::endl;;
60 if (m_man)
delete m_man;
69 user = std::string(
"$(USER)");
71 user = std::string(
"$(USERNAME)");
79 user = std::string(
"");
86 const std::string& user,
87 const std::string& pw, eRet& err,
88 const std::string& dbName) {
96 bool connected = cxt->
open(host, user, pw, dbName);
108 if (m_readCxt == 0) {
113 bool ok = connect(m_readCxt, m_host, std::string(
"guest"),
114 std::string(
"guestpass"), err, m_dbName);
129 bool Metadata::connectWrite(eRet& err) {
130 if (m_writeCxt == 0) {
133 if (m_dbName == std::string(
"calib_test") ) {
134 ok = connect(m_writeCxt, m_host, std::string(
"calib_tester"),
135 std::string(
"udine"), err, m_dbName);
138 ok = connect(m_writeCxt, m_host, std::string(
"calibrator"),
139 std::string(
"calibrator"), err, m_dbName);
146 std::string(
"$(RDBMODELROOT)/xml/")+ m_dbName +
".xml";
147 err = compareSchema(m_writeCxt, schema);
173 const std::string& calibType,
174 const std::string&
SftVer,
175 const std::string& cal_ver,
176 const std::string& cal_par,
177 const std::string& rec_alg,
178 const std::string& rec_par,
179 const std::string& machine,
180 const std::string& flavor) {
187 if (ret !=
RETOk)
return ret;
192 std::vector<Assertion::Operator *> conditions;
193 conditions.reserve(8);
196 FIELDTYPEold, FIELDTYPElit);
199 FIELDTYPEold, FIELDTYPElit);
205 FIELDTYPEold, FIELDTYPElit);
207 FIELDTYPEold, FIELDTYPElit);
209 FIELDTYPEold, FIELDTYPElit);
211 FIELDTYPEold, FIELDTYPElit);
213 FIELDTYPEold, FIELDTYPElit);
215 FIELDTYPEold, FIELDTYPElit);
219 std::cout<<
"run no is::"<<s_run<<std::endl;
222 FIELDTYPEold, FIELDTYPElit);
225 FIELDTYPEold, FIELDTYPElit);
227 conditions.push_back(&completeOp);
228 conditions.push_back(&calibTypeOp);
230 conditions.push_back(&sftverOp);
231 conditions.push_back(&calverOp);
232 conditions.push_back(&calparOp);
233 conditions.push_back(&recalgOp);
234 conditions.push_back(&recparOp);
235 conditions.push_back(&machineOp);
236 conditions.push_back(&runfrmOp);
237 conditions.push_back(&runtoOp);
238 ret = doSelect(conditions, orderBy, ser);
244 const std::string& calibType,
245 const std::string&
SftVer,
246 const std::string& cal_ver,
247 const std::string& cal_par,
248 const std::string& rec_alg,
249 const std::string& rec_par,
250 const std::string& machine,
251 const std::string& flavor)
259 if (ret !=
RETOk)
return ret;
265 std::vector<Assertion::Operator *> conditions;
266 conditions.reserve(8);
268 FIELDTYPEold, FIELDTYPElit);
272 FIELDTYPEold, FIELDTYPElit);
278 FIELDTYPEold, FIELDTYPElit);
280 FIELDTYPEold, FIELDTYPElit);
282 FIELDTYPEold, FIELDTYPElit);
284 FIELDTYPEold, FIELDTYPElit);
286 FIELDTYPEold, FIELDTYPElit);
288 FIELDTYPEold, FIELDTYPElit);
293 FIELDTYPEold, FIELDTYPElit);
296 FIELDTYPEold, FIELDTYPElit);
298 conditions.push_back(&completeOp);
299 conditions.push_back(&calibTypeOp);
301 conditions.push_back(&sftverOp);
302 conditions.push_back(&calverOp);
303 conditions.push_back(&calparOp);
304 conditions.push_back(&recalgOp);
305 conditions.push_back(&recparOp);
306 conditions.push_back(&machineOp);
307 conditions.push_back(&runfrmOp);
308 conditions.push_back(&runtoOp);
310 return doSelect(conditions, orderBy, ser);
317 std::string& dataFmt,
318 std::string& filename) {
328 colNames[0] =
"data_fmt";
329 colNames[1] =
"data_ident";
330 colNames[2] =
"RunFrom";
331 colNames[3] =
"RunTo";
333 std::string serNoVal;
337 FIELDTYPEold, FIELDTYPElit);
347 results = m_readCxt->
select(m_table, colNames, orderBy, &whereClause);
358 std::vector<std::string> fields;
359 std::cout<<
"test id \\"<<std::endl;
362 filename = fields[1];
363 std::string runfrm,runto;
372 if ((dataFmt ==
"") || (filename ==
""))
return RETBadValue;
380 std::string& calParVer,
383 std::string& sftver) {
389 if(sftver==
"default")
390 sftver = getenv(
"BES_RELEASE");
391 const char*
SftVer = sftver.c_str();
393 if(calParVer!=
"default"){
394 const char* calpar = calParVer.c_str();
395 sprintf(stmt1,
"select SigInterval,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigInterval where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
SftVer,run_No,run_No,calpar);}
397 if(calParVer==
"default"){
398 sprintf(stmt1,
"select SigInterval,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigInterval where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);}
399 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
401 std::cout<<
"ERROR:error searching InjSigInterval calibration Data in the database with: "<<stmt1<<std::endl;
return RETMySQLError;
405 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
406 sscanf(records[
"RunTo"],
"%d", &RunTo);
407 cout <<
"@table SigInterval: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
415 std::string& calParVer,
418 std::string& sftver) {
424 if(sftver==
"default")
425 sftver = getenv(
"BES_RELEASE");
426 const char*
SftVer = sftver.c_str();
427 cout<<
"getReadInjSigTimeInfo start:::::"<<endl;
428 if(calParVer!=
"default"){
429 const char* calpar = calParVer.c_str();
430 sprintf(stmt1,
"select ist,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigTime where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
SftVer,run_No,run_No,calpar);}
432 if(calParVer==
"default"){
433 sprintf(stmt1,
"select ist,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigTime where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);}
434 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
436 std::cout<<
"ERROR:error searching InjSigTime calibration Data in the database with: "<<stmt1<<std::endl;
return RETMySQLError;
440 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
441 sscanf(records[
"RunTo"],
"%d", &RunTo);
442 cout <<
"@table InjSigTimeInfo: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
450 std::string& calParVer,
453 std::string& sftver) {
459 if(sftver==
"default")
460 sftver = getenv(
"BES_RELEASE");
461 const char*
SftVer = sftver.c_str();
462 if(calParVer!=
"default"){
463 const char* calpar = calParVer.c_str();
464 sprintf(stmt1,
"select data,oef,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from OffEvtFilter where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
SftVer,run_No,run_No,calpar);}
466 if(calParVer==
"default"){
467 sprintf(stmt1,
"select data,oef,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from OffEvtFilter where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);}
468 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
470 std::cout<<
"ERROR:error searching OffEvtFilter calibration Data in the database with: "<<stmt1<<std::endl;
return RETMySQLError;
474 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
475 sscanf(records[
"RunTo"],
"%d", &RunTo);
476 cout <<
"@table OffEvtFilter: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
486 std::string& Version,
492 const char* parVer = Version.c_str();
493 sprintf(sql,
"select Run,FinalETS,FileName,FilePath from CorrectedETS where Run= %d and FirstEvent = %d and Version = %d",run,FirstEvent,1);
495 int row_no = m_dbsvc->
query(
"offlinedb", sql, res);
497 FileName=(*res[0])[
"FileName"];
498 std::cout<<
"FileName is::::"<<FileName<<std::endl;
500 std::cout<<
"ERROR:error searching CorrectedETS calibration Data in the database with: "<<sql<<std::endl;
510 std::string& calParVer,
513 std::string& sftver) {
518 if(sftver==
"default")
519 sftver = getenv(
"BES_RELEASE");
520 const char*
SftVer = sftver.c_str();
522 if(calParVer!=
"default"){
523 const char* calpar = calParVer.c_str();
524 sprintf(stmt1,
"select BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,EtfTofBunch,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from TofCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
526 if(calParVer==
"default"){
527 sprintf(stmt1,
"select BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,EtfTofBunch,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from TofCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
530 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
532 std::cout<<
"ERROR:error searching TOF calibration Data in the database with: "<<stmt1<<std::endl;
537 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
538 sscanf(records[
"RunTo"],
"%d", &RunTo);
539 cout <<
"@table TofCalConst: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
546 std::string& calParVer,
549 std::string& sftver) {
555 if(sftver==
"default")
556 sftver = getenv(
"BES_RELEASE");
557 const char*
SftVer = sftver.c_str();
559 if(calParVer!=
"default"){
560 const char* calpar = calParVer.c_str();
561 sprintf(stmt1,
"select LayTree,BoxTree,StrTree,ResTree,ClsTree,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MucCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
564 if(calParVer==
"default"){
566 sprintf(stmt1,
"select LayTree,BoxTree,StrTree,ResTree,ClsTree,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MucCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
570 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
572 std::cout<<
"ERROR:error searching MUC calibration Data in the database with: "<<stmt1<<std::endl;
577 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
578 sscanf(records[
"RunTo"],
"%d", &RunTo);
579 cout <<
"@table Muc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
586 std::string& calParVer,
589 std::string& sftver) {
595 if(sftver==
"default")
596 sftver = getenv(
"BES_RELEASE");
597 const char*
SftVer = sftver.c_str();
600 if(calParVer!=
"default"){
601 const char* calpar = calParVer.c_str();
602 sprintf(stmt1,
"select NewXtTrees,XtTree,QtTree,T0Tree,SdTree,R2tTrees,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MdcCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
SftVer,run_No,run_No,calpar);}
604 if(calParVer==
"default"){
606 sprintf(stmt1,
"select NewXtTrees,XtTree,QtTree,T0Tree,SdTree,R2tTrees,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MdcCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);}
608 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
610 std::cout<<
"ERROR:error searching Mdc calibration Data in the database with: "<<stmt1<<std::endl;
615 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
616 sscanf(records[
"RunTo"],
"%d", &RunTo);
617 cout <<
"@table Mdc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
627 std::string& calParVer,
630 std::string& sftver) {
635 if(sftver==
"default")
636 sftver = getenv(
"BES_RELEASE");
637 const char*
SftVer = sftver.c_str();
639 if(calParVer!=
"default"){
640 const char* calpar = calParVer.c_str();
641 sprintf(stmt1,
"select DigiCalibConst,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EmcCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
644 if(calParVer==
"default"){
646 sprintf(stmt1,
"select DigiCalibConst,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EmcCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
649 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
651 std::cout<<
"ERROR:error searching EMC calibration Data in the database with: "<<stmt1<<std::endl;
656 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
657 sscanf(records[
"RunTo"],
"%d", &RunTo);
658 cout <<
"@table Emc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
666 std::string& calParVer,
669 std::string& sftver) {
674 if(sftver==
"default")
675 sftver = getenv(
"BES_RELEASE");
676 const char*
SftVer = sftver.c_str();
678 if(calParVer!=
"default"){
679 const char* calpar = calParVer.c_str();
680 sprintf(stmt1,
"select DriftDist,EntranceAng,MeanGain,GasGain,LayerGain,Resolution,WireGain,ZDep,RunGain,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from DedxCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
683 if(calParVer==
"default"){
685 sprintf(stmt1,
"select DriftDist,EntranceAng,MeanGain,GasGain,LayerGain,Resolution,WireGain,ZDep,RunGain,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from DedxCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
688 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
690 std::cout<<
"ERROR:error searching Dedx calibration Data in the database with: "<<stmt1<<std::endl;
695 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
696 sscanf(records[
"RunTo"],
"%d", &RunTo);
697 cout <<
"@table Dedx: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
705 std::string& calParVer,
708 std::string& sftver) {
713 if(sftver==
"default")
714 sftver = getenv(
"BES_RELEASE");
715 const char*
SftVer = sftver.c_str();
717 if(calParVer!=
"default"){
718 const char* calpar = calParVer.c_str();
719 sprintf(stmt1,
"select EsTimeH2,EsTimeH9,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EsTimeCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
722 if(calParVer==
"default"){
723 sprintf(stmt1,
"select EsTimeH2,EsTimeH9,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EsTimeCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
725 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
727 std::cout<<
"ERROR:error searching EsTime calibration Data in the database with: "<<stmt1<<std::endl;
732 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
733 sscanf(records[
"RunTo"],
"%d", &RunTo);
734 cout <<
"@table EsTime: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
743 std::string& calParVer,
746 std::string& sftver) {
751 if(sftver==
"default")
752 sftver = getenv(
"BES_RELEASE");
753 const char*
SftVer = sftver.c_str();
755 if(calParVer!=
"default"){
756 const char* calpar = calParVer.c_str();
757 sprintf(stmt1,
"select BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EstTofCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
759 if(calParVer==
"default"){
761 sprintf(stmt1,
"select BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from EstTofCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
764 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
766 std::cout<<
"ERROR:error searching EstTOF calibration Data in the database with: "<<stmt1<<std::endl;
771 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
772 sscanf(records[
"RunTo"],
"%d", &RunTo);
773 cout <<
"@table EstTof: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
781 std::string& calParVer,
784 std::string& sftver) {
789 if(sftver==
"default")
790 sftver = getenv(
"BES_RELEASE");
791 const char*
SftVer = sftver.c_str();
793 if(calParVer!=
"default"){
794 const char* calpar = calParVer.c_str();
795 sprintf(stmt1,
"select BTofSim,ETofSim,SimConstants,RunFrom,RunTo,TofSimParVer,FileName,Status,SftVer from TofSimSvc where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and TofSimParVer = %s",
SftVer,run_No,run_No,calpar);
797 if(calParVer==
"default"){
799 sprintf(stmt1,
"select BTofSim,ETofSim,SimConstants,RunFrom,RunTo,TofSimParVer,FileName,Status,SftVer from TofSimSvc where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by TofSimParVer desc",
SftVer,run_No,run_No);
803 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
805 std::cout<<
"ERROR:error searching TOFSim calibration Data in the database with: "<<stmt1<<std::endl;
810 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
811 sscanf(records[
"RunTo"],
"%d", &RunTo);
812 cout <<
"@table TofSim: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
820 std::string& calParVer,
823 std::string& sftver) {
828 if(sftver==
"default")
829 sftver = getenv(
"BES_RELEASE");
830 const char*
SftVer = sftver.c_str();
832 if(calParVer!=
"default"){
833 const char* calpar = calParVer.c_str();
834 sprintf(stmt1,
"select TH1F_Col,bin,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from DedxSim where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
836 if(calParVer==
"default"){
837 sprintf(stmt1,
"select TH1F_Col,bin,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from DedxSim where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
840 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
842 std::cout<<
"ERROR:error searching DedxSim calibration Data in the database with: "<<stmt1<<std::endl;
847 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
848 sscanf(records[
"RunTo"],
"%d", &RunTo);
849 cout <<
"@table DedxSim: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
858 std::string& calParVer,
861 std::string& sftver) {
866 if(sftver==
"default")
867 sftver = getenv(
"BES_RELEASE");
868 const char*
SftVer = sftver.c_str();
870 if(calParVer!=
"default"){
871 const char* calpar = calParVer.c_str();
872 sprintf(stmt1,
"select AlignEndPlate,WirePos,WireTension,RunFrom,RunTo,MdcAlignVer,AlignEPFileName,Status,SftVer from MdcAlignment where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and MdcAlignVer = %s",
SftVer,run_No,run_No,calpar);
874 if(calParVer==
"default"){
876 sprintf(stmt1,
"select AlignEndPlate,WirePos,WireTension,RunFrom,RunTo,MdcAlignVer,AlignEPFileName,Status,SftVer from MdcAlignment where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by MdcAlignVer desc",
SftVer,run_No,run_No);
879 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
881 std::cout<<
"ERROR:error searching MdcAlignment calibration Data in the database with: "<<stmt1<<std::endl;
886 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
887 sscanf(records[
"RunTo"],
"%d", &RunTo);
888 cout <<
"@table MdcAligment: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
895 std::string& calParVer,
898 std::string& sftver) {
903 if(sftver==
"default")
904 sftver = getenv(
"BES_RELEASE");
905 const char*
SftVer = sftver.c_str();
907 if(calParVer!=
"default"){
908 const char* calpar = calParVer.c_str();
909 sprintf(stmt1,
"select WireEff,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MdcDataConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
911 if(calParVer==
"default"){
912 sprintf(stmt1,
"select WireEff,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from MdcDataConst where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
915 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
917 std::cout<<
"ERROR:error searching MdcDataConst Data in the database with: "<<stmt1<<std::endl;
922 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
923 sscanf(records[
"RunTo"],
"%d", &RunTo);
924 cout <<
"@table MdcData: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
931 std::string& calParVer,
934 std::string& sftver) {
939 if(sftver==
"default")
940 sftver = getenv(
"BES_RELEASE");
941 const char*
SftVer = sftver.c_str();
943 if(calParVer!=
"default"){
944 const char* calpar = calParVer.c_str();
945 sprintf(stmt1,
"select BarBoardNum,EndBoardNum,QELecBarParEast,QELecBarParWest,QELecEndPar,SimQELecBarParEast,SimQELecBarParWest,SimQELecEndPar,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from TofQELec where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
SftVer,run_No,run_No,calpar);
947 if(calParVer==
"default"){
948 sprintf(stmt1,
"select BarBoardNum,EndBoardNum,QELecBarParEast,QELecBarParWest,QELecEndPar,SimQELecBarParEast,SimQELecBarParWest,SimQELecEndPar,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from TofQELec where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
SftVer,run_No,run_No);
950 int row_no = m_dbsvc->
query(
"offlinedb", stmt1, res);
952 std::cout<<
"ERROR:error searching TofQElec calibration Data in the database with: "<<stmt1<<std::endl;
957 sscanf(records[
"RunFrom"],
"%d", &RunFrom);
958 sscanf(records[
"RunTo"],
"%d", &RunTo);
959 cout <<
"Read from DB TofQElec: RunFrom " << RunFrom <<
" RunTo= " << RunTo << endl;
960 std::cout<<
"metadata ok"<<std::endl;
994Metadata::doSelect(std::vector<rdbModel::Assertion::Operator *>& conditions,
1001 colNames[0] =
"ser_no";
1016 results = m_readCxt->
select(m_table, colNames, orderBy, &whereClause);
1020 std::cout << ex.
getMsg();
1024 std::cout<<
"no results"<<std::endl;
1030 std::cout<<
"There are results"<<std::endl;
1033 conditions.pop_back();
1034 std::cout<<
"no results"<<std::endl;
1037 std::vector<std::string> fields;
1050 const std::string& flavor,
1051 const std::string& calib_type,
1052 const std::string& data_ident,
1053 const std::string& data_fmt,
1054 unsigned int& runfrm,
1055 unsigned int& runto,
1056 const std::string& input_desc,
1057 const std::string& notes,
1058 const std::string& proc_level,
1059 const std::string& locale,
1060 const std::string& fmt_version,
1061 const std::string& completion)
1070 if (ret !=
RETOk)
return 0;
1078 nullCols.reserve(16);
1080 if (inst.size() * calib_type.size() * flavor.size() * data_fmt.size()
1081 * data_ident.size() * proc_level.size() * completion.size()
1082 * locale.size() == 0) {
1085 cols.push_back(
"calib_type"); vals.push_back(calib_type);
1087 cols.push_back(
"data_fmt"); vals.push_back(data_fmt);
1088 cols.push_back(
"data_ident"); vals.push_back(data_ident);
1089 cols.push_back(
"status"); vals.push_back(completion);
1090 std::string s_runfrm,s_runto;
1093 cols.push_back(
"RunFrom"); vals.push_back(s_runfrm);
1094 cols.push_back(
"RunTo"); vals.push_back(s_runto);
1097 if (input_desc.size() > 0 ) {
1098 cols.push_back(
"input_desc"); vals.push_back(input_desc);
1099 }
else nullCols.push_back(
"input_desc");
1101 if (notes.size() > 0 ) {
1102 cols.push_back(
"notes"); vals.push_back(notes);
1103 }
else nullCols.push_back(
"notes");
1105 if (fmt_version.size() > 0 )
1107 cols.push_back(
"fmt_version");
1108 vals.push_back(fmt_version);
1112 cols.push_back(
"creator"); vals.push_back(
"Metadata::registerCalib");
1115 cols.push_back(
"uid"); vals.push_back(uid);
1117 cols.push_back(
"enter_time");vals.push_back(curTime.
getString());
1120 cols.push_back(
"update_time");vals.push_back(curTime.
getString());
1131 if (!(m_writeCxt->
insertRow(m_table, cols, vals, &ser_no, &nullCols)) ) {
1140 const std::string& schema) {
1155 int errcode = m_man->
build();
1158 std::cerr <<
"Error in database description file " << schema
1160 std::cerr <<
"Parse failed with error " << errcode << std::endl;
1173 std::cout <<
"XML schema and MySQL database are NOT compatible"
1177 std::cout <<
"Connection failed while attempting match" << std::endl;
1185 unsigned nCol = cols.size();
1189 for (
unsigned iCol = 0; iCol < nCol; iCol++) {
1191 if (!col->
okValue(vals[iCol])) {
1192 std::cerr <<
"Value " << vals[iCol] <<
" not allowed for column "
1193 << cols[iCol] <<
" in table " << m_table << std::endl;
1201 unsigned nCol = cols.size();
1205 for (
unsigned iCol = 0; iCol < nCol; iCol++) {
1208 std::cerr <<
"Column "
1209 << cols[iCol] <<
" in table " << m_table
1210 <<
" is not nullable" << std::endl;
1218unsigned Metadata::adjustVend(
int newSer) {
1227 std::string serString;
1230 getCols.push_back(
"flavor");
1231 getCols.push_back(
"calib_type");
1232 getCols.push_back(
"completion");
1239 if (!connectWrite(err))
return 0;
1244 FIELDTYPEold, FIELDTYPElit);
1251 results = m_writeCxt->
select(m_table, getCols, orderBy, where);
1257 std::cout << ex.
getMsg();
1262 std::cout <<
"MySQL failure in SELECT" << std::endl;
1266 std::cout <<
"Look-up of serial# " << serString <<
" failed"
1270 std::vector<std::string> fields;
1272 if (fields[2] !=
"OK")
return 0;
1278 std::vector<Assertion::Operator *> conditions;
1279 conditions.reserve(7);
1280 for (
unsigned ix = 0;
ix < 5;
ix++) {
1283 FIELDTYPEold, FIELDTYPElit));
1288 FIELDTYPEold, FIELDTYPElit));
1292 FIELDTYPEold, FIELDTYPElit));
1300 toUpdate.push_back(
"vend");
1302 newVal.push_back(fields[5]);
1305 toUpdate.push_back(
"update_time");newVal.push_back(curTime.
getString());
1307 unsigned nModified = m_writeCxt->
update(m_table, toUpdate, newVal, where);
std::vector< std::string > StringVector
Simple algorithm to test functioning of "the other" TDS.
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)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
std::string getString() const
Return string representation of time, not including nanoseconds;.
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
static int atoi(const std::string &InStr)
converts an std::string to an integer
static int stringToInt(const std::string &InStr)
static const char * itoa(int val, std::string &outStr)
bool nullAllowed() const
Returns true if column may take on value NULL.
bool okValue(const std::string &val, bool set=true) const
virtual ResultHandle * select(const std::string &tableName, const StringVector &getCols, const StringVector &orderCols, const Assertion *where=0, int rowLimit=0, int rowOffset=0)=0
virtual MATCH matchSchema(Rdb *rdb, bool matchDbName=true)=0
virtual unsigned int update(const std::string &tableName, const StringVector &colNames, const StringVector &values, const Assertion *where=0, const StringVector *nullCols=0)=0
virtual bool open(const std::string &host, const std::string &userid, const std::string &password, const std::string &dbName)=0
virtual bool insertRow(const std::string &tableName, const StringVector &colNames, const StringVector &values, int *auto_value=0, const StringVector *nullCols=0)=0
void setInputSource(std::string pname)
void setBuilder(Builder *b)
static Manager * getManager()
virtual std::string getMsg()
Table * getTable(const std::string &name) const
virtual bool getRow(std::vector< std::string > &fields, unsigned int i=0, bool clear=true)=0
virtual unsigned int getNRows() const =0
Return number of rows in results.
Column * getColumnByName(const std::string &name) const
Module implements methods for clients to get generic services.
std::vector< std::string > StringVector