Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 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/SvcFactory.h"
24 #include "GaudiKernel/DataObject.h"
31 
32 #include "RecordDataSvc.h"
33 using namespace std;
34 
35 // Instantiation of a static factory class used by clients to create
36 // instances of this service
38 
39 
41  // Nothing to do: just call base class initialisation
43  MsgStream log(msgSvc(),name());
44 
45  if ( !sc.isSuccess() ) { // Base class failure
46  return sc;
47  }
48  // Attach data loader facility
49  sc = service(m_persSvcName, m_cnvSvc, true);
50  if ( !sc.isSuccess() ) {
51  log << MSG::ERROR << "Failed to access RecordPersistencySvc." << endmsg;
52  return sc;
53  }
54  SmartIF<IProperty> prp(m_cnvSvc);
55  if ( prp ) {
56  //prp->setProperty();
57  }
58  sc = setDataLoader( m_cnvSvc );
59  if ( !sc.isSuccess() ) {
60  log << MSG::ERROR << "Failed to attach dataloader RecordPersistencySvc." << endmsg;
61  return sc;
62  }
63 
64  sc = setRoot(m_rootName, new DataObject());
65  if( !sc.isSuccess() ) {
66  log << MSG::WARNING << "Error declaring Record root DataObject" << endmsg;
67  return sc;
68  }
69 
70  if( !m_incidentSvc ) {
71  log << MSG::FATAL << "IncidentSvc is invalid--base class failed." << endmsg;
72  return sc;
73  }
74 
79  m_incidentSvc->addListener(this,"FILE_OPEN_READ");
80  m_incidentSvc->addListener(this,m_saveIncidentName);
81  return sc;
82 }
83 
86  // Do nothing for this service
87  return StatusCode::SUCCESS;
88 }
89 
92  if( m_incidentSvc ) m_incidentSvc->removeListener(this);
93  if( m_cnvSvc ) m_cnvSvc->release();
94  m_cnvSvc = 0;
96  return StatusCode::SUCCESS ;
97 }
98 
100 void RecordDataSvc::handle(const Incident& incident) {
101  if ( incident.type() == "FILE_OPEN_READ" ) {
103  const Ctxt* inc = dynamic_cast<const Ctxt*>(&incident);
104  if ( inc ) {
105  registerRecord(inc->source(),inc->tag());
106  if ( !m_incidentName.empty() ) {
107  StringV incidents(m_incidents);
108  m_incidents.clear();
109  for( StringV::const_iterator i=incidents.begin(); i!=incidents.end();++i)
110  m_incidentSvc->fireIncident(Incident(*i,m_incidentName));
111  }
112  return;
113  }
114  MsgStream log(msgSvc(),name());
115  log << MSG::ALWAYS << "Received invalid incident of type:" << incident.type() << endmsg;
116  }
117  else if ( incident.type() == m_saveIncidentName ) {
118  MsgStream log(msgSvc(),name());
119  log << MSG::ALWAYS << "Saving records not implemented." << endmsg;
120  }
121 }
122 
125  if ( 0 != pObj ) {
126  typedef vector<IRegistry*> Leaves;
127  Leaves leaves;
128  DataObject* p = 0;
129  MsgStream log(msgSvc(),name());
130  const string& id0 = pObj->identifier();
131  StatusCode sc = retrieveObject(id0, p);
132  if ( sc.isSuccess() ) {
133  log << MSG::DEBUG << "Loaded records object: " << id0 << endmsg;
134  sc = objectLeaves(pObj, leaves);
135  if ( sc.isSuccess() ) {
136  for ( Leaves::const_iterator i=leaves.begin(); i != leaves.end(); i++ )
137  loadRecords(*i);
138  }
139  }
140  else {
141  log << MSG::ERROR << "Failed to load records object: " << pObj->identifier() << endmsg;
142  }
143  }
144 }
145 
147 void RecordDataSvc::registerRecord(const string& data, IOpaqueAddress* pAddr) {
148  if ( !data.empty() && 0 != pAddr ) {
149  MsgStream log(msgSvc(),name());
150  string fid = data;
151  log << MSG::DEBUG << "Request to load record for file " << fid << endmsg;
152  StatusCode sc = registerAddress(m_root,fid,pAddr);
153  if ( !sc.isSuccess() ) {
154  log << MSG::WARNING << "Failed to register record for:" << fid << endmsg;
155  pAddr->release();
156  return;
157  }
158  if ( m_autoLoad ) {
159  loadRecords(pAddr->registry());
160  }
161  m_incidents.push_back(pAddr->registry()->identifier());
162  }
163  else if ( !data.empty() && 0 == pAddr ) {
164  MsgStream log(msgSvc(),name());
165  log << MSG::INFO << "Failed to register record for:" << data << " [Invalid Address]" << endmsg;
166  }
167 }
168 
171 : base_class(name,svc), m_cnvSvc(0)
172 {
173  m_rootName = "/Records";
174  declareProperty("AutoLoad", m_autoLoad = true);
175  declareProperty("IncidentName", m_incidentName = "");
176  declareProperty("SaveIncident", m_saveIncidentName = "SAVE_RECORD");
177  declareProperty("PersistencySvc", m_persSvcName = "PersistencySvc/RecordPersistencySvc");
178 }
179 
182 }

Generated at Wed Jan 30 2013 17:13:38 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004