6#include "GaudiKernel/DataObject.h"
7#include "GaudiKernel/IAddressCreator.h"
8#include "GaudiKernel/IConversionSvc.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/IIncidentSvc.h"
11#include "GaudiKernel/IOpaqueAddress.h"
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/MsgStream.h"
14#include "GaudiKernel/RegistryEntry.h"
15#include "GaudiKernel/SmartDataPtr.h"
17#include "EventModel/EventHeader.h"
22#include "CalibData/CalibBase1.h"
23#include "CalibData/CalibModelSvc.h"
24#include "CalibDataSvc/ICalibRootSvc.h"
33#define CAST_REGENTRY( x, y ) dynamic_cast<x>( y )
47 : DataSvc( name, svc ) {
52 declareProperty(
"CalibNameList", m_calibList );
53 declareProperty(
"CalibFlavorList", m_flavorList );
54 declareProperty(
"CalibRootName", m_calibRootName =
"Calib" );
66 declareProperty(
"InjSigInterval_CalibStorageType",
79 m_rootName =
"/" + m_calibRootName;
80 m_rootCLID = CLID_DataObject;
85 setDataLoader( 0 ).ignore();
94 sc = DataSvc::initialize();
95 if ( sc.isFailure() )
return sc;
98 MsgStream log(
msgSvc(), name() );
99 IConversionSvc* cnv_svc;
100 sc = serviceLocator()->service(
"DetectorPersistencySvc", cnv_svc,
true );
101 if ( sc.isFailure() )
103 log << MSG::ERROR <<
"Unable to find DetectorPersistencySvc " << endmsg;
107 IIncidentSvc* incsvc;
108 sc = service(
"IncidentSvc", incsvc );
110 if ( sc.isSuccess() ) { incsvc->addListener(
this,
"NewRun", priority ); }
112 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true );
113 if ( sc.isFailure() )
115 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endmsg;
119 sc = setDataLoader( cnv_svc );
120 if ( sc.isFailure() )
122 log << MSG::ERROR <<
"Unable to set data loader " << endmsg;
128 IAddressCreator* calibCreator = 0;
132 sc = serviceLocator()->service(
"DetectorPersistencySvc", calibCreator );
134 if ( sc.isFailure() )
136 log << MSG::ERROR <<
"Unable to locate DetectorPersistencySvc." << endmsg;
137 return StatusCode::FAILURE;
141 debug() <<
"Setting root: " << m_rootName.value() << endmsg;
142 DataObject* rootObj =
new DataObject();
143 sc = setRoot( m_rootName.value(), rootObj );
144 if ( !sc.isSuccess() )
146 log << MSG::ERROR <<
"Unable to set calib data store root." << endmsg;
158 typedef std::vector<CalibData::CalibModelSvc::CalibPair>::const_iterator
PairIt;
163 const std::vector<CalibData::CalibModelSvc::CalibPair>&
pairs = svc.
getPairs();
166 for ( pairIt =
pairs.begin(); pairIt !=
pairs.end(); pairIt++, jj++ )
171 std::string calibTypePath( pairIt->first );
175 unsigned long iargs[] = { 0, 0 };
176 IOpaqueAddress* pAddress;
195 std::string fullpath = calibTypePath;
196 std::string args[] = { fullpath };
198 sc = calibCreator->createAddress( m_calibType[jj],
200 args, iargs, pAddress );
202 if ( !sc.isSuccess() )
203 { log << MSG::INFO <<
"Unable to create Calib address with path " << fullpath << endmsg; }
207 sc = registerAddress( fullpath, pAddress );
208 if ( !sc.isSuccess() )
210 log << MSG::ERROR <<
"Unable to register Calib address with path" << fullpath << endmsg;
244 return StatusCode::SUCCESS;
249 MsgStream log(
msgSvc(), name() );
250 log << MSG::DEBUG <<
"Finalizing" << endmsg;
255 return DataSvc::finalize();
278 DataSvc::clearStore().ignore();
279 return StatusCode::SUCCESS;
284 MsgStream log(
msgSvc(), name() );
289 MsgStream log(
msgSvc(), name() );
290 log << MSG::INFO <<
"begin of CalibDataSvc::updateObject" << endmsg;
294 log << MSG::ERROR <<
"There is no DataObject to update" << endmsg;
295 return Status::INVALID_OBJECT;
298 log << MSG::INFO <<
"begin of CalibDataSvc::updateObject" << endmsg;
300 StatusCode status = DataSvc::updateObject( toUpdate );
301 if ( !status.isSuccess() )
303 log << MSG::ERROR <<
"Could not update DataObject" << endmsg;
304 if ( status == Status::NO_DATA_LOADER )
305 log << MSG::ERROR <<
"There is no data loader" << endmsg;
308 log << MSG::INFO <<
"begin of CalibDataSvc::updateObject successfully updated" << endmsg;
310 return StatusCode::SUCCESS;
314 return DataSvc::loadObject( pLoader, pRegistry );
318 DataObject*& pObject ) {
320 MsgStream log(
msgSvc(), name() );
322 debug() <<
"In retrieveObject" << endmsg;
326 SmartDataPtr<Event::EventHeader> evt( m_eventSvc,
"/Event/EventHeader" );
329 runNo = evt->runNumber();
330 log << MSG::DEBUG <<
"The runNumber of current event is " <<
runNo << endmsg;
335 log << MSG::WARNING <<
"WARNING accessing Event" << endmsg;
339 StatusCode sc = DataSvc::retrieveObject( pDirectory, fullPath, pObject );
340 if ( !sc.isSuccess() )
342 log << MSG::ERROR <<
"Unable to get the retrieveObject" << endmsg;
348 {
return StatusCode::SUCCESS; }
350 {
return StatusCode::SUCCESS; }
352 {
return StatusCode::SUCCESS; }
354 {
return StatusCode::SUCCESS; }
356 {
return StatusCode::SUCCESS; }
358 {
return StatusCode::SUCCESS; }
360 {
return StatusCode::SUCCESS; }
362 {
return StatusCode::SUCCESS; }
364 {
return StatusCode::SUCCESS; }
366 {
return StatusCode::SUCCESS; }
369 {
return StatusCode::SUCCESS; }
371 {
return StatusCode::SUCCESS; }
373 {
return StatusCode::SUCCESS; }
375 {
return StatusCode::SUCCESS; }
378 if ( fullPath ==
"/Calib/TofCal" &&
runNo >= tmpObject->
getrunfrm() &&
380 {
return StatusCode::SUCCESS; }
381 if ( fullPath ==
"/Calib/EstTofCal" &&
runNo >= tmpObject->
getrunfrm() &&
383 {
return StatusCode::SUCCESS; }
384 if ( fullPath ==
"/Calib/TofSim" &&
runNo >= tmpObject->
getrunfrm() &&
386 {
return StatusCode::SUCCESS; }
387 if ( fullPath ==
"/Calib/DedxSim" &&
runNo >= tmpObject->
getrunfrm() &&
389 {
return StatusCode::SUCCESS; }
393 log << MSG::DEBUG << __LINE__ <<
" runfrm @CalibDataSvc is:" << tmpObject->
getrunfrm()
394 <<
" runto min is:" << tmpObject->
getrunto() << endmsg;
395 return StatusCode::SUCCESS;
399 log << MSG::INFO <<
"@CalibDataSvc runfrm=" << tmpObject->
getrunfrm()
400 <<
"runto=" << tmpObject->
getrunto() <<
"runNo=" <<
runNo << endmsg;
401 log << MSG::DEBUG <<
"update the Object" << endmsg;
402 sc = DataSvc::updateObject( pObject );
408 DataObject* pObject ) {
409 fatal() <<
"In registerObject, parentPath=" << parentPath <<
" objPath=" << objPath
410 <<
" pObject=" << pObject << endmsg;
413 StatusCode status = DataSvc::retrieveObject( parentPath, pO );
416 DataSvc::getProperty(
"ForceLeaves" ).toString() ==
"true";
417 if ( !status.isSuccess() && isForceLeaves )
419 pO = createDefaultObject();
420 status = DataSvc::registerObject( parentPath, pO );
421 if ( !status.isSuccess() ) { pO->release(); }
423 if ( status.isSuccess() ) { status = DataSvc::registerObject( pO, objPath, pObject ); }
424 if ( status.isSuccess() )
426 fatal() <<
"registerObject [" << status.isSuccess() <<
"]: parentPath = " << parentPath
427 <<
" objPath = " << objPath <<
" pObject = " << pObject << endmsg;
DECLARE_COMPONENT(BesBdkRc)
DataSvcHelpers::RegistryEntry RegEntry
unsigned const char CALIBROOT_StorageType
virtual StatusCode loadObject(IConversionSvc *pLoader, IRegistry *pRegistry) override
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
virtual StatusCode updateObject(DataObject *toUpdate) override
Update object.
virtual StatusCode clearStore() override
Remove all data objects in the data store.
virtual StatusCode registerObject(std::string_view parentPath, std::string_view objPath, DataObject *pObject) override
virtual StatusCode initialize() override
virtual StatusCode finalize() override
Finalize the service.
virtual void handle(const Incident &) override
Query the interface of the service.
virtual ~CalibDataSvc()
Standard Destructor.
CalibDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
virtual int getrunto() const
virtual int getrunfrm() const
const std::vector< CalibPair > & getPairs() const
CalibPairCol::const_iterator PairIt
_EXTERN_ CalibPairCol pairs