Gaudi Framework, version v20r4

Generated: 8 Jan 2009

RunRecordDataSvc.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      RunRecordDataSvc.cpp
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : System ( The LHCb Offline System)
00006 //
00007 //  Description: implementation of the Transient event data service.
00008 //
00009 //  Author     : M.Frank
00010 //  History    :
00011 // +---------+----------------------------------------------+---------
00012 // |    Date |                 Comment                      | Who     
00013 // +---------+----------------------------------------------+---------
00014 // | 10/12/08| Initial version                              | MF
00015 // +---------+----------------------------------------------+---------
00016 //
00017 //====================================================================
00018 #define  DATASVC_RUNRECORDDATASVC_CPP
00019 
00020 #include "GaudiKernel/SmartIF.h"
00021 #include "GaudiKernel/MsgStream.h"
00022 #include "GaudiKernel/IProperty.h"
00023 #include "GaudiKernel/SvcFactory.h"
00024 #include "GaudiKernel/DataObject.h"
00025 #include "GaudiKernel/ISvcLocator.h"
00026 #include "GaudiKernel/IIncidentSvc.h"
00027 #include "GaudiKernel/IConversionSvc.h"
00028 #include "GaudiKernel/IOpaqueAddress.h"
00029 #include "GaudiKernel/DataIncident.h"
00030 #include "GaudiKernel/RegistryEntry.h"
00031 
00032 #include "RunRecordDataSvc.h"
00033 
00034 // Instantiation of a static factory class used by clients to create
00035 // instances of this service
00036 DECLARE_SERVICE_FACTORY(RunRecordDataSvc)
00037 
00038 
00039 StatusCode RunRecordDataSvc::initialize()    {
00040   // Nothing to do: just call base class initialisation
00041   StatusCode      sc  = DataSvc::initialize();
00042   ISvcLocator*    svc_loc = serviceLocator();
00043   MsgStream log(msgSvc(),name());
00044 
00045   if ( !sc.isSuccess() ) { // Base class failure
00046     return sc;
00047   }
00048   // Attach data loader facility
00049   sc = svc_loc->service("PersistencySvc/RunRecordPersistencySvc", m_cnvSvc, true);
00050   if ( !sc.isSuccess() ) {
00051     log << MSG::ERROR << "Failed to access RunRecordPersistencySvc." << endmsg;
00052     return sc;
00053   }
00054   SmartIF<IProperty> prp(m_cnvSvc);
00055   if ( prp ) {
00056     //prp->setProperty();
00057   }
00058   sc = setDataLoader( m_cnvSvc );
00059   if ( !sc.isSuccess() ) {
00060     log << MSG::ERROR << "Failed to attach dataloader RunRecordPersistencySvc." << endmsg;
00061     return sc;
00062   }
00063 
00064   sc = setRoot(m_rootName, new DataObject());
00065   if( !sc.isSuccess() )  {
00066     log << MSG::WARNING << "Error declaring RunRecord root DataObject" << endreq;
00067     return sc;
00068   } 
00069 
00070   if( !m_incidentSvc )  {
00071     log << MSG::FATAL << "IncidentSvc is invalid--base class failed." << endreq;
00072     return sc;
00073   }
00074 
00079   m_incidentSvc->addListener(this,IncidentType::BeginEvent);
00080   m_incidentSvc->addListener(this,"FILE_OPEN_READ");
00081   m_incidentSvc->addListener(this,"SAVE_RUN_RECORD");
00082 
00083   return sc;
00084 }
00085 
00087 StatusCode RunRecordDataSvc::reinitialize()    {
00088   // Do nothing for this service
00089   return StatusCode::SUCCESS;
00090 }
00091 
00093 StatusCode RunRecordDataSvc::finalize()    {
00094   if( m_cnvSvc ) m_cnvSvc->release();
00095   m_cnvSvc = 0;
00096   DataSvc::finalize().ignore();
00097   return StatusCode::SUCCESS ;
00098 }
00099 
00101 StatusCode RunRecordDataSvc::queryInterface(const InterfaceID& riid,void** ppvIf)  { 
00102   if ( 0 == ppvIf )
00103     return StatusCode::FAILURE;
00104   else if ( IIncidentListener::interfaceID().versionMatch(riid) )
00105     *ppvIf = static_cast<IIncidentListener*>( this );
00106   else
00107     return DataSvc::queryInterface(riid,ppvIf);
00108   // increment reference counter 
00109   addRef();
00110   return SUCCESS;
00111 }
00112 
00114 void RunRecordDataSvc::handle(const Incident& incident) {
00115   if ( incident.type() == "FILE_OPEN_READ" ) {
00116     typedef ContextIncident<IOpaqueAddress*> Ctxt;
00117     const Ctxt* inc = dynamic_cast<const Ctxt*>(&incident);
00118     if ( inc ) {
00119       registerRunRecord(inc->source(),inc->tag());
00120       return;
00121     }
00122     MsgStream log(msgSvc(),name());
00123     log << MSG::ALWAYS << "Received invalid incident of type:" << incident.type() << endmsg;        
00124   }
00125   else if ( incident.type() == "SAVE_RUN_RECORD" ) {
00126     MsgStream log(msgSvc(),name());
00127     log << MSG::ALWAYS << "Saving run records not implemented." << endmsg;    
00128   }
00129 }
00130 
00132 void RunRecordDataSvc::registerRunRecord(const std::string& data, IOpaqueAddress* pAddr)   {
00133   if ( !data.empty() && 0 != pAddr ) {
00134     MsgStream log(msgSvc(),name());
00135     std::string fid = data;
00136     log << MSG::ALWAYS << "Request to load run record for file " << fid << endmsg;
00137     StatusCode sc = registerAddress(m_root,fid,pAddr);
00138     if ( !sc.isSuccess() ) {
00139       log << MSG::ERROR << "Failed to register run record for:" << fid << endmsg;
00140       pAddr->release();
00141     }
00142   }
00143   else if ( !data.empty() && 0 == pAddr ) {
00144     MsgStream log(msgSvc(),name());
00145     log << MSG::ERROR << "Failed to register run record for:" << data << " [Invalid Address]" << endmsg;
00146   }
00147 }
00148 
00150 RunRecordDataSvc::RunRecordDataSvc(const std::string& name,ISvcLocator* svc) 
00151 : DataSvc(name,svc)   {
00152   m_cnvSvc = 0;
00153   m_rootName = "/RunRecords";
00154 }
00155 
00157 RunRecordDataSvc::~RunRecordDataSvc()  {
00158 }

Generated at Thu Jan 8 17:44:23 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004