/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/CalibSvc/CalibDataSvc/CalibDataSvc-00-01-04/src/CalibDataSvc.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibDataSvc/src/CalibDataSvc.cxx,v 1.27 2013/05/02 06:25:03 maqm Exp $
00002 
00003 // Include files
00004 #include "CalibDataSvc/CalibDataSvc.h"
00005 #include "CalibDataSvc/CalibCLIDNode.h"
00006 //#include "CalibData/CalibTime.h"
00007 #include "GaudiKernel/IAddressCreator.h"
00008 #include "GaudiKernel/IConversionSvc.h"
00009 #include "GaudiKernel/IOpaqueAddress.h"
00010 #include "GaudiKernel/ISvcLocator.h"
00011 #include "GaudiKernel/IIncidentSvc.h"
00012 #include "GaudiKernel/IValidity.h"
00013 #include "GaudiKernel/IDataProviderSvc.h"
00014 #include "GaudiKernel/DataObject.h"
00015 #include "GaudiKernel/MsgStream.h"
00016 #include "GaudiKernel/SvcFactory.h"
00017 //#include "GaudiKernel/TimePoint.h"
00018 #include "GaudiKernel/SmartDataPtr.h"
00019 
00020 #include "CalibDataSvc/ICalibRootSvc.h" //maqm add
00021 #include "CalibData/CalibModelSvc.h"
00022 #include "CalibData/CalibBase1.h"
00023 #include "CalibData/Mdc/MdcCalStruct.h"
00024 #include "GaudiKernel/RegistryEntry.h"//huangb add
00025 #include "TROOT.h"
00026 #include "TFile.h"
00027 #include "TTree.h"
00028 
00029 #include "EventModel/EventModel.h"
00030 #include "EventModel/EventHeader.h"
00031 //#include "EventModel/EventList.h"
00032 
00033 //#include "CalibData/Mdc/Mdct0par.h"
00034 #define CAST_REGENTRY(x,y) dynamic_cast<x>(y)
00035 //#define CAST_REGENTRY(x,y) (x)(y)
00036 typedef DataSvcHelpers::RegistryEntry RegEntry;
00037 
00038 using namespace CalibData;
00039 // Instantiation of a static factory class used by clients to create
00040 // instances of this service
00041 //static SvcFactory<CalibDataSvc> s_factory;
00042 //const ISvcFactory& CalibDataSvcFactory = s_factory;
00043 
00045 CalibDataSvc::CalibDataSvc(const std::string& name,ISvcLocator* svc) :
00046   DataSvc(name,svc)
00047  {
00048      
00049   // declare a property which is a list of known calibrations.
00050   // Have default list in one of the standard options files.  
00051   // User can add others.
00052   declareProperty("CalibNameList", m_calibList);
00053   declareProperty("CalibFlavorList", m_flavorList);
00054   declareProperty("CalibRootName",   m_calibRootName  = "Calib" ); 
00055   declareProperty("Mdc_CalibStorageType",
00056                      m_calibType[0] = CALIBROOT_StorageType );
00057   declareProperty("Tof_CalibStorageType",
00058                      m_calibType[1] = CALIBROOT_StorageType );
00059   declareProperty("Dedx_CalibStorageType",
00060                      m_calibType[2] = CALIBROOT_StorageType );
00061   declareProperty("EMC_CalibStorageType",
00062                      m_calibType[3] = CALIBROOT_StorageType ); 
00063   declareProperty("MUC_CalibStorageType",
00064                      m_calibType[4] = CALIBROOT_StorageType );
00065   declareProperty("EsTime_CalibStorageType",
00066                      m_calibType[5] = CALIBROOT_StorageType );
00067   declareProperty("EstTof_CalibStorageType",
00068                      m_calibType[6] = CALIBROOT_StorageType );
00069   declareProperty("TofQElec_CalibStorageType",
00070                      m_calibType[8] = CALIBROOT_StorageType );
00071   declareProperty("TofSim_CalibStorageType",
00072                      m_calibType[9] = CALIBROOT_StorageType );
00073   declareProperty("DedxSim_CalibStorageType",
00074                      m_calibType[10] = CALIBROOT_StorageType );
00075 
00076   //MdcAlign
00077   m_calibType[7]=14;
00078   //MdcDataConst
00079   m_calibType[11]=14;
00080 
00081   // m_rootName and m_rootCLID are declared in base class DataSvc
00082   m_rootName = "/" + m_calibRootName;
00083   m_rootCLID = CLID_DataObject;  
00084 
00085  
00086 
00087 }
00088 
00090 CalibDataSvc::~CalibDataSvc()  {
00091   setDataLoader(0);
00092   clearStore();
00093 }
00094 
00095 // Service initialization
00096 StatusCode CalibDataSvc::initialize()   {
00097 
00098   StatusCode sc;
00099 
00100   sc  = DataSvc::initialize();     // Call base class initialisation
00101   if (sc.isFailure() )  return sc;
00102 
00103   // Set up MsgSvc, Data Loader
00104   MsgStream log(msgSvc(), name());
00105   IConversionSvc* cnv_svc;
00106   sc = serviceLocator()->service("DetectorPersistencySvc", cnv_svc, true);
00107   if (sc .isFailure() ) {
00108     log << MSG::ERROR << "Unable to find DetectorPersistencySvc " << endreq;
00109     return sc;
00110   }
00111  
00112   IIncidentSvc* incsvc;
00113      sc = service("IncidentSvc", incsvc);
00114      int priority = 100;
00115      if( sc.isSuccess() ){
00116           incsvc -> addListener(this, "NewRun", priority);
00117      }
00118   
00119  sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
00120   if (sc .isFailure() ) {
00121     log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
00122     return sc;
00123   }
00124 
00125   sc = setDataLoader(cnv_svc);
00126   if (sc.isFailure() ) {
00127     log << MSG::ERROR << "Unable to set data loader " << endreq;
00128     return sc;
00129   }
00130   sc = setProperties();   
00131 
00132   // Initialize the calibration data transient store
00133   IAddressCreator*     calibCreator = 0;
00134 
00135   // Use Gaudi-supplied DetectorPersistencySvc; it's essentially
00136   // the same as base class PersistencySvc, which is all we need
00137   sc = serviceLocator()->service("DetectorPersistencySvc", calibCreator);
00138   
00139   if( sc.isFailure() ) {
00140     log << MSG::ERROR << "Unable to locate DetectorPersistencySvc." << endreq;
00141     return StatusCode::FAILURE; 
00142   }
00143   
00144   //   Make the root for the TDDS data
00145   DataObject* rootObj = new DataObject();
00146   sc = setRoot(m_rootName, rootObj);
00147   if (!sc.isSuccess() ) {
00148     log << MSG::ERROR << "Unable to set calib data store root." << endreq;
00149     delete rootObj;
00150     return sc;
00151   }
00152 
00153 // Create and register the next level of nodes.
00154 // Have one per calibration type. They are of a class trivially 
00155 // derived from DataObject, CalibCLIDNode.  Only additional 
00156 // information is CLID of child nodes.  List comes from CalibData 
00157 // namespace
00158 //StatusCode CalibDataSvc::makeFlavorNodes(IAddressCreator*  calibCreator,
00159 //                                         MsgStream* log) {
00160   typedef std::vector<CalibData::CalibModelSvc::CalibPair>::const_iterator 
00161     PairIt;
00162   PairIt  pairIt;
00163   CalibData::CalibModelSvc svc;
00164   const std::vector<CalibData::CalibModelSvc::CalibPair>& pairs = 
00165     svc.getPairs();
00166   int jj =0;
00167   for (pairIt = pairs.begin(); pairIt != pairs.end(); pairIt++,jj++) {
00168     
00169     CalibCLIDNode* node = new CalibCLIDNode(pairIt->second);
00170 
00171     std::string calibTypePath(pairIt->first);
00172     // sc =DataSvc::registerObject(calibTypePath, node);
00173 
00174     // Still have to figure out what to do about args, iargs
00175     unsigned long iargs[]={0,0};
00176     IOpaqueAddress* pAddress;
00177 
00178     // Set up nodes for each calibration type, default flavor
00179     // Create and register addresses suitable for the metadata
00180     // conversion service.  Ultimately, in order to find the "right"
00181     // set of constants,  it needs to know
00182     //    Calibration type, e.g. CAL Electronic gain
00183     //    Flavor            e.g. vanilla 
00184     //    Event time        validity period of constants must include this time
00185     //    Instrument        LAT, EM, etc.
00186     // We save the first two, or equivalent information, in the first
00187     // string parameter of a generic address
00188     // Consumers can use utilities in CalibData::CalibModelSvc to
00189     // extract fields they need
00190     // Event time and Instrument will be discovered by conversion service
00191     // when constants are requested by invoking our (CalibDataSvc) time
00192     // and instrument name services, resp.
00193 
00194     // Always do vanilla
00195     std::string fullpath = calibTypePath;
00196     std::string args[] = {fullpath};
00197   
00198 //    sc = calibCreator->createAddress(m_calibStorageType, 
00199 //                                   pairIt->second,   // class id
00200 //                                     args, iargs, pAddress);
00201     sc = calibCreator->createAddress(m_calibType[jj],
00202                                      pairIt->second,   // class id
00203                                      args, iargs, pAddress);
00204 
00205 
00206     if (!sc.isSuccess()) { 
00207       log<< MSG::INFO 
00208           << "Unable to create Calib address with path " << fullpath << endreq;
00209     }
00210  
00211     // A node unof a specific flavor is a child of the per-calibration type
00212     // node for which an object was registered above.
00213     sc = registerAddress(fullpath, pAddress);
00214     if (!sc.isSuccess()) {
00215       log<< MSG::ERROR << "Unable to register Calib address with path" 
00216          << fullpath << endreq;
00217     }
00218     // Now do the same for any requested flavors
00219     /*
00220     unsigned int ix;
00221     
00222     for (ix = 0; ix < m_flavorList.size(); ix++) { 
00223       log<<MSG::DEBUG<<"here is the flavor in the CalibDataSvc"<<endreq; 
00224       // Don't redo vanilla, if present in user list
00225       if (m_flavorList[ix] == std::string("vanilla")) continue;
00226 
00227       fullpath = calibTypePath + "/" + m_flavorList[ix];
00228       args[0] = fullpath;
00229 
00230       sc = calibCreator->createAddress(m_calibStorageType, 
00231                                        pairIt->second, args, iargs, pAddress); 
00232       if (!sc.isSuccess()) {
00233 
00234 
00235         log<< MSG::ERROR << "Unable to create Calib address with path " 
00236             << fullpath << endreq;
00237       }
00238       sc = DataSvc::registerAddress(fullpath, pAddress);
00239       if (!sc.isSuccess()) {
00240         log<< MSG::ERROR << "Unable to register Calib address with path " 
00241             << fullpath << endreq;
00242       }
00243     }   
00244  // end flavor loop 
00245  */
00246   } 
00247 // end calibType loop
00248 // initialize the parameters
00249                                      
00250   return StatusCode::SUCCESS;
00251 }
00252      
00253 
00254 
00256 StatusCode CalibDataSvc::finalize()
00257 {
00258   MsgStream log(msgSvc(), name());
00259   log << MSG::DEBUG << "Finalizing" << endreq;
00260 
00261   //  return StatusCode::SUCCESS;
00262   // Finalize the base class
00263   //  huangb temply delete
00264    return DataSvc::finalize();
00265 }
00266 
00267 StatusCode CalibDataSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
00268 {
00269   // With the highest priority return the specific interfaces
00270   // If interfaces are not directly available, try out a base class
00271   if (IDetDataSvc::interfaceID().versionMatch(riid) ) {
00272     *ppvInterface = (IDetDataSvc*)this;
00273   } else if (IInstrumentName::interfaceID().versionMatch(riid) ) {
00274     *ppvInterface = (IInstrumentName*) this;
00275 //  } else if ( IID_IIncidentListener.versionMatch(riid) ) {
00276 //    *ppvInterface = (IIncidentListener*)this; 
00277   } else {
00278     return DataSvc::queryInterface(riid, ppvInterface);
00279   }
00280   addRef();
00281   return StatusCode::SUCCESS;
00282 }
00283 
00284 
00285 
00286 
00287 
00288 
00290 StatusCode CalibDataSvc::clearStore()   {
00291   DataSvc::clearStore();
00292   return StatusCode::SUCCESS;
00293 }
00294 
00295 //update the calibration in TCDS if a new run comes
00296 void CalibDataSvc::handle ( const Incident& inc ) {
00297    MsgStream log( msgSvc(), name() );
00298      return; 
00299   }
00300 
00301 
00302 
00303 
00304 
00305 
00306 StatusCode CalibDataSvc::updateObject( DataObject* toUpdate ) {
00307 
00308    
00309   MsgStream log( msgSvc(), name() );
00310    log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
00311   // Check that object to update exists
00312   if ( 0 == toUpdate ) { 
00313     log << MSG::ERROR
00314         << "There is no DataObject to update" << endreq;
00315     return INVALID_OBJECT; 
00316   }
00317 
00318    log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
00319   // Now delegate update to the conversion service by calling the base class
00320   StatusCode status = DataSvc::updateObject(toUpdate);
00321   if ( !status.isSuccess() ) {
00322     log << MSG::ERROR 
00323         << "Could not update DataObject" << endreq; 
00324     if ( status == NO_DATA_LOADER )
00325       log << MSG::ERROR << "There is no data loader" << endreq; 
00326     return status;
00327   } 
00328    log << MSG::INFO<<"begin of CalibDataSvc::updateObject successfully updated"<<endreq;
00329   // DataObject was successfully updated
00330   return StatusCode::SUCCESS;
00331 }
00332 
00333 StatusCode CalibDataSvc::loadObject(IConversionSvc* pLoader, 
00334                                     IRegistry* pRegistry) {
00335   return DataSvc::loadObject(pLoader, pRegistry);
00336 
00337 }
00338 
00339 StatusCode CalibDataSvc::retrieveObject(const std::string& fullPath,DataObject*& pObject)
00340 {  
00341    MsgStream log( msgSvc(), name() );
00342   
00343  int runNo;
00344  //maqm SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event");
00345  SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
00346  if( evt ){
00347    runNo = evt -> runNumber();
00348    log << MSG::DEBUG <<"The runNumber of current event is  "<<runNo<<endreq;
00349  }
00350 
00351  else{
00352    log << MSG::WARNING << "WARNING accessing Event" <<endreq;
00353 //   return StatusCode::FAILURE;
00354  }
00355 
00356    
00357 StatusCode  sc =DataSvc::retrieveObject(fullPath,pObject);
00358  if (!sc.isSuccess()) {
00359         log<< MSG::ERROR << "Unable to get the retrieveObject" 
00360             << endreq;
00361         return sc;
00362   }
00363 // if(fullPath=="/Calib/MdcAlign"&&m_calibType[0]==CALIBROOT_StorageType) 
00364 //   { return StatusCode::SUCCESS;}
00365 if(fullPath=="/Calib/MdcCal"&&m_calibType[0]==CALIBROOT_StorageType){
00366     return StatusCode::SUCCESS;}
00367 if(fullPath=="/Calib/DedxCal"&&m_calibType[2]==CALIBROOT_StorageType){
00368     return StatusCode::SUCCESS;}
00369 if(fullPath=="/Calib/TofCal"&&m_calibType[1]==CALIBROOT_StorageType){
00370     return StatusCode::SUCCESS;}
00371 if(fullPath=="/Calib/EmcCal"&&m_calibType[3]==CALIBROOT_StorageType){
00372     return StatusCode::SUCCESS;}
00373 if(fullPath=="/Calib/MucCal"&&m_calibType[4]==CALIBROOT_StorageType){
00374     return StatusCode::SUCCESS;}
00375 if(fullPath=="/Calib/EsTimeCal"&&m_calibType[5]==CALIBROOT_StorageType){
00376     return StatusCode::SUCCESS;}
00377 if(fullPath=="/Calib/EstTofCal"&&m_calibType[6]==CALIBROOT_StorageType){
00378     return StatusCode::SUCCESS;}
00379 if(fullPath=="/Calib/TofQElec"&&m_calibType[8]==CALIBROOT_StorageType){
00380     return StatusCode::SUCCESS;}
00381 if(fullPath=="/Calib/TofSim"&&m_calibType[9]==CALIBROOT_StorageType){
00382     return StatusCode::SUCCESS;}
00383 if(fullPath=="/Calib/DedxSim"&&m_calibType[10]==CALIBROOT_StorageType){
00384     return StatusCode::SUCCESS;}
00385  
00386 
00387 CalibData::CalibBase1* tmpObject = dynamic_cast<CalibData::CalibBase1*>(pObject);
00388 if(fullPath=="/Calib/TofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00389 { return StatusCode::SUCCESS;}
00390 if(fullPath=="/Calib/EstTofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00391 { return StatusCode::SUCCESS;}
00392 if(fullPath=="/Calib/TofSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00393 { return StatusCode::SUCCESS;}
00394 if(fullPath=="/Calib/DedxSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00395 { return StatusCode::SUCCESS;}
00396 
00397 
00398 
00399 if( fabs(runNo) >= tmpObject->getrunfrm() && fabs(runNo)<=tmpObject->getrunto())
00400 {
00401         log << MSG::DEBUG <<__LINE__<< " runfrm @CalibDataSvc is:"<<tmpObject->getrunfrm()<<" runto min is:"<<tmpObject->getrunto()<<endreq;
00402         return StatusCode::SUCCESS;}
00403 else
00404 { 
00405         log<< MSG::INFO <<"@CalibDataSvc runfrm="<< tmpObject->getrunfrm()<<"runto="<<tmpObject->getrunto()<<"runNo="<<runNo<<endreq;
00406         log<< MSG::DEBUG << "update the Object" 
00407                 << endreq;
00408         sc =DataSvc:: updateObject(pObject);
00409         return sc;    
00410 }//end of else
00411 }//end of if
00412 
00413 StatusCode CalibDataSvc::registerObject (const std::string& parentPath,
00414                                     const std::string& objPath,
00415                                     DataObject* pObject)   {
00416   DataObject* pO = 0;
00417   StatusCode status =DataSvc::retrieveObject(parentPath, pO);
00418   if ( !status.isSuccess() && m_forceLeaves )   {
00419     pO = createDefaultObject();
00420     status =DataSvc::registerObject(parentPath, pO);
00421     if ( !status.isSuccess() )   {
00422       pO->release();
00423     }//end of if
00424   }//end of if( !status.isSuccess() && m_forceLeaves )
00425   if ( status.isSuccess() )   {
00426     status =DataSvc::registerObject(pO, objPath, pObject);
00427   }
00428   if(status.isSuccess() ){
00429   return status;
00430 }
00431 }
00432 
00433    

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