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