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;