| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

RecordDataSvc.cpp
Go to the documentation of this file.
1 //====================================================================
2 // RecordDataSvc.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System ( The LHCb Offline System)
6 //
7 // Description: implementation of the Transient event data service.
8 //
9 // Author : M.Frank
10 // History :
11 // +---------+----------------------------------------------+---------
12 // | Date | Comment | Who
13 // +---------+----------------------------------------------+---------
14 // | 10/12/08| Initial version | MF
15 // +---------+----------------------------------------------+---------
16 //
17 //====================================================================
18 #define DATASVC_RECORDDATASVC_CPP
19
20 #include "GaudiKernel/DataIncident.h"
21 #include "GaudiKernel/DataObject.h"
22 #include "GaudiKernel/IConversionSvc.h"
23 #include "GaudiKernel/IIncidentSvc.h"
24 #include "GaudiKernel/IOpaqueAddress.h"
25 #include "GaudiKernel/IProperty.h"
26 #include "GaudiKernel/ISvcLocator.h"
27 #include "GaudiKernel/RegistryEntry.h"
28 #include "GaudiKernel/SmartIF.h"
29
30 #include "RecordDataSvc.h"
31 using namespace std;
32
33 // Instantiation of a static factory class used by clients to create
34 // instances of this service
35 DECLARE_COMPONENT( RecordDataSvc )
36
37 StatusCode RecordDataSvc::initialize()
39 {
40 // Nothing to do: just call base class initialisation
41 StatusCode sc = DataSvc::initialize();
42
43 if ( !sc.isSuccess() ) { // Base class failure
44 return sc;
45 }
46 // Attach data loader facility
47 m_cnvSvc = service( m_persSvcName, true );
48 if ( !m_cnvSvc ) {
49 error() << "Failed to access RecordPersistencySvc." << endmsg;
50 return StatusCode::FAILURE;
51 }
52 auto prp = m_cnvSvc.as<IProperty>();
53 if ( prp ) {
54 // prp->setProperty();
55 }
56 sc = setDataLoader( m_cnvSvc.get() );
57 if ( !sc.isSuccess() ) {
58 error() << "Failed to attach dataloader RecordPersistencySvc." << endmsg;
59 return sc;
60 }
61
62 sc = setRoot( m_rootName, new DataObject() );
63 if ( !sc.isSuccess() ) {
64 warning() << "Error declaring Record root DataObject" << endmsg;
65 return sc;
66 }
67
68 if ( !m_incidentSvc ) {
69 fatal() << "IncidentSvc is invalid--base class failed." << endmsg;
70 return sc;
71 }
72
77 m_incidentSvc->addListener( this, "FILE_OPEN_READ" );
78 m_incidentSvc->addListener( this, m_saveIncidentName );
79 return sc;
80 }
81
83 StatusCode RecordDataSvc::finalize()
84 {
85 if ( m_incidentSvc ) m_incidentSvc->removeListener( this );
86 m_cnvSvc.reset();
87 DataSvc::finalize().ignore();
88 return StatusCode::SUCCESS;
89 }
90
92 void RecordDataSvc::handle( const Incident& incident )
93 {
94 if ( incident.type() == "FILE_OPEN_READ" ) {
95 typedef ContextIncident<IOpaqueAddress*> Ctxt;
96 auto inc = dynamic_cast<const Ctxt*>( &incident );
97 if ( !inc ) {
98 always() << "Received invalid incident of type:" << incident.type() << endmsg;
99 } else {
100 registerRecord( inc->source(), inc->tag() );
101 if ( !m_incidentName.empty() ) {
102 auto incidents = m_incidents;
103 m_incidents.clear();
104 for ( const auto& i : incidents ) m_incidentSvc->fireIncident( Incident{i, m_incidentName} );
105 }
106 }
107 } else if ( incident.type() == m_saveIncidentName ) {
108 always() << "Saving records not implemented." << endmsg;
109 }
110 }
111
113 void RecordDataSvc::loadRecords( IRegistry* pObj )
114 {
115 if ( !pObj ) {
116 error() << "Failed to load records object: " << pObj->identifier() << endmsg;
117 } else {
118 vector<IRegistry*> leaves;
119 DataObject* p = nullptr;
120 const string& id0 = pObj->identifier();
121 StatusCode sc = retrieveObject( id0, p );
122 if ( sc.isSuccess() ) {
123 debug() << "Loaded records object: " << id0 << endmsg;
124 sc = objectLeaves( pObj, leaves );
125 if ( sc.isSuccess() ) {
126 for ( const auto& i : leaves ) loadRecords( i );
127 }
128 }
129 }
130 }
131
133 void RecordDataSvc::registerRecord( const string& data, IOpaqueAddress* pAddr )
134 {
135 if ( !data.empty() && pAddr ) {
136 string fid = data;
137 debug() << "Request to load record for file " << fid << endmsg;
138 StatusCode sc = registerAddress( m_root, fid, pAddr );
139 if ( !sc.isSuccess() ) {
140 warning() << "Failed to register record for:" << fid << endmsg;
141 pAddr->release();
142 return;
143 }
144 if ( m_autoLoad ) {
145 loadRecords( pAddr->registry() );
146 }
147 m_incidents.push_back( pAddr->registry()->identifier() );
148 } else if ( !data.empty() && !pAddr ) {
149 info() << "Failed to register record for:" << data << " [Invalid Address]" << endmsg;
150 }
151 }
152
154 RecordDataSvc::RecordDataSvc( const string& name, ISvcLocator* svc ) : base_class( name, svc )
155 {
156 m_rootName = "/Records";
157 }
StatusCode::SUCCESS
Definition: StatusCode.h:29
RecordDataSvc::finalize
StatusCode finalize() override
Service finalization.
Definition: RecordDataSvc.cpp:83
std::string::empty
T empty(T...args)
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
DataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:57
IOpaqueAddress::registry
virtual IRegistry * registry() const =0
Update branch name.
std
STL namespace.
IOpaqueAddress::release
virtual unsigned long release()=0
release reference to object
RecordDataSvc
A RecordDataSvc is the base class for event services.
Definition: RecordDataSvc.h:24
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:187
ContextIncident
Definition: DataIncident.h:16
SmartIF.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
DataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: DataSvc.cpp:1123
RecordDataSvc.h
IOpaqueAddress.h
RegistryEntry.h
GaudiPython.Bindings.DataObject
DataObject
Definition: Bindings.py:55
IProperty.h
std::vector< IRegistry * >
IConversionSvc.h
DataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: DataSvc.cpp:1086
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
CommonMessaging
Definition: CommonMessaging.h:62
RecordDataSvc::RecordDataSvc
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: RecordDataSvc.cpp:154
RecordDataSvc::handle
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occured.
Definition: RecordDataSvc.cpp:92
StatusCode::FAILURE
Definition: StatusCode.h:29
RecordDataSvc::registerRecord
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Definition: RecordDataSvc.cpp:133
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:84
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
DataIncident.h
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataObject.h
RecordDataSvc::loadRecords
void loadRecords(IRegistry *pReg)
Load dependent records into memory.
Definition: RecordDataSvc.cpp:113