EventAnalysis  1.3.0
DataProvider.h
Go to the documentation of this file.
1 /*
2  * DataProvider.h
3  *
4  * Created on: 08 Feb 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef DATAPROVIDER_H_
11 #define DATAPROVIDER_H_
12 
13 #include "core/Configurable.h"
14 #include "core/Info.h"
15 #include "core/ObjectMap.h"
16 #include "data/ObjectCategory.h"
17 #include "data/ObjectProducer.h"
18 
19 #include <string>
20 
21 namespace EA {
22 
29 class DataProvider : public Info, public Configurable, public ObjectProducer {
30 
31 public:
41  DataProvider(const std::string &name, const std::string &dataSource) : Info(name), _dataSource(dataSource) {}
42 
44  virtual ~DataProvider() = default;
45 
46 private:
53  virtual bool Connect() { return true; }
54 
61  virtual bool Disconnect() { return true; }
62 
88  virtual RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper,
89  std::string &actualName) {
90  if (_disabled) {
91  return DataProvider::GetObject(name, category, wrapper);
92  } else {
93  return GetObject(name, category, wrapper);
94  }
95  }
96 
114  virtual RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper) {
116  }
117 
135  virtual bool SetCurrentEvent(unsigned int event, std::vector<std::string> &notValidGlobalObjects) {
136  if (_disabled) {
137  return DataProvider::SetCurrentEvent(event);
138  } else {
139  return SetCurrentEvent(event);
140  }
141  }
142 
156  virtual bool SetCurrentEvent(unsigned int event) { return true; }
157 
170  virtual bool SetCurrentPass(unsigned int pass, unsigned int iteration) { return true; }
171 
172 public:
177  const std::string &GetDataSource() { return _dataSource; }
178 
186  bool IsDisabled() { return _disabled; }
187 
193  bool SetDisabled(bool disabled = true);
194 
220  RetrievalResult RetrieveObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper,
221  std::string &actualName) {
222  if (_disabled) {
223  return DataProvider::GetObject(name, category, wrapper, actualName); // Static call to base class implementation
224  } else {
225  return GetObject(name, category, wrapper, actualName); // Polymorphic call to derived class override
226  }
227  }
228 
238  virtual bool IsEventAvailable(unsigned int event) { return true; }
239 
247  bool ConnectSource();
248 
256  bool DisconnectSource();
257 
276  bool SetEvent(unsigned int event, std::vector<std::string> &notValidGlobalObjects);
277 
288  bool SetPass(unsigned int pass, unsigned int iteration);
289 
290 private:
291  std::string _dataSource;
292  bool _disabled = false;
293 };
294 
295 } // namespace EA
296 
297 #include "plugin/FactoryMacros.h"
298 #define RegisterDataProvider(className) \
299  RegisterClass(EA::DataProvider, className, const std::string &, const std::string &)
300 #define RegisterNSDataProvider(namespace, className) \
301  RegisterClassAs(EA::DataProvider, className, #namespace "::" #className, const std::string &, const std::string &)
302 
303 #endif /* DATAPROVIDER_H_ */
std::string _dataSource
Definition: DataProvider.h:291
bool SetDisabled(bool disabled=true)
Disables/enables the data provider.
Definition: DataProvider.cpp:14
const std::string & GetDataSource()
Getter for data source string.
Definition: DataProvider.h:177
bool SetPass(unsigned int pass, unsigned int iteration)
Set the current processing pass.
Definition: DataProvider.cpp:47
Interface for retrieving informations about an object.
Definition: Info.h:18
RetrievalResult
Definition: RetrievalResult.h:16
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
virtual bool SetCurrentEvent(unsigned int event)
Set the current event.
Definition: DataProvider.h:156
virtual bool SetCurrentPass(unsigned int pass, unsigned int iteration)
Set the current processing pass.
Definition: DataProvider.h:170
RetrievalResult RetrieveObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper, std::string &actualName)
Retrieve the requested data object for current event.
Definition: DataProvider.h:220
DataProvider(const std::string &name, const std::string &dataSource)
Constructor.
Definition: DataProvider.h:41
virtual bool Connect()
Opens the connection to the data source.
Definition: DataProvider.h:53
virtual RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper, std::string &actualName)
Get the requested data object for current event.
Definition: DataProvider.h:88
ObjectCategory
Category of objects.
Definition: ObjectCategory.h:17
Generic wrapper class.
Definition: ObjectWrapper.h:28
bool ConnectSource()
Opens the connection to the data source.
Definition: DataProvider.cpp:23
Interface for a class which produced data objects.
Definition: ObjectProducer.h:29
virtual bool SetCurrentEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects)
Set the current event.
Definition: DataProvider.h:135
bool DisconnectSource()
Closes the connection to the data source.
Definition: DataProvider.cpp:31
bool _disabled
The data connection.
Definition: DataProvider.h:292
virtual bool IsEventAvailable(unsigned int event)
Checks if the data provider can provide the given event.
Definition: DataProvider.h:238
bool IsDisabled()
Check if the data provider is disabled.
Definition: DataProvider.h:186
virtual bool Disconnect()
Closes the connection to the data source.
Definition: DataProvider.h:61
Object found but class does not match with requested.
bool SetEvent(unsigned int event, std::vector< std::string > &notValidGlobalObjects)
Set the current event.
Definition: DataProvider.cpp:39
Interface for a configurable class.
Definition: Configurable.h:25
virtual ~DataProvider()=default
Destructor.
virtual RetrievalResult GetObject(const std::string &name, ObjectCategory category, ObjectWrapper &wrapper)
Get the requested data object for current event.
Definition: DataProvider.h:114
A base class for data providers.
Definition: DataProvider.h:29