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