| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# DetDataSvc.cpp

Go to the documentation of this file.

    00001 #define  DETECTORDATASVC_DETDATASVC_CPP
    00002
    00003 // Include files
    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 // Instantiation of a static factory class used by clients to create
    00024 // instances of this service
    00025 DECLARE_SERVICE_FACTORY(DetDataSvc)
    00026
    00027 // Service initialization
    00028 StatusCode DetDataSvc::initialize()   {
    00029   // Call base class initialization
    00030   StatusCode sc  = DataSvc::initialize();
    00031   if( UNLIKELY(sc.isFailure()) ) return sc;
    00032
    00033   // Set Data Loader
    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   // Get address creator from the DetectorPersistencySvc
    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   // Initialize the detector data transient store
    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       // if the name of DBlocation is not given - construct it!
    00069           // by retrieving the value of XMLDDBROOT
    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       // Create address
    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     // Writing the description file in the output log file [bugs #2854]
    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 // Service initialisation
    00115 StatusCode DetDataSvc::reinitialize() {
    00116   // The DetectorDataSvc does not need to be re-initialized. If it is done
    00117   // all the Algorithms having references to DetectorElements will become
    00118   // invalid and crash the program.  (Pere Mato)
    00119
    00120   // Call base class reinitialization
    00121   //StatusCode sc  = DataSvc::reinitialize();
    00122   //if( sc.isFailure() ) return sc;
    00123
    00124   // Delete the associated event time
    00125   //if( 0 != m_eventTime ) delete m_eventTime;
    00126   //m_eventTimeDefined = false;
    00127
    00128   //return setupDetectorDescription();
    00129   return StatusCode::SUCCESS;
    00130 }
    00131
    00133 StatusCode DetDataSvc::finalize()
    00134 {
    00135   DEBMSG << "Finalizing" << endmsg;
    00136
    00137   // clears the store
    00138   m_usePersistency = false; // avoid creation of an empty store when clearing
    00139   clearStore().ignore();
    00140
    00141   // Releases the address creator
    00142   m_addrCreator = 0;
    00143
    00144   // Releases the DataLoader
    00145   setDataLoader(0).ignore();
    00146
    00147   // Finalize the base class
    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     // Create root address
    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     // Set detector data store root
    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   // Check that object to update exists
    00235   if ( 0 == toUpdate ) {
    00236     error() << "There is no DataObject to update" << endmsg;
    00237     return INVALID_OBJECT;
    00238   }
    00239
    00240   // Retrieve IValidity interface of object to update
    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   // Check that the event time has been defined
    00250   if ( !validEventTime() ) {
    00251     warning()
    00252         << "Cannot update DataObject: event time undefined"
    00253         << endmsg;
    00254     return StatusCode::SUCCESS;
    00255   }
    00256
    00257   // No need to update if condition is valid
    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   // TODO: before loading updated object, update HERE its parent in data store
    00266
    00267   // Now delegate update to the conversion service by calling the base class
    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   // Now cross-check that the new condition is valid
    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   // DataObject was successfully updated
    00291   DEBMSG << "Method updateObject exiting successfully" << endmsg;
    00292   return StatusCode::SUCCESS;
    00293
    00294 }

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines