BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
CalibRootCnvSvc.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/CalibRootCnvSvc.cxx,v 1.23 2019/09/23 02:53:37 sunss Exp $
2
3#include "GaudiKernel/IDetDataSvc.h"
4#include "GaudiKernel/IConversionSvc.h"
5#include "GaudiKernel/IConverter.h"
6
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/SvcFactory.h"
9#include "GaudiKernel/CnvFactory.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/IDataProviderSvc.h"
12#include "GaudiKernel/GenericAddress.h"
13#include "CalibROOTCnv/CalibRootCnvSvc.h"
14#include "CalibData/CalibBase.h"
15#include "cnv/RootCalBaseCnv.h"
16#include "CalibData/CalibBase1.h"
17#include "CalibDataSvc/IInstrumentName.h"
18
19// Make instances only via static factory class
20//static SvcFactory<CalibRootCnvSvc> calibRootCnvSvc_factory;
21//const ISvcFactory& CalibRootCnvSvcFactory = calibRootCnvSvc_factory;
22
23CalibRootCnvSvc::CalibRootCnvSvc(const std::string& name,
24 ISvcLocator* svc) :
25 ConversionSvc(name, svc, CALIBROOT_StorageType),
26 m_detPersSvc(0), m_detDataSvc(0) {
27 //huangb add
28 declareProperty("Mdcrootfile",m_rootfile[0]= std::string("no rootfile"));
29 declareProperty("Tofrootfile",m_rootfile[1]= std::string("no rootfile"));
30 declareProperty("Dedxrootfile",m_rootfile[2]= std::string("no rootfile"));
31 declareProperty("Emcrootfile",m_rootfile[3]= std::string("no rootfile"));
32 declareProperty("Mucrootfile",m_rootfile[4]= std::string("no rootfile"));
33 declareProperty("EsTimerootfile",m_rootfile[5]= std::string("no rootfile"));
34 declareProperty("EstTofrootfile",m_rootfile[6]= std::string("no rootfile"));
35 declareProperty("TofQElecrootfile",m_rootfile[7]= std::string("no rootfile"));
36 declareProperty("TofSimrootfile",m_rootfile[8]= std::string("no rootfile"));
37 declareProperty("DedxSimrootfile",m_rootfile[9]= std::string("no rootfile"));
38 // Some day might have a property to declare having to do with path to
39 // xml files.
40}
41
42StatusCode CalibRootCnvSvc::queryInterface(const InterfaceID& riid,
43 void** ppvInterface) {
44 /* Uncomment if choose to derive from abstract root conv. interface */
45 if (IID_ICalibRootSvc.versionMatch(riid)) {
46 *ppvInterface = (ICalibRootSvc*)this;
47 }
48 else {
49 // Interface is not directly availible: try out a base class
50 return ConversionSvc::queryInterface(riid, ppvInterface);
51 /* } */
52 addRef();
53 }
54 return StatusCode::SUCCESS;
55}
56
58 StatusCode sc = ConversionSvc::initialize();
59
60 MsgStream log(msgSvc(), "CalibRootCnvSvc");
61
62 if (!sc.isSuccess()) return sc;
63
64 // Locate the Calib Data Service. Since it inherits from DataSvc
65 // it has to implement IDataProviderSvc
66 m_detDataSvc = 0;
67 /*sc = serviceLocator()->getService
68 ("CalibDataSvc", IID_IDataProviderSvc,(IInterface*&) m_detDataSvc);*/
69 sc = serviceLocator()->getService
70 ("CalibDataSvc", IDataProviderSvc::interfaceID(),(IInterface*&) m_detDataSvc);
71 if ( !sc.isSuccess() ) {
72 log << MSG::ERROR << "Could not locate CalibDataSvc" << endreq;
73 return sc;
74 }
75
76 /* IInstrumentName* iInstrumentName;
77 sc = m_detDataSvc->queryInterface(IID_IInstrumentName,
78 (void**) &iInstrumentName);
79*/
80 // Set the CalibDataSvc as data provider service
81 sc = setDataProvider(m_detDataSvc);
82 if ( !sc.isSuccess() ) {
83 log << MSG::ERROR << "Could not set data provider" << endreq;
84 return sc;
85 }
86 //huangb add
87 sc = setProperties();
88
89 // Locate IConversionSvc interface of the DetectorPersistencySvc
90 sc = serviceLocator()->service
91 ("DetectorPersistencySvc", m_detPersSvc, true);
92 if ( !sc.isSuccess() ) {
93 log << MSG::ERROR
94 << "Cannot locate IConversionSvc interface of DetectorPersistencySvc"
95 << endreq;
96 return sc;
97 } else {
98 log << MSG::DEBUG
99 << "Retrieved IConversionSvc interface of DetectorPersistencySvc"
100 << endreq;
101 }
102
103 // Query the IAddressCreator interface of the detector persistency service
104 IAddressCreator* iAddrCreator;
105/* sc = m_detPersSvc->queryInterface(IID_IAddressCreator,
106
107 (void**) &iAddrCreator);*/
108
109 sc = m_detPersSvc->queryInterface(IAddressCreator::interfaceID(),
110 (void**) &iAddrCreator);
111 if ( !sc.isSuccess() ) {
112 log << MSG::ERROR
113 << "Cannot query IAddressCreator interface of DetectorPersistencySvc"
114 << endreq;
115 return sc;
116 } else {
117 log << MSG::DEBUG
118 << "Retrieved IAddressCreator interface of DetectorPersistencySvc"
119 << endreq;
120 }
121 log << MSG::DEBUG
122 << "Set it as the address creator of the CalibRootCnvSvc" << endreq;
123 sc = setAddressCreator(iAddrCreator);
124 if ( !sc.isSuccess() ) {
125 log << MSG::ERROR << "Cannot set the address creator" << endreq;
126 return sc;
127 }
128
129 // set properties if there are any??
130
131 return sc;
132}
133
135 // If anything was allocated, get rid of it. So far, nothing was.
136
137 return ConversionSvc::finalize();
138}
139
140//StatusCode CalibRootCnvSvc::createAddress(unsigned char svc_type,
141 StatusCode CalibRootCnvSvc::createAddress(long svc_type,
142 const CLID& clid,
143 const std::string* par,
144 const unsigned long* ip,
145 IOpaqueAddress*& refpAddress) {
146 MsgStream log( msgSvc(), name() );
147 log << MSG::DEBUG<<"here is the createAddress in the CalibRootCnvSvc"<<endreq;
148 if (svc_type != CALIBROOT_StorageType) {
149 log << MSG::ERROR << "bad storage type" << (int)svc_type << endreq;
150 return StatusCode::FAILURE;
151 }
152 std::cout<<"clid=="<<clid<<std::endl;
153 std::string dataIdent;
154 std::string fullpath;
155 int index=-99;
156 if(clid==6412) return StatusCode::SUCCESS;
157 if(clid==CLID_Calib_MdcCal)
158 { index=0;}
159 else if(clid==CLID_Calib_TofCal)
160 {index =1;}
161 else if(clid==CLID_Calib_DedxCal)
162 {index =2;}
163 else if(clid==CLID_Calib_EmcCal)
164 {index =3;}
165 else if(clid==CLID_Calib_MucCal)
166 {index =4;}
167 else if(clid==CLID_Calib_EsTimeCal)
168 {index =5;}
169 else if(clid==CLID_Calib_EstTofCal)
170 {index =6;}
171 else if(clid==CLID_TofQ_Elec)
172 {index =7;}
173 else if(clid==CLID_Calib_TofSim)
174 {index =8;}
175 else if(clid==CLID_Dedx_Sim)
176 {index =9;}
177
178 else{
179 log << MSG::WARNING<<"Wrong CLID"<<endreq;
180 }
181 std::cout<<"index=="<<index<<std::endl;
182 //see if svctype set in the CalibDataSvc is MYSQL_StorageType or CALIBROOT_StorageType
183 /* IInstrumentName* iInstrumentName;
184 StatusCode sc = m_detDataSvc->queryInterface(IID_IInstrumentName,
185 (void**) &iInstrumentName);
186
187 if ( !sc.isSuccess() ) {
188 log << MSG::ERROR
189 << "Cannot query IInstrumentName interface of CalibDataSvc"
190 << endreq;
191 return sc;
192 } else {
193 log << MSG::DEBUG
194 << "Retrieved IInstrumentName interface of CalibDataSvc"
195 << endreq;
196 }
197
198 int svctype = iInstrumentName->getsvctype();
199 if(svctype== CALIBROOT_StorageType)
200 {
201*/
202// dataIdent = m_rootfile[index];
203if(m_rootfile[index]=="no rootfile")
204{
205log << MSG::INFO<<"no sepcified calibration file path of type "<< index <<endreq;
206return StatusCode::FAILURE;
207}
208 decodeDescription(m_rootfile[index],dataIdent);
209 fullpath = par[0];
210 /* }
211
212 if(svctype== MYSQL_StorageType)
213 { log << MSG::INFO<<"rootfile is not set in the jobOption,get it from MySQL"<<endreq;
214 dataIdent = par[0];
215 fullpath = par[1];
216 }
217
218 if ((svctype != CALIBROOT_StorageType)&&(svctype!= MYSQL_StorageType)) {
219 log << MSG::ERROR << "bad storage type" << (int)svctype << endreq;
220 return StatusCode::FAILURE;
221 }
222*/
223
224 // std::string dataIdent(par[0]); // file identifier for PDS version of data
225 log << MSG::INFO<<"dataIdent is:"<<dataIdent<<endreq;
226 //std::string fullpath(par[1]); // path within TCDS for the object
227 log << MSG::INFO<<"fullpath is :"<<fullpath<<endreq;
228
229
230 int runfrm = ip[0];
231 int runto = ip[1];
232
233 // for now have to ignore fmtVersion because of defective implementation
234 // of GenericAddress. If we want it, should probably write new
235 // opaque address implementation for this package to use. All
236 // dealings with (calibration) opaque addresses are confined to
237 // the CalibSvc package.
238 refpAddress = new GenericAddress(CALIBROOT_StorageType,
239 clid,
240 dataIdent,
241 fullpath,
242 runfrm,
243 runto);
244
245 return StatusCode::SUCCESS;
246
247}
248
249StatusCode CalibRootCnvSvc::writeToRoot(const std::string& outfile,
250 const std::string& tdsPath) {
251 MsgStream log( msgSvc(), name() );
252
253 // Find corresponding object
254 DataObject* pObj;
255 m_detDataSvc->findObject(tdsPath, pObj);
256 if (!pObj) {
257 log << "No object in TDS with path " << tdsPath << endreq;
258 return StatusCode::FAILURE;
259 }
260
261 CalibData::CalibBase1* pCalib =
262 dynamic_cast<CalibData::CalibBase1*> (pObj);
263
264 if (!pCalib) {
265 log << "Object with path " << tdsPath << " not of proper type" << endreq;
266 return StatusCode::FAILURE;
267 }
268 return writeToRoot(outfile, pCalib);
269}
270StatusCode CalibRootCnvSvc::writeToRoot(const std::string& outfile,
271 CalibData::CalibBase1* pCalib) {
272 MsgStream log(msgSvc(), name() );
273 // Find converter corresponding to this object
274 IConverter* converter = ConversionSvc::converter(pCalib->clID());
275 if (!converter) {
276 log << "No converter found for object with CLID " << pCalib->clID()
277 << endreq;
278 return StatusCode::FAILURE;
279 }
280 RootCalBaseCnv* pCnv = dynamic_cast<RootCalBaseCnv*>(converter);
281 if (!pCnv) {
282 log << "Converter for CLID " << pCalib->clID() << " not of proper type"
283 << endreq;
284 return StatusCode::FAILURE;
285 }
286 // Call its createRoot method
287 return pCnv->createRoot(outfile, pCalib);
288}
289
290StatusCode CalibRootCnvSvc::updateObj(IOpaqueAddress* pAddress,
291 DataObject* pObject ) {
292
293 // using facilities::Timestamp;
294
295 MsgStream log(msgSvc(), "CalibRootCnvSvc" );
296
297 // Don't update when we're using enter time
298 log << MSG::DEBUG << "CalibRootCnvSvc::updateObj starting ...."<<endreq;
299 /*
300 if (!m_useEventTime)
301 { log << MSG::DEBUG << "Method updateObj needn't update" << endreq;
302 return StatusCode::SUCCESS;
303 }
304 */
305}
306
307StatusCode CalibRootCnvSvc::decodeDescription(const std::string& oldpath,
308 std::string& realpath )
309{
310 MsgStream log(msgSvc(), "CalibMySQLCnvSvc");
311
312 if(oldpath[0]!='$'){
313 realpath=oldpath;
314 }
315 if(oldpath[0]=='$'){
316 std::string::size_type idx =oldpath.find("/");
317 if( std::string::npos != idx )
318 { std::string relpath;
319 for(int i=1;i<idx-1;i++){
320 relpath[i-1] = oldpath[i];
321 }
322 std::string otherpath;
323 for(int i=idx-1;i<oldpath.size();i++){
324 otherpath[i-idx+1]=oldpath[i];
325 }
326 realpath = std::string(getenv(relpath.c_str()))+otherpath;
327 }
328 if( std::string::npos == idx ){
329 std::string relpath;
330 for(int i=1;i<oldpath.size();i++){
331 relpath[i-1] = oldpath[i];
332 }
333 realpath = std::string(getenv(relpath.c_str()));
334 }
335 }
336
337 return StatusCode::SUCCESS;
338}
339
340
virtual StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *pObject)
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
virtual StatusCode initialize()
StatusCode decodeDescription(const std::string &oldpath, std::string &realpath)
virtual StatusCode writeToRoot(const std::string &outputFile, const std::string &tdsPath)
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
CalibRootCnvSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)