The Gaudi Framework  master (37c0b60a)
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 
31 #include <GaudiKernel/DataObject.h>
35 #include <GaudiKernel/IProperty.h>
38 #include <GaudiKernel/SmartIF.h>
39 
40 #include "RecordDataSvc.h"
41 using namespace std;
42 
43 // Instantiation of a static factory class used by clients to create
44 // instances of this service
46 
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
56  m_cnvSvc = service( m_persSvcName, true );
57  if ( !m_cnvSvc ) {
58  error() << "Failed to access RecordPersistencySvc." << endmsg;
59  return StatusCode::FAILURE;
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();
96  return StatusCode::SUCCESS;
97 }
98 
100 void 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 
139 void 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 
157 RecordDataSvc::RecordDataSvc( const string& name, ISvcLocator* svc ) : base_class( name, svc ) {
158  m_rootName = "/Records";
159 }
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
IOpaqueAddress
Definition: IOpaqueAddress.h:33
std::vector< IRegistry * >
ISvcLocator
Definition: ISvcLocator.h:46
ContextIncident
Definition: DataIncident.h:26
IOpaqueAddress::release
virtual unsigned long release()=0
release reference to object
DataIncident.h
IRegistry
Definition: IRegistry.h:32
RecordDataSvc::initialize
StatusCode initialize() override
Service initialisation.
Definition: RecordDataSvc.cpp:48
RecordDataSvc.h
RegistryEntry.h
RecordDataSvc::RecordDataSvc
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: RecordDataSvc.cpp:157
IIncidentSvc.h
RecordDataSvc::handle
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occured.
Definition: RecordDataSvc.cpp:100
IProperty
Definition: IProperty.h:33
SmartIF.h
RecordDataSvc::registerRecord
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Definition: RecordDataSvc.cpp:139
StatusCode
Definition: StatusCode.h:65
DataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:62
RecordDataSvc::finalize
StatusCode finalize() override
Service finalization.
Definition: RecordDataSvc.cpp:92
IOpaqueAddress.h
CommonMessaging
Definition: CommonMessaging.h:66
RecordDataSvc::loadRecords
void loadRecords(IRegistry *pReg)
Load dependent records into memory.
Definition: RecordDataSvc.cpp:120
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
IOpaqueAddress::registry
virtual IRegistry * registry() const =0
Update branch name.
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
RecordDataSvc
Definition: RecordDataSvc.h:34
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject
Definition: DataObject.h:36
std::string::empty
T empty(T... args)
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:48
IProperty.h
DataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: DataSvc.cpp:821
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IConversionSvc.h
ISvcLocator.h
Incident
Definition: Incident.h:27
DataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: DataSvc.cpp:854