| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

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