Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

RecordDataSvc.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      RecordDataSvc.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_RECORDDATASVC_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 "RecordDataSvc.h"
00033 using namespace std;
00034 
00035 // Instantiation of a static factory class used by clients to create
00036 // instances of this service
00037 DECLARE_SERVICE_FACTORY(RecordDataSvc)
00038 
00039 
00040 StatusCode RecordDataSvc::initialize()    {
00041   // Nothing to do: just call base class initialisation
00042   StatusCode      sc  = DataSvc::initialize();
00043   MsgStream log(msgSvc(),name());
00044 
00045   if ( !sc.isSuccess() ) { // Base class failure
00046     return sc;
00047   }
00048   // Attach data loader facility
00049   sc = service(m_persSvcName, m_cnvSvc, true);
00050   if ( !sc.isSuccess() ) {
00051     log << MSG::ERROR << "Failed to access RecordPersistencySvc." << 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 RecordPersistencySvc." << endmsg;
00061     return sc;
00062   }
00063 
00064   sc = setRoot(m_rootName, new DataObject());
00065   if( !sc.isSuccess() )  {
00066     log << MSG::WARNING << "Error declaring Record root DataObject" << endmsg;
00067     return sc;
00068   }
00069 
00070   if( !m_incidentSvc )  {
00071     log << MSG::FATAL << "IncidentSvc is invalid--base class failed." << endmsg;
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,m_saveIncidentName);
00082   return sc;
00083 }
00084 
00086 StatusCode RecordDataSvc::reinitialize()    {
00087   // Do nothing for this service
00088   return StatusCode::SUCCESS;
00089 }
00090 
00092 StatusCode RecordDataSvc::finalize()    {
00093   if( m_incidentSvc ) m_incidentSvc->removeListener(this);
00094   if( m_cnvSvc ) m_cnvSvc->release();
00095   m_cnvSvc = 0;
00096   DataSvc::finalize().ignore();
00097   return StatusCode::SUCCESS ;
00098 }
00099 
00101 StatusCode RecordDataSvc::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 RecordDataSvc::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       registerRecord(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() == IncidentType::BeginEvent ) {
00126     if ( !m_incidentName.empty() ) {
00127       StringV incidents(m_incidents);
00128       m_incidents.clear();
00129       for( StringV::const_iterator i=incidents.begin(); i!=incidents.end();++i)
00130         m_incidentSvc->fireIncident(Incident(*i,m_incidentName));
00131     }
00132   }
00133   else if ( incident.type() == m_saveIncidentName ) {
00134     MsgStream log(msgSvc(),name());
00135     log << MSG::ALWAYS << "Saving records not implemented." << endmsg;
00136   }
00137 }
00138 
00140 void RecordDataSvc::loadRecords(IRegistry* pObj) {
00141   if ( 0 != pObj )    {
00142     typedef vector<IRegistry*> Leaves;
00143     Leaves leaves;
00144     DataObject* p = 0;
00145     MsgStream log(msgSvc(),name());
00146     const string& id0 = pObj->identifier();
00147     StatusCode sc = retrieveObject(id0, p);
00148     if ( sc.isSuccess() ) {
00149       log << MSG::DEBUG << "Loaded records object: " << id0 << endmsg;
00150       sc = objectLeaves(pObj, leaves);
00151       if ( sc.isSuccess() )  {
00152         for ( Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ )
00153           loadRecords(*i);
00154       }
00155     }
00156     else  {
00157       log << MSG::ERROR << "Failed to load records object: " << pObj->identifier() << endmsg;
00158     }
00159   }
00160 }
00161 
00163 void RecordDataSvc::registerRecord(const string& data, IOpaqueAddress* pAddr)   {
00164   if ( !data.empty() && 0 != pAddr ) {
00165     MsgStream log(msgSvc(),name());
00166     string fid = data;
00167     log << MSG::DEBUG << "Request to load record for file " << fid << endmsg;
00168     StatusCode sc = registerAddress(m_root,fid,pAddr);
00169     if ( !sc.isSuccess() ) {
00170       log << MSG::ERROR << "Failed to register record for:" << fid << endmsg;
00171       pAddr->release();
00172       return;
00173     }
00174     if ( m_autoLoad ) {
00175       loadRecords(pAddr->registry());
00176     }
00177     m_incidents.push_back(pAddr->registry()->identifier());
00178   }
00179   else if ( !data.empty() && 0 == pAddr ) {
00180     MsgStream log(msgSvc(),name());
00181     log << MSG::ERROR << "Failed to register run record for:" << data << " [Invalid Address]" << endmsg;
00182   }
00183 }
00184 
00186 RecordDataSvc::RecordDataSvc(const string& name,ISvcLocator* svc)
00187 : DataSvc(name,svc), m_cnvSvc(0)
00188 {
00189   m_rootName = "/Records";
00190   declareProperty("AutoLoad",       m_autoLoad = true);
00191   declareProperty("IncidentName",   m_incidentName = "");
00192   declareProperty("SaveIncident",   m_saveIncidentName = "SAVE_RECORD");
00193   declareProperty("PersistencySvc", m_persSvcName = "PersistencySvc/RecordPersistencySvc");
00194 }
00195 
00197 RecordDataSvc::~RecordDataSvc()  {
00198 }

Generated at Mon Sep 7 18:05:47 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004