BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
CalibXmlCnvSvc.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibXmlCnvSvc/src/CalibXmlCnvSvc.cxx,v 1.7 2022/02/21 07:16:40 maqm Exp $
2
3// one or both of following includes may not be necessary..
4// depends on whether we keep and use private members
5// m_detPersSvc and m_detDataSvc
6
7#include "GaudiKernel/IDetDataSvc.h"
8#include "GaudiKernel/IConversionSvc.h"
9
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/SvcFactory.h"
12#include "GaudiKernel/CnvFactory.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include "GaudiKernel/IDataProviderSvc.h"
15#include "GaudiKernel/GenericAddress.h"
17#include "xmlBase/XmlParser.h"
18
19// Make instances only via static factory class
20//static SvcFactory<CalibXmlCnvSvc> calibXmlCnvSvc_factory;
21//const ISvcFactory& CalibXmlCnvSvcFactory = calibXmlCnvSvc_factory;
22
23CalibXmlCnvSvc::CalibXmlCnvSvc(const std::string& name,
24 ISvcLocator* svc) :
25 ConversionSvc(name, svc, XML_StorageType),
26 m_detPersSvc(0), m_detDataSvc(0), m_parser(0) {
27
28 // Some day might have a property to declare having to do with path to
29 // xml files.
30}
31
32/*StatusCode CalibXmlCnvSvc::queryInterface(const InterfaceID& riid,
33 void** ppvInterface) {
34 if (IID_ICalibXmlSvc.versionMatch(riid)) {
35 *ppvInterface = (ICalibXmlSvc*)this;
36 }
37 else {
38 // Interface is not directly availible: try out a base class
39 return ConversionSvc::queryInterface(riid, ppvInterface);
40 }
41 addRef();
42 return StatusCode::SUCCESS;
43}*/
44
46 StatusCode sc = ConversionSvc::initialize();
47
48 MsgStream log(msgSvc(), "CalibXmlCnvSvc");
49
50 if (!sc.isSuccess()) return sc;
51
52 /* Paste in a bit of CalibMySQLCnvSvc::initialize */
53
54 // Locate the Calib Data Service. Since it inherits from DataSvc
55 // it has to implement IDataProviderSvc
56 IDataProviderSvc* pCDS = 0;
57 //sc = serviceLocator()->getService("CalibDataSvc", IID_IDataProviderSvc, (IInterface*&)pCDS);
58 sc = serviceLocator()->getService("CalibDataSvc", IDataProviderSvc::interfaceID(), (IInterface*&)pCDS)
59;
60 if ( !sc.isSuccess() ) {
61 log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
62 return sc;
63 }
64
65 // Set the CalibDataSvc as data provider service
66 sc = setDataProvider(pCDS);
67 if ( !sc.isSuccess() ) {
68 log << MSG::ERROR << "Could not set data provider" << endreq;
69 return sc;
70 }
71
72 /* End of pasted bit */
73
74
75 /* Paste in more of CalibMySQLCnvSvc::initialize */
76 // Locate IConversionSvc interface of the DetectorPersistencySvc
77 sc = serviceLocator()->service
78 ("DetectorPersistencySvc", m_detPersSvc, true);
79 if ( !sc.isSuccess() ) {
80 log << MSG::ERROR
81 << "Cannot locate IConversionSvc interface of DetectorPersistencySvc"
82 << endreq;
83 return sc;
84 } else {
85 log << MSG::DEBUG
86 << "Retrieved IConversionSvc interface of DetectorPersistencySvc"
87 << endreq;
88 }
89
90 // Query the IAddressCreator interface of the detector persistency service
91 IAddressCreator* iAddrCreator;
92 //sc = m_detPersSvc->queryInterface(IID_IAddressCreator,
93// (void**) &iAddrCreator);
94 sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(), (void**) &iAddrCreator);
95 if ( !sc.isSuccess() ) {
96 log << MSG::ERROR
97 << "Cannot query IAddressCreator interface of DetectorPersistencySvc"
98 << endreq;
99 return sc;
100 } else {
101 log << MSG::DEBUG
102 << "Retrieved IAddressCreator interface of DetectorPersistencySvc"
103 << endreq;
104 }
105 log << MSG::DEBUG
106 << "Set it as the address creator of the CalibXmlCnvSvc" << endreq;
107 sc = setAddressCreator(iAddrCreator);
108 if ( !sc.isSuccess() ) {
109 log << MSG::ERROR << "Cannot set the address creator" << endreq;
110 return sc;
111 }
112
113 // end of second pasted piece
114
115
116 m_parser = new xmlBase::XmlParser();
117
118 if (m_parser == 0) {
119 log << MSG::FATAL << "Unable to create XML parser instance \n"
120 << endreq;
121 }
122
123 // set properties if there are any??
124
125 return sc;
126}
127
129 delete m_parser;
130 m_parser = 0;
131 return ConversionSvc::finalize();
132}
133
134StatusCode CalibXmlCnvSvc::createAddress(unsigned char svc_type,
135 const CLID& clid,
136 const std::string* par,
137 const unsigned long* ip,
138 IOpaqueAddress*& refpAddress) {
139
140 MsgStream log( msgSvc(), name() );
141
142 if (svc_type != XML_StorageType) {
143 log << MSG::ERROR << "bad storage type" << (int)svc_type << endreq;
144 return StatusCode::FAILURE;
145 }
146
147 std::string dataIdent(par[0]); // file identifier for PDS version of data
148 std::string fullpath(par[1]); // path within TCDS for the object
149 std::string fmtVersion(par[2]);
150 int serNo = ip[0];
151
152 // for now have to ignore fmtVersion because of defective implementation
153 // of GenericAddress. If we want it, should probably write new
154 // opaque address implementation for this package to use. All
155 // dealings with (calibration) opaque addresses are confined to
156 // the CalibSvc package.
157 refpAddress = new GenericAddress(XML_StorageType,
158 clid,
159 dataIdent,
160 fullpath,
161 serNo);
162
163 return StatusCode::SUCCESS;
164
165}
166
167
168
169
170XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*
171CalibXmlCnvSvc::parse(const char* filename) {
172 return m_parser->parse(filename);
173}
IMessageSvc * msgSvc()
virtual StatusCode createAddress(unsigned char svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
virtual StatusCode initialize()
CalibXmlCnvSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode finalize()
virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * parse(const char *filename)
DOMDocument * parse(const char *const filename, const std::string &docType=std::string(""))
Parse an xml file, returning document node if successful.
Definition: XmlParser.cxx:108