10#include "GaudiKernel/IDataManagerSvc.h"
16#include "GaudiKernel/SmartDataPtr.h"
18#include "GaudiKernel/DataObject.h"
19#include "GaudiKernel/GenericAddress.h"
20#include "GaudiKernel/IConverter.h"
21#include "GaudiKernel/IDetDataSvc.h"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/IOpaqueAddress.h"
24#include "GaudiKernel/ISvcLocator.h"
25#include "GaudiKernel/IValidity.h"
26#include "GaudiKernel/MsgStream.h"
27#include "GaudiKernel/SvcFactory.h"
29#include "TBufferFile.h"
46 unsigned int toQualityMask(std::vector<std::string>& qualities) {
49 unsigned int mask = 0;
50 unsigned n = qualities.size();
52 for (
unsigned i = 0; i < n; i++) {
53 std::string iString = qualities[i];
54 if (iString.size() < 3)
continue;
56 if (iString ==
"PRO") mask |= Metadata::LEVELProd;
57 else if (iString ==
"DEV") mask |= Metadata::LEVELDev;
58 else if (iString ==
"TES") mask |= Metadata::LEVELTest;
59 else if (iString ==
"SUP") mask |= Metadata::LEVELSuperseded;
66 : ConversionSvc (name, svc, MYSQL_StorageType)
67 , m_meta(0), m_useEventTime(
true),m_enterTimeStart(0), m_enterTimeEnd(0),
71 declareProperty(
"Host", m_host =
"bes3db2.ihep.ac.cn");
72 declareProperty(
"UseEventTime", m_useEventTime =
true);
73 declareProperty(
"EnterTimeEnd", m_enterTimeEndString = std::string(
"") );
74 declareProperty(
"EnterTimeStart", m_enterTimeStartString = std::string(
"") );
76 declareProperty(
"DbName", m_dbName = std::string(
"offlinedb") );
77 declareProperty(
"QualityList", m_qualityList);
78 declareProperty(
"CrashOnError", m_crash =
true);
79 declareProperty(
"Sft_Ver",sft_ver);
80 declareProperty(
"Cal_Ver",cal_ver);
81 declareProperty(
"MdcFlag",m_flag[0]=
"default");
82 declareProperty(
"DeDxFlag",m_flag[1]=
"default");
83 declareProperty(
"EmcFlag",m_flag[2]=
"default");
84 declareProperty(
"TofFlag",m_flag[3]=
"default");
85 declareProperty(
"MucFlag",m_flag[4]=
"default");
86 declareProperty(
"EsTimeFlag",m_flag[5]=
"default");
87 declareProperty(
"EstTofFlag",m_flag[6]=
"default");
88 declareProperty(
"MdcAlignFlag",m_flag[7]=
"default");
89 declareProperty(
"TofQElecFlag",m_flag[8]=
"default");
90 declareProperty(
"TofSimPFlag",m_flag[9]=
"default");
91 declareProperty(
"DedxSimFlag",m_flag[10]=
"default");
92 declareProperty(
"MdcDataFlag",m_flag[11]=
"default");
94 declareProperty(
"InjSigIntervalFlag",m_flag[12]=
"default");
95 declareProperty(
"InjSigTimeFlag",m_flag[13]=
"default");
96 declareProperty(
"OffEvtFilterFlag",m_flag[14]=
"default");
97 declareProperty(
"CorrectedETSFlag",m_flag[15]=
"default");
99 declareProperty(
"MdcCalPar",m_calPar[0]=
"default");
100 declareProperty(
"DeDxCalPar",m_calPar[1]=
"default");
101 declareProperty(
"EmcCalPar",m_calPar[2]=
"default");
102 declareProperty(
"TofCalPar",m_calPar[3]=
"default");
103 declareProperty(
"MucCalPar",m_calPar[4]=
"default");
104 declareProperty(
"EsTimeCalPar",m_calPar[5]=
"default");
105 declareProperty(
"EstTofCalPar",m_calPar[6]=
"default");
106 declareProperty(
"MdcAlignPar",m_calPar[7]=
"default");
107 declareProperty(
"TofQElecPar",m_calPar[8]=
"default");
108 declareProperty(
"TofSimPar",m_calPar[9]=
"default");
109 declareProperty(
"DedxSimPar",m_calPar[10]=
"default");
110 declareProperty(
"MdcDataConstVer",m_calPar[11]=
"default");
112 declareProperty(
"InjSigIntervalPar",m_calPar[12]=
"default");
113 declareProperty(
"InjSigTimePar",m_calPar[13]=
"default");
114 declareProperty(
"OffEvtFilterPar",m_calPar[14]=
"default");
115 declareProperty(
"CorrectedETSPar",m_calPar[15]=
"default");
117 declareProperty(
"MdcBossVer",m_bossver[0]=
"default");
118 declareProperty(
"DeDxBossVer",m_bossver[1]=
"default");
119 declareProperty(
"EmcBossVer",m_bossver[2]=
"default");
120 declareProperty(
"TofBossVer",m_bossver[3]=
"default");
121 declareProperty(
"MucBossVer",m_bossver[4]=
"default");
122 declareProperty(
"EsTimeBossVer",m_bossver[5]=
"default");
123 declareProperty(
"EstTofBossVer",m_bossver[6]=
"default");
124 declareProperty(
"MdcAlignBossVer",m_bossver[7]=
"default");
125 declareProperty(
"TofQElecBossVer",m_bossver[8]=
"default");
126 declareProperty(
"TofSimBossVer",m_bossver[9]=
"default");
127 declareProperty(
"DedxSimBossVer",m_bossver[10]=
"default");
128 declareProperty(
"MdcDataConstBossVer",m_bossver[11]=
"default");
129 declareProperty(
"InjSigIntervalBossVer",m_bossver[12]=
"default");
130 declareProperty(
"InjSigTimeBossVer",m_bossver[13]=
"default");
131 declareProperty(
"OffEvtFilterBossVer",m_bossver[14]=
"default");
132 declareProperty(
"Align_RunNo",m_MdcAlign_No=8093);
133 declareProperty(
"Db_Status",m_dbStatus=
"OK");
134 declareProperty(
"BossRelease",m_bossRelease=
"default");
142 StatusCode sc = ConversionSvc::initialize();
143 if ( !sc.isSuccess() )
return sc;
145 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
146 log << MSG::INFO <<
"Specific initialization starting" << endreq;
148 IDataProviderSvc* pCDS = 0;
149 sc = serviceLocator()->getService (
"CalibDataSvc", IDataProviderSvc::interfaceID(), (IInterface*&)pCDS);
151 if ( !sc.isSuccess() ) {
152 log << MSG::ERROR <<
"Could not locate CalibDataSvc" << endreq;
156 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
157 if (sc .isFailure() ) {
158 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
163 sc = setDataProvider(pCDS);
164 if ( !sc.isSuccess() ) {
165 log << MSG::ERROR <<
"Could not set data provider" << endreq;
171 sc = serviceLocator()->service
172 (
"DetectorPersistencySvc", m_detPersSvc,
true);
173 if ( !sc.isSuccess() ) {
175 <<
"Cannot locate IConversionSvc interface of DetectorPersistencySvc"
180 <<
"Retrieved IConversionSvc interface of DetectorPersistencySvc"
184 IAddressCreator* iAddrCreator;
185 sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(),(
void**) &iAddrCreator);
187 if ( !sc.isSuccess() ) {
188 log << MSG::ERROR <<
"Could not locate CalibDataSvc" << endreq;
192 sc = setAddressCreator(iAddrCreator);
193 if ( !sc.isSuccess() ) {
194 log << MSG::ERROR <<
"Cannot set the address creator" << endreq;
199 sc = setProperties();
200 if ( !sc.isSuccess() ) {
201 log << MSG::ERROR <<
"Could not set jobOptions properties" << endreq;
204 log << MSG::DEBUG <<
"Properties were read from jobOptions" << endreq;
209 m_qualityMask = toQualityMask(m_qualityList);
210 if (!m_qualityMask) {
222 log << MSG::ERROR <<
"Could not open connection to metadata dbs" << endreq;
230 log << MSG::INFO <<
"Specific initialization completed" << endreq;
237 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
238 log << MSG::DEBUG <<
"Finalizing" << endreq;
241 return ConversionSvc::finalize();
248 if ( IID_ICalibMetaCnvSvc == riid ) {
253 return ConversionSvc::queryInterface(riid, ppvInterface);
256 return StatusCode::SUCCESS;
264 DataObject*& refpObject ) {
266 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
278 pAddress->registry() );
280 if ( !sc.isSuccess() ) {
281 log << MSG::ERROR <<
"Could not create calib DataObject" << endreq;
283 log << MSG::DEBUG <<
"Method createObj exiting" << endreq;
293 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
294 return StatusCode::SUCCESS;
301 DataObject* pObject ) {
305 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
308 log << MSG::DEBUG <<
"CalibMySQLCnvSvc::updateObj starting ...."<<endreq;
311 log << MSG::ERROR <<
"There is no object to update" << endreq;
312 return StatusCode::FAILURE;
315 StatusCode sc =
updateCalib(pObject, pAddress->par()[0],
316 pAddress->clID(), pAddress->registry() );
317 if ( !sc.isSuccess() ) {
318 log << MSG::ERROR <<
"Could not update calib DataObject" << endreq;
322 return StatusCode::SUCCESS;
330 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
331 return StatusCode::SUCCESS;
340 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
342 return StatusCode::SUCCESS;
351 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
353 return StatusCode::SUCCESS;
361 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
363 return StatusCode::SUCCESS;
372 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
374 return StatusCode::SUCCESS;
382 const std::string* par,
383 const unsigned long* ,
384 IOpaqueAddress*& refpAddress ) {
386 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
387 if ( svc_type!= MYSQL_StorageType ) {
389 <<
"Cannot create addresses of type " << (int)svc_type
390 <<
" which is different from " << (
int)MYSQL_StorageType
392 return StatusCode::FAILURE;
395 <<
" create address in CalibMySQLCnvSvc "
398 refpAddress =
new GenericAddress( MYSQL_StorageType,
402 return StatusCode::SUCCESS;
407 std::string& CalParVer,
411 std::string BossRelease,
416 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
422 StatusCode sc=serviceLocator()->service(
"DatabaseSvc",m_dbsvc,
true);
423 if (sc .isFailure() ) {
424 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
427 const char* bossRelease = BossRelease.c_str();
428 const char* dataType = DataType.c_str();
430 sprintf(stmt,
"select RunFrom,RunTo,SftVer,ParVer from CalVtxLumVer where BossRelease = '%s' and RunFrom <= %d and RunTo >= %d and DataType='%s' ",bossRelease,run_No,run_No,dataType);
432 int row_no = m_dbsvc->
query(
"offlinedb",stmt,res);
434 std::cout<<
"ERROR:error searching with:"<<stmt<<std::endl;
439 runfrm=records1->
GetInt(
"RunFrom");
440 runto=records1->
GetInt(
"RunTo");
441 cout<<dataType<<
" runfrm,runto in getSftParVer is:"<<runfrm<<
"::::"<<runto<<endl;
446 cout<<
"ERROR: "<<dataType<<
" set overlapped run number in the table CalVtxLumVer"<<endl;
450 return StatusCode::SUCCESS;
467 const std::string& fullpath,
471 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
477 if (std::string(
"Test") == cType.substr(0, 4)) {
478 cType = std::string(
"Test_Gen");
481 std::string testfile = std::string(getenv(
"CALIBMYSQLCNVROOT"))+
"/share/test.root";
482 TFile *f1=
new TFile(testfile.c_str(),
"read");
483 unsigned int ser = 0;
487 std::string
flag=
"default";
490 MSG::Level msgLevel = MSG::DEBUG;
492 std::string physFmt =
"UNK";
493 std::string fmtVersion;
494 std::string dataIdent;
497 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
498 int runNo=0,FirstEvent=0;
500 log << MSG::WARNING <<
"Unable to read the Event for TDS" << endreq;
504 if(cType!=
"TofCal"&&cType!=
"EstTofCal"&&cType!=
"TofSim"&&cType!=
"DedxSim")
runNo = fabs(evt -> runNumber());
505 if(cType==
"TofCal"||cType==
"EstTofCal"||cType==
"TofSim"||cType==
"DedxSim")
runNo = evt -> runNumber();
506 FirstEvent = evt -> eventNumber();
513 if((cType==
"TofCal")&&(m_bossver[3]==
"default" ))
515 std::string cType=
"Tof";
516 if(m_bossRelease==
"default")
518 log << MSG::FATAL <<
" Boss Release for TofCal not set!" << endreq;
524 st1=
getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,
runNo,m_bossRelease,cType);
526 if (st1 .isFailure() )
528 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
537 else if ((cType==
"TofCal")&&(m_bossver[3]!=
"default" ))
548 if((cType==
"EmcCal")&&(m_bossver[2]==
"default" ))
550 std::string cType=
"Emc";
551 if(m_bossRelease==
"default")
553 log << MSG::FATAL <<
" Boss Release for EmcCal not set!" << endreq;
558 st1=
getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,
runNo,m_bossRelease,cType);
561 if (st1 .isFailure() )
563 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
570 else if((cType==
"EmcCal")&&(m_bossver[2]!=
"default" ))
580 if((cType==
"DedxCal")&&(m_bossver[1]==
"default" ))
582 std::string cType=
"Dedx";
583 if(m_bossRelease==
"default")
585 log << MSG::FATAL <<
" Boss Release for DedxCal not set!" << endreq;
590 st1=
getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,
runNo,m_bossRelease,cType);
592 if (st1 .isFailure() )
594 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
601 else if((cType==
"DedxCal")&&(m_bossver[1]!=
"default" ))
611 if((cType==
"MdcCal")&&(m_bossver[0]==
"default" ))
613 std::string cType=
"Mdc";
615 if(m_bossRelease==
"default")
617 log << MSG::FATAL <<
" Boss Release for MdcCal not set!" << endreq;
622 st1=
getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,
runNo,m_bossRelease,cType);
624 if (st1 .isFailure() )
626 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
634 else if((cType==
"MdcCal")&&(m_bossver[0]!=
"default"))
645 if((cType==
"MucCal")&&(m_bossver[4]==
"default" ))
647 std::string cType=
"Muc";
648 if(m_bossRelease==
"default")
650 log << MSG::FATAL <<
" Boss Release for MucCal not set!" << endreq;
655 st1=
getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,
runNo,m_bossRelease,cType);
657 if (st1 .isFailure() )
659 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
666 else if((cType==
"MucCal")&&(m_bossver[4]!=
"default" ))
676 if((cType==
"EsTimeCal")&&(m_bossver[5]==
"default" ))
678 std::string cType=
"EsTime";
679 if(m_bossRelease==
"default")
681 log << MSG::FATAL <<
" Boss Release for EsTimeCal not set!" << endreq;
686 st1=
getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,
runNo,m_bossRelease,cType);
688 if (st1 .isFailure() )
690 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
697 else if((cType==
"EsTimeCal")&&(m_bossver[5]!=
"default" ))
707 if((cType==
"MdcAlign")&&(m_bossver[7]==
"default" ))
709 std::string cType=
"MdcAlign";
710 if(m_bossRelease==
"default") {
711 log << MSG::FATAL <<
" Boss Release for MdcAlignCal not set!" << endreq;
715 st1=
getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,
runNo,m_bossRelease,cType);
717 if (st1 .isFailure() ) {
718 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
725 else if((cType==
"MdcAlign")&&(m_bossver[7]!=
"default" ))
735 if((cType==
"TofQElec")&&(m_bossver[8]==
"default" ))
737 std::string cType=
"TofQElec";
738 if(m_bossRelease==
"default") {
739 log << MSG::FATAL <<
" Boss Release for TofQElecCal not set!" << endreq;
744 st1=
getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,
runNo,m_bossRelease,cType);
746 if (st1 .isFailure() ) {
747 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
754 else if((cType==
"TofQElec")&&(m_bossver[8]!=
"default" ))
764 if((cType==
"TofSim")&&(m_bossver[9]==
"default" ))
766 std::string cType=
"TofSim";
767 if(m_bossRelease==
"default") {
768 log << MSG::FATAL <<
" Boss Release for TofSimCal not set!" << endreq;
772 st1=
getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,
runNo,m_bossRelease,cType);
774 if (st1 .isFailure() ) {
775 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
782 else if((cType==
"TofSim")&&(m_bossver[9]!=
"default" ))
792 if((cType==
"DedxSim")&&(m_bossver[10]==
"default" ))
794 std::string cType=
"DedxSim";
795 if(m_bossRelease==
"default") {
796 log << MSG::FATAL <<
" Boss Release for DedxSimCal not set!" << endreq;
800 st1=
getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,
runNo,m_bossRelease,cType);
802 if (st1 .isFailure() ) {
803 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
810 else if((cType==
"DedxSim")&&(m_bossver[10]!=
"default" ))
820 if((cType==
"MdcDataConst")&&(m_bossver[11]==
"default" ))
822 std::string cType=
"MdcData";
823 if(m_bossRelease==
"default") {
824 log << MSG::FATAL <<
" Boss Release for MdcDataConst not set!" << endreq;
828 st1=
getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,
runNo,m_bossRelease,cType);
830 if (st1 .isFailure() ) {
831 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
838 else if((cType==
"MdcDataConst")&&(m_bossver[11]!=
"default" ))
848 if((cType==
"EstTofCal")&&(m_bossver[6]==
"default" ))
850 std::string cType=
"EsTof";
851 if(m_bossRelease==
"default") {
852 log << MSG::FATAL <<
" Boss Release for EstTofCal not set!" << endreq;
856 st1=
getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,
runNo,m_bossRelease,cType);
858 if (st1 .isFailure() ) {
859 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
866 else if((cType==
"EstTofCal")&&(m_bossver[6]!=
"default" ))
876 if((cType==
"InjSigInterval")&&(m_bossver[12]==
"default" ))
878 std::string cType=
"InjSigInterval";
879 if(m_bossRelease==
"default")
881 log << MSG::FATAL <<
" Boss Release for InjSigInterval not set!" << endreq;
886 st1=
getSftParVer(m_bossver[12],m_calPar[12],runfrm1,runto1,
runNo,m_bossRelease,cType);
888 if (st1 .isFailure() )
890 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
897 else if((cType==
"InjSigInterval")&&(m_bossver[12]!=
"default"))
907 if((cType==
"InjSigTime")&&(m_bossver[13]==
"default" ))
909 std::string cType=
"InjSigTime";
910 if(m_bossRelease==
"default")
912 log << MSG::FATAL <<
" Boss Release for InjSigTime not set!" << endreq;
917 st1=
getSftParVer(m_bossver[13],m_calPar[13],runfrm1,runto1,
runNo,m_bossRelease,cType);
919 if (st1 .isFailure() )
921 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
928 else if((cType==
"InjSigTime")&&(m_bossver[13]!=
"default"))
938 if((cType==
"OffEvtFilter")&&(m_bossver[14]==
"default" ))
940 std::string cType=
"OffEvtFilter";
941 if(m_bossRelease==
"default")
943 log << MSG::FATAL <<
" Boss Release for OffEvtFilter not set!" << endreq;
948 st1=
getSftParVer(m_bossver[14],m_calPar[14],runfrm1,runto1,
runNo,m_bossRelease,cType);
950 if (st1 .isFailure() )
952 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
959 else if((cType==
"OffEvtFilter")&&(m_bossver[14]!=
"default"))
969 if(cType==
"CorrectedETS")
971 std::string cType=
"CorrectedETS";
975 int _strlenRun = strlen((*res[0])[
"Run"]) + 1;
976 char* _pStatus =
new char[3];
977 char* _pRunFrom =
new char[_strlenRun];
978 char* _pRunTo =
new char[_strlenRun];
979 memcpy(_pStatus,
"OK", 3);
980 memcpy(_pRunFrom, (*res[0])[
"Run"], _strlenRun);
981 memcpy(_pRunTo, (*res[0])[
"Run"], _strlenRun);
983 (*res[0])[
"Status"] = _pStatus;
984 (*res[0])[
"RunFrom"] = _pRunFrom;
985 (*res[0])[
"RunTo"] = _pRunTo;
991 log << MSG::ERROR <<
"no record in the database" << endreq;
996 if(m_dbStatus==
"OK"){
997 if(std::string((*records1)[
"Status"])!=
"OK") {
998 log<<MSG::FATAL<<
"Status of type "<<cType<<
" is "<< (*records1)[
"Status"]<<
" your setting is OK"<<endreq;
1003 log << MSG::DEBUG <<
"dataIdent is:"<<dataIdent<< endreq;
1004 unsigned char storageType;
1013 log << MSG::DEBUG <<
"Creating an address of type "
1014 << (int)storageType <<
" for class " << classID << endreq;
1016 IOpaqueAddress* tmpAddress;
1017 const std::string par[3] = {dataIdent, fullpath, fmtVersion};
1020 const unsigned long ipar[2] = {0,0};
1025 tmpAddress =
new TreeAddress(storageType, classID,*records1,ipar);
1028 sscanf((*records1)[
"RunFrom"],
"%d", &runfrm);
1029 sscanf((*records1)[
"RunTo"],
"%d", &runto);
1030 log << MSG::DEBUG << __LINE__<<
" records @ runfrm is:"<<(*records1)[
"RunFrom"]<<
" runto is:"<<(*records1)[
"RunTo"]<<
" ser_no is:"<<ser<<endreq;
1047 log << MSG::DEBUG <<__LINE__<<
" runfrm of max is:"<<runfrm<<
" runto min is:"<<runto<<endreq;
1063 tmpAddress->addRef();
1066 tmpAddress->setRegistry(entry);
1069 sc = m_detPersSvc->createObj(tmpAddress, refpObject);
1070 tmpAddress->release();
1071 if ( !sc.isSuccess() ) {
1073 <<
"Persistency service could not create a new object" << endreq;
1075 log << msgLevel << std::endl <<
"Exiting... " << std::endl << endreq;
1082 log << MSG::DEBUG <<
"New object successfully created" << endreq;
1083 return StatusCode::SUCCESS;
1100 const std::string& fullpath,
1101 const CLID& classID,
1106 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
1109 std::string testfile = std::string(getenv(
"CALIBMYSQLCNVROOT"))+
"/share/test.root";
1110 TFile *f1=
new TFile(testfile.c_str(),
"read");
1118 if (std::string(
"Test") == cType.substr(0, 4)) {
1119 cType = std::string(
"Test_Gen");
1123 log << MSG::ERROR <<
"There is no DataObject to update" << endreq;
1124 return StatusCode::FAILURE;
1127 if(pObject->clID()!=6411&& classID!=6411){
1128 if ( classID != pObject->clID() ) {
1129 log << MSG::ERROR <<
"Update requested for clID " << classID
1130 <<
" while DataObject is of clID "
1131 << pObject->clID() << endreq;
1133 return StatusCode::FAILURE;
1142 <<
"Object to be updated is not a calib object! " << endreq;
1143 return StatusCode::FAILURE;
1150 int runto,runto1,FirstEvent;
1154 std::string physFmt;
1155 std::string fmtVersion;
1156 std::string dataIdent;
1157 std::string
flag=
"default";
1165 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
1168 log << MSG::WARNING <<
"Unable to read the Event for TDS" << endreq;
1177 if(cType!=
"TofCal"&&cType!=
"EstTofCal"&&cType!=
"TofSim"&&cType!=
"DedxSim")
runNo = fabs(evt -> runNumber());
1178 if(cType==
"TofCal"||cType==
"EstTofCal"||cType==
"TofSim"||cType==
"DedxSim")
runNo = evt -> runNumber();
1179 FirstEvent = evt -> eventNumber();
1183 if((cType==
"TofCal"))
1185 std::string cType=
"Tof";
1186 if(m_flag[3]==
"default")
1188 st1=
getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,
runNo,m_bossRelease,cType);
1189 cout<<cType<<
" runfrm1,runto1 @update is:"<<runfrm1<<
":::"<<runto1<<endl;
1190 if (st1 .isFailure() )
1192 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1206 if((cType==
"EmcCal"))
1208 std::string cType=
"Emc";
1209 if(m_flag[2]==
"default")
1211 st1=
getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,
runNo,m_bossRelease,cType);
1213 if (st1 .isFailure() )
1215 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1228 if((cType==
"DedxCal"))
1230 std::string cType=
"Dedx";
1231 if(m_flag[1]==
"default")
1233 st1=
getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,
runNo,m_bossRelease,cType);
1235 if (st1 .isFailure() )
1237 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1247 if((cType==
"MdcCal"))
1249 std::string cType=
"Mdc";
1250 if(m_flag[0]==
"default")
1253 st1=
getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,
runNo,m_bossRelease,cType);
1255 if (st1 .isFailure() )
1257 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1268 if((cType==
"MucCal"))
1270 std::string cType=
"Muc";
1271 if(m_flag[4]==
"default")
1273 st1=
getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,
runNo,m_bossRelease,cType);
1275 if (st1 .isFailure() )
1277 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1287 if((cType==
"EsTimeCal"))
1289 std::string cType=
"EsTime";
1290 if(m_flag[5]==
"default")
1292 st1=
getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,
runNo,m_bossRelease,cType);
1294 if (st1 .isFailure() )
1296 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1306 if((cType==
"MdcAlign"))
1308 std::string cType=
"MdcAlign";
1309 if(m_flag[7]==
"default")
1311 st1=
getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,
runNo,m_bossRelease,cType);
1313 if (st1 .isFailure() ) {
1314 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1324 if((cType==
"TofQElec"))
1326 std::string cType=
"TofQElec";
1327 if(m_flag[8]==
"default")
1330 st1=
getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,
runNo,m_bossRelease,cType);
1340 if((cType==
"TofSim"))
1342 std::string cType=
"TofSim";
1343 if(m_flag[9]==
"default")
1345 st1=
getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,
runNo,m_bossRelease,cType);
1347 if (st1 .isFailure() ) {
1348 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1359 if((cType==
"DedxSim"))
1361 std::string cType=
"DedxSim";
1362 if(m_flag[10]==
"default")
1364 st1=
getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,
runNo,m_bossRelease,cType);
1366 if (st1 .isFailure() ) {
1367 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1378 if((cType==
"MdcDataConst"))
1380 std::string cType=
"MdcData";
1381 if(m_flag[11]==
"default")
1383 st1=
getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,
runNo,m_bossRelease,cType);
1385 if (st1 .isFailure() ) {
1386 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1397 if(cType==
"InjSigInterval")
1399 std::string cType=
"InjSigInterval";
1400 if(m_flag[12]==
"default")
1402 st1=
getSftParVer(m_bossver[12],m_calPar[12],runfrm1,runto1,
runNo,m_bossRelease,cType);
1403 if (st1 .isFailure() ) {
1404 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1412 if(cType==
"InjSigTime")
1414 std::string cType=
"InjSigTime";
1415 if(m_flag[13]==
"default")
1417 st1=
getSftParVer(m_bossver[13],m_calPar[13],runfrm1,runto1,
runNo,m_bossRelease,cType);
1418 if (st1 .isFailure() ) {
1419 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1427 if(cType==
"OffEvtFilter")
1429 std::string cType=
"OffEvtFilter";
1430 if(m_flag[14]==
"default")
1432 st1=
getSftParVer(m_bossver[14],m_calPar[14],runfrm1,runto1,
runNo,m_bossRelease,cType);
1433 if (st1 .isFailure() ) {
1434 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1442 if(cType==
"CorrectedETS")
1444 std::string cType=
"CorrectedETS";
1447 int _strlenRun = strlen((*res[0])[
"Run"]) + 1;
1448 char* _pStatus =
new char[3];
1449 char* _pRunFrom =
new char[_strlenRun];
1450 char* _pRunTo =
new char[_strlenRun];
1451 memcpy(_pStatus,
"OK", 3);
1452 memcpy(_pRunFrom, (*res[0])[
"Run"], _strlenRun);
1453 memcpy(_pRunTo, (*res[0])[
"Run"], _strlenRun);
1455 (*res[0])[
"Status"] = _pStatus;
1456 (*res[0])[
"RunFrom"] = _pRunFrom;
1457 (*res[0])[
"RunTo"] = _pRunTo;
1464 if((cType==
"EstTofCal"))
1466 std::string cType=
"EsTof";
1467 if(m_flag[6]==
"default")
1469 st1=
getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,
runNo,m_bossRelease,cType);
1471 if (st1 .isFailure() ) {
1472 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1483 log << MSG::ERROR <<
"Error searching in the database" << endreq;
1488 unsigned char storageType;
1495 log << MSG::DEBUG <<
"Creating an address of type "
1496 << (int)storageType <<
" for class " << classID << endreq;
1501 if(m_dbStatus==
"OK"){
1502 if(std::string((*records1)[
"Status"])!=
"OK") {
1503 log<<MSG::FATAL<<
"the status of type "<<cType<<
" is "<< (*records1)[
"Status"]<<
" your setting is OK"<<endreq;
1509 IOpaqueAddress* tmpAddress;
1511 const unsigned long ipar[2] = {0,0};
1513 tmpAddress =
new TreeAddress(storageType, classID,*records1,ipar);
1515 sscanf((*records1)[
"RunFrom"],
"%d", &runfrm);
1516 sscanf((*records1)[
"RunTo"],
"%d", &runto);
1517 log << MSG::DEBUG << __LINE__<<
" records @update runfrm is:"<<(*records1)[
"RunFrom"]<<
" runto is:"<<(*records1)[
"RunTo"]<<
" ser_no is:"<<ser<<endreq;
1534 log << MSG::DEBUG <<__LINE__<<
" runfrm of max is:"<<runfrm<<
" runto min is:"<<runto<<endreq;
1541 log << MSG::DEBUG <<
"Temporary address successfully created" << endreq;
1542 tmpAddress->addRef();
1545 tmpAddress->setRegistry(entry);
1548 DataObject* pNewObject;
1549 status = m_detPersSvc->createObj(tmpAddress, pNewObject);
1550 tmpAddress->release();
1551 if ( !status.isSuccess() ) {
1553 <<
"Persistency service could not create object" << endreq;
1563 if (0 == pNewBase) {
1565 <<
"Cannot update objects other than Calib objects: "
1566 <<
"update() must be defined!"
1568 return StatusCode::FAILURE;
1576 pBase->
update(*pNewBase, &log);
1581 return StatusCode::SUCCESS;
1585 unsigned char& type )
1587 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
1590 if (description == std::string(
"XML")) {
1591 type = XML_StorageType;
1593 else if (description == std::string(
"ROOT")) {
1596 else if (description == std::string(
"TREE")) {
1600 log << MSG::ERROR <<
"unsupported storage type " << description << endreq;
1601 return StatusCode::FAILURE;
1603 return StatusCode::SUCCESS;
unsigned const char CALIBROOT_StorageType
unsigned const char CALIBTREE_StorageType
struct st_mysql_res MYSQL_RES
virtual StatusCode update(CalibBase1 &obj, MsgStream *)
static std::string getCalibType(const std::string &fullpath)
Return calibration type name, extracted from full path name in TCDS.
virtual StatusCode finalize()
virtual StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject)
Update a converted representation of a transient object.
virtual StatusCode decodeDescription(const std::string &description, unsigned char &type)
Decode the string storage type to enumerated storage type.
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Resolve the references of the created transient object.
virtual StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject)
Create a transient representation from another rep of this object.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
Create an address using explicit arguments to identify a single object.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert a transient object to a requested representation.
virtual StatusCode createCalib(DataObject *&refpObject, const std::string &fullpath, const CLID &classID, IRegistry *entry=0)
virtual StatusCode updateCalib(DataObject *pObject, const std::string &fullpath, const CLID &classID, IRegistry *entry=0)
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Resolve the references of a converted object.
StatusCode getSftParVer(std::string &SftVer, std::string &CalParVer, int &runfrm, int &runto, int RunNo, std::string BossRelease, std::string DataType)
virtual StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Update the references of an updated transient object.
CalibMySQLCnvSvc(const std::string &name, ISvcLocator *svc)
virtual calibUtil::Metadata * getMeta()
Handle to the MySQL metadata database.
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *pObject)
Update a transient representation from another rep of this object.
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual ~CalibMySQLCnvSvc()
virtual StatusCode initialize()
virtual StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject)
Update the references of an already converted object.
int GetInt(std::string key)
std::string GetString(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
void setRunFrom(int runFrom)
set run from
void setRunTo(int runTo)
set run to
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)