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

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibXmlCnvSvc/src/CalibXmlCnvSvc.cxx,v 1.4 2011/02/17 05:14:40 maqm Exp $
00002 
00003 // one or both of following includes may not be necessary..
00004 // depends on whether we keep and use private members
00005 // m_detPersSvc and m_detDataSvc
00006 
00007 #include "GaudiKernel/IDetDataSvc.h"
00008 #include "GaudiKernel/IConversionSvc.h"
00009 
00010 #include "GaudiKernel/MsgStream.h"
00011 #include "GaudiKernel/SvcFactory.h"
00012 #include "GaudiKernel/CnvFactory.h"
00013 #include "GaudiKernel/ISvcLocator.h"
00014 #include "GaudiKernel/IDataProviderSvc.h"
00015 #include "GaudiKernel/GenericAddress.h"
00016 #include "CalibXmlCnvSvc/CalibXmlCnvSvc.h"
00017 #include "xmlBase/XmlParser.h"
00018 
00019 // Make instances only via static factory class
00020 //static SvcFactory<CalibXmlCnvSvc> calibXmlCnvSvc_factory;
00021 //const ISvcFactory& CalibXmlCnvSvcFactory = calibXmlCnvSvc_factory;
00022 
00023 CalibXmlCnvSvc::CalibXmlCnvSvc(const std::string& name, 
00024                                ISvcLocator* svc) :
00025   ConversionSvc(name, svc, XML_StorageType),
00026   m_detPersSvc(0), m_detDataSvc(0), m_parser(0) {
00027 
00028   // Some day might have a property to declare having to do with path to
00029   // xml files.
00030 }
00031 
00032 StatusCode CalibXmlCnvSvc::queryInterface(const InterfaceID& riid,
00033                                           void** ppvInterface) {
00034   if (IID_ICalibXmlSvc.versionMatch(riid))  {
00035     *ppvInterface = (ICalibXmlSvc*)this;
00036   }
00037   else {
00038     // Interface is not directly availible: try out a base class
00039     return ConversionSvc::queryInterface(riid, ppvInterface);
00040   }
00041   addRef();
00042   return StatusCode::SUCCESS;
00043 }
00044 
00045 StatusCode CalibXmlCnvSvc::initialize() {
00046   StatusCode sc = ConversionSvc::initialize();
00047 
00048   MsgStream log(msgSvc(), "CalibXmlCnvSvc");
00049 
00050   if (!sc.isSuccess()) return sc;
00051 
00052   /* Paste in a bit of CalibMySQLCnvSvc::initialize */
00053 
00054   // Locate the Calib Data Service.  Since it inherits from DataSvc
00055   // it has to implement IDataProviderSvc
00056   IDataProviderSvc* pCDS = 0;
00057   //sc = serviceLocator()->getService("CalibDataSvc",  IID_IDataProviderSvc, (IInterface*&)pCDS);
00058   sc = serviceLocator()->getService("CalibDataSvc", IDataProviderSvc::interfaceID(), (IInterface*&)pCDS)
00059 ;
00060   if ( !sc.isSuccess() ) {
00061     log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
00062     return sc;
00063   }
00064 
00065   // Set the CalibDataSvc as data provider service
00066   sc = setDataProvider(pCDS);
00067   if ( !sc.isSuccess() ) {
00068     log << MSG::ERROR << "Could not set data provider" << endreq;
00069     return sc;
00070   }
00071 
00072   /*   End of pasted bit */
00073 
00074 
00075   /* Paste in more of CalibMySQLCnvSvc::initialize  */
00076   // Locate IConversionSvc interface of the DetectorPersistencySvc
00077   sc = serviceLocator()->service 
00078     ("DetectorPersistencySvc", m_detPersSvc, true);
00079   if ( !sc.isSuccess() ) {
00080     log << MSG::ERROR 
00081         << "Cannot locate IConversionSvc interface of DetectorPersistencySvc"
00082         << endreq;
00083     return sc;
00084   } else {
00085     log << MSG::DEBUG 
00086         << "Retrieved IConversionSvc interface of DetectorPersistencySvc"
00087         << endreq;
00088   }
00089   
00090   // Query the IAddressCreator interface of the detector persistency service
00091   IAddressCreator* iAddrCreator;
00092   //sc = m_detPersSvc->queryInterface(IID_IAddressCreator, 
00093 //                                  (void**) &iAddrCreator);
00094    sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(), (void**) &iAddrCreator);
00095   if ( !sc.isSuccess() ) {
00096     log << MSG::ERROR 
00097         << "Cannot query IAddressCreator interface of DetectorPersistencySvc" 
00098         << endreq;
00099     return sc;
00100   } else {
00101     log << MSG::DEBUG 
00102         << "Retrieved IAddressCreator interface of DetectorPersistencySvc" 
00103         << endreq;
00104   }
00105   log << MSG::DEBUG 
00106       << "Set it as the address creator of the CalibXmlCnvSvc" << endreq;
00107   sc = setAddressCreator(iAddrCreator);
00108   if ( !sc.isSuccess() ) {
00109     log << MSG::ERROR   << "Cannot set the address creator" << endreq;
00110     return sc;
00111   }
00112 
00113   // end of second pasted piece
00114 
00115 
00116   m_parser = new xmlBase::XmlParser();
00117 
00118   if (m_parser == 0) {
00119     log << MSG::FATAL << "Unable to create XML parser instance \n"
00120         << endreq;
00121   }
00122 
00123   // set properties if there are any??
00124 
00125   return sc;
00126 }
00127 
00128 StatusCode CalibXmlCnvSvc::finalize() {
00129   delete m_parser;
00130   m_parser = 0;
00131   return ConversionSvc::finalize();
00132 }
00133 
00134 StatusCode CalibXmlCnvSvc::createAddress(unsigned char svc_type,
00135                                          const CLID& clid,
00136                                          const std::string* par, 
00137                                          const unsigned long* ip,
00138                                          IOpaqueAddress*& refpAddress) {
00139 
00140   MsgStream log( msgSvc(), name() );
00141 
00142   if (svc_type != XML_StorageType) {
00143     log << MSG::ERROR << "bad storage type" << (int)svc_type << endreq;
00144     return StatusCode::FAILURE;
00145   }
00146 
00147   std::string dataIdent(par[0]); // file identifier for PDS version of data
00148   std::string fullpath(par[1]);  // path within TCDS for the object
00149   std::string fmtVersion(par[2]);
00150   int         serNo = ip[0];
00151 
00152   // for now have to ignore fmtVersion because of defective implementation
00153   // of GenericAddress. If we want it, should probably write new
00154   // opaque address implementation for this package to use.  All
00155   // dealings with (calibration) opaque addresses are confined to
00156   // the CalibSvc package.
00157   refpAddress = new GenericAddress(XML_StorageType,
00158                                    clid,
00159                                    dataIdent,  
00160                                    fullpath,
00161                                    serNo);
00162                                    
00163   return StatusCode::SUCCESS; 
00164 
00165 }
00166 
00167 
00168 
00169 
00170 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* 
00171 CalibXmlCnvSvc::parse(const char* filename) {
00172   return m_parser->parse(filename);
00173 }

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