DataSvcFileEntriesTool Class Reference

Tool to scan a transient store branch that collects all the objects that belong to the same source (file). More...

Inheritance diagram for DataSvcFileEntriesTool:
Collaboration diagram for DataSvcFileEntriesTool:

Public Member Functions

 DataSvcFileEntriesTool (const std::string &type, const std::string &name, const IInterface *parent)
 Standard constructor. More...
 
 ~DataSvcFileEntriesTool () override=default
 Destructor. More...
 
StatusCode initialize () override
 Initialize the tool. More...
 
StatusCode finalize () override
 Finalize the tool. More...
 
const LeavesList & leaves () const override
 Return the list of collected objects. More...
 
void handle (const Incident &incident) override
 Call-back function for the BeginEvent incident. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

void i_collectLeaves ()
 Scan the data service starting from the node specified as Root. More...
 
void i_collectLeaves (IRegistry *reg)
 Scan the data service starting from the specified node. More...
 
IRegistryi_getRootNode ()
 Return the pointer to the IRegistry object associated to the node specified as Root. More...
 

Private Attributes

std::string m_dataSvcName
 Variable for the property DataService. More...
 
std::string m_rootNode
 Variable for the property Root. More...
 
bool m_scanOnBeginEvent
 Variable for the property ScanOnBeginEvent. More...
 
SmartIF< IIncidentSvcm_incidentSvc
 Pointer to the incident service. More...
 
SmartIF< IDataManagerSvcm_dataMgrSvc
 Pointer to the IDataManagerSvc interface of the data service. More...
 
SmartIF< IDataProviderSvcm_dataSvc
 Pointer to the IDataProviderSvc interface of the data service. More...
 
LeavesList m_leaves
 Internal cache for the list of objects found during the scan. More...
 
std::string m_initialBase
 File ID of the Root node. More...
 
bool m_ignoreOriginChange
 Variable for the property ScanOnBeginEvent. More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Tool to scan a transient store branch that collects all the objects that belong to the same source (file).

By default, the list of entries is cached and the cache is cleared at every BeginEvent incident.

Properties:
DataService (string): Name of the data service to use [EventDataSvc]
Root (string): Path to the element from which to start the scan [root of the data service]
ScanOnBeginEvent (bool): If the scan has to be started during the BeginEvent incident (true) or on demand (false, default)

Definition at line 26 of file DataSvcFileEntriesTool.cpp.

Constructor & Destructor Documentation

DataSvcFileEntriesTool::DataSvcFileEntriesTool ( const std::string &  type,
const std::string &  name,
const IInterface parent 
)

Standard constructor.

Definition at line 102 of file DataSvcFileEntriesTool.cpp.

104  :
105  base_class(type, name, parent) {
106 
107  declareProperty("DataService", m_dataSvcName = "EventDataSvc",
108  "Name of the data service to use");
109 
110  declareProperty("Root", m_rootNode,
111  "Path to the element from which to start the scan");
112 
113  declareProperty("ScanOnBeginEvent", m_scanOnBeginEvent = false,
114  "If the scan has to be started during the BeginEvent incident (true) or on demand (false, default)");
115 
116  declareProperty("IgnoreOriginChange", m_ignoreOriginChange = false,
117  "Disable the detection of the change in the origin of object between the BeginEvent and the scan");
118 }
bool m_ignoreOriginChange
Variable for the property ScanOnBeginEvent.
bool m_scanOnBeginEvent
Variable for the property ScanOnBeginEvent.
extends base_class
Typedef to this class.
Definition: extends.h:14
std::string m_dataSvcName
Variable for the property DataService.
std::string m_rootNode
Variable for the property Root.
string type
Definition: gaudirun.py:151
DataSvcFileEntriesTool::~DataSvcFileEntriesTool ( )
overridedefault

Destructor.

Member Function Documentation

StatusCode DataSvcFileEntriesTool::finalize ( )
override

Finalize the tool.

Definition at line 153 of file DataSvcFileEntriesTool.cpp.

153  {
154  // unregister from the incident service
155  if (m_incidentSvc) {
156  m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
157  }
158  // Release the services
161  m_dataSvc.reset();
162 
163  return AlgTool::finalize();
164 }
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
SmartIF< IDataManagerSvc > m_dataMgrSvc
Pointer to the IDataManagerSvc interface of the data service.
StatusCode finalize() override
Definition: AlgTool.cpp:395
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
void DataSvcFileEntriesTool::handle ( const Incident incident)
override

Call-back function for the BeginEvent incident.

