MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TimeTable.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  ** This program is part of 'MOOSE', the
3  ** Messaging Object Oriented Simulation Environment,
4  ** also known as GENESIS 3 base code.
5  ** copyright (C) 2003-2006 Upinder S. Bhalla. and NCBS
6  ** It is made available under the terms of the
7  ** GNU Lesser General Public License version 2.1
8  ** See the file COPYING.LIB for the full notice.
9  **********************************************************************/
10 
11 
12 #include "header.h"
13 #include <fstream>
14 #include "TableBase.h"
15 #include "TimeTable.h"
16 
19  "eventOut",
20  "Sends out spike time if it falls in current timestep.");
21  return &eventOut;
22 }
23 
25 {
27  // Field definitions
29  static ValueFinfo< TimeTable, string > filename( "filename",
30  "File to read lookup data from. The file should be contain two columns\n"
31  "separated by any space character.",
34 
35  static ValueFinfo< TimeTable, int > method( "method",
36  "Method to use for filling up the entries. Currently only method 4\n"
37  "(loading from file) is supported.",
40 
41  static ReadOnlyValueFinfo <TimeTable, double> state( "state",
42  "Current state of the time table.",
44 
46  // MsgDest Definitions
48  static DestFinfo process("process",
49  "Handle process call",
51 
52  static DestFinfo reinit("reinit",
53  "Handles reinit call",
55 
57  // SharedMsg Definitions
59  static Finfo* procShared[] = {
60  &process, &reinit
61  };
62 
63  static SharedFinfo proc( "proc",
64  "Shared message for process and reinit",
65  procShared, sizeof( procShared ) / sizeof( const Finfo* ));
66 
67  static Finfo * timeTableFinfos[] = {
68  &filename,
69  &method,
70  &state,
71  eventOut(),
72  &proc,
73  };
74 
75  static string doc[] = {
76  "Name", "TimeTable",
77  "Author", "Johannes Hjorth, 2008, KTH, Stockholm. Ported to buildQ branch using new API by Subhasis Ray, NCBS, Bangalore, 2013.",
78  "Description", "TimeTable: Read in spike times from file and send out eventOut messages\n"
79  "at the specified times.",
80  };
81 
82  static Dinfo< TimeTable > dinfo;
83  static Cinfo timeTableCinfo(
84  "TimeTable",
86  timeTableFinfos,
87  sizeof( timeTableFinfos )/sizeof(Finfo *),
88  &dinfo,
89  doc,
90  sizeof(doc)/sizeof(string));
91 
92  return &timeTableCinfo;
93 }
94 
96 
98 // Class function definitions
100 
102  :
103  filename_(""),
104  state_( 0.0 ),
105  curPos_( 0 ),
106  method_( 4 )
107 { ; }
108 
110 { ; }
111 
113 // Field function definitions
115 
116 /* Filename */
118 {
119  return filename_;
120 }
121 
122 void TimeTable::setFilename( string filename )
123 {
124  filename_ = filename;
125 
126  std::ifstream fin( filename_.c_str() );
127  string line;
128 
129  if( !fin.good()) {
130  cout << "Error: TimeTable::innerload: Unable to open file"
131  << filename_ << endl;
132  }
133 
134  //~ If lines need to be skipped:
135  //~ for(unsigned int i = 0; (i < skipLines) & fin.good() ; i++)
136  //~ getline( fin, line );
137 
138  vec().clear();
139 
140  double dataPoint, dataPointOld = -1000;
141  while( fin >> dataPoint ) {
142  vec().push_back(dataPoint);
143 
144  if(dataPoint < dataPointOld) {
145  cerr << "TimeTable: Warning: Spike times in file " << filename_
146  << " are not in increasing order."
147  << endl;
148  }
149 
150  dataPointOld = dataPoint;
151  }
152 }
153 
154 /* Method */
155 void TimeTable::setMethod(int method )
156 {
157  if ( method != 4 ) {
158  cerr <<
159  "Error: TimeTable::setMethod: "
160  "Currently only method 4 (loading from file) supported.\n";
161  return;
162  }
163  method_ = method;
164 }
165 
167 {
168  return method_;
169 }
170 
171 /* state */
172 double TimeTable::getState() const
173 {
174  return state_;
175 }
176 
178 // Dest function definitions
180 
181 void TimeTable::reinit(const Eref& e, ProcPtr p)
182 {
183  curPos_ = 0;
184  state_ = 0;
185 }
186 
187 void TimeTable::process(const Eref& e, ProcPtr p)
188 {
189 
190  // Two ways of telling the world about the spike events, both
191  // happening in parallel
192  //
193  // state is a continous variable, switching from 0 to 1 when spiking
194  // event is an event, that happens at the time of a spike
195  //
196 
197  state_ = 0;
198 
199  if ( curPos_ < vec().size() &&
200  p->currTime >= vec()[curPos_] ) {
201  eventOut()->send( e, vec()[curPos_]);
202  curPos_++;
203  state_ = 1;
204  }
205 }
void setFilename(string filename)
Definition: TimeTable.cpp:122
static const Cinfo * initCinfo()
Definition: TimeTable.cpp:24
vector< double > & vec()
Definition: TableBase.cpp:492
double currTime
Definition: ProcInfo.h:19
int method_
Definition: TimeTable.h:57
Definition: Dinfo.h:60
double state_
Definition: TimeTable.h:50
void process(const Eref &e, ProcPtr p)
Definition: TimeTable.cpp:187
void setMethod(int method)
Definition: TimeTable.cpp:155
unsigned int curPos_
Definition: TimeTable.h:53
static const Cinfo * initCinfo()
Definition: TableBase.cpp:15
double getState() const
Definition: TimeTable.cpp:172
static const Cinfo * timeTableCinfo
Definition: TimeTable.cpp:95
Definition: Eref.h:26
void reinit(const Eref &e, ProcPtr p)
Definition: TimeTable.cpp:181
int getMethod() const
Definition: TimeTable.cpp:166
string getFilename() const
Definition: TimeTable.cpp:117
string filename_
Definition: TimeTable.h:44
static SrcFinfo1< double > * eventOut()
Definition: TimeTable.cpp:17
Definition: Cinfo.h:18
Definition: Finfo.h:12