/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/facilities/facilities-00-00-04/src/Scheduler.cxx

Go to the documentation of this file.
00001 // $Heading: Scheduler.cxx$
00002 
00003 #include "facilities/Scheduler.h"
00004 #include "facilities/ScheduledEvent.h"
00005 
00006 #include <cassert>
00007 
00008 Scheduler* Scheduler::s_instance = 0;
00009 Scheduler* Scheduler::instance(){return (s_instance) ? s_instance : new Scheduler();}
00010 
00011 Scheduler::Scheduler()
00012 : m_time(GPStime(0))
00013 , m_running(false)
00014 , m_log(0)
00015 {
00016     assert( s_instance==0);  // require only one
00017     s_instance = this;
00018 }
00019 
00020 Scheduler::~Scheduler()
00021 {
00022     clear();
00023 }
00024 void Scheduler::clear()
00025 {
00026     while( ! empty() ) {
00027         iterator f = begin();
00028         delete (*f).second;
00029         erase(f);
00030     }
00031     m_time = 0;
00032 }
00033 
00034 
00035 void Scheduler::schedule(double deltaT, ScheduledEvent* event)
00036 {
00037     insert(std::make_pair(m_time+deltaT, event));
00038 }
00039 
00040 void Scheduler::start()
00041 {
00042     m_running = true;
00043 
00044     while( !empty() && m_running ) {
00045 
00046         // get the entry at the head of the queue
00047         std::pair<double, ScheduledEvent*> entry = *begin();
00048 
00049         // set current time, remove the entry
00050         m_time = entry.first;
00051         erase(begin());
00052 
00053         // run, then delete it
00054         if( m_log ) {
00055             (*m_log) << "\t" << entry.first << '\t' << entry.second->name() << std::endl ;
00056         }
00057         entry.second->execute();
00058         delete entry.second;
00059     }
00060 }
00061 
00062 void Scheduler::stop()
00063 {
00064     m_running = false;
00065 }
00066 void Scheduler::printOn(std::ostream& out)const
00067 {
00068     out << "\nScheduler stack: current time = " << elapsed_time() << std::endl;
00069     out << "\ttime\tclass name\n";
00070     for( const_iterator it= begin(); it !=end(); ++it){
00071         std::pair<double, ScheduledEvent*> entry = *it;
00072         out << "\t" << entry.first << '\t' << entry.second->name() << std::endl ;
00073     }
00074     out << std::endl;
00075 
00076 }
00077 
00078 void Scheduler::setLog(std::ostream& out)
00079 {
00080     m_log = &out;
00081     out << "\nSchedule event: current time = " << elapsed_time() << std::endl;
00082     out << "\ttime\tEvent\n";
00083 
00084 }
00085 
00086 void Scheduler::endLogging()
00087 {
00088     m_log = 0;
00089 }

Generated on Tue Nov 29 22:57:55 2016 for BOSS_7.0.2 by  doxygen 1.4.7