00001
00002
00003
00004
00005
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
00020
00021
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
00029
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
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
00053
00054
00055
00056 IDataProviderSvc* pCDS = 0;
00057
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
00066 sc = setDataProvider(pCDS);
00067 if ( !sc.isSuccess() ) {
00068 log << MSG::ERROR << "Could not set data provider" << endreq;
00069 return sc;
00070 }
00071
00072
00073
00074
00075
00076
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
00091 IAddressCreator* iAddrCreator;
00092
00093
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
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
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]);
00148 std::string fullpath(par[1]);
00149 std::string fmtVersion(par[2]);
00150 int serNo = ip[0];
00151
00152
00153
00154
00155
00156
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 }