MarlinMT  0.1.0
DataSourcePlugin.h
Go to the documentation of this file.
1 #ifndef MARLINMT_DATASOURCEPLUGIN_h
2 #define MARLINMT_DATASOURCEPLUGIN_h 1
3 
4 // -- marlinmt headers
5 #include <marlinmt/Component.h>
6 #include <marlinmt/Logging.h>
7 
8 // -- std headers
9 #include <functional>
10 #include <memory>
11 #include <string>
12 
13 namespace marlinmt {
14 
15  class Application ;
16  class EventStore ;
17  class RunHeader ;
18 
24  class DataSourcePlugin : public Component {
25  public:
26  using EventFunction = std::function<void(std::shared_ptr<EventStore>)> ;
27  using RunHeaderFunction = std::function<void(std::shared_ptr<RunHeader>)> ;
28 
29  public:
30  virtual ~DataSourcePlugin() = default ;
31 
37  DataSourcePlugin( const std::string &dstype ) ;
38 
42  const std::string &type() const ;
43 
47  const std::string &description() const ;
48 
56  virtual bool readOne() = 0 ;
57 
62  virtual void readAll() ;
63 
69  void onEventRead( EventFunction func ) ;
70 
76  void onRunHeaderRead( RunHeaderFunction func ) ;
77 
78  protected:
85  void processRunHeader( std::shared_ptr<RunHeader> rhdr ) ;
86 
93  void processEvent( std::shared_ptr<EventStore> event ) ;
94 
96  virtual void initialize() override ;
97 
98  protected:
100  std::string _description {"No description"} ;
101 
102  private:
107  };
108 
109 }
110 
111 #endif
std::function< void(std::shared_ptr< EventStore >)> EventFunction
void processRunHeader(std::shared_ptr< RunHeader > rhdr)
Must be called by daughter classes in readStream() to process an event in the framework.
void processEvent(std::shared_ptr< EventStore > event)
Must be called by daughter classes in readStream() to process an event in the framework.
void onEventRead(EventFunction func)
Set the callback function to process on event read.
DataSourcePlugin class Responsible for reading/getting LCEvent and LCRunHeader in the framework for f...
Component class.
Definition: Component.h:22
DataSourcePlugin(const std::string &dstype)
Constructor.
RunHeaderFunction _onRunHeaderRead
std::string _description
< The data source description
virtual void readAll()
Read the full stream until the end See readOne() for details.
virtual void initialize() override
Init data source.
virtual ~DataSourcePlugin()=default
std::function< void(std::shared_ptr< RunHeader >)> RunHeaderFunction
void onRunHeaderRead(RunHeaderFunction func)
Set the callback function to process on run header read.
const std::string & description() const
Get the data source description.
virtual bool readOne()=0
Read one record from the input stream.
const std::string & type() const
Get the data source type.
EventFunction _onEventRead
< The callback function on event read