| The Gaudi Framework v32r1 (f65d50dc)

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 // Nothing to do: just call base class initialisation
40 StatusCode sc = DataSvc::initialize();
41
42 if ( !sc.isSuccess() ) { // Base class failure
43 return sc;
44 }
45 // Attach data loader facility
46 m_cnvSvc = service( m_persSvcName, true );
47 if ( !m_cnvSvc ) {
48 error() << "Failed to access RecordPersistencySvc." << endmsg;
49 return StatusCode::FAILURE;
50 }
51 auto prp = m_cnvSvc.as<IProperty>();
52 if ( prp ) {
53 // prp->setProperty();
54 }
55 sc = setDataLoader( m_cnvSvc.get() );
56 if ( !sc.isSuccess() ) {
57 error() << "Failed to attach dataloader RecordPersistencySvc." << endmsg;
58 return sc;
59 }
60
61 sc = setRoot( m_rootName, new DataObject() );
62 if ( !sc.isSuccess() ) {
63 warning() << "Error declaring Record root DataObject" << endmsg;
64 return sc;
65 }
66
67 if ( !m_incidentSvc ) {
68 fatal() << "IncidentSvc is invalid--base class failed." << endmsg;
69 return sc;
70 }
71
76 m_incidentSvc->addListener( this, "FILE_OPEN_READ" );
77 m_incidentSvc->addListener( this, m_saveIncidentName );
78 return sc;
79 }
80
82 StatusCode RecordDataSvc::finalize() {
83 if ( m_incidentSvc ) m_incidentSvc->removeListener( this );
84 m_cnvSvc.reset();
85 DataSvc::finalize().ignore();
86 return StatusCode::SUCCESS;
87 }
88
90 void RecordDataSvc::handle( const Incident& incident ) {
91 if ( incident.type() == "FILE_OPEN_READ" ) {
92 typedef ContextIncident<IOpaqueAddress*> Ctxt;
93 auto inc = dynamic_cast<const Ctxt*>( &incident );
94 if ( !inc ) {
95 always() << "Received invalid incident of type:" << incident.type() << endmsg;
96 } else {
97 registerRecord( inc->source(), inc->tag() );
98 if ( !m_incidentName.empty() ) {
99 auto incidents = m_incidents;
100 m_incidents.clear();
101 for ( const auto& i : incidents ) m_incidentSvc->fireIncident( Incident{i, m_incidentName} );
102 }
103 }
104 } else if ( incident.type() == m_saveIncidentName ) {
105 always() << "Saving records not implemented." << endmsg;
106 }
107 }
108
110 void RecordDataSvc::loadRecords( IRegistry* pObj ) {
111 if ( !pObj ) {
112 error() << "Failed to load records object" << endmsg;
113 } else {
114 vector<IRegistry*> leaves;
115 DataObject* p = nullptr;
116 const string& id0 = pObj->identifier();
117 StatusCode sc = retrieveObject( id0, p );
118 if ( sc.isSuccess() ) {
119 debug() << "Loaded records object: " << id0 << endmsg;
120 sc = objectLeaves( pObj, leaves );
121 if ( sc.isSuccess() ) {
122 for ( const auto& i : leaves ) loadRecords( i );
123 }
124 }
125 }
126 }
127
129 void RecordDataSvc::registerRecord( const string& data, IOpaqueAddress* pAddr ) {
130 if ( !data.empty() && pAddr ) {
131 string fid = data;
132 debug() << "Request to load record for file " << fid << endmsg;
133 StatusCode sc = registerAddress( m_root.get(), fid, pAddr );
134 if ( !sc.isSuccess() ) {
135 warning() << "Failed to register record for:" << fid << endmsg;
136 pAddr->release();
137 return;
138 }
139 if ( m_autoLoad ) { loadRecords( pAddr->registry() ); }
140 m_incidents.push_back( pAddr->registry()->identifier() );
141 } else if ( !data.empty() && !pAddr ) {
142 info() << "Failed to register record for:" << data << " [Invalid Address]" << endmsg;
143 }
144 }
145
147 RecordDataSvc::RecordDataSvc( const string& name, ISvcLocator* svc ) : base_class( name, svc ) {
148 m_rootName = "/Records";
149 }
RecordDataSvc::finalize
StatusCode finalize() override
Service finalization.
Definition: RecordDataSvc.cpp:82
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
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:38
DataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:52
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
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: PluginServiceV1.h:46
IOpaqueAddress::registry
virtual IRegistry * registry() const =0
Update branch name.
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
MsgStream::clear
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:171
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:845
RecordDataSvc.h
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
IOpaqueAddress.h
RegistryEntry.h
GaudiPython.Bindings.DataObject
DataObject
Definition: Bindings.py:55
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
IProperty.h
std::vector< IRegistry * >
IConversionSvc.h
DataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: DataSvc.cpp:812
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
CommonMessaging
Definition: CommonMessaging.h:56
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
RecordDataSvc::RecordDataSvc
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: RecordDataSvc.cpp:147
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
RecordDataSvc::handle
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occured.
Definition: RecordDataSvc.cpp:90
RecordDataSvc::initialize
StatusCode initialize() override
Service initialisation.
Definition: RecordDataSvc.cpp:38
RecordDataSvc::registerRecord
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Definition: RecordDataSvc.cpp:129
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
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:192
DataObject.h
RecordDataSvc::loadRecords
void loadRecords(IRegistry *pReg)
Load dependent records into memory.
Definition: RecordDataSvc.cpp:110