MarlinMT  0.1.0
SimpleScheduler.cc
Go to the documentation of this file.
2 
3 // -- marlinmt headers
4 #include <marlinmt/Application.h>
5 #include <marlinmt/Utils.h>
6 #include <marlinmt/Sequence.h>
7 #include <marlinmt/Processor.h>
8 
9 // -- std headers
10 #include <algorithm>
11 #include <set>
12 
13 namespace marlinmt {
14 
16  IScheduler() {
17  setName( "SimpleScheduler" ) ;
18  }
19 
20  //--------------------------------------------------------------------------
21 
23  // base init
25  auto &config = application().configuration() ;
26  auto &execSection = config.section("execute") ;
27  auto &procsSection = config.section("processors") ;
28  auto activeProcessors = execSection.parameterNames() ;
29  // auto activeProcessors = app->activeProcessors() ;
30  // create super sequence with only only sequence and fill it
31  _superSequence = std::make_shared<SuperSequence>(1) ;
32  log<DEBUG5>() << "Creating processors ..." << std::endl ;
33  if ( activeProcessors.empty() ) {
34  MARLINMT_THROW( "Active processor list is empty !" ) ;
35  }
36  // populate processor sequences
37  for ( size_t i=0 ; i<activeProcessors.size() ; ++i ) {
38  auto procName = activeProcessors[ i ] ;
39  log<DEBUG5>() << "Active processor " << procName << std::endl ;
40  auto &procSection = procsSection.section( procName ) ;
41  _superSequence->addProcessor( procSection ) ;
42  }
43  _superSequence->init( &application() ) ;
44  log<DEBUG5>() << "Creating processors ... OK" << std::endl ;
45  }
46 
47  //--------------------------------------------------------------------------
48 
50  log<MESSAGE>() << "Terminating application" << std::endl ;
51  _superSequence->end() ;
52  // print some statistics
53  _superSequence->printStatistics( _logger ) ;
54  }
55 
56  //--------------------------------------------------------------------------
57 
58  void SimpleScheduler::processRunHeader( std::shared_ptr<RunHeader> rhdr ) {
59  _superSequence->processRunHeader( rhdr ) ;
60  }
61 
62  //--------------------------------------------------------------------------
63 
64  void SimpleScheduler::pushEvent( std::shared_ptr<EventStore> event ) {
65  _currentEvent = event ;
66  auto sequence = _superSequence->sequence(0) ;
67  sequence->processEvent( _currentEvent ) ;
68  }
69 
70  //--------------------------------------------------------------------------
71 
72  void SimpleScheduler::popFinishedEvents( std::vector<std::shared_ptr<EventStore>> &events ) {
73  if( nullptr != _currentEvent ) {
74  events.push_back( _currentEvent ) ;
75  _currentEvent = nullptr ;
76  }
77  }
78 
79  //--------------------------------------------------------------------------
80 
81  std::size_t SimpleScheduler::freeSlots() const {
82  return ( _currentEvent != nullptr ) ? 0 : 1 ;
83  }
84 
85 }
ConfigSection & section(const std::string &n)
Get a subsection by name.
void end() override
Terminate the scheduler activites Cleanup memory, etc ...
IScheduler interface Interface for implementing a scheduling algorithm for event processing.
Definition: IScheduler.h:23
std::vector< std::string > parameterNames() const
Get the list of parameter names.
virtual void initialize() override
Initialize the scheduler.
Definition: IScheduler.cc:15
void setName(const std::string &n)
Set the component name.
Definition: Component.cc:29
ProcessorSequence _superSequence
< The processor super sequence
LoggerPtr _logger
The logger instance.
Definition: Component.h:173
std::size_t freeSlots() const override
Get the number of free event slots.
void popFinishedEvents(std::vector< std::shared_ptr< EventStore >> &events) override
Retrieve finished events from the scheduler.
std::shared_ptr< EventStore > _currentEvent
#define MARLINMT_THROW(message)
Definition: Exceptions.h:8
ConfigSection & section(const std::string &sn)
Get a section by name.
void processRunHeader(std::shared_ptr< RunHeader > rhdr) override
Process a run header.
const Application & application() const
Get the application in which the component is registered.
Definition: Component.cc:83
void pushEvent(std::shared_ptr< EventStore > event) override
Push a new event to the scheduler for processing.
void initialize() override
Initialize the scheduler.
const Configuration & configuration() const
Get the main application configuration object.
Definition: Application.cc:278