Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

processManager.cpp

Go to the documentation of this file.
00001 #include "Event/processManager.h"
00002 #include "Event/centellaAlgorithms.h"
00003 #include "centella/userAlgorithms.h"
00004 #include "Event/messageManager.h"
00005 
00006 processManager* processManager::m_instance = 0;
00007 
00008 //#####################################
00009 processManager::processManager() 
00010 //#####################################
00011 {
00012         if (m_instance != 0) return;
00013 
00015         m_algorithms     = new serverVI<algorithmVI>();
00017         m_eventTasks = new serverVI<eventTask>();
00019         m_algorithmTasks = new serverVI<algorithmTask>();
00021         m_algConditionalTasks = new serverVI<algConditionalTask>();
00022 
00024         addAlgorithmTask("iniOfRun", new algorithmTask("iniOfRun"));
00027         addEventTask("runEvent", new eventTask("runEvent"));
00029         addAlgorithmTask("endOfRun", new algorithmTask("endOfRun") );
00030 
00032         m_applicationName = "centellaAlg";
00033 
00035         m_eventTaskName = "";
00036         m_algorithmTaskName = "";
00037 
00038         m_instance = this;
00039 
00041         setName("processManager");
00043         centellaAlgorithms();
00045         userAlgorithms();
00046 }
00047 //#####################################
00048 void processManager::setOption(std::string type, std::string name)
00049 //#####################################
00050 {
00052         optionVI::setOption(type,name);
00053         if (type == "newEventTask") {
00055                 addEventTask(name, new eventTask(name));
00056                 message(" processManager: create eventTask "+name);
00057         } else if (type == "newAlgorithmTask") {
00059                 addAlgorithmTask(name, new algorithmTask(name));
00060                 message(" created algorithmTask : "+name);
00061         } else if (type == "newAlgConditionalTask") {
00063                 addAlgConditionalTask(name, new algConditionalTask(name));
00064                 message(" created algConditialTask : "+name);
00065         }
00066 }
00067 //#####################################
00068 processManager::~processManager()
00069 //#####################################
00070 {
00071     // Free dynamically allocated algorithms
00072     // Note that m_algorithms contains each instance
00073     // of m_eventTasks, m_algorithmTasks, m_algConditionalTasks
00074     // So we don't free the elements of these vectors.
00075     unsigned int i;
00076     unsigned int size = m_algorithms->size();
00077     for (i = 0; i < size; i++) {
00078         if(m_algorithms->get(i)) delete (m_algorithms->get(i));
00079      }
00080 
00081         delete m_algorithms;
00082         delete m_eventTasks;
00083         delete m_algorithmTasks;
00084         delete m_algConditionalTasks;
00085 }
00086 //#####################################
00087 void processManager::addAlgorithm(std::string name, algorithmVI* alg) 
00088 //#####################################
00089 {
00090         if (!m_algorithms->search(name)) m_algorithms->add(name,alg);
00091         else message(" algorithm already included in server "+name);
00092 }
00093 //#####################################
00094 void processManager::addAlgorithmTask(std::string name, algorithmTask* alg)
00095 //#####################################
00096 {
00097         if (!m_algorithms->search(name)) {
00098                 m_algorithmTasks->add(name,alg);
00099                 addAlgorithm(name,alg);
00100         } else message(" algorithmTask already included in server "+name);
00101 }
00102 //#####################################
00103 void processManager::addEventTask(std::string name, eventTask* evt)
00104 //#####################################
00105 {
00106         if (!m_algorithms->search(name)) {
00107                 m_eventTasks->add(name,evt);
00108                 addAlgorithm(name,evt);
00109         } else message(" not found evtProcess "+name,"GENERAL");
00110 }
00111 //#####################################
00112 void processManager::addAlgConditionalTask(std::string name, algConditionalTask* alg)
00113 //#####################################
00114 {
00115         if (!m_algorithms->search(name)) {
00116                 m_algConditionalTasks->add(name,alg);
00117                 addAlgorithm(name,alg);
00118         } else message(" not found algConditionalTask "+name,"GENERAL");
00119 }
00120 //#####################################
00121 algorithmVI* processManager::getAlgorithm(std::string name) const
00122 //#####################################
00123 {
00126         if (m_algorithms->search(name)) return m_algorithms->get(name);
00127         else message(" not found algorithm "+name,"GENERAL");
00128         return 0;
00129 }
00130 //#####################################
00131 eventTask* processManager::getEventTask(std::string name) const
00132 //#####################################
00133 {
00134         if (m_eventTasks->search(name)) return m_eventTasks->get(name);
00135         message(" not found evtProcess "+name,"GENERAL");
00136         return 0;
00137 }
00138 //#####################################
00139 algorithmTask* processManager::getAlgorithmTask(std::string name) const
00140 //#####################################
00141 {
00142         if (m_algorithmTasks->search(name)) return m_algorithmTasks->get(name);
00143         message(" not found algorithmTask "+name,"GENERAL");
00144         return 0;
00145 }
00146 //#####################################
00147 algConditionalTask* processManager::getAlgConditionalTask(std::string name) const
00148 //#####################################
00149 {
00150         if (m_algConditionalTasks->search(name)) return m_algConditionalTasks->get(name);
00151         message(" not found algConditionalTask "+name,"GENERAL");
00152         return 0;
00153 }
00154 //########################################
00155 void processManager::defineOption()
00156 //########################################
00157 {
00159         optionVI::defineOption("newEventTask",&m_eventTaskName);
00161         optionVI::defineOption("newAlgorithmTask",&m_algorithmTaskName);
00163         optionVI::defineOption("newAlgConditionalTask",&m_algConditionalTaskName);
00165         optionVI::defineOption("application",&m_applicationName);
00166 }
00167 //########################################
00168 void processManager::writeOut() const
00169 //########################################
00170 {
00171         if (!acceptLevel()) return;     
00172         std::ostream& out = messageManager::instance()->out();
00173 
00174         messageVI::writeOut();
00175 
00177         out << " application = " << m_applicationName <<"\n";
00178 
00180         if (m_algorithms->size() > 0) {
00181                 out << " -- Algorithms declared in algorithms server --" << "\n";
00182                 out << m_algorithms->nameList();
00183         }
00185         if (m_eventTasks->size() > 0) {
00186                 out << " -- eventTasks declared in the eventTasks server --" << "\n";
00187                 out << m_eventTasks->nameList();
00188         }
00190         if (m_algorithmTasks->size() > 0) {
00191                 out << " -- algorithmTask declared in the algorithmTask server --" << "\n";
00192                 out << m_algorithmTasks->nameList();
00193         }
00194                 
00196         if (m_algConditionalTasks->size() > 0) {
00197                 out << " -- algConditionalTask declared in the algConditionalTask server --" << "\n";
00198                 out << m_algConditionalTasks->nameList(); 
00199         }
00200 
00202         for (int ievt = 0; ievt < m_eventTasks->size(); ievt++ )
00203                 m_eventTasks->get(ievt)->writeOut();
00204 
00206         for (int itask = 0; itask < m_algorithmTasks->size(); itask++ )
00207                 m_algorithmTasks->get(itask)->writeOut();
00208         
00210         for (int ic = 0; ic < m_algConditionalTasks->size(); ic++ )
00211                 m_algConditionalTasks->get(ic)->writeOut();
00212 }

Generated at Fri Aug 18 12:57:38 2000 for centella framework by doxygen 1.1.3 written by Dimitri van Heesch, © 1997-2000