CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
Scheduler Class Reference

#include <Scheduler.h>

+ Inheritance diagram for Scheduler:

Public Member Functions

 Scheduler ()
 
 ~Scheduler ()
 
void schedule (double deltaT, ScheduledEvent *event)
 
void start ()
 
void stop ()
 
bool running ()
 
void clear ()
 
GPStime elapsed_time () const
 
void setLog (std::ostream &out)
 
void endLogging ()
 
void printOn (std::ostream &out) const
 

Static Public Member Functions

static Schedulerinstance ()
 

Detailed Description

Definition at line 33 of file Scheduler.h.

Constructor & Destructor Documentation

◆ Scheduler()

Scheduler::Scheduler ( )

Definition at line 11 of file Scheduler.cxx.

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}

Referenced by instance().

◆ ~Scheduler()

Scheduler::~Scheduler ( )

Definition at line 20 of file Scheduler.cxx.

21{
22 clear();
23}
void clear()
Definition Scheduler.cxx:24

Member Function Documentation

◆ clear()

void Scheduler::clear ( )

Definition at line 24 of file Scheduler.cxx.

25{
26 while( ! empty() ) {
27 iterator f = begin();
28 delete (*f).second;
29 erase(f);
30 }
31 m_time = 0;
32}

Referenced by ~Scheduler().

◆ elapsed_time()

GPStime Scheduler::elapsed_time ( ) const
inline

Definition at line 61 of file Scheduler.h.

61{return m_time;}

Referenced by printOn(), and setLog().

◆ endLogging()

void Scheduler::endLogging ( )

Definition at line 86 of file Scheduler.cxx.

87{
88 m_log = 0;
89}

◆ instance()

Scheduler * Scheduler::instance ( )
static

Definition at line 9 of file Scheduler.cxx.

9{return (s_instance) ? s_instance : new Scheduler();}

Referenced by ScheduledEvent::schedule().

◆ printOn()

void Scheduler::printOn ( std::ostream & out) const

Definition at line 66 of file Scheduler.cxx.

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}
GPStime elapsed_time() const
Definition Scheduler.h:61

◆ running()

bool Scheduler::running ( )
inline

Definition at line 55 of file Scheduler.h.

55{return m_running;}

◆ schedule()

void Scheduler::schedule ( double deltaT,
ScheduledEvent * event )

Definition at line 35 of file Scheduler.cxx.

36{
37 insert(std::make_pair(m_time+deltaT, event));
38}

Referenced by ScheduledEvent::schedule().

◆ setLog()

void Scheduler::setLog ( std::ostream & out)

Definition at line 78 of file Scheduler.cxx.

79{
80 m_log = &out;
81 out << "\nSchedule event: current time = " << elapsed_time() << std::endl;
82 out << "\ttime\tEvent\n";
83
84}

◆ start()

void Scheduler::start ( )

Definition at line 40 of file Scheduler.cxx.

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}

◆ stop()

void Scheduler::stop ( )

Definition at line 62 of file Scheduler.cxx.

63{
64 m_running = false;
65}

The documentation for this class was generated from the following files: