BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
CalibDataSvc.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibDataSvc/src/CalibDataSvc.cxx,v 1.30 2020/09/28 05:13:03 maqm Exp $
2
3// Include files
6//#include "CalibData/CalibTime.h"
7#include "GaudiKernel/IAddressCreator.h"
8#include "GaudiKernel/IConversionSvc.h"
9#include "GaudiKernel/IOpaqueAddress.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/IValidity.h"
13#include "GaudiKernel/IDataProviderSvc.h"
14#include "GaudiKernel/DataObject.h"
15#include "GaudiKernel/MsgStream.h"
16#include "GaudiKernel/SvcFactory.h"
17//#include "GaudiKernel/TimePoint.h"
18#include "GaudiKernel/SmartDataPtr.h"
19
20#include "CalibDataSvc/ICalibRootSvc.h" //maqm add
24#include "GaudiKernel/RegistryEntry.h"//huangb add
25#include "TROOT.h"
26#include "TFile.h"
27#include "TTree.h"
28
31//#include "EventModel/EventList.h"
32
33//#include "CalibData/Mdc/Mdct0par.h"
34#define CAST_REGENTRY(x,y) dynamic_cast<x>(y)
35//#define CAST_REGENTRY(x,y) (x)(y)
36typedef DataSvcHelpers::RegistryEntry RegEntry;
37
38using namespace CalibData;
39// Instantiation of a static factory class used by clients to create
40// instances of this service
41//static SvcFactory<CalibDataSvc> s_factory;
42//const ISvcFactory& CalibDataSvcFactory = s_factory;
43
44/// Standard Constructor
45CalibDataSvc::CalibDataSvc(const std::string& name,ISvcLocator* svc) :
46 DataSvc(name,svc)
47{
48
49 // declare a property which is a list of known calibrations.
50 // Have default list in one of the standard options files.
51 // User can add others.
52 declareProperty("CalibNameList", m_calibList);
53 declareProperty("CalibFlavorList", m_flavorList);
54 declareProperty("CalibRootName", m_calibRootName = "Calib" );
55 declareProperty("Mdc_CalibStorageType",
56 m_calibType[0] = CALIBROOT_StorageType );
57 declareProperty("Tof_CalibStorageType",
58 m_calibType[1] = CALIBROOT_StorageType );
59 declareProperty("Dedx_CalibStorageType",
60 m_calibType[2] = CALIBROOT_StorageType );
61 declareProperty("EMC_CalibStorageType",
62 m_calibType[3] = CALIBROOT_StorageType );
63 declareProperty("MUC_CalibStorageType",
64 m_calibType[4] = CALIBROOT_StorageType );
65 declareProperty("EsTime_CalibStorageType",
66 m_calibType[5] = CALIBROOT_StorageType );
67 declareProperty("EstTof_CalibStorageType",
68 m_calibType[6] = CALIBROOT_StorageType );
69 declareProperty("TofQElec_CalibStorageType",
70 m_calibType[8] = CALIBROOT_StorageType );
71 declareProperty("TofSim_CalibStorageType",
72 m_calibType[9] = CALIBROOT_StorageType );
73 declareProperty("DedxSim_CalibStorageType",
74 m_calibType[10] = CALIBROOT_StorageType );
75 //Top_up Qiumei Ma
76 declareProperty("InjSigInterval_CalibStorageType",
77 m_calibType[12] = CALIBROOT_StorageType );
78 declareProperty("InjSigTime_CalibStorageType",
79 m_calibType[13] = CALIBROOT_StorageType );
80 declareProperty("OffEvtFilter_CalibStorageType",
81 m_calibType[14] = CALIBROOT_StorageType );
82 declareProperty("CorrectedETS_CalibStorageType",
83 m_calibType[15] = CALIBROOT_StorageType );
84
85 std::cout<<"CALIBROOT_StorageType " <<CALIBROOT_StorageType<<" "<<std::endl;
86 //MdcAlign
87 m_calibType[7]=14;
88 //MdcDataConst
89 m_calibType[11]=14;
90
91 // m_rootName and m_rootCLID are declared in base class DataSvc
92 m_rootName = "/" + m_calibRootName;
93 m_rootCLID = CLID_DataObject;
94
95
96
97}
98
99/// Standard Destructor
101 setDataLoader(0);
102 clearStore();
103}
104
105// Service initialization
107
108 StatusCode sc;
109
110 sc = DataSvc::initialize(); // Call base class initialisation
111 if (sc.isFailure() ) return sc;
112
113 // Set up MsgSvc, Data Loader
114 MsgStream log(msgSvc(), name());
115 IConversionSvc* cnv_svc;
116 sc = serviceLocator()->service("DetectorPersistencySvc", cnv_svc, true);
117 if (sc .isFailure() ) {
118 log << MSG::ERROR << "Unable to find DetectorPersistencySvc " << endreq;
119 return sc;
120 }
121
122 IIncidentSvc* incsvc;
123 sc = service("IncidentSvc", incsvc);
124 int priority = 100;
125 if( sc.isSuccess() ){
126 incsvc -> addListener(this, "NewRun", priority);
127 }
128
129 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
130 if (sc .isFailure() ) {
131 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
132 return sc;
133 }
134
135 sc = setDataLoader(cnv_svc);
136 if (sc.isFailure() ) {
137 log << MSG::ERROR << "Unable to set data loader " << endreq;
138 return sc;
139 }
140 sc = setProperties();
141
142 // Initialize the calibration data transient store
143 IAddressCreator* calibCreator = 0;
144
145 // Use Gaudi-supplied DetectorPersistencySvc; it's essentially
146 // the same as base class PersistencySvc, which is all we need
147 sc = serviceLocator()->service("DetectorPersistencySvc", calibCreator);
148
149 if( sc.isFailure() ) {
150 log << MSG::ERROR << "Unable to locate DetectorPersistencySvc." << endreq;
151 return StatusCode::FAILURE;
152 }
153
154 // Make the root for the TDDS data
155 DataObject* rootObj = new DataObject();
156 sc = setRoot(m_rootName, rootObj);
157 if (!sc.isSuccess() ) {
158 log << MSG::ERROR << "Unable to set calib data store root." << endreq;
159 delete rootObj;
160 return sc;
161 }
162
163 // Create and register the next level of nodes.
164 // Have one per calibration type. They are of a class trivially
165 // derived from DataObject, CalibCLIDNode. Only additional
166 // information is CLID of child nodes. List comes from CalibData
167 // namespace
168 //StatusCode CalibDataSvc::makeFlavorNodes(IAddressCreator* calibCreator,
169 // MsgStream* log) {
170 typedef std::vector<CalibData::CalibModelSvc::CalibPair>::const_iterator
171 PairIt;
172 PairIt pairIt;
174 const std::vector<CalibData::CalibModelSvc::CalibPair>& pairs =
175 svc.getPairs();
176 int jj =0;
177 for (pairIt = pairs.begin(); pairIt != pairs.end(); pairIt++,jj++) {
178
179 CalibCLIDNode* node = new CalibCLIDNode(pairIt->second);
180
181 std::string calibTypePath(pairIt->first);
182 // sc =DataSvc::registerObject(calibTypePath, node);
183
184 // Still have to figure out what to do about args, iargs
185 unsigned long iargs[]={0,0};
186 IOpaqueAddress* pAddress;
187
188 // Set up nodes for each calibration type, default flavor
189 // Create and register addresses suitable for the metadata
190 // conversion service. Ultimately, in order to find the "right"
191 // set of constants, it needs to know
192 // Calibration type, e.g. CAL Electronic gain
193 // Flavor e.g. vanilla
194 // Event time validity period of constants must include this time
195 // Instrument LAT, EM, etc.
196 // We save the first two, or equivalent information, in the first
197 // string parameter of a generic address
198 // Consumers can use utilities in CalibData::CalibModelSvc to
199 // extract fields they need
200 // Event time and Instrument will be discovered by conversion service
201 // when constants are requested by invoking our (CalibDataSvc) time
202 // and instrument name services, resp.
203
204 // Always do vanilla
205 std::string fullpath = calibTypePath;
206 std::string args[] = {fullpath};
207
208 sc = calibCreator->createAddress(m_calibType[jj],
209 pairIt->second, // class id
210 args, iargs, pAddress);
211
212
213 if (!sc.isSuccess()) {
214 log<< MSG::INFO
215 << "Unable to create Calib address with path " << fullpath << endreq;
216 }
217
218 // A node unof a specific flavor is a child of the per-calibration type
219 // node for which an object was registered above.
220 sc = registerAddress(fullpath, pAddress);
221 if (!sc.isSuccess()) {
222 log<< MSG::ERROR << "Unable to register Calib address with path"
223 << fullpath << endreq;
224 }
225 // Now do the same for any requested flavors
226 /*
227 unsigned int ix;
228
229 for (ix = 0; ix < m_flavorList.size(); ix++) {
230 log<<MSG::DEBUG<<"here is the flavor in the CalibDataSvc"<<endreq;
231 // Don't redo vanilla, if present in user list
232 if (m_flavorList[ix] == std::string("vanilla")) continue;
233
234 fullpath = calibTypePath + "/" + m_flavorList[ix];
235 args[0] = fullpath;
236
237 sc = calibCreator->createAddress(m_calibStorageType,
238 pairIt->second, args, iargs, pAddress);
239 if (!sc.isSuccess()) {
240
241
242 log<< MSG::ERROR << "Unable to create Calib address with path "
243 << fullpath << endreq;
244 }
245 sc = DataSvc::registerAddress(fullpath, pAddress);
246 if (!sc.isSuccess()) {
247 log<< MSG::ERROR << "Unable to register Calib address with path "
248 << fullpath << endreq;
249 }
250 }
251 // end flavor loop
252 */
253 }
254 // end calibType loop
255 // initialize the parameters
256
257 return StatusCode::SUCCESS;
258}
259
260
261
262/// Finalize the service.
264{
265 MsgStream log(msgSvc(), name());
266 log << MSG::DEBUG << "Finalizing" << endreq;
267
268 // return StatusCode::SUCCESS;
269 // Finalize the base class
270 // huangb temply delete
271 return DataSvc::finalize();
272}
273
274StatusCode CalibDataSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
275{
276 // With the highest priority return the specific interfaces
277 // If interfaces are not directly available, try out a base class
278 if (IDetDataSvc::interfaceID().versionMatch(riid) ) {
279 *ppvInterface = (IDetDataSvc*)this;
280 } else if (IInstrumentName::interfaceID().versionMatch(riid) ) {
281 *ppvInterface = (IInstrumentName*) this;
282 // } else if ( IID_IIncidentListener.versionMatch(riid) ) {
283 // *ppvInterface = (IIncidentListener*)this;
284} else {
285 return DataSvc::queryInterface(riid, ppvInterface);
286}
287addRef();
288return StatusCode::SUCCESS;
289}
290
291
292
293
294
295
296/// Remove all data objects in the data store.
298 DataSvc::clearStore();
299 return StatusCode::SUCCESS;
300}
301
302//update the calibration in TCDS if a new run comes
303void CalibDataSvc::handle ( const Incident& inc ) {
304 MsgStream log( msgSvc(), name() );
305 return;
306}
307
308
309
310
311
312
313StatusCode CalibDataSvc::updateObject( DataObject* toUpdate ) {
314
315
316 MsgStream log( msgSvc(), name() );
317 log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
318 // Check that object to update exists
319 if ( 0 == toUpdate ) {
320 log << MSG::ERROR
321 << "There is no DataObject to update" << endreq;
322 return INVALID_OBJECT;
323 }
324
325 log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
326 // Now delegate update to the conversion service by calling the base class
327 StatusCode status = DataSvc::updateObject(toUpdate);
328 if ( !status.isSuccess() ) {
329 log << MSG::ERROR
330 << "Could not update DataObject" << endreq;
331 if ( status == NO_DATA_LOADER )
332 log << MSG::ERROR << "There is no data loader" << endreq;
333 return status;
334 }
335 log << MSG::INFO<<"begin of CalibDataSvc::updateObject successfully updated"<<endreq;
336 // DataObject was successfully updated
337 return StatusCode::SUCCESS;
338}
339
340StatusCode CalibDataSvc::loadObject(IConversionSvc* pLoader,
341 IRegistry* pRegistry) {
342 return DataSvc::loadObject(pLoader, pRegistry);
343
344}
345
346StatusCode CalibDataSvc::retrieveObject(const std::string& fullPath,DataObject*& pObject)
347{
348 MsgStream log( msgSvc(), name() );
349
350 int runNo;
351 //maqm SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event");
352 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
353 if( evt ){
354 runNo = evt -> runNumber();
355 log << MSG::DEBUG <<"The runNumber of current event is "<<runNo<<endreq;
356 }
357
358 else{
359 log << MSG::WARNING << "WARNING accessing Event" <<endreq;
360 // return StatusCode::FAILURE;
361 }
362
363
364 StatusCode sc =DataSvc::retrieveObject(fullPath,pObject);
365 if (!sc.isSuccess()) {
366 log<< MSG::ERROR << "Unable to get the retrieveObject"
367 << endreq;
368 return sc;
369 }
370 // if(fullPath=="/Calib/MdcAlign"&&m_calibType[0]==CALIBROOT_StorageType)
371 // { return StatusCode::SUCCESS;}
372 if(fullPath=="/Calib/MdcCal"&&m_calibType[0]==CALIBROOT_StorageType){
373 return StatusCode::SUCCESS;}
374 if(fullPath=="/Calib/DedxCal"&&m_calibType[2]==CALIBROOT_StorageType){
375 return StatusCode::SUCCESS;}
376 if(fullPath=="/Calib/TofCal"&&m_calibType[1]==CALIBROOT_StorageType){
377 return StatusCode::SUCCESS;}
378 if(fullPath=="/Calib/EmcCal"&&m_calibType[3]==CALIBROOT_StorageType){
379 return StatusCode::SUCCESS;}
380 if(fullPath=="/Calib/MucCal"&&m_calibType[4]==CALIBROOT_StorageType){
381 return StatusCode::SUCCESS;}
382 if(fullPath=="/Calib/EsTimeCal"&&m_calibType[5]==CALIBROOT_StorageType){
383 return StatusCode::SUCCESS;}
384 if(fullPath=="/Calib/EstTofCal"&&m_calibType[6]==CALIBROOT_StorageType){
385 return StatusCode::SUCCESS;}
386 if(fullPath=="/Calib/TofQElec"&&m_calibType[8]==CALIBROOT_StorageType){
387 return StatusCode::SUCCESS;}
388 if(fullPath=="/Calib/TofSim"&&m_calibType[9]==CALIBROOT_StorageType){
389 return StatusCode::SUCCESS;}
390 if(fullPath=="/Calib/DedxSim"&&m_calibType[10]==CALIBROOT_StorageType){
391 return StatusCode::SUCCESS;}
392 //Top_up Qiumei Ma
393 if(fullPath=="/Calib/InjSigInterval"&&m_calibType[12]==CALIBROOT_StorageType){
394 return StatusCode::SUCCESS;}
395 if(fullPath=="/Calib/InjSigTime"&&m_calibType[13]==CALIBROOT_StorageType){
396 return StatusCode::SUCCESS;}
397 if(fullPath=="/Calib/OffEvtFilter"&&m_calibType[14]==CALIBROOT_StorageType){
398 return StatusCode::SUCCESS;}
399 if(fullPath=="/Calib/CorrectedETS"&&m_calibType[15]==CALIBROOT_StorageType){
400 return StatusCode::SUCCESS;}
401
402 CalibData::CalibBase1* tmpObject = dynamic_cast<CalibData::CalibBase1*>(pObject);
403 if(fullPath=="/Calib/TofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
404 { return StatusCode::SUCCESS;}
405 if(fullPath=="/Calib/EstTofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
406 { return StatusCode::SUCCESS;}
407 if(fullPath=="/Calib/TofSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
408 { return StatusCode::SUCCESS;}
409 if(fullPath=="/Calib/DedxSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
410 { return StatusCode::SUCCESS;}
411
412
413
414 if( fabs(runNo) >= tmpObject->getrunfrm() && fabs(runNo)<=tmpObject->getrunto())
415 {
416 log << MSG::DEBUG <<__LINE__<< " runfrm @CalibDataSvc is:"<<tmpObject->getrunfrm()<<" runto min is:"<<tmpObject->getrunto()<<endreq;
417 return StatusCode::SUCCESS;}
418 else
419 {
420 log<< MSG::INFO <<"@CalibDataSvc runfrm="<< tmpObject->getrunfrm()<<"runto="<<tmpObject->getrunto()<<"runNo="<<runNo<<endreq;
421 log<< MSG::DEBUG << "update the Object"
422 << endreq;
423 sc =DataSvc:: updateObject(pObject);
424 return sc;
425 }//end of else
426}//end of if
427
428StatusCode CalibDataSvc::registerObject (const std::string& parentPath,
429 const std::string& objPath,
430 DataObject* pObject) {
431 DataObject* pO = 0;
432 StatusCode status =DataSvc::retrieveObject(parentPath, pO);
433 if ( !status.isSuccess() && m_forceLeaves ) {
434 pO = createDefaultObject();
435 status =DataSvc::registerObject(parentPath, pO);
436 if ( !status.isSuccess() ) {
437 pO->release();
438 }//end of if
439 }//end of if( !status.isSuccess() && m_forceLeaves )
440 if ( status.isSuccess() ) {
441 status =DataSvc::registerObject(pO, objPath, pObject);
442 }
443 if(status.isSuccess() ){
444 return status;
445 }
446}
447
448
DataSvcHelpers::RegistryEntry RegEntry
int runNo
Definition: DQA_TO_DB.cxx:12
unsigned const char CALIBROOT_StorageType
Definition: ICalibRootSvc.h:20
IMessageSvc * msgSvc()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
Query the interface of the service.
virtual StatusCode loadObject(IConversionSvc *pLoader, IRegistry *pRegistry)
virtual StatusCode registerObject(const std::string &parentPath, const std::string &objPath, DataObject *pObject)
virtual StatusCode initialize()
virtual StatusCode updateObject(DataObject *toUpdate)
Update object.
virtual void handle(const Incident &)
Inform that a new incident has occured.
virtual StatusCode retrieveObject(const std::string &fullPath, DataObject *&pObject)
virtual StatusCode finalize()
Finalize the service.
virtual ~CalibDataSvc()
Standard Destructor.
CalibDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
virtual StatusCode clearStore()
Remove all data objects in the data store.
virtual int getrunto() const
Definition: CalibBase1.h:53
virtual int getrunfrm() const
Definition: CalibBase1.h:52
const std::vector< CalibPair > & getPairs() const
Simple interface to keep track of which instrument (LAT, EM, etc.) the process is concerned with....
static const InterfaceID & interfaceID()
CalibPairCol::const_iterator PairIt
Definition: CalibModel.h:124
_EXTERN_ CalibPairCol pairs
Definition: CalibModel.h:125