Clears the internal cache, cache the file ID of the Root node and, if the property ScanOnBeginEvent is set to true, scans the data service.

Definition at line 166 of file DataSvcFileEntriesTool.cpp.

166  {
167  // Get the file id of the root node at every event
168  IOpaqueAddress *addr = i_getRootNode()->address();
169  if (addr)
170  m_initialBase = addr->par()[0];
171  else
172  m_initialBase.clear(); // use empty file id if there is no address
173 
174  m_leaves.clear();
175  if (m_scanOnBeginEvent) {
176  MsgStream log(msgSvc(), name());
177  log << MSG::VERBOSE << "::handle scanning on " << incident.type() << endmsg;
178  i_collectLeaves();
179  }
180 }
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string & type() const
Access to the incident type.
Definition: Incident.h:34
bool m_scanOnBeginEvent
Variable for the property ScanOnBeginEvent.
std::string m_initialBase
File ID of the Root node.
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
Opaque address interface definition.
LeavesList m_leaves
Internal cache for the list of objects found during the scan.
IRegistry * i_getRootNode()
Return the pointer to the IRegistry object associated to the node specified as Root.
void DataSvcFileEntriesTool::i_collectLeaves ( )
private

Scan the data service starting from the node specified as Root.

Definition at line 199 of file DataSvcFileEntriesTool.cpp.

199  {
201 }
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
IRegistry * i_getRootNode()
Return the pointer to the IRegistry object associated to the node specified as Root.
void DataSvcFileEntriesTool::i_collectLeaves ( IRegistry reg)
private

Scan the data service starting from the specified node.

todo: implement the scanning as an IDataStoreAgent

Definition at line 204 of file DataSvcFileEntriesTool.cpp.

