00001
00002
00003
00004 #include "CalibDataSvc/CalibDataSvc.h"
00005 #include "CalibDataSvc/CalibCLIDNode.h"
00006
00007 #include "GaudiKernel/IAddressCreator.h"
00008 #include "GaudiKernel/IConversionSvc.h"
00009 #include "GaudiKernel/IOpaqueAddress.h"
00010 #include "GaudiKernel/ISvcLocator.h"
00011 #include "GaudiKernel/IIncidentSvc.h"
00012 #include "GaudiKernel/IValidity.h"
00013 #include "GaudiKernel/IDataProviderSvc.h"
00014 #include "GaudiKernel/DataObject.h"
00015 #include "GaudiKernel/MsgStream.h"
00016 #include "GaudiKernel/SvcFactory.h"
00017
00018 #include "GaudiKernel/SmartDataPtr.h"
00019
00020 #include "CalibDataSvc/ICalibRootSvc.h"
00021 #include "CalibData/CalibModelSvc.h"
00022 #include "CalibData/CalibBase1.h"
00023 #include "CalibData/Mdc/MdcCalStruct.h"
00024 #include "GaudiKernel/RegistryEntry.h"
00025 #include "TROOT.h"
00026 #include "TFile.h"
00027 #include "TTree.h"
00028
00029 #include "EventModel/EventModel.h"
00030 #include "EventModel/EventHeader.h"
00031
00032
00033
00034 #define CAST_REGENTRY(x,y) dynamic_cast<x>(y)
00035
00036 typedef DataSvcHelpers::RegistryEntry RegEntry;
00037
00038 using namespace CalibData;
00039
00040
00041
00042
00043
00045 CalibDataSvc::CalibDataSvc(const std::string& name,ISvcLocator* svc) :
00046 DataSvc(name,svc)
00047 {
00048
00049
00050
00051
00052 declareProperty("CalibNameList", m_calibList);
00053 declareProperty("CalibFlavorList", m_flavorList);
00054 declareProperty("CalibRootName", m_calibRootName = "Calib" );
00055 declareProperty("Mdc_CalibStorageType",
00056 m_calibType[0] = CALIBROOT_StorageType );
00057 declareProperty("Tof_CalibStorageType",
00058 m_calibType[1] = CALIBROOT_StorageType );
00059 declareProperty("Dedx_CalibStorageType",
00060 m_calibType[2] = CALIBROOT_StorageType );
00061 declareProperty("EMC_CalibStorageType",
00062 m_calibType[3] = CALIBROOT_StorageType );
00063 declareProperty("MUC_CalibStorageType",
00064 m_calibType[4] = CALIBROOT_StorageType );
00065 declareProperty("EsTime_CalibStorageType",
00066 m_calibType[5] = CALIBROOT_StorageType );
00067 declareProperty("EstTof_CalibStorageType",
00068 m_calibType[6] = CALIBROOT_StorageType );
00069 declareProperty("TofQElec_CalibStorageType",
00070 m_calibType[8] = CALIBROOT_StorageType );
00071 declareProperty("TofSim_CalibStorageType",
00072 m_calibType[9] = CALIBROOT_StorageType );
00073 declareProperty("DedxSim_CalibStorageType",
00074 m_calibType[10] = CALIBROOT_StorageType );
00075
00076
00077 m_calibType[7]=14;
00078
00079 m_calibType[11]=14;
00080
00081
00082 m_rootName = "/" + m_calibRootName;
00083 m_rootCLID = CLID_DataObject;
00084
00085
00086
00087 }
00088
00090 CalibDataSvc::~CalibDataSvc() {
00091 setDataLoader(0);
00092 clearStore();
00093 }
00094
00095
00096 StatusCode CalibDataSvc::initialize() {
00097
00098 StatusCode sc;
00099
00100 sc = DataSvc::initialize();
00101 if (sc.isFailure() ) return sc;
00102
00103
00104 MsgStream log(msgSvc(), name());
00105 IConversionSvc* cnv_svc;
00106 sc = serviceLocator()->service("DetectorPersistencySvc", cnv_svc, true);
00107 if (sc .isFailure() ) {
00108 log << MSG::ERROR << "Unable to find DetectorPersistencySvc " << endreq;
00109 return sc;
00110 }
00111
00112 IIncidentSvc* incsvc;
00113 sc = service("IncidentSvc", incsvc);
00114 int priority = 100;
00115 if( sc.isSuccess() ){
00116 incsvc -> addListener(this, "NewRun", priority);
00117 }
00118
00119 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
00120 if (sc .isFailure() ) {
00121 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
00122 return sc;
00123 }
00124
00125 sc = setDataLoader(cnv_svc);
00126 if (sc.isFailure() ) {
00127 log << MSG::ERROR << "Unable to set data loader " << endreq;
00128 return sc;
00129 }
00130 sc = setProperties();
00131
00132
00133 IAddressCreator* calibCreator = 0;
00134
00135
00136
00137 sc = serviceLocator()->service("DetectorPersistencySvc", calibCreator);
00138
00139 if( sc.isFailure() ) {
00140 log << MSG::ERROR << "Unable to locate DetectorPersistencySvc." << endreq;
00141 return StatusCode::FAILURE;
00142 }
00143
00144
00145 DataObject* rootObj = new DataObject();
00146 sc = setRoot(m_rootName, rootObj);
00147 if (!sc.isSuccess() ) {
00148 log << MSG::ERROR << "Unable to set calib data store root." << endreq;
00149 delete rootObj;
00150 return sc;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160 typedef std::vector<CalibData::CalibModelSvc::CalibPair>::const_iterator
00161 PairIt;
00162 PairIt pairIt;
00163 CalibData::CalibModelSvc svc;
00164 const std::vector<CalibData::CalibModelSvc::CalibPair>& pairs =
00165 svc.getPairs();
00166 int jj =0;
00167 for (pairIt = pairs.begin(); pairIt != pairs.end(); pairIt++,jj++) {
00168
00169 CalibCLIDNode* node = new CalibCLIDNode(pairIt->second);
00170
00171 std::string calibTypePath(pairIt->first);
00172
00173
00174
00175 unsigned long iargs[]={0,0};
00176 IOpaqueAddress* pAddress;
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 std::string fullpath = calibTypePath;
00196 std::string args[] = {fullpath};
00197
00198
00199
00200
00201 sc = calibCreator->createAddress(m_calibType[jj],
00202 pairIt->second,
00203 args, iargs, pAddress);
00204
00205
00206 if (!sc.isSuccess()) {
00207 log<< MSG::INFO
00208 << "Unable to create Calib address with path " << fullpath << endreq;
00209 }
00210
00211
00212
00213 sc = registerAddress(fullpath, pAddress);
00214 if (!sc.isSuccess()) {
00215 log<< MSG::ERROR << "Unable to register Calib address with path"
00216 << fullpath << endreq;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 }
00247
00248
00249
00250 return StatusCode::SUCCESS;
00251 }
00252
00253
00254
00256 StatusCode CalibDataSvc::finalize()
00257 {
00258 MsgStream log(msgSvc(), name());
00259 log << MSG::DEBUG << "Finalizing" << endreq;
00260
00261
00262
00263
00264 return DataSvc::finalize();
00265 }
00266
00267 StatusCode CalibDataSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
00268 {
00269
00270
00271 if (IDetDataSvc::interfaceID().versionMatch(riid) ) {
00272 *ppvInterface = (IDetDataSvc*)this;
00273 } else if (IInstrumentName::interfaceID().versionMatch(riid) ) {
00274 *ppvInterface = (IInstrumentName*) this;
00275
00276
00277 } else {
00278 return DataSvc::queryInterface(riid, ppvInterface);
00279 }
00280 addRef();
00281 return StatusCode::SUCCESS;
00282 }
00283
00284
00285
00286
00287
00288
00290 StatusCode CalibDataSvc::clearStore() {
00291 DataSvc::clearStore();
00292 return StatusCode::SUCCESS;
00293 }
00294
00295
00296 void CalibDataSvc::handle ( const Incident& inc ) {
00297 MsgStream log( msgSvc(), name() );
00298 return;
00299 }
00300
00301
00302
00303
00304
00305
00306 StatusCode CalibDataSvc::updateObject( DataObject* toUpdate ) {
00307
00308
00309 MsgStream log( msgSvc(), name() );
00310 log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
00311
00312 if ( 0 == toUpdate ) {
00313 log << MSG::ERROR
00314 << "There is no DataObject to update" << endreq;
00315 return INVALID_OBJECT;
00316 }
00317
00318 log << MSG::INFO<<"begin of CalibDataSvc::updateObject"<<endreq;
00319
00320 StatusCode status = DataSvc::updateObject(toUpdate);
00321 if ( !status.isSuccess() ) {
00322 log << MSG::ERROR
00323 << "Could not update DataObject" << endreq;
00324 if ( status == NO_DATA_LOADER )
00325 log << MSG::ERROR << "There is no data loader" << endreq;
00326 return status;
00327 }
00328 log << MSG::INFO<<"begin of CalibDataSvc::updateObject successfully updated"<<endreq;
00329
00330 return StatusCode::SUCCESS;
00331 }
00332
00333 StatusCode CalibDataSvc::loadObject(IConversionSvc* pLoader,
00334 IRegistry* pRegistry) {
00335 return DataSvc::loadObject(pLoader, pRegistry);
00336
00337 }
00338
00339 StatusCode CalibDataSvc::retrieveObject(const std::string& fullPath,DataObject*& pObject)
00340 {
00341 MsgStream log( msgSvc(), name() );
00342
00343 int runNo;
00344
00345 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
00346 if( evt ){
00347 runNo = evt -> runNumber();
00348 log << MSG::DEBUG <<"The runNumber of current event is "<<runNo<<endreq;
00349 }
00350
00351 else{
00352 log << MSG::WARNING << "WARNING accessing Event" <<endreq;
00353
00354 }
00355
00356
00357 StatusCode sc =DataSvc::retrieveObject(fullPath,pObject);
00358 if (!sc.isSuccess()) {
00359 log<< MSG::ERROR << "Unable to get the retrieveObject"
00360 << endreq;
00361 return sc;
00362 }
00363
00364
00365 if(fullPath=="/Calib/MdcCal"&&m_calibType[0]==CALIBROOT_StorageType){
00366 return StatusCode::SUCCESS;}
00367 if(fullPath=="/Calib/DedxCal"&&m_calibType[2]==CALIBROOT_StorageType){
00368 return StatusCode::SUCCESS;}
00369 if(fullPath=="/Calib/TofCal"&&m_calibType[1]==CALIBROOT_StorageType){
00370 return StatusCode::SUCCESS;}
00371 if(fullPath=="/Calib/EmcCal"&&m_calibType[3]==CALIBROOT_StorageType){
00372 return StatusCode::SUCCESS;}
00373 if(fullPath=="/Calib/MucCal"&&m_calibType[4]==CALIBROOT_StorageType){
00374 return StatusCode::SUCCESS;}
00375 if(fullPath=="/Calib/EsTimeCal"&&m_calibType[5]==CALIBROOT_StorageType){
00376 return StatusCode::SUCCESS;}
00377 if(fullPath=="/Calib/EstTofCal"&&m_calibType[6]==CALIBROOT_StorageType){
00378 return StatusCode::SUCCESS;}
00379 if(fullPath=="/Calib/TofQElec"&&m_calibType[8]==CALIBROOT_StorageType){
00380 return StatusCode::SUCCESS;}
00381 if(fullPath=="/Calib/TofSim"&&m_calibType[9]==CALIBROOT_StorageType){
00382 return StatusCode::SUCCESS;}
00383 if(fullPath=="/Calib/DedxSim"&&m_calibType[10]==CALIBROOT_StorageType){
00384 return StatusCode::SUCCESS;}
00385
00386
00387 CalibData::CalibBase1* tmpObject = dynamic_cast<CalibData::CalibBase1*>(pObject);
00388 if(fullPath=="/Calib/TofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00389 { return StatusCode::SUCCESS;}
00390 if(fullPath=="/Calib/EstTofCal"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00391 { return StatusCode::SUCCESS;}
00392 if(fullPath=="/Calib/TofSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00393 { return StatusCode::SUCCESS;}
00394 if(fullPath=="/Calib/DedxSim"&&runNo>= tmpObject->getrunfrm()&&runNo<=tmpObject->getrunto())
00395 { return StatusCode::SUCCESS;}
00396
00397
00398
00399 if( fabs(runNo) >= tmpObject->getrunfrm() && fabs(runNo)<=tmpObject->getrunto())
00400 {
00401 log << MSG::DEBUG <<__LINE__<< " runfrm @CalibDataSvc is:"<<tmpObject->getrunfrm()<<" runto min is:"<<tmpObject->getrunto()<<endreq;
00402 return StatusCode::SUCCESS;}
00403 else
00404 {
00405 log<< MSG::INFO <<"@CalibDataSvc runfrm="<< tmpObject->getrunfrm()<<"runto="<<tmpObject->getrunto()<<"runNo="<<runNo<<endreq;
00406 log<< MSG::DEBUG << "update the Object"
00407 << endreq;
00408 sc =DataSvc:: updateObject(pObject);
00409 return sc;
00410 }
00411 }
00412
00413 StatusCode CalibDataSvc::registerObject (const std::string& parentPath,
00414 const std::string& objPath,
00415 DataObject* pObject) {
00416 DataObject* pO = 0;
00417 StatusCode status =DataSvc::retrieveObject(parentPath, pO);
00418 if ( !status.isSuccess() && m_forceLeaves ) {
00419 pO = createDefaultObject();
00420 status =DataSvc::registerObject(parentPath, pO);
00421 if ( !status.isSuccess() ) {
00422 pO->release();
00423 }
00424 }
00425 if ( status.isSuccess() ) {
00426 status =DataSvc::registerObject(pO, objPath, pObject);
00427 }
00428 if(status.isSuccess() ){
00429 return status;
00430 }
00431 }
00432
00433