CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CalibTreeCnvSvc.cxx
Go to the documentation of this file.
1
2#include "GaudiKernel/IDetDataSvc.h"
3#include "GaudiKernel/IConversionSvc.h"
4#include "GaudiKernel/IConverter.h"
5
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/CnvFactory.h"
9#include "GaudiKernel/ISvcLocator.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/GenericAddress.h"
13#include "CalibData/CalibBase.h"
14#include "cnv/TreeCalBaseCnv.h"
17// Make instances only via static factory class
18//static SvcFactory<CalibTreeCnvSvc> calibRootCnvSvc_factory;
19//const ISvcFactory& CalibTreeCnvSvcFactory = calibRootCnvSvc_factory;
20
21CalibTreeCnvSvc::CalibTreeCnvSvc(const std::string& name,
22 ISvcLocator* svc) :
23 ConversionSvc(name, svc, CALIBTREE_StorageType),
24 m_detPersSvc(0), m_detDataSvc(0) {
25 //huangb add
26}
27
28StatusCode CalibTreeCnvSvc::queryInterface(const InterfaceID& riid,
29 void** ppvInterface) {
30 /* Uncomment if choose to derive from abstract root conv. interface */
31 if (IID_ICalibTreeSvc.versionMatch(riid)) {
32 *ppvInterface = (ICalibTreeSvc*)this;
33 }
34 else {
35 // Interface is not directly availible: try out a base class
36 return ConversionSvc::queryInterface(riid, ppvInterface);
37 /* } */
38 addRef();
39 }
40 return StatusCode::SUCCESS;
41}
42
44 StatusCode sc = ConversionSvc::initialize();
45
46 MsgStream log(msgSvc(), "CalibTreeCnvSvc");
47
48 if (!sc.isSuccess()) return sc;
49
50 // Locate the Calib Data Service. Since it inherits from DataSvc
51 // it has to implement IDataProviderSvc
52 m_detDataSvc = 0;
53 /*sc = serviceLocator()->getService
54 ("CalibDataSvc", IID_IDataProviderSvc,(IInterface*&) m_detDataSvc);*/
55 sc = serviceLocator()->getService
56 ("CalibDataSvc", IDataProviderSvc::interfaceID(),(IInterface*&) m_detDataSvc);
57 if ( !sc.isSuccess() ) {
58 log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
59 return sc;
60 }
61
62 /* IInstrumentName* iInstrumentName;
63 sc = m_detDataSvc->queryInterface(IID_IInstrumentName,
64 (void**) &iInstrumentName);
65*/
66 // Set the CalibDataSvc as data provider service
67 sc = setDataProvider(m_detDataSvc);
68 if ( !sc.isSuccess() ) {
69 log << MSG::ERROR << "Could not set data provider" << endreq;
70 return sc;
71 }
72 //huangb add
73 sc = setProperties();
74
75 // Locate IConversionSvc interface of the DetectorPersistencySvc
76 sc = serviceLocator()->service
77 ("DetectorPersistencySvc", m_detPersSvc, true);
78 if ( !sc.isSuccess() ) {
79 log << MSG::ERROR
80 << "Cannot locate IConversionSvc interface of DetectorPersistencySvc"
81 << endreq;
82 return sc;
83 } else {
84 log << MSG::DEBUG
85 << "Retrieved IConversionSvc interface of DetectorPersistencySvc"
86 << endreq;
87 }
88
89 // Query the IAddressCreator interface of the detector persistency service
90 IAddressCreator* iAddrCreator;
91 /*sc = m_detPersSvc->queryInterface(IID_IAddressCreator,
92 (void**) &iAddrCreator);*/
93 sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(),
94 (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 CalibTreeCnvSvc" << 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 // set properties if there are any??
114
115 return sc;
116}
117
119 // If anything was allocated, get rid of it. So far, nothing was.
120
121 return ConversionSvc::finalize();
122}
123
124 StatusCode CalibTreeCnvSvc::createAddress(long svc_type,
125 const CLID& clid,
126 const std::string* par,
127 const unsigned long* ip,
128 IOpaqueAddress*& refpAddress) {
129 //createAddress of CalibTreeCnvSvc
130 MsgStream log( msgSvc(), name() );
131 if (svc_type != CALIBTREE_StorageType) {
132 log << MSG::ERROR << "bad storage type" << (int)svc_type << endreq;
133 return StatusCode::FAILURE;
134 }
135 std::string dataIdent;
136 std::string fullpath;
137 int index ;
138 if(clid==CLID_Calib_MdcCal)
139 { index=0;}
140 else if(clid==CLID_Calib_TofCal)
141 {index =1;}
142 else if(clid==CLID_Calib_DedxCal)
143 {index =2;}
144 else if(clid==CLID_Calib_EmcCal)
145 {index =3;}
146 else{
147 log << MSG::WARNING<<"Wrong CLID"<<endreq;
148 }
149
150 //see if svctype set in the CalibDataSvc is MYSQL_StorageType or CALIBROOT_StorageType
151/* IInstrumentName* iInstrumentName;
152 StatusCode sc = m_detDataSvc->queryInterface(IID_IInstrumentName,
153 (void**) &iInstrumentName);
154
155 if ( !sc.isSuccess() ) {
156 log << MSG::ERROR
157 << "Cannot query IInstrumentName interface of CalibDataSvc"
158 << endreq;
159 return sc;
160 } else {
161 log << MSG::DEBUG
162 << "Retrieved IInstrumentName interface of CalibDataSvc"
163 << endreq;
164 }
165
166 int svctype = iInstrumentName->getsvctype();
167 if(svctype== CALIBROOT_StorageType)
168 {
169 dataIdent = m_rootfile[index];
170 fullpath = par[0];
171 }
172
173 if(svctype== MYSQL_StorageType)
174 { log << MSG::INFO<<"rootfile is not set in the jobOption,get it from MySQL"<<endreq;
175 dataIdent = par[0];
176 fullpath = par[1];
177 }
178
179 if ((svctype != CALIBROOT_StorageType)&&(svctype!= MYSQL_StorageType)) {
180 log << MSG::ERROR << "bad storage type" << (int)svctype << endreq;
181 return StatusCode::FAILURE;
182 }
183*/
184 // std::string dataIdent(par[0]); // file identifier for PDS version of data
185 // log << MSG::INFO<<"dataIdent is:"<<dataIdent<<endreq;
186 //std::string fullpath(par[1]); // path within TCDS for the object
187 // log << MSG::INFO<<"fullpath is :"<<fullpath<<endreq;
188
189
190 int runfrm = ip[0];
191 int runto = ip[1];
192 dataIdent = par[0];
193 fullpath = par[1];
194
195 // for now have to ignore fmtVersion because of defective implementation
196 // of GenericAddress. If we want it, should probably write new
197 // opaque address implementation for this package to use. All
198 // dealings with (calibration) opaque addresses are confined to
199 // the CalibSvc package.
200 refpAddress = new GenericAddress(CALIBTREE_StorageType,
201 clid,
202 dataIdent,
203 fullpath,
204 runfrm,
205 runto);
206
207
208 return StatusCode::SUCCESS;
209
210}
211
212
213StatusCode CalibTreeCnvSvc::updateObj(IOpaqueAddress* pAddress,
214 DataObject* pObject ) {
215
216 // using facilities::Timestamp;
217
218 MsgStream log(msgSvc(), "CalibTreeCnvSvc" );
219
220 // Don't update when we're using enter time
221 log << MSG::DEBUG << "CalibTreeCnvSvc::updateObj starting ...."<<endreq;
222}
const CLID CLID_Calib_EmcCal
Definition: CalibModel.h:47
const CLID CLID_Calib_DedxCal
Definition: CalibModel.h:45
const CLID CLID_Calib_MdcCal
Definition: CalibModel.h:41
const CLID CLID_Calib_TofCal
Definition: CalibModel.h:43
unsigned const char CALIBTREE_StorageType
Definition: ICalibTreeSvc.h:20
IMessageSvc * msgSvc()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode finalize()
virtual StatusCode initialize()
CalibTreeCnvSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)