The Gaudi Framework  v33r1 (b1225454)
RecordDataSvc.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 ( incident.type() == m_saveIncidentName ) {
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 finalize() override
Service finalization.
T empty(T... args)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
const std::string & type() const
Access to the incident type.
Definition: Incident.h:48
Gaudi::Property< std::string > m_rootName
Definition: DataSvc.h:62
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
STL namespace.
virtual unsigned long release()=0
release reference to object
A RecordDataSvc is the base class for event services.
Definition: RecordDataSvc.h:34
#define DECLARE_COMPONENT(type)
virtual IRegistry * registry() const =0
Update branch name.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
void clear(STATE_TYPE _i=std::ios_base::failbit)
Definition: MsgStream.h:181
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:32
StatusCode finalize() override
Service initialization.
Definition: DataSvc.cpp:855
bool isSuccess() const
Definition: StatusCode.h:365
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:168
StatusCode initialize() override
Service initialization.
Definition: DataSvc.cpp:822
Base class for all Incidents (computing events).
Definition: Incident.h:27
constexpr static const auto FAILURE
Definition: StatusCode.h:101
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
virtual const id_type & identifier() const =0
Full identifier (or key)
void handle(const Incident &incident) override
IIncidentListener override: Inform that a new incident has occured.
StatusCode initialize() override
Service initialisation.
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Opaque address interface definition.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:30
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void loadRecords(IRegistry *pReg)
Load dependent records into memory.