| The Gaudi Framework v32r1 (f65d50dc)

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