SpikeStream Application Library  0.2
AbstractConnectionBuilder.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "AbstractConnectionBuilder.h"
00003 #include "Globals.h"
00004 #include "Network.h"
00005 #include "SpikeStreamException.h"
00006 using namespace spikestream;
00007 
00009 AbstractConnectionBuilder::AbstractConnectionBuilder(){
00010 }
00011 
00012 
00014 AbstractConnectionBuilder::~AbstractConnectionBuilder(){
00015 }
00016 
00017 
00018 /*----------------------------------------------------------*/
00019 /*-----                 PUBLIC METHODS                 -----*/
00020 /*----------------------------------------------------------*/
00021 
00023 void AbstractConnectionBuilder::run(){
00024         clearError();
00025         stopThread = false;
00026         newConnectionGroup = NULL;
00027 
00028         try{
00029                 //Seed the random number generator
00030                 srand(12345678);
00031 
00032                 //Create network and archive dao for this thread
00033                 Network* currentNetwork = Globals::getNetwork();
00034                 threadNetworkDao = new NetworkDao(Globals::getNetworkDao()->getDBInfo());
00035 
00036                 //Build connection group and add it to network
00037                 buildConnectionGroup();
00038                 if(stopThread)
00039                         return;
00040 
00041                 QList<ConnectionGroup*> conGrpList;
00042                 conGrpList.append(newConnectionGroup);
00043                 Globals::getNetwork()->addConnectionGroups(conGrpList);
00044 
00045                 //Wait for network to finish adding connection groups
00046                 while(currentNetwork->isBusy()){
00047                         emit progress(threadNetworkDao->getConnectionCount(newConnectionGroup), newConnectionGroup->size(), "Adding connections to database...");
00048                         if(stopThread)
00049                                 currentNetwork->cancel();
00050                         msleep(250);
00051                 }
00052 
00053                 //Check for errors
00054                 if(currentNetwork->isError())
00055                         setError(currentNetwork->getErrorMessage());
00056 
00057                 //Clean up network dao
00058                 delete threadNetworkDao;
00059         }
00060         catch (SpikeStreamException& ex){
00061                 setError(ex.getMessage());
00062         }
00063         catch(...){
00064                 setError("Abstract Connection Builder: An unknown error occurred.");
00065         }
00066 }
00067 
00068 
00070 void AbstractConnectionBuilder::startBuildConnectionGroup(const ConnectionGroupInfo& conGrpInfo){
00071         //Store information about the neuron group to be added
00072         this->connectionGroupInfo = conGrpInfo;
00073 
00074         //Check that the required parameters exist in the connection group and are in the appropriate range
00075         checkParameters();
00076 
00077         if(!Globals::networkLoaded())
00078                 throw SpikeStreamException("Cannot add connection group - no network loaded.");
00079 
00080         this->start();
00081 }
00082 
00083 
00084 /*----------------------------------------------------------*/
00085 /*-----                PROTECTED METHODS               -----*/
00086 /*----------------------------------------------------------*/
00087 
00089 double AbstractConnectionBuilder::getParameter(const QString& paramName){
00090         if(!connectionGroupInfo.hasParameter(paramName))
00091                 throw SpikeStreamException("Parameter with " + paramName + " does not exist in connection group's parameter map.");
00092         return connectionGroupInfo.getParameter(paramName);
00093 }
00094 
 All Classes Files Functions Variables Typedefs Friends Defines