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