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