BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Scheduler.cxx
Go to the documentation of this file.
1// $Heading: Scheduler.cxx$
2
3#include "facilities/Scheduler.h"
4#include "facilities/ScheduledEvent.h"
5
6#include <cassert>
7
8Scheduler* Scheduler::s_instance = 0;
9Scheduler* Scheduler::instance() { return ( s_instance ) ? s_instance : new Scheduler(); }
10
11Scheduler::Scheduler() : m_time( GPStime( 0 ) ), m_running( false ), m_log( 0 ) {
12 assert( s_instance == 0 ); // require only one
13 s_instance = this;
14}
15
18 while ( !empty() )
19 {
20 iterator f = begin();
21 delete ( *f ).second;
22 erase( f );
23 }
24 m_time = 0;
25}
26
27void Scheduler::schedule( double deltaT, ScheduledEvent* event ) {
28 insert( std::make_pair( m_time + deltaT, event ) );
29}
30
32 m_running = true;
33
34 while ( !empty() && m_running )
35 {
36
37 // get the entry at the head of the queue
38 std::pair<double, ScheduledEvent*> entry = *begin();
39
40 // set current time, remove the entry
41 m_time = entry.first;
42 erase( begin() );
43
44 // run, then delete it
45 if ( m_log )
46 { ( *m_log ) << "\t" << entry.first << '\t' << entry.second->name() << std::endl; }
47 entry.second->execute();
48 delete entry.second;
49 }
50}
51
52void Scheduler::stop() { m_running = false; }
53void Scheduler::printOn( std::ostream& out ) const {
54 out << "\nScheduler stack: current time = " << elapsed_time() << std::endl;
55 out << "\ttime\tclass name\n";
56 for ( const_iterator it = begin(); it != end(); ++it )
57 {
58 std::pair<double, ScheduledEvent*> entry = *it;
59 out << "\t" << entry.first << '\t' << entry.second->name() << std::endl;
60 }
61 out << std::endl;
62}
63
64void Scheduler::setLog( std::ostream& out ) {
65 m_log = &out;
66 out << "\nSchedule event: current time = " << elapsed_time() << std::endl;
67 out << "\ttime\tEvent\n";
68}
69
70void Scheduler::endLogging() { m_log = 0; }
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
void endLogging()
Definition Scheduler.cxx:70
void printOn(std::ostream &out) const
Definition Scheduler.cxx:53
void clear()
Definition Scheduler.cxx:17
void start()
Definition Scheduler.cxx:31
void stop()
Definition Scheduler.cxx:52
static Scheduler * instance()
Definition Scheduler.cxx:9
void setLog(std::ostream &out)
Definition Scheduler.cxx:64
void schedule(double deltaT, ScheduledEvent *event)
Definition Scheduler.cxx:27