Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

SimulationManager.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #ifndef SIMULATIONMANAGER_H
00024 #define SIMULATIONMANAGER_H
00025 
00026 //SpikeStream includes
00027 #include "DBInterface.h"
00028 #include "NetworkMonitor.h"
00029 #include "SimulationTypes.h"
00030 #include "BusyDialog.h"
00031 #include "MonitorDataPlotter.h"
00032 #include "GlobalVariables.h"
00033 
00034 //Qt includes
00035 #include <qthread.h>
00036 #include <qwidget.h>
00037 #include <qprogressdialog.h>
00038 #include <qstring.h>
00039 
00040 
00041 /*! Struct holding the outcome of an attempt to initialise the simulation. 
00042         The simulation may have started or the initialisation may have been 
00043         cancelled by the user. */
00044 struct StartSimRes {
00045         bool started;
00046         bool canceled;
00047 };
00048 
00049 
00050 //------------------------ Simulation Manager ------------------------------
00051 /*! Initiates and controls the simulation using PVM. */
00052 //--------------------------------------------------------------------------
00053 /* FIXME WOULD BE GREATLY IMPROVED IF THE INITIALISATION TASKS WERE CARRIED
00054         OUT BY A SEPARATE THREAD TO ENABLE THEM TO BE CLEANLY CANCELLED. */
00055 
00056 class SimulationManager : public QObject, public QThread {
00057         Q_OBJECT
00058 
00059         public: 
00060                 SimulationManager(DBInterface *networkDBInterface, DBInterface *archiveDBInterface, DBInterface *patternDBInterface, DBInterface *deviceDBInterface, QWidget *simulationWidget);
00061                 ~SimulationManager();
00062                 void clearSimulationError();
00063                 bool destroySimulation();
00064                 void fireNeuron(unsigned int neuronGrpID, unsigned int neuronID);
00065                 bool getCleanUpError();
00066                 QString getCleanUpErrorMsg();
00067                 QString getInitErrorMsg();
00068                 QString getSimulationErrorMsg();
00069                 bool getViewWeightsSaved();
00070                 bool getWeightsLoaded();
00071                 bool getWeightsSaved();
00072                 StartSimRes initialiseSimulation(QString archiveName, map<unsigned int, unsigned int> patternInputMap, map<unsigned int, unsigned int> deviceInOutMap, map<unsigned int, double>deviceFiringModeMap, map<const char*, unsigned int> paramMap);
00073                 void injectNoise(unsigned int neuronGrpID, int amount);
00074                 static bool isInitialised();
00075                 bool isRunning();
00076                 bool loadWeights();
00077                 void monitorNeuronGroup(unsigned int neuronGrpID, bool monitorType);
00078                 bool saveViewWeights();
00079                 bool saveWeights();
00080                 void setFrameRate(int fr);
00081                 bool setGlobalParameters();
00082                 void setGraphicsLoading(bool gl);
00083                 void setMaxNeurDataLoadTime_sec(int mNeurData);
00084                 void setNetworkMonitors(map<unsigned int, NetworkMonitor*> nwMonitorMap);
00085                 void setNeuronMonitors(map<unsigned int, MonitorDataPlotter*> *neurMonMap);
00086                 bool setNeuronParameters();
00087                 void setSynapseMonitors(map<unsigned int*, MonitorDataPlotter*, synapseKeyCompare> *synMonMap);
00088                 bool setNoiseParameters();
00089                 bool setSynapseParameters();
00090                 void setUpdateMode(bool, bool);
00091                 bool simulationError();
00092                 bool startNeuronMonitoring(unsigned int neuronGrpID, unsigned int neuronID, bool restart);
00093                 bool startRecording();
00094                 bool startSimulation();
00095                 bool startSynapseMonitoring(unsigned int neuronGrpID, unsigned int fromNeuronID, unsigned int toNeuronID, bool restart);
00096                 bool stepSimulation();
00097                 void stopMonitoringNeuronGroup(unsigned int neuronGrpID, bool monitorType);
00098                 bool stopNeuronMonitoring(unsigned int neuronGrpID, unsigned int neuronID);
00099                 bool stopRecording();
00100                 bool stopSimulation();
00101                 bool stopSynapseMonitoring(unsigned int neurGrpID, unsigned int fromNeurID, unsigned int toNeurID);
00102 
00103 
00104         signals:
00105                 void simulationStartTimeChanged(unsigned int newSimStartTime);
00106 
00107 
00108         protected:
00109                 //Method inherited from QThread
00110                 void run();
00111 
00112 
00113         private:
00114                 //===================== VARIABLES ===============================
00115                 /*! The task id of the SpikeStream Application.*/
00116                 int thisTaskID;
00117 
00118                 //References to classes for database handling
00119                 DBInterface *networkDBInterface;
00120                 DBInterface *archiveDBInterface;
00121                 DBInterface *patternDBInterface;
00122                 DBInterface *deviceDBInterface;
00123 
00124                 /*! Reference to SimulationWidget stored as QWidget to avoid include problems.*/
00125                 QWidget *simulationWidget; 
00126 
00127                 /*! Short version of the reference to the main QApplication.*/
00128                 SpikeStreamApplication *spikeStrApp;
00129 
00130                 /*! Task id of archive.*/
00131                 int archiveTaskID;
00132                 
00133                 /*! Records which task is processing which neuron group
00134                         The key is the neuron group ID, the data is the task ID.*/
00135                 map<unsigned int, int> neuronGrpTaskMap;
00136                 
00137                 /*! Links tasks to network monitors that are running in this process
00138                         The key is the taskID.*/
00139                 map<int, NetworkMonitor*> networkMonitorMap;
00140                 
00141                 /*! Complete list of all the tasks that are processing neuron groups.*/
00142                 vector<int> neuronGrpTaskVector;
00143 
00144                 /*! Used to control run loop. Made static so that isInitialised() can be static.*/
00145                 static bool stop;
00146 
00147                 /*! Records whether an error was generated during the cleaning up of a simulation.*/
00148                 bool cleanUpError;
00149 
00150                 /*! Error messages generated during simulation clean up.*/
00151                 QString cleanUpErrorMsg;
00152 
00153                 /*! Error messages generated during simulation initialisation.*/
00154                 QString initErrorMsg;
00155 
00156                 /*! Records whether there have been errors during the running of the simulation.*/
00157                 bool simError;
00158 
00159                 /*! Stores error messages generated during a simulation run.*/
00160                 QString simulationErrorMsg;
00161 
00162                 /*! Records whether the simulation manager is in its run loop.*/
00163                 bool simulationRunning;
00164 
00165                 /*! Used to keep track of whether weights have been saved or not.*/
00166                 bool weightsSaved;
00167 
00168                 /*! Used to record confirmtion messages about weights being saved.*/
00169                 map<int, bool> weightsSavedAcknowledgementMap;
00170 
00171                 /*! Used to keep track of whether weights have been saved to TempWeight 
00172                         for viewing. */
00173                 bool viewWeightsSaved;
00174 
00175                 /*! Used to record confirmtion messages about view weights being saved.*/
00176                 map<int, bool> viewWeightsSavedAcknowledgementMap;
00177 
00178                 /*! Used to keep track of whether weights have been reloaded or not.*/
00179                 bool synapseWeightsLoaded;
00180 
00181                 /*! Used to record confirmtion messages about weights being reloaded.*/
00182                 map<int, bool> weightsLoadedAcknowledgementMap;
00183 
00184                 /*! Dialog shown to indicate a process taking place whose duration is not known.*/
00185                 BusyDialog *busyDialog;
00186 
00187                 /*! Records when the graphics is loading to avoid sending stray messages.*/
00188                 //FIXME NOT SURE IF THIS IS WORKING
00189                 bool graphicsLoading;
00190 
00191                 /*! Pointer to the map holding the neuron monitors.*/
00192                 map<unsigned int, MonitorDataPlotter*> *neuronMonitorMap;
00193 
00194                 /*! Pointer to the map holding the synapse monitors.*/
00195                 map<unsigned int*, MonitorDataPlotter*, synapseKeyCompare> *synapseMonitorMap;
00196 
00197                 /*! The amount of time the simulation manager will wait for tasks to load their neuron data
00198                         This variable is set in the config file. */
00199                 int maxNeurDataLoadTime_sec;
00200 
00201 
00202                 //========================= METHODS ==============================
00203                 /*! Declare copy constructor private so it cannot be used inadvertently.*/
00204                 SimulationManager (const SimulationManager&);
00205 
00206                 /*! Declare assignment private so it cannot be used inadvertently.*/
00207                 SimulationManager operator = (const SimulationManager&);
00208 
00209                 bool checkNeuronGroupTasks();
00210                 void cleanUpErrorMsgReceived(int senderTID);
00211                 void cleanUpSimulation();
00212                 bool createTempVirtualConnections();
00213                 bool deleteTempVirtualConnections();
00214                 void initErrorMsgReceived(int senderTID);
00215                 StartSimRes loadNeuronData(map<unsigned int, unsigned int> patternInputMap, map<unsigned int, unsigned int> deviceInOutMap, map<unsigned int, double>deviceFiringModeMap, map<const char*, unsigned int> paramMap, QProgressDialog* progressDialog);
00216                 bool sendMessage(int taskID, int msgtag);
00217                 bool sendMessage(int taskID, int msgtag, unsigned int*, int arrayLength);
00218                 bool sendMessage(int taskID, int msgtag, int msgData);
00219                 bool sendMessage_unsigned(int taskID, int msgtag, unsigned int msgData);
00220                 bool sendMessage(int taskID, int msgtag, unsigned int msgData1, unsigned int msgData2);
00221                 bool sendMessage(int taskId, int msgtag, double [], int arrayLength);
00222                 void showErrorMessage(int senderTID);
00223                 void showErrorMessage(const char* msg);
00224                 void showInformationMessage();
00225                 bool spawnArchiveTask(const QString& archiveName, map<const char*, unsigned int>);
00226                 bool spawnNeuronGroupTasks();
00227                 bool startPvm();
00228                 void unpackMonitorNeuronData();
00229                 void unpackMonitorNeuronInfo();
00230                 void unpackMonitorSynapseData();
00231                 void unpackMonitorSynapseInfo();
00232                 void updateViewWeightsSavedState(int taskID);
00233                 void updateWeightsLoadedState(int taskID);
00234                 void updateWeightsSavedState(int taskID);
00235 
00236 };
00237 
00238 
00239 #endif//SIMULATIONMANAGER_H
00240 
00241 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4