204  {
205  MsgStream log(msgSvc(), name());
206  // I do not put sanity checks on the pointers because I know how I'm calling the function
207  IOpaqueAddress *addr = reg->address();
208  if (addr) { // we consider only objects that are in a file
209  if (outputLevel() <= MSG::VERBOSE)
210  log << MSG::VERBOSE << "::i_collectLeaves added " << reg->identifier() << endmsg;
211  m_leaves.push_back(reg->object()); // add this object
212  // Origin of the current object
213  const std::string& base = addr->par()[0];
214  // Compare with the origin seen during BeginEvent
215  if ( !m_ignoreOriginChange && (m_initialBase != base) )
216  throw GaudiException("Origin of data has changed ('"
217  + m_initialBase + "' != '" + base
218  + "'), probably OutputStream was called before "
219  "InputCopyStream: check options",
221 
222  std::vector<IRegistry*> lfs; // leaves of the current object
223  StatusCode sc = m_dataMgrSvc->objectLeaves(reg, lfs);
224  if (sc.isSuccess()) {
225  for(const auto& i : lfs) {
226  // Continue if the leaf has the same database as the parent
227  if ( i->address() && i->address()->par()[0] == base ) {
228  DataObject* obj = nullptr;
229  sc = m_dataSvc->retrieveObject(reg, i->name(), obj);
230  if (sc.isSuccess()) {
232  } else {
233  throw GaudiException("Cannot get " + i->identifier() + " from " + m_dataSvcName, name(), StatusCode::FAILURE);
234  }
235  }
236  }
237  }
238  }
239 }
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_ignoreOriginChange
Variable for the property ScanOnBeginEvent.
Define general base for Gaudi exception.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
std::string m_initialBase
File ID of the Root node.
SmartIF< IDataManagerSvc > m_dataMgrSvc
Pointer to the IDataManagerSvc interface of the data service.
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
virtual DataObject * object() const =0
Retrieve object behind the link.
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
std::string m_dataSvcName
Variable for the property DataService.
virtual const id_type & identifier() const =0
Full identifier (or key)
Opaque address interface definition.
LeavesList m_leaves
Internal cache for the list of objects found during the scan.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
list i
Definition: ana.py:128
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
IRegistry * DataSvcFileEntriesTool::i_getRootNode ( )
private

Return the pointer to the IRegistry object associated to the node specified as Root.

Definition at line 189 of file DataSvcFileEntriesTool.cpp.

189  {
190  DataObject * obj = nullptr;
192  if (sc.isFailure()) {
193  throw GaudiException("Cannot get " + m_rootNode + " from " + m_dataSvcName, name(), StatusCode::FAILURE);
194  }
195  return obj->registry();
196 }
Define general base for Gaudi exception.
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:74
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string m_dataSvcName
Variable for the property DataService.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
std::string m_rootNode
Variable for the property Root.
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
StatusCode DataSvcFileEntriesTool::initialize ( )
override

Initialize the tool.

Definition at line 120 of file DataSvcFileEntriesTool.cpp.

120  {
122  if (sc.isFailure()) return sc;
123 
124  // Retrieve the pointer to the needed services.
125 
126  m_incidentSvc = serviceLocator()->service("IncidentSvc");
127  if ( ! m_incidentSvc ) {
128  MsgStream log(msgSvc(), name());
129  log << MSG::ERROR << "Cannot get IncidentSvc" << endmsg;
130  return StatusCode::FAILURE;
131  }
132 
133  m_dataMgrSvc = m_dataSvc = serviceLocator()->service(m_dataSvcName);
134  if ( ! m_dataSvc || ! m_dataMgrSvc ) {
135  MsgStream log(msgSvc(), name());
136  log << MSG::ERROR << "Cannot get IDataProviderSvc+IDataManagerSvc " << m_dataSvcName << endmsg;
137  return StatusCode::FAILURE;
138  }
139 
140  // Register ourself to the incident service as listener for BeginEvent
141  m_incidentSvc->addListener(this, IncidentType::BeginEvent);
142 
143  // If the Root node is not specified, take the name from the data service itself.
144  if (m_rootNode.empty()) {
146  }
147 
148  // Clear the cache (in case the instance is re-initilized).
149  m_leaves.clear();
150  return StatusCode::SUCCESS;
151 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode initialize() override
Definition: AlgTool.cpp:325
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
SmartIF< IDataManagerSvc > m_dataMgrSvc
Pointer to the IDataManagerSvc interface of the data service.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual const std::string & rootName() const =0
Get Name of root Event.
std::string m_dataSvcName
Variable for the property DataService.
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
LeavesList m_leaves
Internal cache for the list of objects found during the scan.
std::string m_rootNode
Variable for the property Root.
const IDataStoreLeaves::LeavesList & DataSvcFileEntriesTool::leaves ( ) const
override

Return the list of collected objects.

If the scan was not yet done since the last BeginEvent incident, it is done when calling this function. The result of the scan is cached.

Definition at line 182 of file DataSvcFileEntriesTool.cpp.

182  {
183  if (m_leaves.empty()) {
184  const_cast<DataSvcFileEntriesTool*>(this)->i_collectLeaves();
185  }
186  return m_leaves;
187 }
Tool to scan a transient store branch that collects all the objects that belong to the same source (f...
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
LeavesList m_leaves
Internal cache for the list of objects found during the scan.

Member Data Documentation

SmartIF<IDataManagerSvc> DataSvcFileEntriesTool::m_dataMgrSvc
private

Pointer to the IDataManagerSvc interface of the data service.

Definition at line 65 of file DataSvcFileEntriesTool.cpp.

SmartIF<IDataProviderSvc> DataSvcFileEntriesTool::m_dataSvc
private

Pointer to the IDataProviderSvc interface of the data service.

Definition at line 67 of file DataSvcFileEntriesTool.cpp.

std::string DataSvcFileEntriesTool::m_dataSvcName
private

Variable for the property DataService.

Definition at line 56 of file DataSvcFileEntriesTool.cpp.

bool DataSvcFileEntriesTool::m_ignoreOriginChange
private

Variable for the property ScanOnBeginEvent.

Definition at line 88 of file DataSvcFileEntriesTool.cpp.

SmartIF<IIncidentSvc> DataSvcFileEntriesTool::m_incidentSvc
private

Pointer to the incident service.

Definition at line 63 of file DataSvcFileEntriesTool.cpp.

std::string DataSvcFileEntriesTool::m_initialBase
private

File ID of the Root node.

It is cached every BeginEvent to be compared with the one seen during the collection of the leaves, to avoid that the collection is altered by previous calls to an OutputStream.

Definition at line 85 of file DataSvcFileEntriesTool.cpp.

LeavesList DataSvcFileEntriesTool::m_leaves
private

Internal cache for the list of objects found during the scan.

Definition at line 70 of file DataSvcFileEntriesTool.cpp.

std::string DataSvcFileEntriesTool::m_rootNode
private

Variable for the property Root.

Definition at line 58 of file DataSvcFileEntriesTool.cpp.

bool DataSvcFileEntriesTool::m_scanOnBeginEvent
private

Variable for the property ScanOnBeginEvent.

Definition at line 60 of file DataSvcFileEntriesTool.cpp.


The documentation for this class was generated from the following file: