| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

DataSvcFileEntriesTool.cpp
Go to the documentation of this file.
1 // ========== header
2 #include "GaudiKernel/AlgTool.h"
3 #include "GaudiKernel/IDataStoreLeaves.h"
4 #include "GaudiKernel/IIncidentListener.h"
5 #include "GaudiKernel/SmartIF.h"
6
7 class IIncidentSvc;
8 class IDataManagerSvc;
9 class IDataProviderSvc;
10 class IRegistry;
27 class DataSvcFileEntriesTool : public extends<AlgTool, IDataStoreLeaves, IIncidentListener>
28 {
29 public:
31 using extends::extends;
32
34 ~DataSvcFileEntriesTool() override = default;
35
37 StatusCode initialize() override;
38
40 StatusCode finalize() override;
41
46 const LeavesList& leaves() const override;
47
51 void handle( const Incident& incident ) override;
52
53 private:
54 Gaudi::Property<std::string> m_dataSvcName{this, "DataService", "EventDataSvc", "Name of the data service to use"};
55 Gaudi::Property<std::string> m_rootNode{this, "Root", "", "Path to the element from which to start the scan"};
56 Gaudi::Property<bool> m_scanOnBeginEvent{
57 this, "ScanOnBeginEvent", false,
58 "If the scan has to be started during the BeginEvent incident (true) or on demand (false, default)"};
59 Gaudi::Property<bool> m_ignoreOriginChange{
60 this, "IgnoreOriginChange", false,
61 "Disable the detection of the change in the origin of object between the BeginEvent and the scan"};
62
64 SmartIF<IIncidentSvc> m_incidentSvc;
66 SmartIF<IDataManagerSvc> m_dataMgrSvc;
68 SmartIF<IDataProviderSvc> m_dataSvc;
69
71 LeavesList m_leaves;
72
74 void i_collectLeaves();
76 void i_collectLeaves( IRegistry* reg );
77
80 IRegistry* i_getRootNode();
81
86 std::string m_initialBase;
87 };
88
89 // ========== implementation
90 #include "GaudiKernel/DataObject.h"
91 #include "GaudiKernel/DataStoreItem.h"
92 #include "GaudiKernel/IDataManagerSvc.h"
93 #include "GaudiKernel/IDataProviderSvc.h"
94 #include "GaudiKernel/IIncidentSvc.h"
95 #include "GaudiKernel/IOpaqueAddress.h"
96 #include "GaudiKernel/IRegistry.h"
97
98 #include "GaudiKernel/GaudiException.h"
99
100 StatusCode DataSvcFileEntriesTool::initialize()
101 {
102 StatusCode sc = AlgTool::initialize();
103 if ( sc.isFailure() ) return sc;
104
105 // Retrieve the pointer to the needed services.
106
107 m_incidentSvc = serviceLocator()->service( "IncidentSvc" );
108 if ( !m_incidentSvc ) {
109 error() << "Cannot get IncidentSvc" << endmsg;
110 return StatusCode::FAILURE;
111 }
112
113 m_dataMgrSvc = m_dataSvc = serviceLocator()->service( m_dataSvcName );
114 if ( !m_dataSvc || !m_dataMgrSvc ) {
115 error() << "Cannot get IDataProviderSvc+IDataManagerSvc " << m_dataSvcName << endmsg;
116 return StatusCode::FAILURE;
117 }
118
119 // Register ourself to the incident service as listener for BeginEvent
120 m_incidentSvc->addListener( this, IncidentType::BeginEvent );
121
122 // If the Root node is not specified, take the name from the data service itself.
123 if ( m_rootNode.empty() ) {
124 m_rootNode = m_dataMgrSvc->rootName();
125 }
126
127 // Clear the cache (in case the instance is re-initilized).
128 m_leaves.clear();
129 return StatusCode::SUCCESS;
130 }
131
132 StatusCode DataSvcFileEntriesTool::finalize()
133 {
134 // unregister from the incident service
135 if ( m_incidentSvc ) {
136 m_incidentSvc->removeListener( this, IncidentType::BeginEvent );
137 }
138 // Release the services
139 m_incidentSvc.reset();
140 m_dataMgrSvc.reset();
141 m_dataSvc.reset();
142
143 return AlgTool::finalize();
144 }
145
146 void DataSvcFileEntriesTool::handle( const Incident& incident )
147 {
148 // Get the file id of the root node at every event
149 IOpaqueAddress* addr = i_getRootNode()->address();
150 if ( addr )
151 m_initialBase = addr->par()[0];
152 else
153 m_initialBase.clear(); // use empty file id if there is no address
154
155 m_leaves.clear();
156 if ( m_scanOnBeginEvent ) {
157 verbose() << "::handle scanning on " << incident.type() << endmsg;
158 i_collectLeaves();
159 }
160 }
161
162 const IDataStoreLeaves::LeavesList& DataSvcFileEntriesTool::leaves() const
163 {
164 if ( m_leaves.empty() ) {
165 const_cast<DataSvcFileEntriesTool*>( this )->i_collectLeaves();
166 }
167 return m_leaves;
168 }
169
170 IRegistry* DataSvcFileEntriesTool::i_getRootNode()
171 {
172 DataObject* obj = nullptr;
173 StatusCode sc = m_dataSvc->retrieveObject( m_rootNode, obj );
174 if ( sc.isFailure() ) {
175 throw GaudiException( "Cannot get " + m_rootNode + " from " + m_dataSvcName, name(), StatusCode::FAILURE );
176 }
177 return obj->registry();
178 }
179
180 void DataSvcFileEntriesTool::i_collectLeaves() { i_collectLeaves( i_getRootNode() ); }
181
183 void DataSvcFileEntriesTool::i_collectLeaves( IRegistry* reg )
184 {
185 // I do not put sanity checks on the pointers because I know how I'm calling the function
186 IOpaqueAddress* addr = reg->address();
187 if ( addr ) { // we consider only objects that are in a file
188 if ( msgLevel( MSG::VERBOSE ) ) verbose() << "::i_collectLeaves added " << reg->identifier() << endmsg;
189 m_leaves.push_back( reg->object() ); // add this object
190 // Origin of the current object
191 const std::string& base = addr->par()[0];
192 // Compare with the origin seen during BeginEvent
193 if ( !m_ignoreOriginChange && ( m_initialBase != base ) )
194 throw GaudiException( "Origin of data has changed ('" + m_initialBase + "' != '" + base +
195 "'), probably OutputStream was called before "
196 "InputCopyStream: check options",
197 name(), StatusCode::FAILURE );
198
199 std::vector<IRegistry*> lfs; // leaves of the current object
200 StatusCode sc = m_dataMgrSvc->objectLeaves( reg, lfs );
201 if ( sc.isSuccess() ) {
202 for ( const auto& i : lfs ) {
203 // Continue if the leaf has the same database as the parent
204 if ( i->address() && i->address()->par()[0] == base ) {
205 DataObject* obj = nullptr;
206 sc = m_dataSvc->retrieveObject( reg, i->name(), obj );
207 if ( sc.isSuccess() ) {
208 i_collectLeaves( i );
209 } else {
210 throw GaudiException( "Cannot get " + i->identifier() + " from " + m_dataSvcName, name(),
211 StatusCode::FAILURE );
212 }
213 }
214 }
215 }
216 }
217 }
218
219 DECLARE_COMPONENT( DataSvcFileEntriesTool )
IDataStoreLeaves.h
StatusCode::SUCCESS
Definition: StatusCode.h:31
SmartIF< IIncidentSvc >
IDataManagerSvc::rootName
virtual const std::string & rootName() const =0
Get Name of root Event.
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
AlgTool::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: AlgTool.cpp:84
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
StatusCode::FAILURE
Definition: StatusCode.h:31
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
AlgTool::initialize
StatusCode initialize() override
Definition: AlgTool.cpp:241
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
AlgTool.h
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:123
IRegistry::name
virtual const name_type & name() const =0
Name of the directory (or key)
DataSvcFileEntriesTool::m_rootNode
Gaudi::Property< std::string > m_rootNode
Definition: DataSvcFileEntriesTool.cpp:55
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
DataSvcFileEntriesTool::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
Definition: DataSvcFileEntriesTool.cpp:64
MSG::VERBOSE
Definition: IMessageSvc.h:16
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
DataSvcFileEntriesTool::m_dataSvc
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
Definition: DataSvcFileEntriesTool.cpp:68
DataSvcFileEntriesTool::m_initialBase
std::string m_initialBase
File ID of the Root node.
Definition: DataSvcFileEntriesTool.cpp:86
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
DataSvcFileEntriesTool
Tool to scan a transient store branch that collects all the objects that belong to the same source (f...
Definition: DataSvcFileEntriesTool.cpp:27
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
DataSvcFileEntriesTool::m_dataMgrSvc
SmartIF< IDataManagerSvc > m_dataMgrSvc
Pointer to the IDataManagerSvc interface of the data service.
Definition: DataSvcFileEntriesTool.cpp:66
std::string
STL class.
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:311
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:111
DataStoreItem.h
IDataManagerSvc.h
DataSvcFileEntriesTool::finalize
StatusCode finalize() override
Finalize the tool.
Definition: DataSvcFileEntriesTool.cpp:132
IDataProviderSvc.h
DataSvcFileEntriesTool::i_collectLeaves
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
Definition: DataSvcFileEntriesTool.cpp:180
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
IIncidentSvc.h
DataSvcFileEntriesTool::m_ignoreOriginChange
Gaudi::Property< bool > m_ignoreOriginChange
Definition: DataSvcFileEntriesTool.cpp:59
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
DataSvcFileEntriesTool::~DataSvcFileEntriesTool
~DataSvcFileEntriesTool() override=default
Destructor.
GaudiException.h
SmartIF.h
DataSvcFileEntriesTool::m_dataSvcName
Gaudi::Property< std::string > m_dataSvcName
Definition: DataSvcFileEntriesTool.cpp:54
DataSvcFileEntriesTool::m_scanOnBeginEvent
Gaudi::Property< bool > m_scanOnBeginEvent
Definition: DataSvcFileEntriesTool.cpp:56
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
std::string::clear
T clear(T...args)
DataSvcFileEntriesTool::initialize
StatusCode initialize() override
Initialize the tool.
Definition: DataSvcFileEntriesTool.cpp:100
IRegistry::object
virtual DataObject * object() const =0
Retrieve object behind the link.
IOpaqueAddress.h
IDataManagerSvc::objectLeaves
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 ...
AlgTool::name
const std::string & name() const override
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:63
std::vector< DataObject * >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
IDataManagerSvc
Definition: IDataManagerSvc.h:45
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
IIncidentSvc::addListener
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
IIncidentListener.h
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:92
DataSvcFileEntriesTool::leaves
const LeavesList & leaves() const override
Return the list of collected objects.
Definition: DataSvcFileEntriesTool.cpp:162
IIncidentSvc::removeListener
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
DataSvcFileEntriesTool::m_leaves
LeavesList m_leaves
Internal cache for the list of objects found during the scan.
Definition: DataSvcFileEntriesTool.cpp:71
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:129
IRegistry::address
virtual IOpaqueAddress * address() const =0
Retrieve opaque storage address.
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
DataSvcFileEntriesTool::i_getRootNode
IRegistry * i_getRootNode()
Return the pointer to the IRegistry object associated to the node specified as Root.
Definition: DataSvcFileEntriesTool.cpp:170
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataSvcFileEntriesTool::handle
void handle(const Incident &incident) override
Call-back function for the BeginEvent incident.
Definition: DataSvcFileEntriesTool.cpp:146
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
DataObject.h
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.