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"
47 unsigned int toQualityMask(std::vector<std::string>& qualities) {
50 unsigned int mask = 0;
51 unsigned n = qualities.size();
53 for (
unsigned i = 0; i <
n; i++) {
54 std::string iString = qualities[i];
55 if (iString.size() < 3)
continue;
57 if (iString ==
"PRO") mask |= Metadata::LEVELProd;
58 else if (iString ==
"DEV") mask |= Metadata::LEVELDev;
59 else if (iString ==
"TES") mask |= Metadata::LEVELTest;
60 else if (iString ==
"SUP") mask |= Metadata::LEVELSuperseded;
67 : ConversionSvc (name, svc, MYSQL_StorageType)
68 , m_meta(0), m_useEventTime(
true),m_enterTimeStart(0), m_enterTimeEnd(0),
72 declareProperty(
"Host", m_host =
"bes3db2.ihep.ac.cn");
73 declareProperty(
"UseEventTime", m_useEventTime =
true);
74 declareProperty(
"EnterTimeEnd", m_enterTimeEndString = std::string(
"") );
75 declareProperty(
"EnterTimeStart", m_enterTimeStartString = std::string(
"") );
77 declareProperty(
"DbName", m_dbName = std::string(
"offlinedb") );
78 declareProperty(
"QualityList", m_qualityList);
79 declareProperty(
"CrashOnError", m_crash =
true);
80 declareProperty(
"Sft_Ver",sft_ver);
81 declareProperty(
"Cal_Ver",cal_ver);
82 declareProperty(
"MdcFlag",m_flag[0]=
"default");
83 declareProperty(
"DeDxFlag",m_flag[1]=
"default");
84 declareProperty(
"EmcFlag",m_flag[2]=
"default");
85 declareProperty(
"TofFlag",m_flag[3]=
"default");
86 declareProperty(
"MucFlag",m_flag[4]=
"default");
87 declareProperty(
"EsTimeFlag",m_flag[5]=
"default");
88 declareProperty(
"EstTofFlag",m_flag[6]=
"default");
89 declareProperty(
"MdcAlignFlag",m_flag[7]=
"default");
90 declareProperty(
"TofQElecFlag",m_flag[8]=
"default");
91 declareProperty(
"TofSimPFlag",m_flag[9]=
"default");
92 declareProperty(
"DedxSimFlag",m_flag[10]=
"default");
93 declareProperty(
"MdcDataFlag",m_flag[11]=
"default");
95 declareProperty(
"InjSigIntervalFlag",m_flag[12]=
"default");
96 declareProperty(
"InjSigTimeFlag",m_flag[13]=
"default");
97 declareProperty(
"OffEvtFilterFlag",m_flag[14]=
"default");
98 declareProperty(
"CorrectedETSFlag",m_flag[15]=
"default");
100 declareProperty(
"MdcCalPar",m_calPar[0]=
"default");
101 declareProperty(
"DeDxCalPar",m_calPar[1]=
"default");
102 declareProperty(
"EmcCalPar",m_calPar[2]=
"default");
103 declareProperty(
"TofCalPar",m_calPar[3]=
"default");
104 declareProperty(
"MucCalPar",m_calPar[4]=
"default");
105 declareProperty(
"EsTimeCalPar",m_calPar[5]=
"default");
106 declareProperty(
"EstTofCalPar",m_calPar[6]=
"default");
107 declareProperty(
"MdcAlignPar",m_calPar[7]=
"default");
108 declareProperty(
"TofQElecPar",m_calPar[8]=
"default");
109 declareProperty(
"TofSimPar",m_calPar[9]=
"default");
110 declareProperty(
"DedxSimPar",m_calPar[10]=
"default");
111 declareProperty(
"MdcDataConstVer",m_calPar[11]=
"default");
113 declareProperty(
"InjSigIntervalPar",m_calPar[12]=
"default");
114 declareProperty(
"InjSigTimePar",m_calPar[13]=
"default");
115 declareProperty(
"OffEvtFilterPar",m_calPar[14]=
"default");
116 declareProperty(
"CorrectedETSPar",m_calPar[15]=
"default");
118 declareProperty(
"MdcBossVer",m_bossver[0]=
"default");
119 declareProperty(
"DeDxBossVer",m_bossver[1]=
"default");
120 declareProperty(
"EmcBossVer",m_bossver[2]=
"default");
121 declareProperty(
"TofBossVer",m_bossver[3]=
"default");
122 declareProperty(
"MucBossVer",m_bossver[4]=
"default");
123 declareProperty(
"EsTimeBossVer",m_bossver[5]=
"default");
124 declareProperty(
"EstTofBossVer",m_bossver[6]=
"default");
125 declareProperty(
"MdcAlignBossVer",m_bossver[7]=
"default");
126 declareProperty(
"TofQElecBossVer",m_bossver[8]=
"default");
127 declareProperty(
"TofSimBossVer",m_bossver[9]=
"default");
128 declareProperty(
"DedxSimBossVer",m_bossver[10]=
"default");
129 declareProperty(
"MdcDataConstBossVer",m_bossver[11]=
"default");
130 declareProperty(
"InjSigIntervalBossVer",m_bossver[12]=
"default");
131 declareProperty(
"InjSigTimeBossVer",m_bossver[13]=
"default");
132 declareProperty(
"OffEvtFilterBossVer",m_bossver[14]=
"default");
133 declareProperty(
"Align_RunNo",m_MdcAlign_No=8093);
134 declareProperty(
"Db_Status",m_dbStatus=
"OK");
135 declareProperty(
"BossRelease",m_bossRelease=
"default");
143 StatusCode sc = ConversionSvc::initialize();
144 if ( !sc.isSuccess() )
return sc;
146 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
147 log << MSG::INFO <<
"Specific initialization starting" << endreq;
149 IDataProviderSvc* pCDS = 0;
150 sc = serviceLocator()->getService (
"CalibDataSvc", IDataProviderSvc::interfaceID(), (IInterface*&)pCDS);
152 if ( !sc.isSuccess() ) {
153 log << MSG::ERROR <<
"Could not locate CalibDataSvc" << endreq;
157 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
158 if (sc .isFailure() ) {
159 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
164 sc = setDataProvider(pCDS);
165 if ( !sc.isSuccess() ) {
166 log << MSG::ERROR <<
"Could not set data provider" << endreq;
172 sc = serviceLocator()->service
173 (
"DetectorPersistencySvc", m_detPersSvc,
true);
174 if ( !sc.isSuccess() ) {
176 <<
"Cannot locate IConversionSvc interface of DetectorPersistencySvc"
181 <<
"Retrieved IConversionSvc interface of DetectorPersistencySvc"
185 IAddressCreator* iAddrCreator;
186 sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(),(
void**) &iAddrCreator);
188 if ( !sc.isSuccess() ) {
189 log << MSG::ERROR <<
"Could not locate CalibDataSvc" << endreq;
193 sc = setAddressCreator(iAddrCreator);
194 if ( !sc.isSuccess() ) {
195 log << MSG::ERROR <<
"Cannot set the address creator" << endreq;
200 sc = setProperties();
201 if ( !sc.isSuccess() ) {
202 log << MSG::ERROR <<
"Could not set jobOptions properties" << endreq;
205 log << MSG::DEBUG <<
"Properties were read from jobOptions" << endreq;
210 m_qualityMask = toQualityMask(m_qualityList);
211 if (!m_qualityMask) {
223 log << MSG::ERROR <<
"Could not open connection to metadata dbs" << endreq;
231 log << MSG::INFO <<
"Specific initialization completed" << endreq;
238 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
239 log << MSG::DEBUG <<
"Finalizing" << endreq;
242 return ConversionSvc::finalize();
265 DataObject*& refpObject ) {
267 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
279 pAddress->registry() );
281 if ( !sc.isSuccess() ) {
282 log << MSG::ERROR <<
"Could not create calib DataObject" << endreq;
284 log << MSG::DEBUG <<
"Method createObj exiting" << endreq;
294 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
295 return StatusCode::SUCCESS;
302 DataObject* pObject ) {
306 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
309 log << MSG::DEBUG <<
"CalibMySQLCnvSvc::updateObj starting ...."<<endreq;
312 log << MSG::ERROR <<
"There is no object to update" << endreq;
313 return StatusCode::FAILURE;
316 StatusCode sc =
updateCalib(pObject, pAddress->par()[0],
317 pAddress->clID(), pAddress->registry() );
318 if ( !sc.isSuccess() ) {
319 log << MSG::ERROR <<
"Could not update calib DataObject" << endreq;
323 return StatusCode::SUCCESS;
331 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
332 return StatusCode::SUCCESS;
341 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
343 return StatusCode::SUCCESS;
352 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
354 return StatusCode::SUCCESS;
362 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
364 return StatusCode::SUCCESS;
373 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
375 return StatusCode::SUCCESS;
383 const std::string* par,
384 const unsigned long* ,
385 IOpaqueAddress*& refpAddress ) {
387 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
388 if ( svc_type!= MYSQL_StorageType ) {
390 <<
"Cannot create addresses of type " << (int)svc_type
391 <<
" which is different from " << (
int)MYSQL_StorageType
393 return StatusCode::FAILURE;
396 <<
" create address in CalibMySQLCnvSvc "
399 refpAddress =
new GenericAddress( MYSQL_StorageType,
403 return StatusCode::SUCCESS;
408 std::string& CalParVer,
412 std::string BossRelease,
417 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
423 StatusCode sc=serviceLocator()->service(
"DatabaseSvc",m_dbsvc,
true);
424 if (sc .isFailure() ) {
425 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
428 const char* bossRelease = BossRelease.c_str();
429 const char* dataType = DataType.c_str();
431 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);
433 int row_no = m_dbsvc->
query(
"offlinedb",stmt,res);
435 std::cout<<
"ERROR:error searching with:"<<stmt<<std::endl;
440 runfrm=records1->
GetInt(
"RunFrom");
441 runto=records1->
GetInt(
"RunTo");
442 cout<<dataType<<
" runfrm,runto in getSftParVer is:"<<runfrm<<
"::::"<<runto<<endl;
447 cout<<
"ERROR: "<<dataType<<
" set overlapped run number in the table CalVtxLumVer"<<endl;
451 return StatusCode::SUCCESS;
468 const std::string& fullpath,
472 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
478 if (std::string(
"Test") == cType.substr(0, 4)) {
479 cType = std::string(
"Test_Gen");
482 std::string testfile = std::string(getenv(
"CALIBMYSQLCNVROOT"))+
"/share/test.root";
483 TFile *
f1=
new TFile(testfile.c_str(),
"read");
484 unsigned int ser = 0;
488 std::string
flag=
"default";
491 MSG::Level msgLevel = MSG::DEBUG;
493 std::string physFmt =
"UNK";
494 std::string fmtVersion;
495 std::string dataIdent;
498 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
499 int runNo=0,FirstEvent=0;
501 log << MSG::WARNING <<
"Unable to read the Event for TDS" << endreq;
505 if(cType!=
"TofCal"&&cType!=
"EstTofCal"&&cType!=
"TofSim"&&cType!=
"DedxSim")
runNo = fabs(evt -> runNumber());
506 if(cType==
"TofCal"||cType==
"EstTofCal"||cType==
"TofSim"||cType==
"DedxSim")
runNo = evt -> runNumber();
507 FirstEvent = evt -> eventNumber();
514 if((cType==
"TofCal")&&(m_bossver[3]==
"default" ))
516 std::string cType=
"Tof";
517 if(m_bossRelease==
"default")
519 log << MSG::FATAL <<
" Boss Release for TofCal not set!" << endreq;
525 st1=
getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,
runNo,m_bossRelease,cType);
527 if (st1 .isFailure() )
529 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
538 else if ((cType==
"TofCal")&&(m_bossver[3]!=
"default" ))
549 if((cType==
"EmcCal")&&(m_bossver[2]==
"default" ))
551 std::string cType=
"Emc";
552 if(m_bossRelease==
"default")
554 log << MSG::FATAL <<
" Boss Release for EmcCal not set!" << endreq;
559 st1=
getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,
runNo,m_bossRelease,cType);
562 if (st1 .isFailure() )
564 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
571 else if((cType==
"EmcCal")&&(m_bossver[2]!=
"default" ))
581 if((cType==
"DedxCal")&&(m_bossver[1]==
"default" ))
583 std::string cType=
"Dedx";
584 if(m_bossRelease==
"default")
586 log << MSG::FATAL <<
" Boss Release for DedxCal not set!" << endreq;
591 st1=
getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,
runNo,m_bossRelease,cType);
593 if (st1 .isFailure() )
595 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
602 else if((cType==
"DedxCal")&&(m_bossver[1]!=
"default" ))
612 if((cType==
"MdcCal")&&(m_bossver[0]==
"default" ))
614 std::string cType=
"Mdc";
616 if(m_bossRelease==
"default")
618 log << MSG::FATAL <<
" Boss Release for MdcCal not set!" << endreq;
623 st1=
getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,
runNo,m_bossRelease,cType);
625 if (st1 .isFailure() )
627 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
635 else if((cType==
"MdcCal")&&(m_bossver[0]!=
"default"))
646 if((cType==
"MucCal")&&(m_bossver[4]==
"default" ))
648 std::string cType=
"Muc";
649 if(m_bossRelease==
"default")
651 log << MSG::FATAL <<
" Boss Release for MucCal not set!" << endreq;
656 st1=
getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,
runNo,m_bossRelease,cType);
658 if (st1 .isFailure() )
660 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
667 else if((cType==
"MucCal")&&(m_bossver[4]!=
"default" ))
677 if((cType==
"EsTimeCal")&&(m_bossver[5]==
"default" ))
679 std::string cType=
"EsTime";
680 if(m_bossRelease==
"default")
682 log << MSG::FATAL <<
" Boss Release for EsTimeCal not set!" << endreq;
687 st1=
getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,
runNo,m_bossRelease,cType);
689 if (st1 .isFailure() )
691 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
698 else if((cType==
"EsTimeCal")&&(m_bossver[5]!=
"default" ))
708 if((cType==
"MdcAlign")&&(m_bossver[7]==
"default" ))
710 std::string cType=
"MdcAlign";
711 if(m_bossRelease==
"default") {
712 log << MSG::FATAL <<
" Boss Release for MdcAlignCal not set!" << endreq;
716 st1=
getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,
runNo,m_bossRelease,cType);
718 if (st1 .isFailure() ) {
719 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
726 else if((cType==
"MdcAlign")&&(m_bossver[7]!=
"default" ))
736 if((cType==
"TofQElec")&&(m_bossver[8]==
"default" ))
738 std::string cType=
"TofQElec";
739 if(m_bossRelease==
"default") {
740 log << MSG::FATAL <<
" Boss Release for TofQElecCal not set!" << endreq;
745 st1=
getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,
runNo,m_bossRelease,cType);
747 if (st1 .isFailure() ) {
748 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
755 else if((cType==
"TofQElec")&&(m_bossver[8]!=
"default" ))
765 if((cType==
"TofSim")&&(m_bossver[9]==
"default" ))
767 std::string cType=
"TofSim";
768 if(m_bossRelease==
"default") {
769 log << MSG::FATAL <<
" Boss Release for TofSimCal not set!" << endreq;
773 st1=
getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,
runNo,m_bossRelease,cType);
775 if (st1 .isFailure() ) {
776 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
783 else if((cType==
"TofSim")&&(m_bossver[9]!=
"default" ))
793 if((cType==
"DedxSim")&&(m_bossver[10]==
"default" ))
795 std::string cType=
"DedxSim";
796 if(m_bossRelease==
"default") {
797 log << MSG::FATAL <<
" Boss Release for DedxSimCal not set!" << endreq;
801 st1=
getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,
runNo,m_bossRelease,cType);
803 if (st1 .isFailure() ) {
804 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
811 else if((cType==
"DedxSim")&&(m_bossver[10]!=
"default" ))
821 if((cType==
"MdcDataConst")&&(m_bossver[11]==
"default" ))
823 std::string cType=
"MdcData";
824 if(m_bossRelease==
"default") {
825 log << MSG::FATAL <<
" Boss Release for MdcDataConst not set!" << endreq;
829 st1=
getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,
runNo,m_bossRelease,cType);
831 if (st1 .isFailure() ) {
832 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
839 else if((cType==
"MdcDataConst")&&(m_bossver[11]!=
"default" ))
849 if((cType==
"EstTofCal")&&(m_bossver[6]==
"default" ))
851 std::string cType=
"EsTof";
852 if(m_bossRelease==
"default") {
853 log << MSG::FATAL <<
" Boss Release for EstTofCal not set!" << endreq;
857 st1=
getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,
runNo,m_bossRelease,cType);
859 if (st1 .isFailure() ) {
860 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
867 else if((cType==
"EstTofCal")&&(m_bossver[6]!=
"default" ))
877 if((cType==
"InjSigInterval")&&(m_bossver[12]==
"default" ))
879 std::string cType=
"InjSigInterval";
880 if(m_bossRelease==
"default")
882 log << MSG::FATAL <<
" Boss Release for InjSigInterval not set!" << endreq;
887 st1=
getSftParVer(m_bossver[12],m_calPar[12],runfrm1,runto1,
runNo,m_bossRelease,cType);
889 if (st1 .isFailure() )
891 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
898 else if((cType==
"InjSigInterval")&&(m_bossver[12]!=
"default"))
908 if((cType==
"InjSigTime")&&(m_bossver[13]==
"default" ))
910 std::string cType=
"InjSigTime";
911 if(m_bossRelease==
"default")
913 log << MSG::FATAL <<
" Boss Release for InjSigTime not set!" << endreq;
918 st1=
getSftParVer(m_bossver[13],m_calPar[13],runfrm1,runto1,
runNo,m_bossRelease,cType);
920 if (st1 .isFailure() )
922 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
929 else if((cType==
"InjSigTime")&&(m_bossver[13]!=
"default"))
939 if((cType==
"OffEvtFilter")&&(m_bossver[14]==
"default" ))
941 std::string cType=
"OffEvtFilter";
942 if(m_bossRelease==
"default")
944 log << MSG::FATAL <<
" Boss Release for OffEvtFilter not set!" << endreq;
949 st1=
getSftParVer(m_bossver[14],m_calPar[14],runfrm1,runto1,
runNo,m_bossRelease,cType);
951 if (st1 .isFailure() )
953 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
960 else if((cType==
"OffEvtFilter")&&(m_bossver[14]!=
"default"))
970 if(cType==
"CorrectedETS")
972 std::string cType=
"CorrectedETS";
976 int _strlenRun = strlen((*res[0])[
"Run"]) + 1;
977 char* _pStatus =
new char[3];
978 char* _pRunFrom =
new char[_strlenRun];
979 char* _pRunTo =
new char[_strlenRun];
980 memcpy(_pStatus,
"OK", 3);
981 memcpy(_pRunFrom, (*res[0])[
"Run"], _strlenRun);
982 memcpy(_pRunTo, (*res[0])[
"Run"], _strlenRun);
984 (*res[0])[
"Status"] = _pStatus;
985 (*res[0])[
"RunFrom"] = _pRunFrom;
986 (*res[0])[
"RunTo"] = _pRunTo;
992 log << MSG::ERROR <<
"no record in the database" << endreq;
997 if(m_dbStatus==
"OK"){
998 if(std::string((*records1)[
"Status"])!=
"OK") {
999 log<<MSG::FATAL<<
"Status of type "<<cType<<
" is "<< (*records1)[
"Status"]<<
" your setting is OK"<<endreq;
1004 log << MSG::DEBUG <<
"dataIdent is:"<<dataIdent<< endreq;
1005 unsigned char storageType;
1014 log << MSG::DEBUG <<
"Creating an address of type "
1015 << (int)storageType <<
" for class " << classID << endreq;
1017 IOpaqueAddress* tmpAddress;
1018 const std::string par[3] = {dataIdent, fullpath, fmtVersion};
1021 const unsigned long ipar[2] = {0,0};
1026 tmpAddress =
new TreeAddress(storageType, classID,*records1,ipar);
1029 sscanf((*records1)[
"RunFrom"],
"%d", &runfrm);
1030 sscanf((*records1)[
"RunTo"],
"%d", &runto);
1031 log << MSG::DEBUG << __LINE__<<
" records @ runfrm is:"<<(*records1)[
"RunFrom"]<<
" runto is:"<<(*records1)[
"RunTo"]<<
" ser_no is:"<<ser<<endreq;
1048 log << MSG::DEBUG <<__LINE__<<
" runfrm of max is:"<<runfrm<<
" runto min is:"<<runto<<endreq;
1064 tmpAddress->addRef();
1067 tmpAddress->setRegistry(entry);
1070 sc = m_detPersSvc->createObj(tmpAddress, refpObject);
1071 tmpAddress->release();
1072 if ( !sc.isSuccess() ) {
1074 <<
"Persistency service could not create a new object" << endreq;
1076 log << msgLevel << std::endl <<
"++++CalibMySQLCnvSvc Exiting... " << std::endl << endreq;
1083 log << MSG::DEBUG <<
"New object successfully created" << endreq;
1084 return StatusCode::SUCCESS;
1101 const std::string& fullpath,
1102 const CLID& classID,
1107 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc" );
1110 std::string testfile = std::string(getenv(
"CALIBMYSQLCNVROOT"))+
"/share/test.root";
1111 TFile *
f1=
new TFile(testfile.c_str(),
"read");
1119 if (std::string(
"Test") == cType.substr(0, 4)) {
1120 cType = std::string(
"Test_Gen");
1124 log << MSG::ERROR <<
"There is no DataObject to update" << endreq;
1125 return StatusCode::FAILURE;
1128 if(pObject->clID()!=6411&& classID!=6411){
1129 if ( classID != pObject->clID() ) {
1130 log << MSG::ERROR <<
"Update requested for clID " << classID
1131 <<
" while DataObject is of clID "
1132 << pObject->clID() << endreq;
1134 return StatusCode::FAILURE;
1143 <<
"Object to be updated is not a calib object! " << endreq;
1144 return StatusCode::FAILURE;
1151 int runto,runto1,FirstEvent;
1155 std::string physFmt;
1156 std::string fmtVersion;
1157 std::string dataIdent;
1158 std::string
flag=
"default";
1166 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,
"/Event/EventHeader");
1169 log << MSG::WARNING <<
"Unable to read the Event for TDS" << endreq;
1178 if(cType!=
"TofCal"&&cType!=
"EstTofCal"&&cType!=
"TofSim"&&cType!=
"DedxSim")
runNo = fabs(evt -> runNumber());
1179 if(cType==
"TofCal"||cType==
"EstTofCal"||cType==
"TofSim"||cType==
"DedxSim")
runNo = evt -> runNumber();
1180 FirstEvent = evt -> eventNumber();
1184 if((cType==
"TofCal"))
1186 std::string cType=
"Tof";
1187 if(m_flag[3]==
"default")
1189 st1=
getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,
runNo,m_bossRelease,cType);
1190 cout<<cType<<
" runfrm1,runto1 @update is:"<<runfrm1<<
":::"<<runto1<<endl;
1191 if (st1 .isFailure() )
1193 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1207 if((cType==
"EmcCal"))
1209 std::string cType=
"Emc";
1210 if(m_flag[2]==
"default")
1212 st1=
getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,
runNo,m_bossRelease,cType);
1214 if (st1 .isFailure() )
1216 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1229 if((cType==
"DedxCal"))
1231 std::string cType=
"Dedx";
1232 if(m_flag[1]==
"default")
1234 st1=
getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,
runNo,m_bossRelease,cType);
1236 if (st1 .isFailure() )
1238 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1248 if((cType==
"MdcCal"))
1250 std::string cType=
"Mdc";
1251 if(m_flag[0]==
"default")
1254 st1=
getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,
runNo,m_bossRelease,cType);
1256 if (st1 .isFailure() )
1258 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1269 if((cType==
"MucCal"))
1271 std::string cType=
"Muc";
1272 if(m_flag[4]==
"default")
1274 st1=
getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,
runNo,m_bossRelease,cType);
1276 if (st1 .isFailure() )
1278 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1288 if((cType==
"EsTimeCal"))
1290 std::string cType=
"EsTime";
1291 if(m_flag[5]==
"default")
1293 st1=
getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,
runNo,m_bossRelease,cType);
1295 if (st1 .isFailure() )
1297 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1307 if((cType==
"MdcAlign"))
1309 std::string cType=
"MdcAlign";
1310 if(m_flag[7]==
"default")
1312 st1=
getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,
runNo,m_bossRelease,cType);
1314 if (st1 .isFailure() ) {
1315 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1325 if((cType==
"TofQElec"))
1327 std::string cType=
"TofQElec";
1328 if(m_flag[8]==
"default")
1331 st1=
getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,
runNo,m_bossRelease,cType);
1341 if((cType==
"TofSim"))
1343 std::string cType=
"TofSim";
1344 if(m_flag[9]==
"default")
1346 st1=
getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,
runNo,m_bossRelease,cType);
1348 if (st1 .isFailure() ) {
1349 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1360 if((cType==
"DedxSim"))
1362 std::string cType=
"DedxSim";
1363 if(m_flag[10]==
"default")
1365 st1=
getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,
runNo,m_bossRelease,cType);
1367 if (st1 .isFailure() ) {
1368 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1379 if((cType==
"MdcDataConst"))
1381 std::string cType=
"MdcData";
1382 if(m_flag[11]==
"default")
1384 st1=
getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,
runNo,m_bossRelease,cType);
1386 if (st1 .isFailure() ) {
1387 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1398 if(cType==
"InjSigInterval")
1400 std::string cType=
"InjSigInterval";
1401 if(m_flag[12]==
"default")
1403 st1=
getSftParVer(m_bossver[12],m_calPar[12],runfrm1,runto1,
runNo,m_bossRelease,cType);
1404 if (st1 .isFailure() ) {
1405 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1413 if(cType==
"InjSigTime")
1415 std::string cType=
"InjSigTime";
1416 if(m_flag[13]==
"default")
1418 st1=
getSftParVer(m_bossver[13],m_calPar[13],runfrm1,runto1,
runNo,m_bossRelease,cType);
1419 if (st1 .isFailure() ) {
1420 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1428 if(cType==
"OffEvtFilter")
1430 std::string cType=
"OffEvtFilter";
1431 if(m_flag[14]==
"default")
1433 st1=
getSftParVer(m_bossver[14],m_calPar[14],runfrm1,runto1,
runNo,m_bossRelease,cType);
1434 if (st1 .isFailure() ) {
1435 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1443 if(cType==
"CorrectedETS")
1445 std::string cType=
"CorrectedETS";
1448 int _strlenRun = strlen((*res[0])[
"Run"]) + 1;
1449 char* _pStatus =
new char[3];
1450 char* _pRunFrom =
new char[_strlenRun];
1451 char* _pRunTo =
new char[_strlenRun];
1452 memcpy(_pStatus,
"OK", 3);
1453 memcpy(_pRunFrom, (*res[0])[
"Run"], _strlenRun);
1454 memcpy(_pRunTo, (*res[0])[
"Run"], _strlenRun);
1456 (*res[0])[
"Status"] = _pStatus;
1457 (*res[0])[
"RunFrom"] = _pRunFrom;
1458 (*res[0])[
"RunTo"] = _pRunTo;
1465 if((cType==
"EstTofCal"))
1467 std::string cType=
"EsTof";
1468 if(m_flag[6]==
"default")
1470 st1=
getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,
runNo,m_bossRelease,cType);
1472 if (st1 .isFailure() ) {
1473 log << MSG::ERROR <<
" Unable to find DatabaseSvc " << endreq;
1484 log << MSG::ERROR <<
"Error searching in the database" << endreq;
1489 unsigned char storageType;
1496 log << MSG::DEBUG <<
"Creating an address of type "
1497 << (int)storageType <<
" for class " << classID << endreq;
1502 if(m_dbStatus==
"OK"){
1503 if(std::string((*records1)[
"Status"])!=
"OK") {
1504 log<<MSG::FATAL<<
"the status of type "<<cType<<
" is "<< (*records1)[
"Status"]<<
" your setting is OK"<<endreq;
1510 IOpaqueAddress* tmpAddress;
1512 const unsigned long ipar[2] = {0,0};
1514 tmpAddress =
new TreeAddress(storageType, classID,*records1,ipar);
1516 sscanf((*records1)[
"RunFrom"],
"%d", &runfrm);
1517 sscanf((*records1)[
"RunTo"],
"%d", &runto);
1518 log << MSG::DEBUG << __LINE__<<
" records @update runfrm is:"<<(*records1)[
"RunFrom"]<<
" runto is:"<<(*records1)[
"RunTo"]<<
" ser_no is:"<<ser<<endreq;
1535 log << MSG::DEBUG <<__LINE__<<
" runfrm of max is:"<<runfrm<<
" runto min is:"<<runto<<endreq;
1542 log << MSG::DEBUG <<
"Temporary address successfully created" << endreq;
1543 tmpAddress->addRef();
1546 tmpAddress->setRegistry(entry);
1549 DataObject* pNewObject;
1550 status = m_detPersSvc->createObj(tmpAddress, pNewObject);
1551 tmpAddress->release();
1552 if ( !status.isSuccess() ) {
1554 <<
"Persistency service could not create object" << endreq;
1564 if (0 == pNewBase) {
1566 <<
"Cannot update objects other than Calib objects: "
1567 <<
"update() must be defined!"
1569 return StatusCode::FAILURE;
1577 pBase->
update(*pNewBase, &log);
1582 return StatusCode::SUCCESS;
1586 unsigned char& type )
1588 MsgStream log(
msgSvc(),
"CalibMySQLCnvSvc");
1591 if (description == std::string(
"XML")) {
1592 type = XML_StorageType;
1594 else if (description == std::string(
"ROOT")) {
1597 else if (description == std::string(
"TREE")) {
1601 log << MSG::ERROR <<
"unsupported storage type " << description << endreq;
1602 return StatusCode::FAILURE;
1604 return StatusCode::SUCCESS;
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)
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 ~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