Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

DetDataSvc.cpp

Go to the documentation of this file.
00001 // $Id: DetDataSvc.cpp,v 1.24 2008/10/27 19:22:21 marcocle Exp $
00002 #define  DETECTORDATASVC_DETDATASVC_CPP
00003 
00004 // Include files
00005 #include "DetDataSvc.h"
00006 #include "GaudiKernel/IAddressCreator.h"
00007 #include "GaudiKernel/IConversionSvc.h"
00008 #include "GaudiKernel/IOpaqueAddress.h"
00009 #include "GaudiKernel/ISvcLocator.h"
00010 #include "GaudiKernel/IValidity.h"
00011 #include "GaudiKernel/DataObject.h"
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "GaudiKernel/SvcFactory.h"
00014 #include "GaudiKernel/System.h"
00015 using System::isEnvSet;
00016 using System::getEnv;
00017 
00018 // Instantiation of a static factory class used by clients to create
00019 // instances of this service
00020 DECLARE_SERVICE_FACTORY(DetDataSvc)
00021 
00022 // Service initialization
00023 StatusCode DetDataSvc::initialize()   {
00024   MsgStream log(msgSvc(), name());
00025 
00026   // Call base class initialization
00027   StatusCode sc  = DataSvc::initialize();
00028   if( sc.isFailure() ) return sc;
00029 
00030   // Set Data Loader
00031   SmartIF<IConversionSvc> cnv_svc(serviceLocator()->service(m_persistencySvcName));
00032   if( !cnv_svc.isValid() ) {
00033     log << MSG::ERROR << "Unable to retrieve " << m_persistencySvcName << endmsg;
00034     return StatusCode::FAILURE;
00035   }
00036 
00037   sc = setDataLoader(cnv_svc);
00038   if( sc.isFailure() ) {
00039     log << MSG::ERROR << "Unable to set DataLoader" << endmsg;
00040     return sc;
00041   }
00042 
00043   // Get address creator from the DetectorPersistencySvc
00044   m_addrCreator = cnv_svc;
00045   if (!m_addrCreator.isValid()) {
00046     log << MSG::ERROR << "Unable to get AddressCreator." << endmsg;
00047     return StatusCode::FAILURE;
00048   }
00049 
00050   return setupDetectorDescription();
00051 }
00052 
00053 StatusCode DetDataSvc::setupDetectorDescription() {
00054   // Now you can use the MsgSvc
00055   MsgStream log(msgSvc(), name());
00056 
00057   // Initialize the detector data transient store
00058   log << MSG::DEBUG << "Storage type used is: " << m_detStorageType << endmsg;
00059   log << MSG::DEBUG << "Setting DetectorDataSvc root node... " << endmsg;
00060 
00061   if( m_usePersistency ) {
00062 
00063     IOpaqueAddress* rootAddr;
00064     if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
00065 
00066       // if the name of DBlocation is not given - construct it!
00067           // by retrieving the value of XMLDDBROOT
00068 
00070       if ( isEnvSet("XMLDDDBROOT") ) {
00071         m_detDbLocation  = getEnv("XMLDDDBROOT");
00072         m_detDbLocation += "/DDDB/lhcb.xml";
00073       }
00074     }
00075     if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
00076       log << MSG::ERROR
00077           << "Detector data location name not set. Detector data will "
00078           << "not be found." << endmsg;
00079       return StatusCode::FAILURE;
00080     }
00081     else {
00082       // Create address
00083       unsigned long iargs[]={0,0};
00084       const std::string args[] = {m_detDbLocation, m_detDbRootName};
00085       StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
00086                                                     CLID_Catalog,
00087                                                     args,
00088                                                     iargs,
00089                                                     rootAddr);
00090       if( sc.isSuccess() ) {
00091         std::string dbrName = "/" + m_detDbRootName;
00092         sc = i_setRoot( dbrName, rootAddr );
00093         if( sc.isFailure() ) {
00094           log << MSG::ERROR << "Unable to set detector data store root"
00095               << endmsg;
00096           return sc;
00097         }
00098       }
00099       else {
00100         log << MSG::ERROR << "Unable to create address for  /dd" << endmsg;
00101         return sc;
00102       }
00103     }
00104     // Writing the description file in the output log file [bugs #2854]
00105     log << MSG::ALWAYS << "Detector description database: " << m_detDbLocation << endmsg;
00106   }
00107   else {
00108     log << MSG::INFO << "Detector description not requested to be loaded"
00109         << endmsg;
00110   }
00111 
00112   return StatusCode::SUCCESS;
00113 }
00114 
00115 // Service initialisation
00116 StatusCode DetDataSvc::reinitialize()   {
00117   MsgStream log(msgSvc(), name());
00118 
00119   // The DetectorDataSvc does not need to be re-initialized. If it is done
00120   // all the Algorithms having references to DetectorElements will become
00121   // invalid and crash the program.  (Pere Mato)
00122 
00123   // Call base class reinitialization
00124   //StatusCode sc  = DataSvc::reinitialize();
00125   //if( sc.isFailure() ) return sc;
00126 
00127   // Delete the associated event time
00128   //if( 0 != m_eventTime ) delete m_eventTime;
00129   //m_eventTimeDefined = false;
00130 
00131   //return setupDetectorDescription();
00132   return StatusCode::SUCCESS;
00133 }
00134 
00136 StatusCode DetDataSvc::finalize()
00137 {
00138   MsgStream log(msgSvc(), name());
00139   log << MSG::DEBUG << "Finalizing" << endmsg;
00140 
00141   // clears the store
00142   m_usePersistency = false; // avoid creation of an empty store when clearing
00143   clearStore().ignore();
00144 
00145   // Releases the address creator
00146   m_addrCreator = 0;
00147 
00148   // Releases the DataLoader
00149   setDataLoader(0).ignore();
00150 
00151   // Finalize the base class
00152   return DataSvc::finalize();
00153 }
00154 
00156 StatusCode DetDataSvc::clearStore()   {
00157 
00158   MsgStream log(msgSvc(), name());
00159 
00160   DataSvc::clearStore().ignore();
00161 
00162   if( m_usePersistency ) {
00163     // Create root address
00164     unsigned long iargs[]    = {0,0};
00165     const std::string args[] = {m_detDbLocation, m_detDbRootName};
00166     IOpaqueAddress*   rootAddr;
00167     StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
00168                                                   CLID_Catalog,
00169                                                   args,
00170                                                   iargs,
00171                                                   rootAddr);
00172     // Set detector data store root
00173     if( sc.isSuccess() ) {
00174       std::string dbrName = "/" + m_detDbRootName;
00175       sc = i_setRoot( dbrName, rootAddr );
00176       if( sc.isFailure() ) {
00177         log << MSG::ERROR
00178             << "Unable to set detector data store root" << endmsg;
00179       }
00180     } else {
00181       log << MSG::ERROR << "Unable to create address for  /dd" << endmsg;
00182     }
00183     return sc;
00184 
00185   }
00186   return StatusCode::SUCCESS;
00187 
00188 }
00189 
00191 DetDataSvc::DetDataSvc(const std::string& name,ISvcLocator* svc) :
00192   base_class(name,svc), m_eventTime(0)  {
00193   declareProperty("DetStorageType",  m_detStorageType = XML_StorageType );
00194   declareProperty("DetDbLocation",   m_detDbLocation  = "empty" );
00195   declareProperty("DetDbRootName",   m_detDbRootName  = "dd" );
00196   declareProperty("UsePersistency",  m_usePersistency = false );
00197   declareProperty("PersistencySvc",  m_persistencySvcName = "DetectorPersistencySvc" );
00198   m_rootName = "/dd";
00199   m_rootCLID = CLID_Catalog;
00200   m_addrCreator = 0;
00201 }
00202 
00204 DetDataSvc::~DetDataSvc()  {
00205 }
00206 
00208 void DetDataSvc::setEventTime ( const Gaudi::Time& time ) {
00209   m_eventTime = time;
00210   if ( msgSvc()->outputLevel() <= MSG::DEBUG) {
00211     MsgStream log( msgSvc(), name() );
00212     log << MSG::DEBUG << "Event Time set to " << eventTime() << endmsg;
00213   }
00214 }
00215 
00217 bool DetDataSvc::validEventTime ( ) const {
00218   return true;
00219 }
00220 
00222 const Gaudi::Time& DetDataSvc::eventTime ( ) const {
00223   return m_eventTime;
00224 }
00225 
00227 void DetDataSvc::handle ( const Incident& inc ) {
00228   MsgStream log( msgSvc(), name() );
00229   log << MSG::DEBUG << "New incident received" << endmsg;
00230   log << MSG::DEBUG << "Incident source: " << inc.source() << endmsg;
00231   log << MSG::DEBUG << "Incident type: " << inc.type() << endmsg;
00232   return;
00233 }
00234 
00237 StatusCode DetDataSvc::updateObject( DataObject* toUpdate ) {
00238 
00239   MsgStream log( msgSvc(), name() );
00240   log << MSG::DEBUG << "Method updateObject starting" << endmsg;
00241 
00242   // Check that object to update exists
00243   if ( 0 == toUpdate ) {
00244     log << MSG::ERROR
00245         << "There is no DataObject to update" << endmsg;
00246     return INVALID_OBJECT;
00247   }
00248 
00249   // Retrieve IValidity interface of object to update
00250   IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
00251   if ( 0 == condition ) {
00252     log << MSG::WARNING
00253         << "Cannot update DataObject: DataObject does not implement IValidity"
00254         << endmsg;
00255     return StatusCode::SUCCESS;
00256   }
00257 
00258   // Check that the event time has been defined
00259   if ( !validEventTime() ) {
00260     log << MSG::WARNING
00261         << "Cannot update DataObject: event time undefined"
00262         << endmsg;
00263     return StatusCode::SUCCESS;
00264   }
00265 
00266   // No need to update if condition is valid
00267   if ( condition->isValid( eventTime() ) ) {
00268     log << MSG::DEBUG
00269         << "DataObject is valid: no need to update" << endmsg;
00270     return StatusCode::SUCCESS;
00271   } else {
00272     log << MSG::DEBUG
00273         << "DataObject is invalid: update it" << endmsg;
00274   }
00275 
00276   // TODO: before loading updated object, update HERE its parent in data store
00277 
00278   // Now delegate update to the conversion service by calling the base class
00279   log << MSG::DEBUG
00280       << "Delegate update to relevant conversion service" << endmsg;
00281   StatusCode status = DataSvc::updateObject(toUpdate);
00282   if ( !status.isSuccess() ) {
00283     log << MSG::ERROR
00284         << "Could not update DataObject" << endmsg;
00285     if ( status == NO_DATA_LOADER )
00286       log << MSG::ERROR << "There is no data loader" << endmsg;
00287     return status;
00288   }
00289 
00290   // Now cross-check that the new condition is valid
00291   condition = dynamic_cast<IValidity*>(toUpdate);
00292   if ( 0 == condition ) {
00293     log << MSG::ERROR
00294         << "Updated DataObject does not implement IValidity" << endmsg;
00295     return StatusCode::FAILURE;
00296   }
00297   if ( FSMState() == Gaudi::StateMachine::RUNNING &&
00298        !condition->isValid( eventTime() ) ) {
00299     log << MSG::ERROR
00300         << "Updated DataObject is not valid" << endmsg;
00301     log << MSG::ERROR
00302         << "Are you sure the conversion service has updated it?" << endmsg;
00303     return StatusCode::FAILURE;
00304   }
00305 
00306   // DataObject was successfully updated
00307   log << MSG::DEBUG << "Method updateObject exiting successfully" << endmsg;
00308   return StatusCode::SUCCESS;
00309 
00310 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:53:57 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004