MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Synapse.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) 2003-2009 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 "header.h"
11 #include "ElementValueFinfo.h"
12 #include "SynHandlerBase.h"
13 #include "Synapse.h"
14 
16 {
17  static ValueFinfo< Synapse, double > weight(
18  "weight",
19  "Synaptic weight",
22  );
23 
24  static ValueFinfo< Synapse, double > delay(
25  "delay",
26  "Axonal propagation delay to this synapse",
29  );
30  static ElementValueFinfo< Synapse, double > spikeTime(
31  "spikeTime",
32  "Value field interface to add spike (by assignment) and to "
33  "read the value of the spike on top of the queue.",
36  );
37 
38  static DestFinfo addSpike( "addSpike",
39  "Handles arriving spike messages, inserts into event queue.",
41 
42  static Finfo* synapseFinfos[] = {
43  &weight, // Field
44  &delay, // Field
45  &spikeTime, // ElementField
46  &addSpike, // DestFinfo
47  };
48 
49  static string doc[] =
50  {
51  "Name", "Synapse",
52  "Author", "Upi Bhalla",
53  "Description", "Synapse using ring buffer for events.",
54  };
55  static Dinfo< Synapse > dinfo;
56  static Cinfo synapseCinfo (
57  "Synapse",
59  synapseFinfos,
60  sizeof( synapseFinfos ) / sizeof ( Finfo* ),
61  &dinfo,
62  doc,
63  sizeof( doc ) / sizeof( string ),
64  true // This is a FieldElement.
65  );
66 
67  return &synapseCinfo;
68 }
69 
71 
73  : weight_( 1.0 ), delay_( 0.0 ), handler_( 0 )
74 {
75  ;
76 }
77 
78 void Synapse::setWeight( const double v )
79 {
80  weight_ = v;
81 }
82 
83 void Synapse::setDelay( const double v )
84 {
85  delay_ = v;
86 }
87 
88 double Synapse::getWeight() const
89 {
90  return weight_;
91 }
92 
93 double Synapse::getDelay() const
94 {
95  return delay_;
96 }
97 
99 {
100  handler_ = h;
101 }
102 
103 
104 void Synapse::addSpike( const Eref& e, double time )
105 {
106  static bool report = false;
107  static unsigned int tgtDataIndex = 0;
108  // static unsigned int tgtFieldIndex = 0;
109  if ( report && e.dataIndex() == tgtDataIndex ) {
110  cout << " " << time << "," << e.fieldIndex();
111  }
112  handler_->addSpike( e.fieldIndex(), time + delay_, weight_ );
113 }
114 
115 double Synapse::getTopSpike( const Eref& e ) const
116 {
117  return handler_->getTopSpike( e.fieldIndex() );
118 }
119 
121 // Callbacks for message add/drop
123 
124 // static function, executed by the Synapse Element when a message is
125 // added to the Element. Expands the parent synapse array to fit.
127  const Eref& e, const string& finfoName,
128  ObjId msg, unsigned int msgLookup )
129 {
130  if ( finfoName == "addSpike" ) {
131  ObjId pa = Neutral::parent( e );
132  SynHandlerBase* sh =
133  reinterpret_cast< SynHandlerBase* >( pa.data() );
134  unsigned int synapseNumber = sh->addSynapse();
136  msg, "fieldIndex", msgLookup, synapseNumber );
137  }
138 }
139 
140 // static function, executed by the Synapse Element when a message is
141 // dropped from the Element. Contracts the parent synapse array to fit.
142 // Typically the SynHandler won't resize, easier to just leave an
143 // unused entry. Could even reuse if a synapse is added later, but all
144 // this policy is independent of the Synapse class.
146  const Eref& e, const string& finfoName,
147  ObjId msg, unsigned int msgLookup )
148 {
149  if ( finfoName == "addSpike" ) {
150  ObjId pa = Neutral::parent( e );
151  SynHandlerBase* sh =
152  reinterpret_cast< SynHandlerBase* >( pa.data() );
153  sh->dropSynapse( msgLookup );
154  }
155 }
156 
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
static const Cinfo * synapseCinfo
Definition: Synapse.cpp:70
char * data() const
Definition: ObjId.cpp:113
virtual double getTopSpike(unsigned int index) const =0
void setWeight(double v)
Definition: Synapse.cpp:78
Definition: Dinfo.h:60
Definition: EpFunc.h:64
double getWeight() const
Definition: Synapse.cpp:88
unsigned int dataIndex() const
Definition: Eref.h:50
virtual unsigned int addSynapse()=0
Definition: ObjId.h:20
unsigned int fieldIndex() const
Definition: Eref.h:61
double delay_
Definition: Synapse.h:43
virtual void addSpike(unsigned int index, double time, double weight)=0
static const Cinfo * initCinfo()
Definition: Synapse.cpp:15
virtual void dropSynapse(unsigned int droppedSynNumber)=0
void addSpike(const Eref &e, double time)
Definition: Synapse.cpp:104
double weight_
Definition: Synapse.h:42
Definition: Eref.h:26
void setHandler(SynHandlerBase *h)
Definition: Synapse.cpp:98
double getTopSpike(const Eref &e) const
Definition: Synapse.cpp:115
static void addMsgCallback(const Eref &e, const string &finfoName, ObjId msg, unsigned int msgLookup)
Definition: Synapse.cpp:126
double getDelay() const
Definition: Synapse.cpp:93
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Synapse()
Definition: Synapse.cpp:72
static void dropMsgCallback(const Eref &e, const string &finfoName, ObjId msg, unsigned int msgLookup)
Definition: Synapse.cpp:145
void setDelay(double v)
Definition: Synapse.cpp:83
SynHandlerBase * handler_
Definition: Synapse.h:44
Definition: Cinfo.h:18
Definition: Finfo.h:12
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
Definition: SetGet.h:365