MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SimpleSynHandler.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2011 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include <queue>
11 #include "header.h"
12 #include "Synapse.h"
13 #include "SynEvent.h"
14 #include "SynHandlerBase.h"
15 #include "SimpleSynHandler.h"
16 
18 {
19  static string doc[] =
20  {
21  "Name", "SimpleSynHandler",
22  "Author", "Upi Bhalla",
23  "Description",
24  "The SimpleSynHandler handles simple synapses without plasticity. "
25  "It uses a priority queue to manage them."
26  };
27 
29  "synapse",
30  "Sets up field Elements for synapse",
35  );
36 
37  static Finfo* synHandlerFinfos[] = {
38  &synFinfo // FieldElement
39  };
40 
41  static Dinfo< SimpleSynHandler > dinfo;
42  static Cinfo synHandlerCinfo (
43  "SimpleSynHandler",
45  synHandlerFinfos,
46  sizeof( synHandlerFinfos ) / sizeof ( Finfo* ),
47  &dinfo,
48  doc,
49  sizeof( doc ) / sizeof( string )
50  );
51 
52  return &synHandlerCinfo;
53 }
54 
56 
58 { ; }
59 
61 { ; }
62 
64 {
65  synapses_ = ssh.synapses_;
66  for ( vector< Synapse >::iterator
67  i = synapses_.begin(); i != synapses_.end(); ++i )
68  i->setHandler( this );
69 
70  // For no apparent reason, priority queues don't have a clear operation.
71  while( !events_.empty() )
72  events_.pop();
73 
74  return *this;
75 }
76 
77 void SimpleSynHandler::vSetNumSynapses( const unsigned int v )
78 {
79  unsigned int prevSize = synapses_.size();
80  synapses_.resize( v );
81  for ( unsigned int i = prevSize; i < v; ++i )
82  synapses_[i].setHandler( this );
83 }
84 
86 {
87  return synapses_.size();
88 }
89 
91 {
92  static Synapse dummy;
93  if ( i < synapses_.size() )
94  return &synapses_[i];
95  cout << "Warning: SimpleSynHandler::getSynapse: index: " << i <<
96  " is out of range: " << synapses_.size() << endl;
97  return &dummy;
98 }
99 
101  unsigned int index, double time, double weight )
102 {
103  assert( index < synapses_.size() );
104  events_.push( SynEvent( time, weight ) );
105 }
106 
107 double SimpleSynHandler::getTopSpike( unsigned int index ) const
108 {
109  if ( events_.empty() )
110  return 0.0;
111  return events_.top().time;
112 }
113 
115 {
116  double activation = 0.0;
117  while( !events_.empty() && events_.top().time <= p->currTime ) {
118  // Send out weight / dt for every spike
119  // Since it is an impulse active only for one dt,
120  // need to send it divided by dt.
121  // Can connect activation to SynChan (double exp)
122  // or to LIF as an impulse to voltage.
123  // See: http://www.genesis-sim.org/GENESIS/Hyperdoc/Manual-26.html#synchan
124  activation += events_.top().weight / p->dt;
125  events_.pop();
126  }
127  if ( activation != 0.0 )
128  SynHandlerBase::activationOut()->send( e, activation );
129 }
130 
132 {
133  // For no apparent reason, priority queues don't have a clear operation.
134  while( !events_.empty() )
135  events_.pop();
136 }
137 
139 {
140  unsigned int newSynIndex = synapses_.size();
141  synapses_.resize( newSynIndex + 1 );
142  synapses_[newSynIndex].setHandler( this );
143  return newSynIndex;
144 }
145 
146 
147 void SimpleSynHandler::dropSynapse( unsigned int msgLookup )
148 {
149  assert( msgLookup < synapses_.size() );
150  synapses_[msgLookup].setWeight( -1.0 );
151 }
void setNumSynapses(unsigned int num)
double currTime
Definition: ProcInfo.h:19
Definition: Dinfo.h:60
static DestFinfo dummy("dummy","This Finfo is a dummy. If you are reading this you have used an invalid index", 0)
void dropSynapse(unsigned int droppedSynNumber)
unsigned int getNumSynapses() const
double getTopSpike(unsigned int index) const
SimpleSynHandler & operator=(const SimpleSynHandler &other)
static const Cinfo * initCinfo()
Synapse * getSynapse(unsigned int i)
priority_queue< SynEvent, vector< SynEvent >, CompareSynEvent > events_
static const Cinfo * initCinfo()
Definition: Synapse.cpp:15
void addSpike(unsigned int index, double time, double weight)
vector< Synapse > synapses_
void vProcess(const Eref &e, ProcPtr p)
double dt
Definition: ProcInfo.h:18
Definition: Eref.h:26
void vSetNumSynapses(unsigned int num)
void vReinit(const Eref &e, ProcPtr p)
unsigned int vGetNumSynapses() const
unsigned int addSynapse()
Adds a new synapse, returns its index.
static SrcFinfo1< double > * activationOut()
static const Cinfo * initCinfo()
Synapse * vGetSynapse(unsigned int i)
static const Cinfo * synHandlerCinfo
Definition: Cinfo.h:18
Definition: Finfo.h:12