Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 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 
38 
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 }

Generated at Wed Jun 4 2014 14:48:56 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004