Go to the documentation of this file.00001 #define DETECTORDATASVC_DETDATASVC_CPP
00002
00003
00004 #include "DetDataSvc.h"
00005 #include "GaudiKernel/IAddressCreator.h"
00006 #include "GaudiKernel/IConversionSvc.h"
00007 #include "GaudiKernel/IOpaqueAddress.h"
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "GaudiKernel/IValidity.h"
00010 #include "GaudiKernel/DataObject.h"
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "GaudiKernel/SvcFactory.h"
00013 #include "GaudiKernel/System.h"
00014 using System::isEnvSet;
00015 using System::getEnv;
00016
00017 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
00018 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
00019
00020 #define DEBMSG ON_DEBUG debug()
00021 #define VERMSG ON_VERBOSE verbose()
00022
00023
00024
00025 DECLARE_SERVICE_FACTORY(DetDataSvc)
00026
00027
00028 StatusCode DetDataSvc::initialize() {
00029
00030 StatusCode sc = DataSvc::initialize();
00031 if( UNLIKELY(sc.isFailure()) ) return sc;
00032
00033
00034 SmartIF<IConversionSvc> cnv_svc(serviceLocator()->service(m_persistencySvcName));
00035 if( UNLIKELY(!cnv_svc.isValid()) ) {
00036 error() << "Unable to retrieve " << m_persistencySvcName << endmsg;
00037 return StatusCode::FAILURE;
00038 }
00039
00040 sc = setDataLoader(cnv_svc);
00041 if( UNLIKELY(sc.isFailure()) ) {
00042 error() << "Unable to set DataLoader" << endmsg;
00043 return sc;
00044 }
00045
00046
00047 m_addrCreator = cnv_svc;
00048 if ( UNLIKELY(!m_addrCreator.isValid()) ) {
00049 error() << "Unable to get AddressCreator." << endmsg;
00050 return StatusCode::FAILURE;
00051 }
00052
00053 return setupDetectorDescription();
00054 }
00055
00056 StatusCode DetDataSvc::setupDetectorDescription() {
00057
00058 ON_DEBUG {
00059 debug() << "Storage type used is: " << m_detStorageType << endmsg;
00060 debug() << "Setting DetectorDataSvc root node... " << endmsg;
00061 }
00062
00063 if( m_usePersistency ) {
00064
00065 IOpaqueAddress* rootAddr;
00066 if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
00067
00068
00069
00070
00072 if ( isEnvSet("XMLDDDBROOT") ) {
00073 m_detDbLocation = getEnv("XMLDDDBROOT");
00074 m_detDbLocation += "/DDDB/lhcb.xml";
00075 }
00076 }
00077 if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
00078 error() << "Detector data location name not set. Detector data will "
00079 "not be found." << endmsg;
00080 return StatusCode::FAILURE;
00081 }
00082 else {
00083
00084 unsigned long iargs[]={0,0};
00085 const std::string args[] = {m_detDbLocation, m_detDbRootName};
00086 StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
00087 CLID_Catalog,
00088 args,
00089 iargs,
00090 rootAddr);
00091 if( sc.isSuccess() ) {
00092 std::string dbrName = "/" + m_detDbRootName;
00093 sc = i_setRoot( dbrName, rootAddr );
00094 if( sc.isFailure() ) {
00095 error() << "Unable to set detector data store root" << endmsg;
00096 return sc;
00097 }
00098 }
00099 else {
00100 error() << "Unable to create address for /dd" << endmsg;
00101 return sc;
00102 }
00103 }
00104
00105 always() << "Detector description database: " << m_detDbLocation << endmsg;
00106 }
00107 else {
00108 info() << "Detector description not requested to be loaded" << endmsg;
00109 }
00110
00111 return StatusCode::SUCCESS;
00112 }
00113
00114
00115 StatusCode DetDataSvc::reinitialize() {
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 return StatusCode::SUCCESS;
00130 }
00131
00133 StatusCode DetDataSvc::finalize()
00134 {
00135 DEBMSG << "Finalizing" << endmsg;
00136
00137
00138 m_usePersistency = false;
00139 clearStore().ignore();
00140
00141
00142 m_addrCreator = 0;
00143
00144
00145 setDataLoader(0).ignore();
00146
00147
00148 return DataSvc::finalize();
00149 }
00150
00152 StatusCode DetDataSvc::clearStore() {
00153
00154 MsgStream log(msgSvc(), name());
00155
00156 DataSvc::clearStore().ignore();
00157
00158 if( m_usePersistency ) {
00159
00160 unsigned long iargs[] = {0,0};
00161 const std::string args[] = {m_detDbLocation, m_detDbRootName};
00162 IOpaqueAddress* rootAddr;
00163 StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
00164 CLID_Catalog,
00165 args,
00166 iargs,
00167 rootAddr);
00168
00169 if( sc.isSuccess() ) {
00170 std::string dbrName = "/" + m_detDbRootName;
00171 sc = i_setRoot( dbrName, rootAddr );
00172 if( sc.isFailure() ) {
00173 error() << "Unable to set detector data store root" << endmsg;
00174 }
00175 } else {
00176 error() << "Unable to create address for /dd" << endmsg;
00177 }
00178 return sc;
00179
00180 }
00181 return StatusCode::SUCCESS;
00182
00183 }
00184
00186 DetDataSvc::DetDataSvc(const std::string& name,ISvcLocator* svc) :
00187 base_class(name,svc), m_eventTime(0) {
00188 declareProperty("DetStorageType", m_detStorageType = XML_StorageType );
00189 declareProperty("DetDbLocation", m_detDbLocation = "empty" );
00190 declareProperty("DetDbRootName", m_detDbRootName = "dd" );
00191 declareProperty("UsePersistency", m_usePersistency = false );
00192 declareProperty("PersistencySvc", m_persistencySvcName = "DetectorPersistencySvc" );
00193 m_rootName = "/dd";
00194 m_rootCLID = CLID_Catalog;
00195 m_addrCreator = 0;
00196 }
00197
00199 DetDataSvc::~DetDataSvc() {
00200 }
00201
00203 void DetDataSvc::setEventTime ( const Gaudi::Time& time ) {
00204 m_eventTime = time;
00205 DEBMSG << "Event Time set to " << eventTime() << endmsg;
00206 }
00207
00209 bool DetDataSvc::validEventTime ( ) const {
00210 return true;
00211 }
00212
00214 const Gaudi::Time& DetDataSvc::eventTime ( ) const {
00215 return m_eventTime;
00216 }
00217
00219 void DetDataSvc::handle ( const Incident& inc ) {
00220 ON_DEBUG {
00221 debug() << "New incident received" << endmsg;
00222 debug() << "Incident source: " << inc.source() << endmsg;
00223 debug() << "Incident type: " << inc.type() << endmsg;
00224 }
00225 return;
00226 }
00227
00230 StatusCode DetDataSvc::updateObject( DataObject* toUpdate ) {
00231
00232 DEBMSG << "Method updateObject starting" << endmsg;
00233
00234
00235 if ( 0 == toUpdate ) {
00236 error() << "There is no DataObject to update" << endmsg;
00237 return INVALID_OBJECT;
00238 }
00239
00240
00241 IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
00242 if ( 0 == condition ) {
00243 warning()
00244 << "Cannot update DataObject: DataObject does not implement IValidity"
00245 << endmsg;
00246 return StatusCode::SUCCESS;
00247 }
00248
00249
00250 if ( !validEventTime() ) {
00251 warning()
00252 << "Cannot update DataObject: event time undefined"
00253 << endmsg;
00254 return StatusCode::SUCCESS;
00255 }
00256
00257
00258 if ( condition->isValid( eventTime() ) ) {
00259 DEBMSG << "DataObject is valid: no need to update" << endmsg;
00260 return StatusCode::SUCCESS;
00261 } else {
00262 DEBMSG << "DataObject is invalid: update it" << endmsg;
00263 }
00264
00265
00266
00267
00268 DEBMSG << "Delegate update to relevant conversion service" << endmsg;
00269 StatusCode status = DataSvc::updateObject(toUpdate);
00270 if ( !status.isSuccess() ) {
00271 error() << "Could not update DataObject" << endmsg;
00272 if ( status == NO_DATA_LOADER )
00273 error() << "There is no data loader" << endmsg;
00274 return status;
00275 }
00276
00277
00278 condition = dynamic_cast<IValidity*>(toUpdate);
00279 if ( 0 == condition ) {
00280 error() << "Updated DataObject does not implement IValidity" << endmsg;
00281 return StatusCode::FAILURE;
00282 }
00283 if ( FSMState() == Gaudi::StateMachine::RUNNING &&
00284 !condition->isValid( eventTime() ) ) {
00285 error() << "Updated DataObject is not valid" << endmsg;
00286 error() << "Are you sure the conversion service has updated it?" << endmsg;
00287 return StatusCode::FAILURE;
00288 }
00289
00290
00291 DEBMSG << "Method updateObject exiting successfully" << endmsg;
00292 return StatusCode::SUCCESS;
00293
00294 }