MarlinMT  0.1.0
DataSourcePlugin.cc
Go to the documentation of this file.
2 
3 // -- marlinmt headers
4 #include <marlinmt/Application.h>
5 #include <marlinmt/EventStore.h>
6 #include <marlinmt/RunHeader.h>
7 
8 namespace marlinmt {
9 
10  DataSourcePlugin::DataSourcePlugin( const std::string &dstype ) :
11  Component(dstype) {
12  /* nop */
13  }
14 
15  //--------------------------------------------------------------------------
16 
18  while( readOne() ) ;
19  }
20 
21  //--------------------------------------------------------------------------
22 
24  _onEventRead = func ;
25  }
26 
27  //--------------------------------------------------------------------------
28 
30  _onRunHeaderRead = func ;
31  }
32 
33  //--------------------------------------------------------------------------
34 
35  void DataSourcePlugin::processRunHeader( std::shared_ptr<RunHeader> rhdr ) {
36  if( nullptr == _onRunHeaderRead ) {
37  throw Exception( "DataSourcePlugin::processRunHeader: no callback function available" ) ;
38  }
39  _onRunHeaderRead( rhdr ) ;
40  }
41 
42  //--------------------------------------------------------------------------
43 
44  void DataSourcePlugin::processEvent( std::shared_ptr<EventStore> event ) {
45  if( nullptr == _onEventRead ) {
46  throw Exception( "DataSourcePlugin::processEvent: no callback function available" ) ;
47  }
48  _onEventRead( event ) ;
49  }
50 
51  //--------------------------------------------------------------------------
52 
54  auto &config = application().configuration() ;
55  if( config.hasSection("datasource") ) {
56  setParameters( config.section("datasource") ) ;
57  }
58  }
59 
60 }
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 setParameters(const ConfigSection &section, bool throwIfNotFound=false)
Set the parameters from the configuration section.
Definition: Component.cc:124
void onEventRead(EventFunction func)
Set the callback function to process on event read.
Component class.
Definition: Component.h:22
DataSourcePlugin(const std::string &dstype)
Constructor.
RunHeaderFunction _onRunHeaderRead
virtual void readAll()
Read the full stream until the end See readOne() for details.
virtual void initialize() override
Init data source.
const Application & application() const
Get the application in which the component is registered.
Definition: Component.cc:83
std::function< void(std::shared_ptr< RunHeader >)> RunHeaderFunction
void onRunHeaderRead(RunHeaderFunction func)
Set the callback function to process on run header read.
virtual bool readOne()=0
Read one record from the input stream.
Exception class.
Definition: Exceptions.h:60
EventFunction _onEventRead
< The callback function on event read
const Configuration & configuration() const
Get the main application configuration object.
Definition: Application.cc:278