/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/CalibSvc/CalibTreeCnv/CalibTreeCnv-00-01-18/src/cnv/TreeCalBaseCnv.cxx

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibTreeCnv/src/cnv/TreeCalBaseCnv.cxx,v 1.4 2012/01/05 03:53:29 zhangy Exp $
00008 #include "TreeCalBaseCnv.h"
00009 
00010 #include "GaudiKernel/CnvFactory.h"
00011 #include "GaudiKernel/IOpaqueAddress.h"
00012 #include "GaudiKernel/DataObject.h"
00013 #include "GaudiKernel/IAddressCreator.h"
00014 #include "GaudiKernel/IDataProviderSvc.h"
00015 #include "GaudiKernel/IConversionSvc.h"
00016 #include "GaudiKernel/MsgStream.h"
00017 
00018 #include "facilities/Util.h"   // for translating env variables
00019 #include "CalibDataSvc/ICalibRootSvc.h" 
00020 #include "CalibDataSvc/ICalibMetaCnvSvc.h"
00021 #include "CalibDataSvc/IInstrumentName.h"
00022 #include "CalibData/CalibBase.h"
00023 #include "CalibData/CalibBase1.h"
00024 // Guessing at needed Root includes
00025 #include "TROOT.h"    // need this for cd??
00026 #include "TFile.h"
00027 #include "TTree.h"
00028 #include "TObject.h"
00029 #include "DatabaseSvc/IDatabaseSvc.h"
00030 #include "CalibMySQLCnv/TreeAddress.h"
00031 
00032 TreeCalBaseCnv::~TreeCalBaseCnv() {
00033   // release TFile, TTree if they need releasing.  With normal 
00034   // termination they should already have been released.
00035 
00036   // doClean();
00037 
00038 }
00039 
00040 // static CnvFactory<TreeCalBaseCnv> s_factory;
00041 // const ICnvFactory& TreeCalBaseCnvFactory = s_factory;
00042 TreeCalBaseCnv::TreeCalBaseCnv( ISvcLocator* svc, const CLID& clid) :
00043   Converter (CALIBTREE_StorageType, clid, svc),
00044   m_treeSvc (0), m_metaSvc(0), m_instrSvc(0),m_outFile(0), m_ttree(0), m_inFile(0), m_saveDir(0) {}
00045 
00046 StatusCode TreeCalBaseCnv::initialize() {
00047   StatusCode status = Converter::initialize();
00048 
00049   IDataProviderSvc* dp;
00050 
00051   // I guess the service names are assigned in jobOptions?
00052 
00053 /*  serviceLocator()->getService ("CalibDataSvc",
00054                                 IID_IDataProviderSvc,
00055                                 (IInterface*&)dp);*/
00056   serviceLocator()->getService ("CalibDataSvc",
00057                                 IDataProviderSvc::interfaceID(),
00058                                 (IInterface*&)dp);
00059   setDataProvider(dp);
00060   
00061   // Locate the Root Conversion Service
00062   serviceLocator()->getService ("CalibTreeCnvSvc",
00063                                 IID_ICalibTreeSvc,
00064                                 (IInterface*&) m_treeSvc);
00065 
00066   // Locate meta conversion service
00067   // Will anything need to be changed here to accommodate possibility
00068   // of two concrete implementations of ICalibMetaCnvSvc?  Would
00069   // have different storage types.  Could specify type desired
00070   // as job option.  Ditto for name of class?
00071   serviceLocator()->getService("CalibMySQLCnvSvc", 
00072                                IID_ICalibMetaCnvSvc,
00073                                 (IInterface*&)m_metaSvc);
00074 
00075   serviceLocator()->getService ("CalibDataSvc",
00076                                 IID_IInstrumentName,
00077                                 (IInterface*&)m_instrSvc);
00078 
00079   return status;
00080 }
00081 
00082 StatusCode TreeCalBaseCnv::finalize() {
00083   return Converter::finalize();
00084 }
00085 
00086 
00087             /******      ROOT services     *****/
00088 
00089 StatusCode TreeCalBaseCnv::createRoot(const std::string& /* fname */, 
00090                                    CalibData::CalibBase1* /* pTDSObj */) {
00091   MsgStream log(msgSvc(), "TreeCalBaseCnv");
00092   log << MSG::ERROR 
00093       << "createRoot method not implemented for this calibration type" 
00094       << endreq;
00095   return StatusCode::FAILURE;
00096 }
00097 
00098 
00099 // Do our part to write out object -- which is nothing
00100 StatusCode TreeCalBaseCnv::fillRoot(CalibData::CalibBase* /*pTDSObj */, 
00101                                  TObject* /* pRootObj */) {
00102 
00103   // Get instrument name from InstrumentName service  Now handled by 
00104   // TreeCalBaseCnv
00105   //  TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
00106   //  pRootObj->setInstrument(instr);
00107   return StatusCode::SUCCESS;
00108 }
00109 
00110 // (To TDS) Conversion stuff
00111 StatusCode TreeCalBaseCnv::createObj(IOpaqueAddress* addr,
00112                                   DataObject*& refpObject) {
00113   //  StatusCode ret;
00114 
00115   // first do the things we always need:
00116   //   First string parameter of opaque address is file ident
00117   MsgStream log(msgSvc(), "TreeCalBaseCnv");
00118    log << MSG::DEBUG<<"TreeCalBaseCnv::createObj( starting ...."<<endreq;
00119  //  const std::string* par = addr->par();
00120 
00121  // std::string par0 = par[0];
00122    
00123 //  return internalCreateObj(par0, refpObject, addr);
00124   return internalCreateObj(refpObject, addr);
00125 
00126 }
00127 
00128 //StatusCode TreeCalBaseCnv::internalCreateObj(const std::string& fname,
00129 //                                          DataObject*& refpObject,
00130 //                                          IOpaqueAddress* address) {
00131   StatusCode TreeCalBaseCnv::internalCreateObj(DataObject*& refpObject,
00132                                           IOpaqueAddress* address) {
00133 
00134   MsgStream log(msgSvc(), "TreeCalBaseCnv");
00135    log << MSG::DEBUG<<"TreeCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
00136    TreeCalBaseCnv* converter = this;
00137   CLID classId = address->clID();
00138 
00139   IConverter* conv = this->conversionSvc()->converter(classId);
00140   if (0 == conv) {
00141     log << MSG::WARNING
00142         << "No proper converter found for classID " << classId
00143             << ", the default converter"
00144             << " will be used. " << endreq;
00145   } else {
00146     converter = dynamic_cast <TreeCalBaseCnv*> (conv);
00147     if (0 == converter) {
00148       log << MSG::ERROR
00149           << "The converter found for classID " << classId
00150               << " was not a descendent of TreeCalBaseCnv as it should be "
00151               << "( was of type " << typeid (*converter).name() << "). "
00152               << "The default converter will be used" << endreq;
00153       converter = this;
00154     }
00155   }
00156 
00157   TreeAddress* treeAddress =  dynamic_cast <TreeAddress*> (address);
00158   m_runfrm = treeAddress->getRunFrom();
00159   m_runto = treeAddress->getRunTo();
00160     //m_runfrm =*( address->ipar());
00161     //m_runto =*( address->ipar()+1);
00162  //   m_runfrm = 100;
00163  //   m_runto =1000;
00164    // creates an object for the node found
00165    StatusCode sc = converter->i_createObj(address, refpObject);
00166      if (sc.isFailure()) {
00167     return sc;
00168   } 
00169      CalibData::CalibBase1* tmpObject =  dynamic_cast <CalibData::CalibBase1*> (refpObject);
00170      setBaseInfo(tmpObject);
00171   // ends up the object construction
00172   sc = converter->i_processObj(refpObject, address);
00173   if (sc.isSuccess()) {
00174     log << MSG::DEBUG << "Successfully created calib. object " << endreq;
00175   }
00176  // closeRead();
00177   return sc;
00178 }
00179 
00180 /* 
00181    Base class version of this routine shouldn't really be called
00182    since it doesn't correspond to a TDS object.
00183 */
00184 StatusCode TreeCalBaseCnv::i_createObj (IOpaqueAddress* address,
00185                                      DataObject*& /* refpObject */) {
00186   return StatusCode::FAILURE;  // shouldn't ever get here
00187 }
00188   
00189 // Default is to do nothing.  Derived classes may override.
00190 StatusCode TreeCalBaseCnv::i_processObj(DataObject*, // pObject,
00191                                      IOpaqueAddress* ) /* address */  {
00192   return StatusCode::SUCCESS;
00193 }
00194 
00196 void TreeCalBaseCnv::setBaseInfo(CalibData::CalibBase1* pObj) {
00197    MsgStream log(msgSvc(), "TreeCalBaseCnv");
00198    log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
00199   pObj->setrunfrm(m_runfrm);
00200   pObj->setrunto(m_runto);
00201 }

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