The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
RecordDataSvc.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11//====================================================================
12// RecordDataSvc.cpp
13//--------------------------------------------------------------------
14//
15// Package : System ( The LHCb Offline System)
16//
17// Description: implementation of the Transient event data service.
18//
19// Author : M.Frank
20// History :
21// +---------+----------------------------------------------+---------
22// | Date | Comment | Who
23// +---------+----------------------------------------------+---------
24// | 10/12/08| Initial version | MF
25// +---------+----------------------------------------------+---------
26//
27//====================================================================
28#define DATASVC_RECORDDATASVC_CPP
29
38#include <GaudiKernel/SmartIF.h>
39
40#include "RecordDataSvc.h"
41using namespace std;
42
43// Instantiation of a static factory class used by clients to create
44// instances of this service
46
47
49 // Nothing to do: just call base class initialisation
51
52 if ( !sc.isSuccess() ) { // Base class failure
53 return sc;
54 }
55 // Attach data loader facility
57 if ( !m_cnvSvc ) {
58 error() << "Failed to access RecordPersistencySvc." << endmsg;
60 }
61 auto prp = m_cnvSvc.as<IProperty>();
62 if ( prp ) {
63 // prp->setProperty();
64 }
65 sc = setDataLoader( m_cnvSvc.get() );
66 if ( !sc.isSuccess() ) {
67 error() << "Failed to attach dataloader RecordPersistencySvc." << endmsg;
68 return sc;
69 }
70
71 sc = setRoot( m_rootName, new DataObject() );
72 if ( !sc.isSuccess() ) {
73 warning() << "Error declaring Record root DataObject" << endmsg;
74 return sc;
75 }
76
77 if ( !m_incidentSvc ) {
78 fatal() << "IncidentSvc is invalid--base class failed." << endmsg;
79 return sc;
80 }
81
86 m_incidentSvc->addListener( this, "FILE_OPEN_READ" );
87 m_incidentSvc->addListener( this, m_saveIncidentName );
88 return sc;
89}
90
93 if ( m_incidentSvc ) m_incidentSvc->removeListener( this );
94 m_cnvSvc.reset();
97}
98
100void RecordDataSvc::handle( const Incident& incident ) {
101 if ( incident.type() == "FILE_OPEN_READ" ) {
103 auto inc = dynamic_cast<const Ctxt*>( &incident );
104 if ( !inc ) {
105 always() << "Received invalid incident of type:" << incident.type() << endmsg;
106 } else {
107 registerRecord( inc->source(), inc->tag() );
108 if ( !m_incidentName.empty() ) {
109 auto incidents = m_incidents;
110 m_incidents.clear();
111 for ( const auto& i : incidents ) m_incidentSvc->fireIncident( Incident{ i, m_incidentName } );
112 }
113 }
114 } else if ( m_saveIncidentName == incident.type() ) {
115 always() << "Saving records not implemented." << endmsg;
116 }
117}
118
121 if ( !pObj ) {
122 error() << "Failed to load records object" << endmsg;
123 } else {
124 vector<IRegistry*> leaves;
125 DataObject* p = nullptr;
126 const string& id0 = pObj->identifier();
127 StatusCode sc = retrieveObject( id0, p );
128 if ( sc.isSuccess() ) {
129 debug() << "Loaded records object: " << id0 << endmsg;
130 sc = objectLeaves( pObj, leaves );
131 if ( sc.isSuccess() ) {
132 for ( const auto& i : leaves ) loadRecords( i );
133 }
134 }
135 }
136}
137
139void RecordDataSvc::registerRecord( const string& data, IOpaqueAddress* pAddr ) {
140 if ( !data.empty() && pAddr ) {
141 string fid = data;
142 debug() << "Request to load record for file " << fid << endmsg;
143 StatusCode sc = registerAddress( m_root.get(), fid, pAddr );
144 if ( !sc.isSuccess() ) {
145 warning() << "Failed to register record for:" << fid << endmsg;
146 pAddr->release();
147 return;
148 }
149 if ( m_autoLoad ) { loadRecords( pAddr->registry() ); }
150 m_incidents.push_back( pAddr->registry()->identifier() );
151 } else if ( !data.empty() && !pAddr ) {
152 info() << "Failed to register record for:" << data << " [Invalid Address]" << endmsg;
153 }
154}
155
158 m_rootName = "/Records";
159}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
StatusCode setRoot(std::string root_name, DataObject *pRootObj) override
Initialize data store for new event by giving new event path and root object.
Definition DataSvc.cpp:115
StatusCode finalize() override
Service initialization.
Definition DataSvc.cpp:828
Gaudi::Property< std::string > m_rootName
Definition DataSvc.h:53
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
Definition DataSvc.cpp:160
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves) override
IDataManagerSvc: Explore the object store: retrieve all leaves attached to the object.
Definition DataSvc.cpp:181
StatusCode initialize() override
Service initialization.
Definition DataSvc.cpp:795
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to incident service.
Definition DataSvc.h:50
StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject) override
Retrieve object from data store.
Definition DataSvc.cpp:601
StatusCode registerAddress(std::string_view fullPath, IOpaqueAddress *pAddress) override
IDataManagerSvc: Register object address with the data store.
Definition DataSvc.cpp:198
std::unique_ptr< DataSvcHelpers::RegistryEntry > m_root
Pointer to root entry.
Definition DataSvc.h:73
Opaque address interface definition.
virtual unsigned long release()=0
release reference to object
virtual IRegistry * registry() const =0
Update branch name.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition IProperty.h:32
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Base class for all Incidents (computing events).
Definition Incident.h:24
const std::string & type() const
Access to the incident type.
Definition Incident.h:43
A RecordDataSvc is the base class for event services.
Gaudi::Property< std::string > m_incidentName
StatusCode initialize() override
Service initialisation.
SmartIF< IConversionSvc > m_cnvSvc
Reference to the main data conversion service.
std::vector< std::string > m_incidents
Pending new file incidents.
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Gaudi::Property< std::string > m_persSvcName
Gaudi::Property< bool > m_autoLoad
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occured.
Gaudi::Property< std::string > m_saveIncidentName
StatusCode finalize() override
Service finalization.
void loadRecords(IRegistry *pReg)
Load dependent records into memory.
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
STL namespace.