Gaudi Framework, version v21r6

Home   Generated: 11 Nov 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 void RecordDataSvc::handle(const Incident& incident) {
00102   if ( incident.type() == "FILE_OPEN_READ" ) {
00103     typedef ContextIncident<IOpaqueAddress*> Ctxt;
00104     const Ctxt* inc = dynamic_cast<const Ctxt*>(&incident);
00105     if ( inc ) {
00106       registerRecord(inc->source(),inc->tag());
00107       return;
00108     }
00109     MsgStream log(msgSvc(),name());
00110     log << MSG::ALWAYS << "Received invalid incident of type:" << incident.type() << endmsg;
00111   }
00112   else if ( incident.type() == IncidentType::BeginEvent ) {
00113     if ( !m_incidentName.empty() ) {
00114       StringV incidents(m_incidents);
00115       m_incidents.clear();
00116       for( StringV::const_iterator i=incidents.begin(); i!=incidents.end();++i)
00117         m_incidentSvc->fireIncident(Incident(*i,m_incidentName));
00118     }
00119   }
00120   else if ( incident.type() == m_saveIncidentName ) {
00121     MsgStream log(msgSvc(),name());
00122     log << MSG::ALWAYS << "Saving records not implemented." << endmsg;
00123   }
00124 }
00125 
00127 void RecordDataSvc::loadRecords(IRegistry* pObj) {
00128   if ( 0 != pObj )    {
00129     typedef vector<IRegistry*> Leaves;
00130     Leaves leaves;
00131     DataObject* p = 0;
00132     MsgStream log(msgSvc(),name());
00133     const string& id0 = pObj->identifier();
00134     StatusCode sc = retrieveObject(id0, p);
00135     if ( sc.isSuccess() ) {
00136       log << MSG::DEBUG << "Loaded records object: " << id0 << endmsg;
00137       sc = objectLeaves(pObj, leaves);
00138       if ( sc.isSuccess() )  {
00139         for ( Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ )
00140           loadRecords(*i);
00141       }
00142     }
00143     else  {
00144       log << MSG::ERROR << "Failed to load records object: " << pObj->identifier() << endmsg;
00145     }
00146   }
00147 }
00148 
00150 void RecordDataSvc::registerRecord(const string& data, IOpaqueAddress* pAddr)   {
00151   if ( !data.empty() && 0 != pAddr ) {
00152     MsgStream log(msgSvc(),name());
00153     string fid = data;
00154     log << MSG::DEBUG << "Request to load record for file " << fid << endmsg;
00155     StatusCode sc = registerAddress(m_root,fid,pAddr);
00156     if ( !sc.isSuccess() ) {
00157       log << MSG::ERROR << "Failed to register record for:" << fid << endmsg;
00158       pAddr->release();
00159       return;
00160     }
00161     if ( m_autoLoad ) {
00162       loadRecords(pAddr->registry());
00163     }
00164     m_incidents.push_back(pAddr->registry()->identifier());
00165   }
00166   else if ( !data.empty() && 0 == pAddr ) {
00167     MsgStream log(msgSvc(),name());
00168     log << MSG::ERROR << "Failed to register run record for:" << data << " [Invalid Address]" << endmsg;
00169   }
00170 }
00171 
00173 RecordDataSvc::RecordDataSvc(const string& name,ISvcLocator* svc)
00174 : base_class(name,svc), m_cnvSvc(0)
00175 {
00176   m_rootName = "/Records";
00177   declareProperty("AutoLoad",       m_autoLoad = true);
00178   declareProperty("IncidentName",   m_incidentName = "");
00179   declareProperty("SaveIncident",   m_saveIncidentName = "SAVE_RECORD");
00180   declareProperty("PersistencySvc", m_persSvcName = "PersistencySvc/RecordPersistencySvc");
00181 }
00182 
00184 RecordDataSvc::~RecordDataSvc()  {
00185 }

Generated at Wed Nov 11 16:23:11 2009 for Gaudi Framework, version v21r6 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004