/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/CalibSvc/CalibMySQLCnv/CalibMySQLCnv-00-01-09/src/CalibMySQLCnvSvc.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibMySQLCnv/src/CalibMySQLCnvSvc.cxx,v 1.49 2013/05/22 07:57:53 maqm Exp $
00002 #include <string>
00003 #include <cstdio>
00004 #include <stdexcept>
00005 
00006 #include "CalibMySQLCnv/CalibMySQLCnvSvc.h"
00007 #include "CalibDataSvc/ICalibRootSvc.h"   // for def. of CALIBROOT_StorageType
00008 #include "CalibDataSvc/ICalibTreeSvc.h" 
00009 #include "calibUtil/Metadata.h"
00010 #include "GaudiKernel/IDataManagerSvc.h"
00011 
00012 #include "CalibData/CalibBase.h"
00013 #include "CalibData/CalibBase1.h"
00014 //#include "CalibData/CalibTime.h"
00015 #include "CalibData/CalibModelSvc.h"
00016 #include "GaudiKernel/SmartDataPtr.h"
00017 
00018 #include "GaudiKernel/DataObject.h"
00019 #include "GaudiKernel/GenericAddress.h"
00020 #include "GaudiKernel/IConverter.h"
00021 #include "GaudiKernel/IDetDataSvc.h"
00022 #include "GaudiKernel/IDataProviderSvc.h"
00023 #include "GaudiKernel/IOpaqueAddress.h"
00024 #include "GaudiKernel/ISvcLocator.h"
00025 #include "GaudiKernel/IValidity.h"
00026 #include "GaudiKernel/MsgStream.h"
00027 #include "GaudiKernel/SvcFactory.h"
00028 #include "TBuffer.h"
00029 #include "TBufferFile.h"
00030 #include "TTree.h"
00031 #include "CalibMySQLCnv/TreeAddress.h"
00032 #include "EventModel/EventModel.h"
00033 #include "EventModel/EventHeader.h"
00034 #include "DatabaseSvc/IDatabaseSvc.h"
00035 #include "TROOT.h"
00036 #include "TFile.h"
00037 #include <iostream>
00038 
00039 using namespace CalibData;
00041 //static SvcFactory<CalibMySQLCnvSvc>          CalibMySQLCnvSvc_factory;
00042 //const ISvcFactory& CalibMySQLCnvSvcFactory = CalibMySQLCnvSvc_factory;
00043 
00044 // Local utility to translate calibration quality list to bit map
00045 namespace {
00046         unsigned int toQualityMask(std::vector<std::string>& qualities) {
00047                 using calibUtil::Metadata;
00048 
00049                 unsigned int mask = 0;
00050                 unsigned n = qualities.size();
00051 
00052                 for (unsigned i = 0; i < n; i++) {
00053                         std::string iString = qualities[i];
00054                         if (iString.size() < 3) continue;
00055                         iString.resize(3);
00056                         if (iString == "PRO") mask |= Metadata::LEVELProd;
00057                         else if (iString =="DEV") mask |= Metadata::LEVELDev;
00058                         else if (iString =="TES") mask |= Metadata::LEVELTest;
00059                         else if (iString =="SUP") mask |= Metadata::LEVELSuperseded;
00060                 }
00061                 return mask;
00062         }
00063 }
00064 
00065         CalibMySQLCnvSvc::CalibMySQLCnvSvc( const std::string& name, ISvcLocator* svc)
00066         : ConversionSvc (name, svc, MYSQL_StorageType)
00067                 , m_meta(0), m_useEventTime(true),m_enterTimeStart(0), m_enterTimeEnd(0),
00068                 m_qualityMask(0)
00069 {
00070         // declareProperty("Host", m_host = "202.122.37.69");
00071         declareProperty("Host", m_host = "bes3db2.ihep.ac.cn");
00072         declareProperty("UseEventTime", m_useEventTime = true);
00073         declareProperty("EnterTimeEnd", m_enterTimeEndString = std::string("") );
00074         declareProperty("EnterTimeStart", m_enterTimeStartString = std::string("") );
00075         //  declareProperty("DbName", m_dbName = std::string("calib") );
00076         declareProperty("DbName", m_dbName = std::string("offlinedb") );
00077         declareProperty("QualityList", m_qualityList);
00078         declareProperty("CrashOnError", m_crash = true);
00079         declareProperty("Sft_Ver",sft_ver);
00080         declareProperty("Cal_Ver",cal_ver);
00081         declareProperty("MdcFlag",m_flag[0]="default");
00082         declareProperty("DeDxFlag",m_flag[1]="default");
00083         declareProperty("EmcFlag",m_flag[2]="default");
00084         declareProperty("TofFlag",m_flag[3]="default");
00085         declareProperty("MucFlag",m_flag[4]="default");
00086         declareProperty("EsTimeFlag",m_flag[5]="default");
00087         declareProperty("EstTofFlag",m_flag[6]="default");
00088         declareProperty("MdcAlignFlag",m_flag[7]="default");
00089         declareProperty("TofQElecFlag",m_flag[8]="default");
00090         declareProperty("TofSimPFlag",m_flag[9]="default");
00091         declareProperty("DedxSimFlag",m_flag[10]="default");
00092         declareProperty("MdcDataFlag",m_flag[11]="default");
00093         declareProperty("MdcCalPar",m_calPar[0]="default");
00094         declareProperty("DeDxCalPar",m_calPar[1]="default");
00095         declareProperty("EmcCalPar",m_calPar[2]="default");
00096         declareProperty("TofCalPar",m_calPar[3]="default"); 
00097         declareProperty("MucCalPar",m_calPar[4]="default");
00098         declareProperty("EsTimeCalPar",m_calPar[5]="default");
00099         declareProperty("EstTofCalPar",m_calPar[6]="default");
00100         declareProperty("MdcAlignPar",m_calPar[7]="default");
00101         declareProperty("TofQElecPar",m_calPar[8]="default");
00102         declareProperty("TofSimPar",m_calPar[9]="default");
00103         declareProperty("DedxSimPar",m_calPar[10]="default");
00104         declareProperty("MdcDataConstVer",m_calPar[11]="default");
00105         declareProperty("MdcBossVer",m_bossver[0]="default");
00106         declareProperty("DeDxBossVer",m_bossver[1]="default");
00107         declareProperty("EmcBossVer",m_bossver[2]="default");
00108         declareProperty("TofBossVer",m_bossver[3]="default");
00109         declareProperty("MucBossVer",m_bossver[4]="default");
00110         declareProperty("EsTimeBossVer",m_bossver[5]="default");
00111         declareProperty("EstTofBossVer",m_bossver[6]="default");
00112         declareProperty("MdcAlignBossVer",m_bossver[7]="default");
00113         declareProperty("TofQElecBossVer",m_bossver[8]="default");
00114         declareProperty("TofSimBossVer",m_bossver[9]="default");
00115         declareProperty("DedxSimBossVer",m_bossver[10]="default");
00116         declareProperty("MdcDataConstBossVer",m_bossver[11]="default");
00117         declareProperty("Align_RunNo",m_MdcAlign_No=8093);
00118         declareProperty("Db_Status",m_dbStatus="OK");
00119         declareProperty("BossRelease",m_bossRelease="default");
00120 }
00121 
00122 CalibMySQLCnvSvc::~CalibMySQLCnvSvc(){ }
00123 
00124 StatusCode CalibMySQLCnvSvc::initialize()
00125 {
00126         // Initialize base class
00127         StatusCode sc = ConversionSvc::initialize();
00128         if ( !sc.isSuccess() ) return sc;
00129 
00130         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00131         log << MSG::INFO << "Specific initialization starting" << endreq;
00132 
00133         IDataProviderSvc* pCDS = 0;
00134         sc = serviceLocator()->getService ("CalibDataSvc",  IDataProviderSvc::interfaceID(), (IInterface*&)pCDS);
00135 
00136         if ( !sc.isSuccess() ) {
00137                 log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
00138                 return sc;
00139         }
00140 
00141         sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
00142         if (sc .isFailure() ) {
00143                 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
00144                 return sc;
00145         }
00146 
00147         // Set the CalibDataSvc as data provider service
00148         sc = setDataProvider(pCDS);
00149         if ( !sc.isSuccess() ) {
00150                 log << MSG::ERROR << "Could not set data provider" << endreq;
00151                 return sc;
00152         }
00153 
00154         // Query the IAddressCreator interface of the detector persistency service
00155 
00156         sc = serviceLocator()->service 
00157                 ("DetectorPersistencySvc", m_detPersSvc, true);
00158         if ( !sc.isSuccess() ) {
00159                 log << MSG::ERROR 
00160                         << "Cannot locate IConversionSvc interface of DetectorPersistencySvc"
00161                         << endreq;
00162                 return sc;
00163         } else {
00164                 log << MSG::DEBUG 
00165                         << "Retrieved IConversionSvc interface of DetectorPersistencySvc"
00166                         << endreq;
00167         }
00168 
00169         IAddressCreator* iAddrCreator;
00170         sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(),(void**) &iAddrCreator);
00171         //  sc = m_detPersSvc->queryInterface(IID_IAddressCreator,(void**) &iAddrCreator);
00172         if ( !sc.isSuccess() ) {
00173                 log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
00174                 return sc;
00175         }
00176 
00177         sc = setAddressCreator(iAddrCreator);
00178         if ( !sc.isSuccess() ) {
00179                 log << MSG::ERROR       << "Cannot set the address creator" << endreq;
00180                 return sc;
00181         }
00182 
00183         // Get properties from the JobOptionsSvc
00184         sc = setProperties();
00185         if ( !sc.isSuccess() ) {
00186                 log << MSG::ERROR << "Could not set jobOptions properties" << endreq;
00187                 return sc;
00188         }
00189         log << MSG::DEBUG << "Properties were read from jobOptions" << endreq;
00190 
00191         // Translate list of calibration quality names to bit mask form used 
00192         // by calibUtil::Metadata::findBest     Defaults to PROD + DEV for now
00193         // (that was old fixed value)
00194         m_qualityMask = toQualityMask(m_qualityList);
00195         if (!m_qualityMask) {
00196                 m_qualityMask = calibUtil::Metadata::LEVELProd |
00197                         calibUtil::Metadata::LEVELDev;
00198         }
00199 
00200         // Make a calibUtil::Metadata instance 
00201         // Conceivably, could start up a different conversion service, depending 
00202         // on job options parameters, which would look very much like this one
00203         // except for having a different way to access metadata.
00204         m_meta = new calibUtil::Metadata(m_host, "*", m_dbName);
00205 
00206         if (!m_meta) {
00207                 log << MSG::ERROR << "Could not open connection to metadata dbs" << endreq;
00208                 return MSG::ERROR;
00209         }
00210         // Probably should get this value from job options. 
00211         // Now we do.  See m_qualityMask, m_qualityList
00212         //  m_calibLevelMask = calibUtil::Metadata::LEVELProd + 
00213         //    calibUtil::Metadata::LEVELDev;
00214 
00215         log << MSG::INFO << "Specific initialization completed" << endreq;
00216         return sc;
00217 }
00218 
00219 
00220 StatusCode CalibMySQLCnvSvc::finalize()
00221 {
00222         MsgStream log(msgSvc(), "CalibMySQLCnvSvc");
00223         log << MSG::DEBUG << "Finalizing" << endreq;
00224         delete m_meta;
00225         m_meta = 0;
00226         return ConversionSvc::finalize();
00227 }
00228 
00229 
00230 StatusCode CalibMySQLCnvSvc::queryInterface(const InterfaceID& riid, 
00231                 void** ppvInterface)
00232 {
00233         if ( IID_ICalibMetaCnvSvc == riid )  {
00234                 // With the highest priority return the specific interface of this service
00235                 *ppvInterface = (ICalibMetaCnvSvc*)this;
00236         } else  {
00237                 // Interface is not directly available: try out a base class
00238                 return ConversionSvc::queryInterface(riid, ppvInterface);
00239         }
00240         addRef();
00241         return StatusCode::SUCCESS;
00242 }
00243 
00244 
00248 StatusCode CalibMySQLCnvSvc::createObj (IOpaqueAddress* pAddress, 
00249                 DataObject*&    refpObject ) {
00250 
00251         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00252 
00253 
00254         // Create the object according to calib type, flavor, time, instrument, clid.
00255         // Notice that the CalibMySQLCnvSvc has no converters of its own:
00256         // object creation is delegated to another CnvSvc via a temporary address
00257         // The IOpaqueAddress specifies calibration type and specific flavor.
00258         // The secondary storage type is always discovered dynamically
00259         StatusCode sc;
00260 
00261         sc = createCalib(refpObject,
00262                         pAddress->par()[0],
00263                         pAddress->clID(),
00264                         pAddress->registry() );
00265 
00266 
00267         if ( !sc.isSuccess() ) {
00268                 log << MSG::ERROR << "Could not create calib DataObject" << endreq;
00269         }
00270         log << MSG::DEBUG << "Method createObj exiting" << endreq;
00271         return sc;
00272 }
00273 
00278 StatusCode CalibMySQLCnvSvc::fillObjRefs(IOpaqueAddress* /*pAddress*/, 
00279                 DataObject*     /*pObject */ ) {
00280         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00281         return StatusCode::SUCCESS;
00282 }
00283 
00284 
00287 StatusCode CalibMySQLCnvSvc::updateObj(IOpaqueAddress* pAddress, 
00288                 DataObject*     pObject  ) {
00289 
00290         //  using facilities::Timestamp;
00291 
00292         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00293 
00294         // Don't update when we're using enter time
00295         log << MSG::DEBUG << "CalibMySQLCnvSvc::updateObj starting ...."<<endreq;
00296 
00297         if( 0 == pObject ) {
00298                 log << MSG::ERROR << "There is no object to update" << endreq;
00299                 return StatusCode::FAILURE;
00300         } 
00301 
00302         StatusCode sc = updateCalib(pObject, pAddress->par()[0], 
00303                         pAddress->clID(), pAddress->registry() );
00304         if ( !sc.isSuccess() ) {
00305                 log << MSG::ERROR << "Could not update calib DataObject" << endreq;
00306                 return sc;
00307         }
00308 
00309         return StatusCode::SUCCESS;  
00310 }
00311 
00315 StatusCode CalibMySQLCnvSvc::updateObjRefs (IOpaqueAddress* /*pAddress*/, 
00316                 DataObject*     /*pObject */ ) {
00317         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00318         return StatusCode::SUCCESS;
00319 }
00320 
00321 
00324 StatusCode CalibMySQLCnvSvc::createRep(DataObject* /*pObject*/,
00325                 IOpaqueAddress*& /*refpAddress*/ ) {
00326 
00327         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00328         // log << MSG::WARNING << "Method createRep is not implemented" << endreq;
00329         return StatusCode::SUCCESS;
00330 }
00331 
00332 
00336 StatusCode CalibMySQLCnvSvc::fillRepRefs (IOpaqueAddress* /*pAddress*/, 
00337                 DataObject*     /*pObject */ ) {
00338         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00339         //  log << MSG::WARNING << "Method fillRepRefs is not implemented" << endreq;
00340         return StatusCode::SUCCESS;
00341 }
00342 
00343 
00346 StatusCode CalibMySQLCnvSvc::updateRep (IOpaqueAddress* /*pAddress*/, 
00347                 DataObject*     /*pObject */ ) {
00348         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00349         // log << MSG::WARNING << "Method updateRep is not implemented" << endreq;
00350         return StatusCode::SUCCESS;
00351 }
00352 
00353 
00357 StatusCode CalibMySQLCnvSvc::updateRepRefs (IOpaqueAddress* /*pAddress*/, 
00358                 DataObject*     /*pObject */ ) {
00359         MsgStream log(msgSvc(), "CalibMySQLCnvSvc");
00360         //log << MSG::WARNING << "Method updateRepRefs is not implemented" << endreq;
00361         return StatusCode::SUCCESS;
00362 }
00363 
00367 StatusCode CalibMySQLCnvSvc::createAddress(long svc_type,
00368                 const CLID& clid,
00369                 const std::string* par, 
00370                 const unsigned long* /*ipar*/,
00371                 IOpaqueAddress*& refpAddress ) {
00372         // First check that requested address is of type MYSQL_StorageType
00373         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00374         if ( svc_type!= MYSQL_StorageType ) {
00375                 log << MSG::ERROR 
00376                         << "Cannot create addresses of type " << (int)svc_type 
00377                         << " which is different from " << (int)MYSQL_StorageType 
00378                         << endreq;
00379                 return StatusCode::FAILURE;
00380         }
00381         log << MSG::INFO
00382                 << " create address in CalibMySQLCnvSvc "
00383                 << endreq;
00384 
00385         refpAddress = new GenericAddress( MYSQL_StorageType, 
00386                         clid, 
00387                         par[0]);
00388 
00389         return StatusCode::SUCCESS;
00390 }
00391 
00392 //select sftver and parver frm table CalVtxLum
00393 StatusCode CalibMySQLCnvSvc::getSftParVer(std::string& SftVer,
00394                 std::string& CalParVer,
00395                 int &runfrm,
00396                 int &runto,
00397                 int RunNo,
00398                 std::string BossRelease,
00399                 std::string DataType
00400                 )
00401 {
00402         using namespace rdbModel;
00403         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00404         char stmt[300];
00405         int run_No =RunNo;
00406         MYSQL_RES *res_set;
00407         IDatabaseSvc* m_dbsvc;
00408         DatabaseRecordVector res;
00409         StatusCode sc=serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
00410         if (sc .isFailure() ) {
00411                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00412                 return sc;
00413         }
00414 
00415         const char* bossRelease = BossRelease.c_str();
00416         const char* dataType = DataType.c_str();
00417 
00418         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);
00419 
00420         int row_no = m_dbsvc->query("offlinedb",stmt,res);
00421         if(row_no<1){
00422                 std::cout<<"ERROR:error searching with:"<<stmt<<std::endl;
00423                 exit(1);
00424         }
00425         if(row_no=1){
00426                 DatabaseRecord* records1 = res[0];
00427     runfrm=records1->GetInt("RunFrom");
00428     runto=records1->GetInt("RunTo");
00429                 //cout<<dataType<<" runfrm,runto in getSftParVer is:"<<runfrm<<"::::"<<runto<<endl;
00430                 SftVer=records1->GetString("SftVer");
00431                 CalParVer=records1->GetString("ParVer");
00432         }
00433         if(row_no>1){
00434                 cout<<"ERROR: "<<dataType<<" set overlapped run number in the table CalVtxLumVer"<<endl;
00435                 exit(1);
00436                 }
00437         return StatusCode::SUCCESS;
00438 }
00439 
00440 
00452 
00453 StatusCode CalibMySQLCnvSvc::createCalib(DataObject*&       refpObject,
00454                 const std::string& fullpath,
00455                 const CLID&        classID,
00456                 IRegistry*         entry)
00457 {
00458         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00459 
00460         // Look up calib object in the Metadata database
00461         std::string cType = CalibData::CalibModelSvc::getCalibType(fullpath);
00462 
00463         // ..and extra special munging for test
00464         if (std::string("Test") == cType.substr(0, 4)) {
00465                 cType = std::string("Test_Gen");
00466         }
00467 
00468         std::string testfile = std::string(getenv("CALIBMYSQLCNVROOT"))+"/share/test.root";
00469         TFile *f1=new TFile(testfile.c_str(),"read");
00470         unsigned int ser = 0;
00471         //runfrm,runto are the value from the table ***CalConst;runfrm1,runto1 are the value from the table CalVtxLumVer
00472         int runfrm,runfrm1;
00473         int runto,runto1;
00474         std::string flag="default";
00475         calibUtil::Metadata::eRet ret;
00476 
00477         MSG::Level msgLevel =  MSG::DEBUG;
00478 
00479         std::string physFmt = "UNK";
00480         std::string fmtVersion;
00481         std::string dataIdent;
00482 
00483         // Get the runNo of current event:
00484         SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
00485         int runNo=0;
00486         if( !evt ){
00487                 log << MSG::WARNING << "Unable to read the Event for TDS" << endreq;
00488                 //         return StatusCode::FAILURE;
00489         }   
00490         if( evt ){
00491                 if(cType!="TofCal"&&cType!="EstTofCal"&&cType!="TofSim"&&cType!="DedxSim") runNo = fabs(evt -> runNumber());
00492                 if(cType=="TofCal"||cType=="EstTofCal"||cType=="TofSim"||cType=="DedxSim") runNo = evt -> runNumber();
00493         }
00494         DatabaseRecordVector res;
00495 
00496         StatusCode st1;
00497 
00498         //TofCalConst
00499         if((cType=="TofCal")&&(m_bossver[3]== "default" ))
00500         {
00501                 std::string cType="Tof";
00502                 if(m_bossRelease=="default")
00503                         {
00504                                 log << MSG::FATAL << " Boss Release for TofCal not set!" << endreq;
00505                                 exit(1);
00506                                 
00507                         }
00508                 else
00509                         {
00510                         st1=getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,runNo,m_bossRelease,cType);
00511                         //cout<<cType<<" runfrm1,runto1 is:"<<runfrm1<<"::"<<runto1<<endl;
00512                         if (st1 .isFailure() ) 
00513                         {
00514                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00515                                 return st1;                                                         
00516                         }
00517                         //cout<<"SftVer and CalParVer are:"<<sft_ver<<";"<<cal_ver<<endl;
00518                         ret = m_meta->getReadTOFInfo(ser,&runfrm,&runto,m_calPar[3],res,runNo,m_bossver[3]);
00519 
00520                 }
00521         }
00522         else if ((cType=="TofCal")&&(m_bossver[3]!= "default" ))
00523         {
00524     m_flag[3]="set";
00525                 flag=m_flag[3];
00526                 //cout<<"flag @create Tof is:"<<m_flag[3]<<endl;
00527                 ret = m_meta->getReadTOFInfo(ser,&runfrm,&runto,m_calPar[3],res,runNo,m_bossver[3]);
00528         }
00529 
00530 
00531         //EmcCalConst
00532         if((cType=="EmcCal")&&(m_bossver[2]== "default" ))   
00533         { 
00534                 std::string cType="Emc";
00535                 if(m_bossRelease=="default") 
00536                 {
00537                         log << MSG::FATAL << " Boss Release for EmcCal not set!" << endreq;
00538                         exit(1);
00539                 }
00540                 else{
00541 
00542                         st1=getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,runNo,m_bossRelease,cType);
00543                         //cout<<cType<<" runfrm1,runto1 is:"<<runfrm1<<"::"<<runto1<<endl;
00544                         //cout<<"flag @create Emc is:"<<flag<<endl;
00545                         if (st1 .isFailure() ) 
00546                         {
00547                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00548                                 return st1; 
00549                         }
00550                         ret = m_meta->getReadEMCInfo(ser,&runfrm,&runto, m_calPar[2], res,runNo,m_bossver[2]);                    
00551                 }
00552         }
00553         else if((cType=="EmcCal")&&(m_bossver[2]!= "default" ))
00554         {
00555                 m_flag[2]="set";
00556                 flag=m_flag[2];
00557     //cout<<"flag @create Emc is:"<<m_flag[2]<<endl;
00558                 ret = m_meta->getReadEMCInfo(ser,&runfrm,&runto, m_calPar[2], res,runNo,m_bossver[2]);
00559         }
00560 
00561         //DedxCalConst
00562         if((cType=="DedxCal")&&(m_bossver[1]== "default" ))
00563         { 
00564                 std::string cType="Dedx";
00565                 if(m_bossRelease=="default") 
00566                 {
00567                         log << MSG::FATAL << " Boss Release for DedxCal not set!" << endreq;
00568                         exit(1);                                                                                             
00569                 }
00570                 else              
00571                 {
00572                         st1=getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,runNo,m_bossRelease,cType);
00573                         //cout<<cType<<" runfrm1,runto1 is:"<<runfrm1<<"::"<<runto1<<endl;
00574                         if (st1 .isFailure() ) 
00575                         {
00576                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00577                                 return st1;                              
00578                         }
00579                         ret = m_meta->getReadDedxInfo(ser,&runfrm,&runto, m_calPar[1], res,runNo,m_bossver[1]);                 
00580                 }         
00581         }
00582         else if((cType=="DedxCal")&&(m_bossver[1]!= "default" ))   
00583         {
00584     m_flag[1]="set";
00585     flag=m_flag[1];
00586                 //cout<<"flag @create Dedx is:"<<m_flag[1]<<endl;
00587                 ret = m_meta->getReadDedxInfo(ser,&runfrm,&runto, m_calPar[1], res,runNo,m_bossver[1]);
00588         }
00589 
00590         //MdcCalConst
00591         if((cType=="MdcCal")&&(m_bossver[0]== "default" ))
00592         {
00593                 std::string cType="Mdc";
00594                 //cout<<"cType is"<<cType<<"m_bossver[0] is:"<<m_bossver[0]<<endl;
00595                 if(m_bossRelease=="default") 
00596                 {
00597                         log << MSG::FATAL << " Boss Release for MdcCal not set!" << endreq;
00598                         exit(1);      
00599                 }
00600                 else 
00601                 {
00602                         st1=getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,runNo,m_bossRelease,cType);
00603                         //cout<<cType<<" runfrm1,runto1 is:"<<runfrm1<<"::"<<runto1<<endl;
00604                         if (st1 .isFailure() ) 
00605                         {
00606                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00607                                 return st1;                                                                            
00608                         }
00609                         ret = m_meta->getReadMDCInfo(ser,&runfrm,&runto,m_calPar[0],res,runNo,m_bossver[0]);                    
00610                 }        
00611         }
00612         else if((cType=="MdcCal")&&(m_bossver[0]!= "default"))      
00613         {
00614     m_flag[0]="set";
00615     flag=m_flag[0];
00616                 //cout<<"flag @create Mdc is:"<<m_flag[0]<<endl;
00617                 ret = m_meta->getReadMDCInfo(ser,&runfrm,&runto, m_calPar[0], res,runNo,m_bossver[0]);
00618 
00619         }
00620 
00621         //MucCalConst
00622         if((cType=="MucCal")&&(m_bossver[4]== "default" ))
00623         {
00624                 std::string cType="Muc";
00625                 if(m_bossRelease=="default") 
00626                 {
00627                         log << MSG::FATAL << " Boss Release for MucCal not set!" << endreq;
00628                         exit(1);                                                                                     
00629                 }
00630                 else 
00631                 {
00632                         st1=getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,runNo,m_bossRelease,cType);
00633                         if (st1 .isFailure() ) 
00634                         {
00635                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00636                                 return st1;                                                                                                                                                                                        
00637                         }
00638                         ret = m_meta->getReadMUCInfo(ser,&runfrm,&runto, m_calPar[4], res,runNo,m_bossver[4]);                                                                                                                   
00639                 }                                                
00640         }
00641         else if((cType=="MucCal")&&(m_bossver[4]!= "default" ))
00642         {
00643     m_flag[4]="set";
00644     flag=m_flag[4];
00645                 //cout<<"flag @create Muc is:"<<m_flag[4]<<endl;
00646                 ret = m_meta->getReadMUCInfo(ser,&runfrm,&runto, m_calPar[4], res,runNo,m_bossver[4]);                                               
00647         }
00648 
00649         //EsTimeCal
00650         if((cType=="EsTimeCal")&&(m_bossver[5]== "default" ))
00651         {
00652                 std::string cType="EsTime";
00653                 if(m_bossRelease=="default") 
00654                 {
00655                         log << MSG::FATAL << " Boss Release for EsTimeCal not set!" << endreq;
00656                         exit(1);                                                                                                                              
00657                 }
00658                 else 
00659                 {
00660                         st1=getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,runNo,m_bossRelease,cType);
00661                         if (st1 .isFailure() ) 
00662                         {
00663                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00664                                 return st1;                                                                                                                                                                                                                                                        
00665                         }
00666                         ret = m_meta->getReadEsTimeInfo(ser,&runfrm,&runto,m_calPar[5], res,runNo,m_bossver[5]);
00667                 }                                                                                  
00668         }
00669         else if((cType=="EsTimeCal")&&(m_bossver[5]!= "default" ))
00670         {
00671     m_flag[5]="set";
00672     flag=m_flag[5];
00673                 //cout<<"flag @create EsTime is:"<<m_flag[5]<<endl;
00674                 ret = m_meta->getReadEsTimeInfo(ser,&runfrm,&runto, m_calPar[5], res,runNo,m_bossver[5]);                                                                    
00675         }
00676 
00677         //MdcAlign
00678         if((cType=="MdcAlign")&&(m_bossver[7]== "default" ))
00679         {
00680                 std::string cType="MdcAlign";
00681                 if(m_bossRelease=="default") {
00682                         log << MSG::FATAL << " Boss Release for MdcAlignCal not set!" << endreq;
00683                         exit(1);
00684                 }
00685                 else {
00686                         st1=getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,runNo,m_bossRelease,cType);
00687                         if (st1 .isFailure() ) {
00688                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00689                                 return st1;
00690                         }
00691                         ret = m_meta->getReadMdcAlignInfo(ser,&runfrm,&runto,m_calPar[7], res,runNo,m_bossver[7]);
00692                 }
00693         }
00694         else if((cType=="MdcAlign")&&(m_bossver[7]!= "default" ))
00695         {
00696     m_flag[7]="set";
00697     flag=m_flag[7];
00698                 //cout<<"flag @create MdcAlign is:"<<m_flag[7]<<endl;
00699                 ret = m_meta->getReadMdcAlignInfo(ser,&runfrm,&runto, m_calPar[7], res,runNo,m_bossver[7]);
00700         }
00701 
00702         //TofQElec
00703         if((cType=="TofQElec")&&(m_bossver[8]== "default" ))
00704         {
00705                 std::string cType="TofQElec";
00706                 if(m_bossRelease=="default") {
00707                         log << MSG::FATAL << " Boss Release for TofQElecCal not set!" << endreq;
00708                         exit(1);
00709                 }
00710                 else {
00711                         //cout<<"TofQElec @create"<<endl;
00712                         st1=getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,runNo,m_bossRelease,cType);
00713                         if (st1 .isFailure() ) {
00714                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00715                                 return st1;
00716                         }
00717                         ret = m_meta->getReadTofQElecInfo(ser,&runfrm,&runto,m_calPar[8],res,runNo,m_bossver[8]);
00718                 }
00719         }
00720         else if((cType=="TofQElec")&&(m_bossver[8]!= "default" ))
00721         {
00722     m_flag[8]="set";
00723     flag=m_flag[8];
00724                 //cout<<"flag @create TofQElec is:"<<flag<<endl;
00725                 ret = m_meta->getReadTofQElecInfo(ser,&runfrm,&runto, m_calPar[8], res,runNo,m_bossver[8]);
00726         }
00727 
00728         //TofSim
00729         if((cType=="TofSim")&&(m_bossver[9]== "default" ))
00730         {
00731                 std::string cType="TofSim";
00732                 if(m_bossRelease=="default") {
00733                         log << MSG::FATAL << " Boss Release for TofSimCal not set!" << endreq;
00734                         exit(1);
00735                 }
00736                 else {
00737                         st1=getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,runNo,m_bossRelease,cType);
00738                         if (st1 .isFailure() ) {
00739                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00740                                 return st1;
00741                         }
00742                         ret = m_meta->getReadTofSimInfo(ser,&runfrm,&runto, m_calPar[9], res,runNo,m_bossver[9]);
00743                 }
00744         }
00745         else if((cType=="TofSim")&&(m_bossver[9]!= "default" ))
00746         {
00747     m_flag[9]="set";
00748     flag=m_flag[9];
00749                 //cout<<"flag @create TofSim is:"<<m_flag[9]<<endl;
00750                 ret = m_meta->getReadTofSimInfo(ser,&runfrm,&runto, m_calPar[9], res,runNo,m_bossver[9]);
00751         }
00752 
00753         //DedxSim
00754         if((cType=="DedxSim")&&(m_bossver[10]== "default" ))
00755         {
00756                 std::string cType="DedxSim";
00757                 if(m_bossRelease=="default") {
00758                         log << MSG::FATAL << " Boss Release for DedxSimCal not set!" << endreq;
00759                         exit(1);
00760                 }
00761                 else {
00762                         st1=getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,runNo,m_bossRelease,cType);
00763                         if (st1 .isFailure() ) {
00764                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00765                                 return st1;
00766                         }
00767                         ret = m_meta->getReadDedxSimInfo(ser,&runfrm,&runto,m_calPar[10], res,runNo,m_bossver[10]);
00768                 }
00769         }
00770         else if((cType=="DedxSim")&&(m_bossver[10]!= "default" ))
00771         {
00772     m_flag[10]="set";
00773     flag=m_flag[10];
00774                 //cout<<"flag @create DedxSim is:"<<m_flag[10]<<endl;
00775                 ret = m_meta->getReadDedxSimInfo(ser,&runfrm,&runto, m_calPar[10], res,runNo,m_bossver[10]);
00776         }
00777 
00778         //MdcDataConst
00779         if((cType=="MdcDataConst")&&(m_bossver[11]== "default" ))
00780         {
00781                 std::string cType="MdcData";
00782                 if(m_bossRelease=="default") {
00783                         log << MSG::FATAL << " Boss Release for MdcDataConst not set!" << endreq;
00784                         exit(1);
00785                 }
00786                 else {
00787                         st1=getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,runNo,m_bossRelease,cType);
00788                         if (st1 .isFailure() ) {
00789                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00790                                 return st1;
00791                         }
00792                         ret = m_meta->getReadMdcDataConstInfo(ser,&runfrm,&runto,m_calPar[11], res,runNo,m_bossver[11]);
00793                 }
00794         }
00795         else if((cType=="MdcDataConst")&&(m_bossver[11]!= "default" ))
00796         {
00797     m_flag[11]="set";
00798     flag=m_flag[11];
00799                 //cout<<"flag @create MdcData is:"<<m_flag[11]<<endl;
00800                 ret = m_meta->getReadMdcDataConstInfo(ser,&runfrm,&runto, m_calPar[11], res,runNo,m_bossver[11]);
00801         }
00802 
00803         //EstTofCalConst
00804         if((cType=="EstTofCal")&&(m_bossver[6]== "default" ))
00805         {
00806                 std::string cType="EsTof";
00807                 if(m_bossRelease=="default") {
00808                         log << MSG::FATAL << " Boss Release for EstTofCal not set!" << endreq;
00809                         exit(1);
00810                 }
00811                 else {
00812                         st1=getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,runNo,m_bossRelease,cType);
00813                         if (st1 .isFailure() ) {
00814                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
00815                                 return st1;
00816                         }
00817                         ret = m_meta->getReadEstTofInfo(ser,&runfrm,&runto,m_calPar[6],res,runNo,m_bossver[6]);
00818                 }
00819         }
00820         else if((cType=="EstTofCal")&&(m_bossver[6]!= "default" ))
00821         {
00822     m_flag[6]="set";
00823     flag=m_flag[6];
00824                 //cout<<"flag @create EstTof is:"<<m_flag[6]<<endl;
00825                 ret = m_meta->getReadEstTofInfo(ser,&runfrm,&runto, m_calPar[6], res,runNo,m_bossver[6]);
00826         }
00827 
00828         if(ret!=calibUtil::Metadata::RETOk){
00829                 log <<  MSG::ERROR   << "no record in the database" << endreq;
00830                 exit(1);
00831         }
00832         int sz=res.size();
00833         DatabaseRecord* records1 = res[0];
00834 //      DatabaseRecord* records2 = res1[0];
00835  // runfrm1=records1->GetInt("RunFrom");
00836  // runto1=records1->GetInt("RunTo");
00837  // cout<<cType<<" runfrm1,runto1 is:"<<runfrm3<<":::"<<runto3<<endl;
00838         if(m_dbStatus=="OK"){
00839                 if(std::string((*records1)["Status"])!="OK") {
00840                         log<<MSG::FATAL<<"Status of type "<<cType<<" is "<< (*records1)["Status"]<<"  your setting is OK"<<endreq;
00841                         exit(1);
00842                 }
00843         }
00844 
00845         log << MSG::DEBUG << "dataIdent is:"<<dataIdent<< endreq;
00846         unsigned char storageType;
00847         physFmt="TREE";
00848         StatusCode sc = decodeDescription(physFmt, storageType);
00849 
00850 
00851         // Depending on value of eDataFmt, figure out which private
00852         // conversion service to invoke.  Pass dataIdent and fmtVersion
00853         // as part of the opaque address.  
00854         // Create temporary address for the relevant type and classID 
00855         log << MSG::DEBUG << "Creating an address of type "
00856                 << (int)storageType << " for class " << classID << endreq;
00857 
00858         IOpaqueAddress* tmpAddress;
00859         const std::string par[3] = {dataIdent, fullpath, fmtVersion};
00860         //const unsigned long ipar[2] = {int(runfrm),int(runto)};
00861         //log << MSG::DEBUG << "ipar is:"<<ipar[0]<<":"<<ipar[1]<<"ipar[1]"<<endreq;
00862         const unsigned long ipar[2] = {0,0};//yzhang fix unsigned bug for runfrom runto
00863 
00864         //  sc = addressCreator()->createAddress(storageType, classID,
00865         //                                       par, ipar, tmpAddress);
00866 
00867         tmpAddress = new TreeAddress(storageType, classID,*records1,ipar);
00868   //sscanf((*records2)["RunFrom"], "%d", &runfrm1);
00869   //sscanf((*records2)["RunTo"], "%d", &runto1);
00870         
00871         cout<<cType<<" runfrm,runto @CalVtxLumVer is:"<<runfrm1<<":::"<<runto1<<endl;
00872         sscanf((*records1)["RunFrom"], "%d", &runfrm);
00873         sscanf((*records1)["RunTo"], "%d", &runto);
00874   log << MSG::DEBUG << __LINE__<<" records @ runfrm is:"<<(*records1)["RunFrom"]<<" runto is:"<<(*records1)["RunTo"]<<" ser_no is:"<<ser<<endreq;
00875         //log << MSG::DEBUG <<__LINE__<< " runfrm is:"<<runfrm<<" runto is:"<<runto<<" ser_no is:"<<ser<<endreq;
00876  if(flag=="default")
00877  {
00878         if(runfrm1>runfrm)
00879         {
00880                 runfrm=runfrm1;
00881         }
00882         if(runto1<runto)
00883         {
00884                 runto=runto1;
00885         }
00886  }
00887  if(flag=="set")
00888  {
00889          flag="default";
00890  }
00891         log << MSG::DEBUG <<__LINE__<< " runfrm of max is:"<<runfrm<<" runto min is:"<<runto<<endreq;
00892         TreeAddress* treeAddress =  dynamic_cast <TreeAddress*> (tmpAddress);
00893         treeAddress->setRunFrom(runfrm);
00894         treeAddress->setRunTo(runto);
00895 //      log << MSG::DEBUG << __LINE__<<" records @ runfrm is:"<<(*records1)["RunFrom"]<<" runto is:"<<(*records1)["RunTo"]<<" ser_no is:"<<ser<<endreq;
00896 //      log << MSG::DEBUG <<__LINE__<< " runfrm is:"<<runfrm<<" runto is:"<<runto<<" ser_no is:"<<ser<<endreq;
00897         /*
00898                  if ( !sc.isSuccess() ) {
00899                  log << msgLevel  << "Persistency service could not create a new address" << endreq;
00900                  if (m_crash) {
00901                  log << msgLevel << std::endl << "Exiting... " << std::endl << endreq;
00902                  exit(1);
00903                  }
00904                  return sc;
00905                  }
00906                  */
00907         tmpAddress->addRef();
00908 
00909         // Set the transient store registry for the object associated to this address
00910         tmpAddress->setRegistry(entry);
00911 
00912         // Now create the object
00913         sc = m_detPersSvc->createObj(tmpAddress, refpObject);
00914         tmpAddress->release();
00915         if ( !sc.isSuccess() ) {
00916                 log << msgLevel
00917                         << "Persistency service could not create a new object" << endreq;
00918                 if (m_crash) {
00919                         log << msgLevel << std::endl << "Exiting... " << std::endl << endreq;
00920                         exit(1);
00921                 }
00922                 return sc;
00923         }
00924         //  std::cout<<" CalibMySQLCnvSvc  res.size()=="<<res.size()<<std::endl;
00925         res.clear();
00926         log << MSG::DEBUG << "New object successfully created" << endreq;
00927         return StatusCode::SUCCESS;
00928         f1->Close();
00929         delete f1;
00930 }
00931 
00932 
00942 
00943 StatusCode CalibMySQLCnvSvc::updateCalib( DataObject*        pObject,
00944                 const std::string& fullpath,
00945                 const CLID&        classID,
00946                 IRegistry*         entry )
00947 {
00948         using CalibData::CalibBase;
00949 
00950         MsgStream log(msgSvc(), "CalibMySQLCnvSvc" );
00951         StatusCode status;
00952 
00953         std::string testfile = std::string(getenv("CALIBMYSQLCNVROOT"))+"/share/test.root";
00954         TFile *f1=new TFile(testfile.c_str(),"read");
00955 
00956 
00957         // Look up calib object in the Metadata database
00958         //std::string flavor = CalibData::CalibModelSvc::getFlavor(fullpath);
00959         std::string cType = CalibData::CalibModelSvc::getCalibType(fullpath);
00960 
00961         // ..and extra special munging for test
00962         if (std::string("Test") == cType.substr(0, 4)) {
00963                 cType = std::string("Test_Gen");
00964         }
00965 
00966         if (0 == pObject) {
00967                 log << MSG::ERROR << "There is no DataObject to update" << endreq;
00968                 return StatusCode::FAILURE;
00969         }
00970         // Is object an instance of the specified class?
00971         if(pObject->clID()!=6411&& classID!=6411){
00972                 if ( classID != pObject->clID() ) {
00973                         log << MSG::ERROR << "Update requested for clID " << classID
00974                                 << " while DataObject is of clID " 
00975                                 << pObject->clID() << endreq;
00976                         exit(1);
00977                         return StatusCode::FAILURE;
00978                 }
00979         }
00980 
00981         // check if already valid.  If so, we're done.
00982         //  Need access to IValidity interface
00983         CalibBase1* pBase = dynamic_cast<CalibBase1*>(pObject);
00984         if (pBase == 0) {
00985                 log << MSG::WARNING
00986                         << "Object to be updated is not a calib object! " << endreq;
00987                 return StatusCode::FAILURE;
00988         }
00989 
00990         // Following comes from createCalib.  Perhaps create and update
00991         // should be calling common utility since much of what they do is identical.
00992         unsigned int ser;
00993         int runfrm,runfrm1;
00994         int runto,runto1;
00995         calibUtil::Metadata::eRet ret;
00996 
00997         //  calibUtil::Metadata::eDataFmt physFmt = calibUtil::Metadata::FMTUnknown;
00998         std::string physFmt;
00999         std::string fmtVersion;
01000         std::string dataIdent;
01001         std::string flag="default";
01002         // Get the information needed to find and interpret the bulk data:
01003         //   * physical storage type
01004         //   * version of the physical format
01005         //   * pathname or similar identifying information so the data can be found
01006         //   maqm comment remove fmtversion :
01007         //    ret = m_meta->getReadInfo(ser, physFmt, fmtVersion, dataIdent);
01008 
01009         SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
01010         int runNo=0;
01011         if( !evt ){
01012                 log << MSG::WARNING << "Unable to read the Event for TDS" << endreq;
01013                 //     return StatusCode::FAILURE;
01014         }
01015 
01016         //  eRet ret;
01017 
01018         DatabaseRecordVector res;
01019         StatusCode st1;
01020         if( evt ){
01021                 if(cType!="TofCal"&&cType!="EstTofCal"&&cType!="TofSim"&&cType!="DedxSim") runNo = fabs(evt -> runNumber());
01022                 if(cType=="TofCal"||cType=="EstTofCal"||cType=="TofSim"||cType=="DedxSim") runNo = evt -> runNumber();
01023         }
01024 
01025         //TofCalConst
01026         if((cType=="TofCal"))
01027         {
01028                 std::string cType="Tof";
01029                 if(m_flag[3]=="default")
01030                 {
01031                         st1=getSftParVer(m_bossver[3],m_calPar[3],runfrm1,runto1,runNo,m_bossRelease,cType);
01032                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01033                         if (st1 .isFailure() ) 
01034                         {
01035                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01036                                 return st1;                                                         
01037                         }
01038                 }
01039         
01040                 flag=m_flag[3];
01041 
01042     //cout<<"flag @update Tof is:"<<flag<<endl;
01043                         //cout<<"SftVer and CalParVer are:"<<sft_ver<<";"<<cal_ver<<endl;
01044                 ret = m_meta->getReadTOFInfo(ser,&runfrm,&runto,m_calPar[3],res,runNo,m_bossver[3]);
01045         }
01046 
01047         //EmcCalConst
01048         if((cType=="EmcCal"))   
01049         { 
01050                 std::string cType="Emc";
01051                 if(m_flag[2]=="default")
01052                 {
01053                         st1=getSftParVer(m_bossver[2],m_calPar[2],runfrm1,runto1,runNo,m_bossRelease,cType);
01054                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01055                         if (st1 .isFailure() ) 
01056                         {
01057                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01058                                 return st1;                                
01059                         }
01060                 }
01061                 flag=m_flag[2];
01062                 //cout<<"flag @update Emc is:"<<m_flag[2]<<endl;
01063                 ret = m_meta->getReadEMCInfo(ser,&runfrm,&runto, m_calPar[2], res,runNo,m_bossver[2]);                    
01064         }
01065 
01066 
01067 
01068         //DedxCalConst
01069         if((cType=="DedxCal"))
01070         { 
01071                 std::string cType="Dedx";
01072                 if(m_flag[1]=="default")
01073                 {
01074                         st1=getSftParVer(m_bossver[1],m_calPar[1],runfrm1,runto1,runNo,m_bossRelease,cType);
01075                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01076                         if (st1 .isFailure() ) 
01077                         {
01078                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01079                                 return st1;                              
01080                         }
01081                 }
01082                 flag=m_flag[1];
01083                 //cout<<"flag @update Dedx  is:"<<m_flag[1]<<endl;
01084                 ret = m_meta->getReadDedxInfo(ser,&runfrm,&runto, m_calPar[1], res,runNo,m_bossver[1]);                 
01085         }         
01086 
01087         //MdcCalConst
01088         if((cType=="MdcCal"))
01089         {
01090                 std::string cType="Mdc";
01091                 if(m_flag[0]=="default")
01092                 {
01093                         //cout<<"cType is"<<cType<<"m_bossver[0] is:"<<m_bossver[0]<<endl;
01094                         st1=getSftParVer(m_bossver[0],m_calPar[0],runfrm1,runto1,runNo,m_bossRelease,cType);
01095                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01096                         if (st1 .isFailure() ) 
01097                         {
01098                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01099                                 return st1;                                                                            
01100                         }
01101                 }
01102                 flag=m_flag[0];
01103                 //cout<<"flag @update Mdc is:"<<m_flag[0]<<endl;
01104                 ret = m_meta->getReadMDCInfo(ser,&runfrm,&runto,m_calPar[0],res,runNo,m_bossver[0]);                    
01105         }        
01106 
01107         //MucCalConst
01108         if((cType=="MucCal"))
01109         {
01110                 std::string cType="Muc";
01111                 if(m_flag[4]=="default")
01112                 {
01113                         st1=getSftParVer(m_bossver[4],m_calPar[4],runfrm1,runto1,runNo,m_bossRelease,cType);
01114                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01115                         if (st1 .isFailure() ) 
01116                         {
01117                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01118                                 return st1;                                                                                                                                                                                        
01119                         }
01120                 }
01121                 flag=m_flag[4];
01122                 //cout<<"flag @update Muc is:"<<m_flag[4]<<endl;
01123                 ret = m_meta->getReadMUCInfo(ser,&runfrm,&runto, m_calPar[4], res,runNo,m_bossver[4]);                                                                                                                   
01124         }                                                
01125 
01126         //EsTimeCal
01127         if((cType=="EsTimeCal"))
01128         {
01129                 std::string cType="EsTime";
01130                 if(m_flag[5]=="default")
01131                 {
01132                         st1=getSftParVer(m_bossver[5],m_calPar[5],runfrm1,runto1,runNo,m_bossRelease,cType);
01133                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01134                         if (st1 .isFailure() ) 
01135                         {
01136                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01137                                 return st1;                                                                                                                                                                                                                                                        
01138                         }
01139                 }
01140                 flag=m_flag[5];
01141                 //cout<<"flag @update EsTime is:"<<m_flag[5]<<endl;
01142                 ret = m_meta->getReadEsTimeInfo(ser,&runfrm,&runto,m_calPar[5], res,runNo,m_bossver[5]);
01143         }                                                                                  
01144 
01145         //MdcAlign
01146         if((cType=="MdcAlign"))
01147         {
01148                 std::string cType="MdcAlign";
01149                 if(m_flag[7]=="default")
01150                 {
01151                         st1=getSftParVer(m_bossver[7],m_calPar[7],runfrm1,runto1,runNo,m_bossRelease,cType);
01152                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01153                         if (st1 .isFailure() ) {
01154                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01155                                 return st1;
01156                         }
01157                 }
01158                 flag=m_flag[7];
01159                 //cout<<"flag @update MdcAlign is:"<<m_flag[7]<<endl;
01160                 ret = m_meta->getReadMdcAlignInfo(ser,&runfrm,&runto,m_calPar[7], res,runNo,m_bossver[7]);
01161         }
01162 
01163         //TofQElec
01164         if((cType=="TofQElec"))
01165         {
01166                 std::string cType="TofQElec";
01167                 if(m_flag[8]=="default")
01168                 {
01169                         //cout<<"TofQElec @update"<<endl;
01170                         st1=getSftParVer(m_bossver[8],m_calPar[8],runfrm1,runto1,runNo,m_bossRelease,cType);
01171                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01172                 }
01173                 flag=m_flag[8];
01174                 //cout<<"flag @update TofQElec is:"<<m_flag[8]<<endl;
01175                 ret = m_meta->getReadTofQElecInfo(ser,&runfrm,&runto,m_calPar[8],res,runNo,m_bossver[8]);
01176         }
01177 
01178         //TofSim
01179         if((cType=="TofSim"))
01180         {
01181                 std::string cType="TofSim";
01182                 if(m_flag[9]=="default")
01183                 {
01184                         st1=getSftParVer(m_bossver[9],m_calPar[9],runfrm1,runto1,runNo,m_bossRelease,cType);
01185                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01186                         if (st1 .isFailure() ) {
01187                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01188                                 return st1;
01189                         }
01190                 }
01191                 flag=m_flag[9];
01192                 //cout<<"flag @update TofSim is:"<<m_flag[9]<<endl;
01193                 ret = m_meta->getReadTofSimInfo(ser,&runfrm,&runto, m_calPar[9], res,runNo,m_bossver[9]);
01194         }
01195 
01196         //DedxSim
01197         if((cType=="DedxSim"))
01198         {
01199                 std::string cType="DedxSim";
01200                 if(m_flag[10]=="default")
01201                 {
01202                         st1=getSftParVer(m_bossver[10],m_calPar[10],runfrm1,runto1,runNo,m_bossRelease,cType);
01203                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01204                         if (st1 .isFailure() ) {
01205                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01206                                 return st1;
01207                         }
01208                 }
01209                 flag=m_flag[10];
01210                 //cout<<"flag @update DedxSim is:"<<m_flag[10]<<endl;
01211                 ret = m_meta->getReadDedxSimInfo(ser,&runfrm,&runto,m_calPar[10], res,runNo,m_bossver[10]);
01212         }
01213 
01214         //MdcDataConst
01215         if((cType=="MdcDataConst"))
01216         {
01217                 std::string cType="MdcData";
01218                 if(m_flag[11]=="default")
01219                 {
01220                         st1=getSftParVer(m_bossver[11],m_calPar[11],runfrm1,runto1,runNo,m_bossRelease,cType);
01221                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01222                         if (st1 .isFailure() ) {
01223                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01224                                 return st1;
01225                         }
01226                 }
01227                 flag=m_flag[11];
01228                 //cout<<"flag @update MdcData is:"<<m_flag[11]<<endl;
01229                 ret = m_meta->getReadMdcDataConstInfo(ser,&runfrm,&runto,m_calPar[11], res,runNo,m_bossver[11]);
01230         }
01231 
01232         //EstTofCalConst
01233         if((cType=="EstTofCal"))
01234         {
01235                 std::string cType="EsTof";
01236                 if(m_flag[6]=="default")
01237                 {
01238                         st1=getSftParVer(m_bossver[6],m_calPar[6],runfrm1,runto1,runNo,m_bossRelease,cType);
01239                         //cout<<cType<<" runfrm1,runto1 @update is:"<<runfrm1<<":::"<<runto1<<endl;
01240                         if (st1 .isFailure() ) {
01241                                 log << MSG::ERROR << " Unable to find DatabaseSvc " << endreq;
01242                                 return st1;
01243                         }
01244                 }
01245                 flag=m_flag[6];
01246                 //cout<<"flag @update EstTof is:"<<m_flag[6]<<endl;
01247                 ret = m_meta->getReadEstTofInfo(ser,&runfrm,&runto,m_calPar[6],res,runNo,m_bossver[6]);
01248         }
01249 
01250         if(ret!=calibUtil::Metadata::RETOk){
01251                 log <<  MSG::ERROR   << "Error searching in the database" << endreq;
01252                 exit(1);
01253         }
01254 
01255         physFmt="TREE";
01256         unsigned char storageType;
01257         status = decodeDescription(physFmt, storageType);
01258 
01259         // Depending on value of eDataFmt, figure out which private
01260         // conversion service to invoke.  Pass dataIdent and fmtVersion
01261         // as part of the opaque address.  
01262         // Create temporary address for the relevant type and classID 
01263         log << MSG::DEBUG << "Creating an address of type " 
01264                 << (int)storageType << " for class " << classID << endreq;
01265 
01266         //   int sz=res.size();
01267         DatabaseRecord* records1 = res[0];
01268 
01269         if(m_dbStatus=="OK"){
01270                 if(std::string((*records1)["Status"])!="OK") {
01271                         log<<MSG::FATAL<<"the status of type  "<<cType<<" is "<< (*records1)["Status"]<<"  your setting is OK"<<endreq;
01272                         exit(1);
01273                 }
01274         }
01275 
01276 
01277         IOpaqueAddress* tmpAddress;
01278         //const unsigned long ipar[2] = {runfrm,runto};
01279         const unsigned long ipar[2] = {0,0};//yzhang fix unsigned bug for runfrom runto
01280 
01281         tmpAddress = new TreeAddress(storageType, classID,*records1,ipar);
01282   log << MSG::DEBUG <<__LINE__<<cType<<" runfrm,runto @CalVtxLumVer/update  is:"<<runfrm1<<":::"<<runto1<<endreq;
01283         sscanf((*records1)["RunFrom"], "%d", &runfrm);
01284         sscanf((*records1)["RunTo"], "%d", &runto);
01285         log << MSG::DEBUG << __LINE__<<" records @update runfrm is:"<<(*records1)["RunFrom"]<<" runto is:"<<(*records1)["RunTo"]<<" ser_no is:"<<ser<<endreq;
01286         if(flag=="default")
01287         {
01288                 if(runfrm1>runfrm)
01289                   {
01290                     runfrm=runfrm1;
01291                         }
01292     if(runto1<runto)
01293       {
01294        runto=runto1;
01295       } 
01296         }
01297         if(flag=="set")
01298         {
01299                 flag=="default";
01300         }
01301 
01302  log << MSG::DEBUG <<__LINE__<< " runfrm of max is:"<<runfrm<<" runto min is:"<<runto<<endreq;
01303         TreeAddress* treeAddress =  dynamic_cast <TreeAddress*> (tmpAddress);
01304         treeAddress->setRunFrom(runfrm);
01305         treeAddress->setRunTo(runto);
01306         //log << MSG::DEBUG << __LINE__<<" records runfrm is:"<<(*records1)["RunFrom"]<<" runto is:"<<(*records1)["RunTo"]<<" ser_no is:"<<ser<<endreq;
01307         //log << MSG::DEBUG <<__LINE__<< " runfrm is:"<<runfrm<<" runto is:"<<runto<<" ser_no is:"<<ser<<endreq;
01308 
01309         log << MSG::DEBUG << "Temporary address successfully created" << endreq;
01310         tmpAddress->addRef();
01311 
01312         // Set the transient store registry for the object associated to this address
01313         tmpAddress->setRegistry(entry);
01314 
01315         // Now update the object
01316         DataObject* pNewObject;
01317         status = m_detPersSvc->createObj(tmpAddress, pNewObject);
01318         tmpAddress->release();
01319         if ( !status.isSuccess() ) {
01320                 log << MSG::ERROR 
01321                         << "Persistency service could not create object" << endreq;
01322                 return status;
01323         }
01324 
01325         // Since DataObject::operator= operator is not virtual, dynamic cast first!
01326         // Overloaded virtual method Condition::update() must be properly defined!
01327         // The memory pointed to by the old pointer must contain the new object    
01328         // Note this dynamic cast only gets us part-way.  The object is
01329         // actually of some type derived from CalibBase.
01330         CalibBase1* pNewBase = dynamic_cast<CalibBase1*>(pNewObject);
01331         if  (0 == pNewBase) {
01332                 log << MSG::ERROR
01333                         << "Cannot update objects other than Calib objects: " 
01334                         << "update() must be defined!"
01335                         << endreq;
01336                 return StatusCode::FAILURE;
01337         }
01338 
01339         // Deep copy the new calib into the old DataObject.  To copy the *whole*
01340         // object, not just the CalibBase part, classes derived from CalibBase
01341         // must override update method.  
01342         // NOTE:  classes directly derived from CalibBase must call
01343         //        CalibBase::update in their own update method.
01344         pBase->update(*pNewBase, &log);  
01345         res.clear();
01346         f1->Close();
01347         delete f1;
01348         delete pNewBase;
01349         return StatusCode::SUCCESS;
01350 }
01351 
01352 StatusCode  CalibMySQLCnvSvc::decodeDescription(const std::string& description,
01353                 unsigned char& type )
01354 {
01355         MsgStream log(msgSvc(), "CalibMySQLCnvSvc");
01356 
01357         //   description ="ROOT";
01358         if (description == std::string("XML")) {
01359                 type = XML_StorageType;
01360         }
01361         else if (description == std::string("ROOT")) {
01362                 type = CALIBROOT_StorageType;
01363         }
01364         else if (description == std::string("TREE")) {
01365                 type = CALIBTREE_StorageType;
01366         }
01367         else {       // unsupported
01368                 log << MSG::ERROR << "unsupported storage type " << description << endreq;
01369                 return StatusCode::FAILURE;
01370         }
01371         return StatusCode::SUCCESS;
01372 }
01373 
01374 
01376 calibUtil::Metadata* CalibMySQLCnvSvc::getMeta( ) {
01377         return m_meta;
01378 }
01379 
01380 
01381 

Generated on Tue Nov 29 22:57:50 2016 for BOSS_7.0.2 by  doxygen 1.4.7