All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/SmartIF.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/IProperty.h"
23 #include "GaudiKernel/DataObject.h"
30 
31 #include "RecordDataSvc.h"
32 using namespace std;
33 
34 // Instantiation of a static factory class used by clients to create
35 // instances of this service
37 
40  // Nothing to do: just call base class initialisation
42  MsgStream log(msgSvc(),name());
43 
44  if ( !sc.isSuccess() ) { // Base class failure
45  return sc;
46  }
47  // Attach data loader facility
48  sc = service(m_persSvcName, m_cnvSvc, true);
49  if ( !sc.isSuccess() ) {
50  log << MSG::ERROR << "Failed to access RecordPersistencySvc." << endmsg;
51  return sc;
52  }
53  SmartIF<IProperty> prp(m_cnvSvc);
54  if ( prp ) {
55  //prp->setProperty();
56  }
57  sc = setDataLoader( m_cnvSvc );
58  if ( !sc.isSuccess() ) {
59  log << MSG::ERROR << "Failed to attach dataloader RecordPersistencySvc." << endmsg;
60  return sc;
61  }
62 
63  sc = setRoot(m_rootName, new DataObject());
64  if( !sc.isSuccess() ) {
65  log << MSG::WARNING << "Error declaring Record root DataObject" << endmsg;
66  return sc;
67  }
68 
69  if( !m_incidentSvc ) {
70  log << MSG::FATAL << "IncidentSvc is invalid--base class failed." << endmsg;
71  return sc;
72  }
73 
78  m_incidentSvc->addListener(this,"FILE_OPEN_READ");
79  m_incidentSvc->addListener(this,m_saveIncidentName);
80  return sc;
81 }
82 
85  // Do nothing for this service
86  return StatusCode::SUCCESS;
87 }
88 
91  if( m_incidentSvc ) m_incidentSvc->removeListener(this);
92  if( m_cnvSvc ) m_cnvSvc->release();
93  m_cnvSvc = 0;
95  return StatusCode::SUCCESS ;
96 }
97 
99 void RecordDataSvc::handle(const Incident& incident) {
100  if ( incident.type() == "FILE_OPEN_READ" ) {
102  const Ctxt* inc = dynamic_cast<const Ctxt*>(&incident);
103  if ( inc ) {
104  registerRecord(inc->source(),inc->tag());
105  if ( !m_incidentName.empty() ) {
106  StringV incidents(m_incidents);
107  m_incidents.clear();
108  for( StringV::const_iterator i=incidents.begin(); i!=incidents.end();++i)
109  m_incidentSvc->fireIncident(Incident(*i,m_incidentName));
110  }
111  return;
112  }
113  MsgStream log(msgSvc(),name());
114  log << MSG::ALWAYS << "Received invalid incident of type:" << incident.type() << endmsg;
115  }
116  else if ( incident.type() == m_saveIncidentName ) {
117  MsgStream log(msgSvc(),name());
118  log << MSG::ALWAYS << "Saving records not implemented." << endmsg;
119  }
120 }
121 
124  if ( 0 != pObj ) {
125  typedef vector<IRegistry*> Leaves;
126  Leaves leaves;
127  DataObject* p = 0;
128  MsgStream log(msgSvc(),name());
129  const string& id0 = pObj->identifier();
130  StatusCode sc = retrieveObject(id0, p);
131  if ( sc.isSuccess() ) {
132  log << MSG::DEBUG << "Loaded records object: " << id0 << endmsg;
133  sc = objectLeaves(pObj, leaves);
134  if ( sc.isSuccess() ) {
135  for ( Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ )
136  loadRecords(*i);
137  }
138  }
139  else {
140  log << MSG::ERROR << "Failed to load records object: " << pObj->identifier() << endmsg;
141  }
142  }
143 }
144 
146 void RecordDataSvc::registerRecord(const string& data, IOpaqueAddress* pAddr) {
147  if ( !data.empty() && 0 != pAddr ) {
148  MsgStream log(msgSvc(),name());
149  string fid = data;
150  log << MSG::DEBUG << "Request to load record for file " << fid << endmsg;
151  StatusCode sc = registerAddress(m_root,fid,pAddr);
152  if ( !sc.isSuccess() ) {
153  log << MSG::WARNING << "Failed to register record for:" << fid << endmsg;
154  pAddr->release();
155  return;
156  }
157  if ( m_autoLoad ) {
158  loadRecords(pAddr->registry());
159  }
160  m_incidents.push_back(pAddr->registry()->identifier());
161  }
162  else if ( !data.empty() && 0 == pAddr ) {
163  MsgStream log(msgSvc(),name());
164  log << MSG::INFO << "Failed to register record for:" << data << " [Invalid Address]" << endmsg;
165  }
166 }
167 
170 : base_class(name,svc), m_cnvSvc(0)
171 {
172  m_rootName = "/Records";
173  declareProperty("AutoLoad", m_autoLoad = true);
174  declareProperty("IncidentName", m_incidentName = "");
175  declareProperty("SaveIncident", m_saveIncidentName = "SAVE_RECORD");
176  declareProperty("PersistencySvc", m_persSvcName = "PersistencySvc/RecordPersistencySvc");
177 }
178 
181 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string m_persSvcName
Property: name of the persistency service.
Definition: RecordDataSvc.h:58
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual StatusCode reinitialize()
Service reinitialisation.
const std::string & type() const
Access to the incident type.
Definition: Incident.h:34
std::string m_incidentName
Property: name of incident to be fired if new record arrives.
Definition: RecordDataSvc.h:54
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
bool m_autoLoad
Property: autoload of records (default: true)
Definition: RecordDataSvc.h:52
std::string m_rootName
Name of root event.
Definition: DataSvc.h:50
virtual void handle(const Incident &incident)
IIncidentListener override: Inform that a new incident has occured.
virtual unsigned long release()=0
release reference to object
A RecordDataSvc is the base class for event services.
Definition: RecordDataSvc.h:26
virtual StatusCode finalize()
Service finalization.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string m_saveIncidentName
Property: name of the "save" incident.
Definition: RecordDataSvc.h:56
virtual IRegistry * registry() const =0
Update branch name.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
virtual StatusCode initialize()
Service initialization.
Definition: DataSvc.cpp:1201
virtual ~RecordDataSvc()
Standard Destructor.
Base class for all Incidents (computing events).
Definition: Incident.h:16
Templated class to add the standard messaging functionalities.
RecordDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
virtual const id_type & identifier() const =0
Full identifier (or key)
void registerRecord(const std::string &data, IOpaqueAddress *pAddr)
Load new record into the data store if necessary.
Opaque address interface definition.
void ignore() const
Definition: StatusCode.h:107
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
list i
Definition: ana.py:128
std::vector< std::string > StringV
Definition: RecordDataSvc.h:28
virtual StatusCode finalize()
Service initialization.
Definition: DataSvc.cpp:1241
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void loadRecords(IRegistry *pReg)
Load dependent records into memory.