10#include "GaudiKernel/Bootstrap.h"
11#include "GaudiKernel/ISvcLocator.h"
12#include "calibUtil/Metadata.h"
13#include "facilities/Timestamp.h"
14#include "facilities/Util.h"
15#include "rdbModel/Management/Manager.h"
16#include "rdbModel/Management/XercesBuilder.h"
20#include "rdbModel/Db/MysqlConnection.h"
21#include "rdbModel/Db/MysqlResults.h"
22#include "rdbModel/Rdb.h"
23#include "rdbModel/RdbException.h"
24#include "rdbModel/Tables/Assertion.h"
25#include "rdbModel/Tables/Column.h"
26#include "rdbModel/Tables/Table.h"
39 const std::string& dbName )
49 if ( table.compare(
"*" ) == 0 ) m_table = std::string(
"$(MYSQL_METATABLE)" );
50 if ( host.compare(
"*" ) == 0 ) m_host = std::string(
"$(MYSQL_HOST)" );
54 if ( nsub < 0 ) m_table = std::string(
"metadata" );
55 StatusCode sc = Gaudi::svcLocator()->service(
"DatabaseSvc", m_dbsvc,
true );
56 if ( !sc.isSuccess() )
58 std::cout <<
"Metadata ERROR ::Could not retrieve the DataBaseSvc" << std::endl;
67 if ( m_man )
delete m_man;
75 user = std::string(
"$(USER)" );
77 user = std::string(
"$(USERNAME)" );
81 if ( nsub == 1 ) {
return RETOk; }
84 user = std::string(
"" );
90 bool Metadata::connect( rdbModel::Connection* cxt, std::string& host,
91 const std::string& user,
const std::string& pw, eRet& err,
92 const std::string& dbName ) {
101 bool connected = cxt->
open( host, user, pw, dbName );
115 if ( m_readCxt == 0 )
121 bool ok = connect( m_readCxt, m_host, std::string(
"guest" ), std::string(
"guestpass" ),
138 bool Metadata::connectWrite( eRet& err ) {
139 if ( m_writeCxt == 0 )
143 if ( m_dbName == std::string(
"calib_test" ) )
145 ok = connect( m_writeCxt, m_host, std::string(
"calib_tester" ),
146 std::string(
"udine" ), err, m_dbName );
150 ok = connect( m_writeCxt, m_host, std::string(
"calibrator" ),
151 std::string(
"calibrator" ), err, m_dbName );
160 std::string schema = std::string(
"$(RDBMODELROOT)/xml/" ) + m_dbName +
".xml";
161 err = compareSchema( m_writeCxt, schema );
188 unsigned int* ser,
const std::string& calibType,
const std::string&
SftVer,
189 const std::string& cal_ver,
const std::string& cal_par,
const std::string& rec_alg,
190 const std::string& rec_par,
const std::string& machine,
const std::string& flavor ) {
198 if ( ret !=
RETOk )
return ret;
203 std::vector<Assertion::Operator*> conditions;
204 conditions.reserve( 8 );
228 std::cout <<
"run no is::" << s_run << std::endl;
236 conditions.push_back( &completeOp );
237 conditions.push_back( &calibTypeOp );
239 conditions.push_back( &sftverOp );
240 conditions.push_back( &calverOp );
241 conditions.push_back( &calparOp );
242 conditions.push_back( &recalgOp );
243 conditions.push_back( &recparOp );
244 conditions.push_back( &machineOp );
245 conditions.push_back( &runfrmOp );
246 conditions.push_back( &runtoOp );
247 ret = doSelect( conditions, orderBy, ser );
253 const std::string&
SftVer,
const std::string& cal_ver,
254 const std::string& cal_par,
const std::string& rec_alg,
255 const std::string& rec_par,
const std::string& machine,
256 const std::string& flavor ) {
264 if ( ret !=
RETOk )
return ret;
270 std::vector<Assertion::Operator*> conditions;
271 conditions.reserve( 8 );
301 conditions.push_back( &completeOp );
302 conditions.push_back( &calibTypeOp );
304 conditions.push_back( &sftverOp );
305 conditions.push_back( &calverOp );
306 conditions.push_back( &calparOp );
307 conditions.push_back( &recalgOp );
308 conditions.push_back( &recparOp );
309 conditions.push_back( &machineOp );
310 conditions.push_back( &runfrmOp );
311 conditions.push_back( &runtoOp );
313 return doSelect( conditions, orderBy, ser );
317 std::string& dataFmt, std::string& filename ) {
323 if ( ret !=
RETOk ) {
return ret; }
326 colNames[0] =
"data_fmt";
327 colNames[1] =
"data_ident";
328 colNames[2] =
"RunFrom";
329 colNames[3] =
"RunTo";
331 std::string serNoVal;
344 results = m_readCxt->select( m_table, colNames, orderBy, &whereClause );
354 std::vector<std::string> fields;
355 std::cout <<
"test id \\" << std::endl;
356 results->
getRow( fields );
358 filename = fields[1];
359 std::string runfrm, runto;
368 if ( ( dataFmt ==
"" ) || ( filename ==
"" ) )
return RETBadValue;
374 int* runTo, std::string& calParVer,
376 std::string& sftver ) {
382 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
383 const char*
SftVer = sftver.c_str();
385 if ( calParVer !=
"default" )
387 const char* calpar = calParVer.c_str();
389 "select SigInterval,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
390 "InjSigInterval where SftVer = "
391 "'%s' and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
392 SftVer, run_No, run_No, calpar );
395 if ( calParVer ==
"default" )
398 "select SigInterval,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
399 "InjSigInterval where SftVer = "
400 "'%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
403 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
407 <<
"ERROR:error searching InjSigInterval calibration Data in the database with: "
408 << stmt1 << std::endl;
413 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
414 sscanf( records[
"RunTo"],
"%d", &RunTo );
415 cout <<
"@table SigInterval: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
420 int* runTo, std::string& calParVer,
422 std::string& sftver ) {
428 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
429 const char*
SftVer = sftver.c_str();
430 cout <<
"getReadInjSigTimeInfo start:::::" << endl;
431 if ( calParVer !=
"default" )
433 const char* calpar = calParVer.c_str();
435 "select ist,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigTime "
436 "where SftVer = '%s' and "
437 "RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
438 SftVer, run_No, run_No, calpar );
441 if ( calParVer ==
"default" )
444 "select ist,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from InjSigTime "
445 "where SftVer = '%s' and "
446 "RunFrom <= %d and RunTo >= %d order by CalParVer desc",
449 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
452 std::cout <<
"ERROR:error searching InjSigTime calibration Data in the database with: "
453 << stmt1 << std::endl;
458 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
459 sscanf( records[
"RunTo"],
"%d", &RunTo );
460 cout <<
"@table InjSigTimeInfo: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
465 int* runTo, std::string& calParVer,
467 std::string& sftver ) {
473 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
474 const char*
SftVer = sftver.c_str();
475 if ( calParVer !=
"default" )
477 const char* calpar = calParVer.c_str();
479 "select data,oef,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
480 "OffEvtFilter where SftVer = '%s' "
481 "and RunFrom <= %d and RunTo >= %d and CalParVer = '%s'",
482 SftVer, run_No, run_No, calpar );
485 if ( calParVer ==
"default" )
488 "select data,oef,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
489 "OffEvtFilter where SftVer = '%s' "
490 "and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
493 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
496 std::cout <<
"ERROR:error searching OffEvtFilter calibration Data in the database with: "
497 << stmt1 << std::endl;
502 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
503 sscanf( records[
"RunTo"],
"%d", &RunTo );
504 cout <<
"@table OffEvtFilter: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
510 int FirstEvent, std::string& Version,
515 const char* parVer = Version.c_str();
517 "select Run,FinalETS,FileName,FilePath from CorrectedETS where Run= %d and "
518 "FirstEvent = %d and Version = %d",
519 run, FirstEvent, 1 );
521 int row_no = m_dbsvc->query(
"offlinedb", sql, res );
523 FileName = ( *res[0] )[
"FileName"];
524 std::cout <<
"FileName is::::" << FileName << std::endl;
527 std::cout <<
"ERROR:error searching CorrectedETS calibration Data in the database with: "
537 int runNo, std::string& sftver ) {
542 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
543 const char*
SftVer = sftver.c_str();
545 if ( calParVer !=
"default" )
547 const char* calpar = calParVer.c_str();
550 "BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,EtfTofBunch,RunFrom,RunTo,"
551 "CalParVer,FileName,Status,"
552 "SftVer from TofCalConst where SftVer = '%s' and RunFrom "
553 "<= %d and RunTo >= %d and CalParVer = %s",
554 SftVer, run_No, run_No, calpar );
556 if ( calParVer ==
"default" )
560 "BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,EtfTofBunch,RunFrom,RunTo,"
561 "CalParVer,FileName,Status,"
562 "SftVer from TofCalConst where SftVer = '%s' and RunFrom "
563 "<= %d and RunTo >= %d order by CalParVer desc",
567 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
570 std::cout <<
"ERROR:error searching TOF calibration Data in the database with: " << stmt1
576 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
577 sscanf( records[
"RunTo"],
"%d", &RunTo );
578 cout <<
"@table TofCalConst: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
584 int runNo, std::string& sftver ) {
590 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
591 const char*
SftVer = sftver.c_str();
593 if ( calParVer !=
"default" )
595 const char* calpar = calParVer.c_str();
598 "LayTree,BoxTree,StrTree,ResTree,ClsTree,RunFrom,RunTo,CalParVer,FileName,"
599 "Status,SftVer from "
600 "MucCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= "
601 "%d order by CalParVer desc",
605 if ( calParVer ==
"default" )
613 "LayTree,BoxTree,StrTree,ResTree,ClsTree,RunFrom,RunTo,CalParVer,FileName,"
614 "Status,SftVer from "
615 "MucCalConst where SftVer = '%s' and RunFrom <= %d and RunTo >= "
616 "%d order by CalParVer desc",
620 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
623 std::cout <<
"ERROR:error searching MUC calibration Data in the database with: " << stmt1
629 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
630 sscanf( records[
"RunTo"],
"%d", &RunTo );
631 cout <<
"@table Muc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
637 int runNo, std::string& sftver ) {
643 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
644 const char*
SftVer = sftver.c_str();
646 if ( calParVer !=
"default" )
648 const char* calpar = calParVer.c_str();
651 "NewXtTrees,XtTree,QtTree,T0Tree,SdTree,R2tTrees,RunFrom,RunTo,CalParVer,"
652 "FileName,Status,SftVer "
653 "from MdcCalConst where SftVer = '%s' and RunFrom <= %d and "
654 "RunTo >= %d and CalParVer = '%s'",
655 SftVer, run_No, run_No, calpar );
658 if ( calParVer ==
"default" )
666 "NewXtTrees,XtTree,QtTree,T0Tree,SdTree,R2tTrees,RunFrom,RunTo,CalParVer,"
667 "FileName,Status,SftVer "
668 "from MdcCalConst where SftVer = '%s' and RunFrom <= %d and "
669 "RunTo >= %d order by CalParVer desc",
673 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
676 std::cout <<
"ERROR:error searching Mdc calibration Data in the database with: " << stmt1
682 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
683 sscanf( records[
"RunTo"],
"%d", &RunTo );
684 cout <<
"@table Mdc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
691 int runNo, std::string& sftver ) {
696 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
697 const char*
SftVer = sftver.c_str();
699 if ( calParVer !=
"default" )
701 const char* calpar = calParVer.c_str();
703 "select DigiCalibConst,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
704 "EmcCalConst where SftVer = "
705 "'%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
706 SftVer, run_No, run_No, calpar );
709 if ( calParVer ==
"default" )
715 "select DigiCalibConst,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
716 "EmcCalConst where SftVer = "
717 "'%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
721 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
724 std::cout <<
"ERROR:error searching EMC calibration Data in the database with: " << stmt1
730 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
731 sscanf( records[
"RunTo"],
"%d", &RunTo );
732 cout <<
"@table Emc: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
738 int runNo, std::string& sftver ) {
743 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
744 const char*
SftVer = sftver.c_str();
746 if ( calParVer !=
"default" )
748 const char* calpar = calParVer.c_str();
751 "DriftDist,EntranceAng,MeanGain,GasGain,LayerGain,Resolution,WireGain,ZDep,"
752 "RunGain,RunFrom,RunTo,"
753 "CalParVer,FileName,Status,SftVer from DedxCalConst where "
754 "SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
755 SftVer, run_No, run_No, calpar );
757 if ( calParVer ==
"default" )
765 "DriftDist,EntranceAng,MeanGain,GasGain,LayerGain,Resolution,WireGain,ZDep,"
766 "RunGain,RunFrom,RunTo,"
767 "CalParVer,FileName,Status,SftVer from DedxCalConst where "
768 "SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
772 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
775 std::cout <<
"ERROR:error searching Dedx calibration Data in the database with: "
776 << stmt1 << std::endl;
781 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
782 sscanf( records[
"RunTo"],
"%d", &RunTo );
783 cout <<
"@table Dedx: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
788 std::string& calParVer,
790 std::string& sftver ) {
795 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
796 const char*
SftVer = sftver.c_str();
798 if ( calParVer !=
"default" )
800 const char* calpar = calParVer.c_str();
802 "select EsTimeH2,EsTimeH9,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
803 "EsTimeCalConst where "
804 "SftVer = '%s' and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
805 SftVer, run_No, run_No, calpar );
808 if ( calParVer ==
"default" )
811 "select EsTimeH2,EsTimeH9,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
812 "EsTimeCalConst where "
813 "SftVer = '%s' and RunFrom <= %d and RunTo >= %d order by "
817 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
820 std::cout <<
"ERROR:error searching EsTime calibration Data in the database with: "
821 << stmt1 << std::endl;
826 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
827 sscanf( records[
"RunTo"],
"%d", &RunTo );
828 cout <<
"@table EsTime: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
834 std::string& calParVer,
836 std::string& sftver ) {
841 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
842 const char*
SftVer = sftver.c_str();
844 if ( calParVer !=
"default" )
846 const char* calpar = calParVer.c_str();
849 "BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,RunFrom,RunTo,CalParVer,"
850 "FileName,Status,SftVer "
851 "from EstTofCalConst where SftVer = '%s' and RunFrom <= %d and "
852 "RunTo >= %d and CalParVer = %s",
853 SftVer, run_No, run_No, calpar );
855 if ( calParVer ==
"default" )
863 "BarTofPar,EndTofPar,TofConPar,BarTof,EtfTofPar,RunFrom,RunTo,CalParVer,"
864 "FileName,Status,SftVer "
865 "from EstTofCalConst where SftVer = '%s' and RunFrom <= %d and "
866 "RunTo >= %d order by CalParVer desc",
870 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
873 std::cout <<
"ERROR:error searching EstTOF calibration Data in the database with: "
874 << stmt1 << std::endl;
879 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
880 sscanf( records[
"RunTo"],
"%d", &RunTo );
881 cout <<
"@table EstTof: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
886 std::string& calParVer,
888 std::string& sftver ) {
893 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
894 const char*
SftVer = sftver.c_str();
896 if ( calParVer !=
"default" )
898 const char* calpar = calParVer.c_str();
901 "BTofSim,ETofSim,SimConstants,RunFrom,RunTo,TofSimParVer,FileName,Status,"
902 "SftVer from TofSimSvc "
903 "where SftVer = '%s' and RunFrom <= %d and RunTo >= %d and "
905 SftVer, run_No, run_No, calpar );
907 if ( calParVer ==
"default" )
915 "BTofSim,ETofSim,SimConstants,RunFrom,RunTo,TofSimParVer,FileName,Status,"
916 "SftVer from TofSimSvc "
917 "where SftVer = '%s' and RunFrom <= %d and RunTo >= %d order "
918 "by TofSimParVer desc",
922 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
925 std::cout <<
"ERROR:error searching TOFSim calibration Data in the database with: "
926 << stmt1 << std::endl;
931 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
932 sscanf( records[
"RunTo"],
"%d", &RunTo );
933 cout <<
"@table TofSim: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
938 std::string& calParVer,
940 std::string& sftver ) {
945 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
946 const char*
SftVer = sftver.c_str();
948 if ( calParVer !=
"default" )
950 const char* calpar = calParVer.c_str();
952 "select TH1F_Col,bin,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
953 "DedxSim where SftVer = '%s' "
954 "and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
955 SftVer, run_No, run_No, calpar );
957 if ( calParVer ==
"default" )
960 "select TH1F_Col,bin,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
961 "DedxSim where SftVer = '%s' "
962 "and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
966 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
969 std::cout <<
"ERROR:error searching DedxSim calibration Data in the database with: "
970 << stmt1 << std::endl;
975 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
976 sscanf( records[
"RunTo"],
"%d", &RunTo );
977 cout <<
"@table DedxSim: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
982 std::string& calParVer,
984 std::string& sftver ) {
989 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
990 const char*
SftVer = sftver.c_str();
992 if ( calParVer !=
"default" )
994 const char* calpar = calParVer.c_str();
997 "AlignEndPlate,WirePos,WireTension,RunFrom,RunTo,MdcAlignVer,AlignEPFileName,"
998 "Status,SftVer from "
999 "MdcAlignment where SftVer = '%s' and RunFrom <= %d and RunTo "
1000 ">= %d and MdcAlignVer = %s",
1001 SftVer, run_No, run_No, calpar );
1003 if ( calParVer ==
"default" )
1011 "AlignEndPlate,WirePos,WireTension,RunFrom,RunTo,MdcAlignVer,AlignEPFileName,"
1012 "Status,SftVer from "
1013 "MdcAlignment where SftVer = '%s' and RunFrom <= %d and RunTo "
1014 ">= %d order by MdcAlignVer desc",
1015 SftVer, run_No, run_No );
1018 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
1021 std::cout <<
"ERROR:error searching MdcAlignment calibration Data in the database with: "
1022 << stmt1 << std::endl;
1027 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
1028 sscanf( records[
"RunTo"],
"%d", &RunTo );
1029 cout <<
"@table MdcAligment: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
1034 int* runTo, std::string& calParVer,
1036 std::string& sftver ) {
1041 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
1042 const char*
SftVer = sftver.c_str();
1044 if ( calParVer !=
"default" )
1046 const char* calpar = calParVer.c_str();
1048 "select WireEff,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
1049 "MdcDataConst where SftVer = '%s' "
1050 "and RunFrom <= %d and RunTo >= %d and CalParVer = %s",
1051 SftVer, run_No, run_No, calpar );
1053 if ( calParVer ==
"default" )
1056 "select WireEff,RunFrom,RunTo,CalParVer,FileName,Status,SftVer from "
1057 "MdcDataConst where SftVer = '%s' "
1058 "and RunFrom <= %d and RunTo >= %d order by CalParVer desc",
1059 SftVer, run_No, run_No );
1062 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
1065 std::cout <<
"ERROR:error searching MdcDataConst Data in the database with: " << stmt1
1071 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
1072 sscanf( records[
"RunTo"],
"%d", &RunTo );
1073 cout <<
"@table MdcData: RunFrom is:" << RunFrom <<
" RunTo is:" << RunTo << endl;
1078 std::string& calParVer,
1080 std::string& sftver ) {
1085 if ( sftver ==
"default" ) sftver = getenv(
"BES_RELEASE" );
1086 const char*
SftVer = sftver.c_str();
1088 if ( calParVer !=
"default" )
1090 const char* calpar = calParVer.c_str();
1093 "BarBoardNum,EndBoardNum,QELecBarParEast,QELecBarParWest,QELecEndPar,"
1094 "SimQELecBarParEast,"
1095 "SimQELecBarParWest,SimQELecEndPar,RunFrom,RunTo,CalParVer,FileName,Status,"
1096 "SftVer from TofQELec where SftVer = '%s' and RunFrom <= %d and RunTo >= %d "
1097 "and CalParVer = %s",
1098 SftVer, run_No, run_No, calpar );
1100 if ( calParVer ==
"default" )
1104 "BarBoardNum,EndBoardNum,QELecBarParEast,QELecBarParWest,QELecEndPar,"
1105 "SimQELecBarParEast,"
1106 "SimQELecBarParWest,SimQELecEndPar,RunFrom,RunTo,CalParVer,FileName,Status,"
1107 "SftVer from TofQELec where SftVer = '%s' and RunFrom <= %d and RunTo >= %d "
1108 "order by CalParVer desc",
1109 SftVer, run_No, run_No );
1111 int row_no = m_dbsvc->query(
"offlinedb", stmt1, res );
1114 std::cout <<
"ERROR:error searching TofQElec calibration Data in the database with: "
1115 << stmt1 << std::endl;
1120 sscanf( records[
"RunFrom"],
"%d", &RunFrom );
1121 sscanf( records[
"RunTo"],
"%d", &RunTo );
1122 cout <<
"Read from DB TofQElec: RunFrom " << RunFrom <<
" RunTo= " << RunTo << endl;
1123 std::cout <<
"metadata ok" << std::endl;
1155 Metadata::eRet Metadata::doSelect( std::vector<rdbModel::Assertion::Operator*>& conditions,
1161 colNames[0] =
"ser_no";
1168 Assertion whereClause( &andOp, 0,
true );
1171 if ( results ) {
delete results; }
1175 results = m_readCxt->
select( m_table, colNames, orderBy, &whereClause );
1177 }
catch ( RdbException ex )
1178 { std::cout << ex.
getMsg(); }
1182 std::cout <<
"no results" << std::endl;
1186 std::cout <<
"There are results" << std::endl;
1190 conditions.pop_back();
1191 std::cout <<
"no results" << std::endl;
1196 std::vector<std::string> fields;
1197 results->
getRow( fields );
1199 if ( results ) {
delete results; }
1206 const std::string& calib_type,
const std::string& data_ident,
1207 const std::string& data_fmt,
unsigned int& runfrm,
1208 unsigned int& runto,
const std::string& input_desc,
1209 const std::string& notes,
const std::string& proc_level,
1210 const std::string& locale,
const std::string& fmt_version,
1211 const std::string& completion ) {
1219 connectWrite( ret );
1220 if ( ret !=
RETOk )
return 0;
1228 nullCols.reserve( 16 );
1230 if ( inst.size() * calib_type.size() * flavor.size() * data_fmt.size() *
1231 data_ident.size() * proc_level.size() * completion.size() * locale.size() ==
1236 cols.push_back(
"calib_type" );
1237 vals.push_back( calib_type );
1239 cols.push_back(
"data_fmt" );
1240 vals.push_back( data_fmt );
1241 cols.push_back(
"data_ident" );
1242 vals.push_back( data_ident );
1243 cols.push_back(
"status" );
1244 vals.push_back( completion );
1245 std::string s_runfrm, s_runto;
1248 cols.push_back(
"RunFrom" );
1249 vals.push_back( s_runfrm );
1250 cols.push_back(
"RunTo" );
1251 vals.push_back( s_runto );
1254 if ( input_desc.size() > 0 )
1256 cols.push_back(
"input_desc" );
1257 vals.push_back( input_desc );
1259 else nullCols.push_back(
"input_desc" );
1261 if ( notes.size() > 0 )
1263 cols.push_back(
"notes" );
1264 vals.push_back( notes );
1266 else nullCols.push_back(
"notes" );
1268 if ( fmt_version.size() > 0 )
1270 cols.push_back(
"fmt_version" );
1271 vals.push_back( fmt_version );
1275 cols.push_back(
"creator" );
1276 vals.push_back(
"Metadata::registerCalib" );
1279 cols.push_back(
"uid" );
1280 vals.push_back( uid );
1282 cols.push_back(
"enter_time" );
1286 cols.push_back(
"update_time" );
1293 if ( !ok )
return 0;
1298 if ( !( m_writeCxt->insertRow( m_table, cols, vals, &ser_no, &nullCols ) ) ) {
return 0; }
1301 adjustVend( ser_no );
1307 const std::string& schema ) {
1322 int errcode = m_man->
build();
1326 std::cerr <<
"Error in database description file " << schema << std::endl;
1327 std::cerr <<
"Parse failed with error " << errcode << std::endl;
1330 m_rdb = m_man->getRdb();
1339 std::cout <<
"XML schema and MySQL database are NOT compatible" << std::endl;
1342 std::cout <<
"Connection failed while attempting match" << std::endl;
1350 unsigned nCol = cols.size();
1353 for (
unsigned iCol = 0; iCol < nCol; iCol++ )
1356 if ( !col->
okValue( vals[iCol] ) )
1358 std::cerr <<
"Value " << vals[iCol] <<
" not allowed for column " << cols[iCol]
1359 <<
" in table " << m_table << std::endl;
1367 unsigned nCol = cols.size();
1370 for (
unsigned iCol = 0; iCol < nCol; iCol++ )
1375 std::cerr <<
"Column " << cols[iCol] <<
" in table " << m_table <<
" is not nullable"
1383 unsigned Metadata::adjustVend(
int newSer ) {
1390 getCols.reserve( 7 );
1392 std::string serString;
1395 getCols.push_back(
"flavor" );
1396 getCols.push_back(
"calib_type" );
1397 getCols.push_back(
"completion" );
1406 if ( !connectWrite( err ) )
return 0;
1417 results = m_writeCxt->
select( m_table, getCols, orderBy, where );
1421 }
catch ( RdbException ex )
1423 std::cout << ex.
getMsg();
1429 std::cout <<
"MySQL failure in SELECT" << std::endl;
1434 std::cout <<
"Look-up of serial# " << serString <<
" failed" << std::endl;
1437 std::vector<std::string> fields;
1438 results->
getRow( fields );
1439 if ( fields[2] !=
"OK" )
return 0;
1445 std::vector<Assertion::Operator*> conditions;
1446 conditions.reserve( 7 );
1447 for (
unsigned ix = 0;
ix < 5;
ix++ )
1449 conditions.push_back(
new Assertion::Operator( OPTYPEequal, getCols[
ix], fields[
ix],
1450 FIELDTYPEold, FIELDTYPElit ) );
1453 conditions.push_back(
new Assertion::Operator( OPTYPElessThan,
"vstart", fields[5],
1454 FIELDTYPEold, FIELDTYPElit ) );
1456 conditions.push_back(
new Assertion::Operator( OPTYPEgreaterThan,
"vend", fields[5],
1457 FIELDTYPEold, FIELDTYPElit ) );
1460 Assertion::Operator* andOp =
new Assertion::Operator( OPTYPEand, conditions );
1461 where =
new Assertion( andOp );
1464 toUpdate.push_back(
"vend" );
1466 newVal.push_back( fields[5] );
1468 facilities::Timestamp curTime;
1469 toUpdate.push_back(
"update_time" );
1470 newVal.push_back( curTime.
getString() );
1472 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)
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 bool open(const std::string &host, const std::string &userid, const std::string &password, const std::string &dbName)=0
void setInputSource(std::string pname)
void setBuilder(Builder *b)
static Manager * getManager()
virtual std::string getMsg()
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