| The Gaudi Framework v27r1

- 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;
26 class DataSvcFileEntriesTool: public extends<AlgTool,
27 IDataStoreLeaves,
28 IIncidentListener> {
29 public:
31 DataSvcFileEntriesTool(const std::string& type,
32 const std::string& name,
33 const IInterface* parent);
34
36 ~DataSvcFileEntriesTool() override = default;
37
39 StatusCode initialize() override;
40
42 StatusCode finalize() override;
43
48 const LeavesList & leaves() const override;
49
53 void handle(const Incident& incident) override;
54
55 private:
56
58 std::string m_dataSvcName;
60 std::string m_rootNode;
62 bool m_scanOnBeginEvent;
63
65 SmartIF<IIncidentSvc> m_incidentSvc;
67 SmartIF<IDataManagerSvc> m_dataMgrSvc;
69 SmartIF<IDataProviderSvc> m_dataSvc;
70
72 LeavesList m_leaves;
73
75 void i_collectLeaves();
77 void i_collectLeaves(IRegistry *reg);
78
81 IRegistry* i_getRootNode();
82
87 std::string m_initialBase;
88
90 bool m_ignoreOriginChange;
91 };
92
93 // ========== implementation
94 #include "GaudiKernel/IIncidentSvc.h"
95 #include "GaudiKernel/IDataManagerSvc.h"
96 #include "GaudiKernel/IDataProviderSvc.h"
97 #include "GaudiKernel/IRegistry.h"
98 #include "GaudiKernel/IOpaqueAddress.h"
99 #include "GaudiKernel/DataObject.h"
100 #include "GaudiKernel/DataStoreItem.h"
101
102 #include "GaudiKernel/GaudiException.h"
103
104 DataSvcFileEntriesTool::DataSvcFileEntriesTool(const std::string& type,
105 const std::string& name,
106 const IInterface* parent):
107 base_class(type, name, parent) {
108
109 declareProperty("DataService", m_dataSvcName = "EventDataSvc",
110 "Name of the data service to use");
111
112 declareProperty("Root", m_rootNode,
113 "Path to the element from which to start the scan");
114
115 declareProperty("ScanOnBeginEvent", m_scanOnBeginEvent = false,
116 "If the scan has to be started during the BeginEvent incident (true) or on demand (false, default)");
117
118 declareProperty("IgnoreOriginChange", m_ignoreOriginChange = false,
119 "Disable the detection of the change in the origin of object between the BeginEvent and the scan");
120 }
121
122 StatusCode DataSvcFileEntriesTool::initialize(){
123 StatusCode sc = AlgTool::initialize();
124 if (sc.isFailure()) return sc;
125
126 // Retrieve the pointer to the needed services.
127
128 m_incidentSvc = serviceLocator()->service("IncidentSvc");
129 if ( ! m_incidentSvc ) {
130 error() << "Cannot get IncidentSvc" << endmsg;
131 return StatusCode::FAILURE;
132 }
133
134 m_dataMgrSvc = m_dataSvc = serviceLocator()->service(m_dataSvcName);
135 if ( ! m_dataSvc || ! m_dataMgrSvc ) {
136 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()) {
145 m_rootNode = m_dataMgrSvc->rootName();
146 }
147
148 // Clear the cache (in case the instance is re-initilized).
149 m_leaves.clear();
150 return StatusCode::SUCCESS;
151 }
152
153 StatusCode DataSvcFileEntriesTool::finalize(){
154 // unregister from the incident service
155 if (m_incidentSvc) {
156 m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
157 }
158 // Release the services
159 m_incidentSvc.reset();
160 m_dataMgrSvc.reset();
161 m_dataSvc.reset();
162
163 return AlgTool::finalize();
164 }
165
166 void DataSvcFileEntriesTool::handle(const Incident& incident) {
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 verbose() << "::handle scanning on " << incident.type() << endmsg;
177 i_collectLeaves();
178 }
179 }
180
181 const IDataStoreLeaves::LeavesList & DataSvcFileEntriesTool::leaves() const {
182 if (m_leaves.empty()) {
183 const_cast<DataSvcFileEntriesTool*>(this)->i_collectLeaves();
184 }
185 return m_leaves;
186 }
187
188 IRegistry* DataSvcFileEntriesTool::i_getRootNode() {
189 DataObject * obj = nullptr;
190 StatusCode sc = m_dataSvc->retrieveObject(m_rootNode, obj);
191 if (sc.isFailure()) {
192 throw GaudiException("Cannot get " + m_rootNode + " from " + m_dataSvcName, name(), StatusCode::FAILURE);
193 }
194 return obj->registry();
195 }
196
197
198 void DataSvcFileEntriesTool::i_collectLeaves() {
199 i_collectLeaves(i_getRootNode());
200 }
201
203 void DataSvcFileEntriesTool::i_collectLeaves(IRegistry* reg) {
204 // I do not put sanity checks on the pointers because I know how I'm calling the function
205 IOpaqueAddress *addr = reg->address();
206 if (addr) { // we consider only objects that are in a file
207 if (msgLevel(MSG::VERBOSE))
208 verbose() << "::i_collectLeaves added " << reg->identifier() << endmsg;
209 m_leaves.push_back(reg->object()); // add this object
210 // Origin of the current object
211 const std::string& base = addr->par()[0];
212 // Compare with the origin seen during BeginEvent
213 if ( !m_ignoreOriginChange && (m_initialBase != base) )
214 throw GaudiException("Origin of data has changed ('"
215 + m_initialBase + "' != '" + base
216 + "'), probably OutputStream was called before "
217 "InputCopyStream: check options",
218 name(), StatusCode::FAILURE);
219
220 std::vector<IRegistry*> lfs; // leaves of the current object
221 StatusCode sc = m_dataMgrSvc->objectLeaves(reg, lfs);
222 if (sc.isSuccess()) {
223 for(const auto& i : lfs) {
224 // Continue if the leaf has the same database as the parent
225 if ( i->address() && i->address()->par()[0] == base ) {
226 DataObject* obj = nullptr;
227 sc = m_dataSvc->retrieveObject(reg, i->name(), obj);
228 if (sc.isSuccess()) {
229 i_collectLeaves(i);
230 } else {
231 throw GaudiException("Cannot get " + i->identifier() + " from " + m_dataSvcName, name(), StatusCode::FAILURE);
232 }
233 }
234 }
235 }
236 }
237 }
238
239
240 DECLARE_COMPONENT(DataSvcFileEntriesTool)
IDataStoreLeaves.h
IOpaqueAddress::par
virtual const std::string * par() const =0
Retrieve String parameters.
SmartIF< IIncidentSvc >
std::string::empty
T empty(T...args)
DataSvcFileEntriesTool::leaves
const LeavesList & leaves() const override
Return the list of collected objects.
Definition: DataSvcFileEntriesTool.cpp:181
DataSvcFileEntriesTool::m_ignoreOriginChange
bool m_ignoreOriginChange
Variable for the property ScanOnBeginEvent.
Definition: DataSvcFileEntriesTool.cpp:90
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
AlgTool::initialize
StatusCode initialize() override
Definition: AlgTool.cpp:290
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
AlgTool.h
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:130
DataSvcFileEntriesTool::m_scanOnBeginEvent
bool m_scanOnBeginEvent
Variable for the property ScanOnBeginEvent.
Definition: DataSvcFileEntriesTool.cpp:62
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
DataSvcFileEntriesTool::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
Definition: DataSvcFileEntriesTool.cpp:65
MSG::VERBOSE
Definition: IMessageSvc.h:17
merge_files.sc
int sc
Definition: merge_files.py:167
DataSvcFileEntriesTool::m_dataSvc
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to the IDataProviderSvc interface of the data service.
Definition: DataSvcFileEntriesTool.cpp:69
DataSvcFileEntriesTool::m_initialBase
std::string m_initialBase
File ID of the Root node.
Definition: DataSvcFileEntriesTool.cpp:87
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:74
DataSvcFileEntriesTool
Tool to scan a transient store branch that collects all the objects that belong to the same source (f...
Definition: DataSvcFileEntriesTool.cpp:26
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
DataSvcFileEntriesTool::m_dataMgrSvc
SmartIF< IDataManagerSvc > m_dataMgrSvc
Pointer to the IDataManagerSvc interface of the data service.
Definition: DataSvcFileEntriesTool.cpp:67
std::string
STL class.
AlgTool::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: AlgTool.cpp:86
AlgTool::finalize
StatusCode finalize() override
Definition: AlgTool.cpp:360
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:78
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
DataStoreItem.h
IDataManagerSvc.h
DataSvcFileEntriesTool::finalize
StatusCode finalize() override
Finalize the tool.
Definition: DataSvcFileEntriesTool.cpp:153
IDataProviderSvc.h
gaudirun.type
string type
Definition: gaudirun.py:151
DataSvcFileEntriesTool::i_collectLeaves
void i_collectLeaves()
Scan the data service starting from the node specified as Root.
Definition: DataSvcFileEntriesTool.cpp:198
StatusCode::FAILURE
Definition: StatusCode.h:29
IIncidentSvc.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
AlgTool::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: AlgTool.h:249
DataSvcFileEntriesTool::~DataSvcFileEntriesTool
~DataSvcFileEntriesTool() override=default
Destructor.
GaudiException.h
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
SmartIF.h
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)
IDataManagerSvc::rootName
virtual const std::string & rootName() const =0
Get Name of root Event.
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:122
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 ...
DataSvcFileEntriesTool::m_dataSvcName
std::string m_dataSvcName
Variable for the property DataService.
Definition: DataSvcFileEntriesTool.cpp:58
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.
CommonMessaging
Definition: CommonMessaging.h:58
IIncidentListener.h
AlgTool::type
const std::string & type() const override
Retrieve type (concrete class) of the sub-algtool.
Definition: AlgTool.cpp:72
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:88
DataSvcFileEntriesTool::DataSvcFileEntriesTool
DataSvcFileEntriesTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: DataSvcFileEntriesTool.cpp:104
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:72
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ana.i
list i
Definition: ana.py:128
DataSvcFileEntriesTool::m_rootNode
std::string m_rootNode
Variable for the property Root.
Definition: DataSvcFileEntriesTool.cpp:60
AlgTool::name
const std::string & name() const override
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:65
DataSvcFileEntriesTool::i_getRootNode
IRegistry * i_getRootNode()
Return the pointer to the IRegistry object associated to the node specified as Root.
Definition: DataSvcFileEntriesTool.cpp:188
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DataSvcFileEntriesTool::handle
void handle(const Incident &incident) override
Call-back function for the BeginEvent incident.
Definition: DataSvcFileEntriesTool.cpp:166
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:21
DataObject.h
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
AlgTool::parent
const IInterface * parent() const override
Retrieve parent of the sub-algtool.
Definition: AlgTool.cpp:79