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