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

SpikeStreamArchiver.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Archiver                                                  *
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 SPIKESTREAMARCHIVER_H
00024 #define SPIKESTREAMARCHIVER_H
00025 
00026 //SpikeStream includes
00027 #include "DBInterface.h"
00028 #include "GlobalVariables.h"
00029 
00030 //Other includes
00031 #include "mysql++.h"
00032 #include <string>
00033 
00034 
00035 /*! Holds data from a time step when messages have not yet been received
00036         from all neuron groups.*/
00037 struct TimeStepHolder {
00038         unsigned int spikeMessageCount;
00039         string xmlString;
00040 };
00041 
00042 
00043 //------------------------- SpikeStream Archiver ---------------------------
00044 /*! Main class for the archiver that records firing neuron or spike patterns 
00045         in the database. Patterns are stored as a model XML file, which records 
00046         the structure of the neural network, and data XML files that record the 
00047         firing or spike pattern of the network at each time step.
00048 */
00049 //      FIXME CONVERT TO DENSE_HASH_MAP FOR SPEED 
00050 //--------------------------------------------------------------------------*/
00051 
00052 class SpikeStreamArchiver {
00053 
00054         public:
00055                 SpikeStreamArchiver(int argc, char **argv);
00056                 ~SpikeStreamArchiver();
00057                 static void systemError(const string &message);
00058                 static void systemError(const char *message, int messageData1);
00059                 static void systemError(const char *message);
00060 
00061 
00062         private: 
00063                 //======================== VARIABLES ==============================
00064                 /*! PVM task id of this process */
00065                 int myTaskID;
00066 
00067                 /*! PVM task id of the process that spawned this process. Static so
00068                         that it can be used in the static systemError methods. */
00069                 static int parentTaskID;
00070 
00071                 /*! Reference to archive database handling class. */
00072                 DBInterface *archiveDBInterface;
00073 
00074                 /*! Reference to network database handling class. */
00075                 DBInterface *neuralNetworkDBInterface;
00076 
00077                 /*! Controls whether the main run method is running. */
00078                 bool stop;
00079                 
00080                 /*! A network model is stored at the beginning of each simulation run.
00081                         This variable keeps track of whether any network data has been stored
00082                         for this archive. If not, then the network model is deleted
00083                         when this task exits to avoid the build up of empty archives.*/
00084                 bool networkDataStored;
00085                 
00086                 /*! Controls whether the archive records firing neurons or spikes. */
00087                 unsigned int archiveType;       
00088 
00089                 /*! The sum of the task ids from the neuron groups that send data
00090                         to this class. Used to keeps track of whether all messages 
00091                         have been received. */
00092                 unsigned int spikeMessageTotal;
00093 
00094                 /*! Records the link between taskIDs and neuron groups IDs
00095                         The key is the taskID, the data is the neuronGrpID. */
00096                 map<int, unsigned int> taskToNeuronGrpMap;
00097 
00098                 /*! Holds the time step holders for each time step. These are
00099                         removed when all messages have been received for the time
00100                         step. */
00101                 map<unsigned int, TimeStepHolder> timeStepMap;
00102 
00103                 /*! Holds all the currently firing neurons.
00104                         Use a map for this to eliminate duplicates */
00105                 map<unsigned int, bool> firingNeuronMap;
00106 
00107                 /*! Used to unpack the number of spikes from a message.
00108                         Declare it here to save declaring it each
00109                         time a message is received. */
00110                 unsigned int numberOfSpikes;
00111 
00112                 /*! Array to unpack the spikes or neuron ids into. */
00113                 unsigned int* unpackArray;
00114 
00115                 /*! Define integer here to extract from neuron id. */
00116                 unsigned int unpkFromNeurID;
00117 
00118                 /*! Keeps track of the time step in the current and previous messages. */
00119                 unsigned int messageTimeStep;
00120 
00121                 /*! Records when the simulation is started. This is used to link the model
00122                         and data files for a simulation run. */
00123                 unsigned int simulationStartTime;
00124 
00125 
00126                 /*! Name of the archive. */
00127                 char archiveName[MAX_DATABASE_NAME_LENGTH];
00128 
00129 
00130                 /*! Holds the start neuron ID for each task processing neurons 
00131                         The key is the task id, the data is the start neuron id of that neuron group. */
00132                 map<int, unsigned int> startNeurIDTaskMap;
00133 
00134                 /*! When the archiver has an error it enters error state, waits for an exit 
00135                         message and then exits. This is to enable the Simulation Manager to clean up
00136                         properly. */
00137                 static bool errorState;
00138 
00139 
00140                 //========================= METHODS ==================================
00141                 /*! Declare copy constructor private so that it cannot be used inadvertently.*/
00142                 SpikeStreamArchiver(const SpikeStreamArchiver&);
00143 
00144                 /*! Declare assignment private so that it cannot be used inadvertently.*/
00145                 SpikeStreamArchiver operator = (const SpikeStreamArchiver&);
00146 
00147                 bool archiveNeuralNetwork();
00148                 void cleanUpArchiver();
00149                 string getString(unsigned int);
00150                 bool loadTaskIDs();
00151                 void processFiringNeuronList(int senderTID);
00152                 void processSpikeList(int senderTID);
00153                 void run();
00154                 static bool sendMessage(int taskID, int msgtag);
00155                 static bool sendMessage(int taskId, int msgtag, unsigned int msgInteger);
00156                 static bool sendMessage(int taskID, int msgtag, const char* charArray);
00157                 void startArchiving();
00158                 void stopArchiving();
00159                 bool storeNetworkData(unsigned int unixTime, string networkDataString);
00160 
00161 };
00162 
00163 
00164 #endif //SPIKESTREAMARCHIVER_H
00165 
00166 

Generated on Mon Sep 3 22:09:16 2007 for SpikeStream Archiver by  doxygen 1.4.4