NEST main@caf0ae8
 
Loading...
Searching...
No Matches
secondary_event.h
Go to the documentation of this file.
1/*
2 * secondary_event.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef SECONDARY_EVENT_H
24#define SECONDARY_EVENT_H
25
26// Includes from nestkernel
27#include "event.h"
28
29// C++ includes
30#include <set>
31
32namespace nest
33{
34
49class SecondaryEvent : public Event
50{
51
52public:
53 SecondaryEvent* clone() const override = 0;
54
55 virtual void add_syn_id( const synindex synid ) = 0;
56
58 virtual size_t size() = 0;
59 virtual std::vector< unsigned int >::iterator& operator<<( std::vector< unsigned int >::iterator& pos ) = 0;
60 virtual std::vector< unsigned int >::iterator& operator>>( std::vector< unsigned int >::iterator& pos ) = 0;
61
62 virtual const std::set< synindex >& get_supported_syn_ids() const = 0;
63
64 virtual void reset_supported_syn_ids() = 0;
65};
66
73template < typename T >
74size_t
76{
77 size_t num_uints = sizeof( T ) / sizeof( unsigned int );
78 if ( num_uints * sizeof( unsigned int ) < sizeof( T ) )
79 {
80 num_uints += 1;
81 }
82 return num_uints;
83}
84
95template < typename T >
96void
97write_to_comm_buffer( T d, std::vector< unsigned int >::iterator& pos )
98{
99 // there is no aliasing problem here, since cast to char* invalidate strict
100 // aliasing assumptions
101 char* const c = reinterpret_cast< char* >( &d );
102
103 const size_t num_uints = number_of_uints_covered< T >();
104 size_t left_to_copy = sizeof( T );
105
106 for ( size_t i = 0; i < num_uints; i++ )
107 {
108 memcpy( &( *( pos + i ) ), c + i * sizeof( unsigned int ), std::min( left_to_copy, sizeof( unsigned int ) ) );
109 left_to_copy -= sizeof( unsigned int );
110 }
111
112 pos += num_uints;
113}
114
122template < typename T >
123void
124read_from_comm_buffer( T& d, std::vector< unsigned int >::iterator& pos )
125{
126 // there is no aliasing problem here, since cast to char* invalidate strict
127 // aliasing assumptions
128 char* const c = reinterpret_cast< char* >( &d );
129
130 const size_t num_uints = number_of_uints_covered< T >();
131 size_t left_to_copy = sizeof( T );
132
133 for ( size_t i = 0; i < num_uints; i++ )
134 {
135 memcpy( c + i * sizeof( unsigned int ), &( *( pos + i ) ), std::min( left_to_copy, sizeof( unsigned int ) ) );
136 left_to_copy -= sizeof( unsigned int );
137 }
138
139 pos += num_uints;
140}
141
163template < typename DataType, typename Subclass >
165{
166private:
167 static std::set< synindex > supported_syn_ids_;
168 static size_t coeff_length_; // length of coeffarray
169
171 {
172 std::vector< unsigned int >::iterator as_uint;
173 typename std::vector< DataType >::iterator as_DataType;
174
175 CoeffarrayBegin() {}; // need to provide default constructor due to
176 // non-trivial constructors of iterators
178
180 {
181 std::vector< unsigned int >::iterator as_uint;
182 typename std::vector< DataType >::iterator as_DataType;
183
184 CoeffarrayEnd() {}; // need to provide default constructor due to
185 // non-trivial constructors of iterators
187
188public:
200 void add_syn_id( const synindex synid ) override;
201
202 const std::set< synindex >&
203 get_supported_syn_ids() const override
204 {
205 return supported_syn_ids_;
206 }
207
215 void
217 {
218 supported_syn_ids_.clear();
219 }
220
221 static void set_coeff_length( const size_t coeff_length );
222
223 void
224 set_coeffarray( std::vector< DataType >& ca )
225 {
226 coeffarray_begin_.as_DataType = ca.begin();
227 coeffarray_end_.as_DataType = ca.end();
228 assert( coeff_length_ == ca.size() );
229 }
230
235 std::vector< unsigned int >::iterator&
236 operator<<( std::vector< unsigned int >::iterator& pos ) override
237 {
238 // The synid can be skipped here as it is stored in a static vector
239
240 // generating a copy of the coeffarray is too time consuming
241 // therefore we save an iterator to the beginning+end of the coeffarray
243
244 pos += coeff_length_ * number_of_uints_covered< DataType >();
245
247
248 return pos;
249 }
250
257 std::vector< unsigned int >::iterator&
258 operator>>( std::vector< unsigned int >::iterator& pos ) override
259 {
260 for ( auto it = coeffarray_begin_.as_DataType; it != coeffarray_end_.as_DataType; ++it )
261 {
262 // we need the static_cast here as the size of a stand-alone variable
263 // and a std::vector entry may differ (e.g. for std::vector< bool >)
264 write_to_comm_buffer( static_cast< DataType >( *it ), pos );
265 }
266 return pos;
267 }
268
269 size_t
270 size() override
271 {
272 size_t s = number_of_uints_covered< synindex >();
273 s += number_of_uints_covered< size_t >();
274 s += number_of_uints_covered< DataType >() * coeff_length_;
275
276 return s;
277 }
278
279 const std::vector< unsigned int >::iterator&
281 {
283 }
284
285 const std::vector< unsigned int >::iterator&
287 {
289 }
290
291 DataType get_coeffvalue( std::vector< unsigned int >::iterator& pos );
292};
293
298class GapJunctionEvent : public DataSecondaryEvent< double, GapJunctionEvent >
299{
300
301public:
303 {
304 }
305
306 void operator()() override;
307 GapJunctionEvent* clone() const override;
308};
309
314class InstantaneousRateConnectionEvent : public DataSecondaryEvent< double, InstantaneousRateConnectionEvent >
315{
316
317public:
321
322 void operator()() override;
323 InstantaneousRateConnectionEvent* clone() const override;
324};
325
330class DelayedRateConnectionEvent : public DataSecondaryEvent< double, DelayedRateConnectionEvent >
331{
332
333public:
337
338 void operator()() override;
339 DelayedRateConnectionEvent* clone() const override;
340};
341
342
347class DiffusionConnectionEvent : public DataSecondaryEvent< double, DiffusionConnectionEvent >
348{
349private:
350 // drift factor of the corresponding connection
352 // diffusion factor of the corresponding connection
354
355public:
359
360 void operator()() override;
361 DiffusionConnectionEvent* clone() const override;
362
363 void
364 set_diffusion_factor( double t ) override
365 {
367 };
368
369 void
370 set_drift_factor( double t ) override
371 {
372 drift_factor_ = t;
373 };
374
375 double get_drift_factor() const;
376 double get_diffusion_factor() const;
377};
378
383class LearningSignalConnectionEvent : public DataSecondaryEvent< double, LearningSignalConnectionEvent >
384{
385
386public:
390
391 void operator()() override;
392 LearningSignalConnectionEvent* clone() const override;
393};
394
395template < typename DataType, typename Subclass >
396inline DataType
397DataSecondaryEvent< DataType, Subclass >::get_coeffvalue( std::vector< unsigned int >::iterator& pos )
398{
399 DataType elem;
400 read_from_comm_buffer( elem, pos );
401 return elem;
402}
403
404template < typename DataType, typename Subclass >
406
407template < typename DataType, typename Subclass >
409
410inline GapJunctionEvent*
412{
413 return new GapJunctionEvent( *this );
414}
415
421
424{
425 return new DelayedRateConnectionEvent( *this );
426}
427
430{
431 return new DiffusionConnectionEvent( *this );
432}
433
434inline double
439
440inline double
445
451
457class SICEvent : public DataSecondaryEvent< double, SICEvent >
458{
459
460public:
462 {
463 }
464
465 void operator()();
466 SICEvent* clone() const;
467};
468
469inline SICEvent*
471{
472 return new SICEvent( *this );
473}
474
475} // namespace nest
476
477#endif /* #ifndef SECONDARY_EVENT_H */
Template class for the storage and communication of a std::vector of type DataType.
Definition secondary_event.h:165
static std::set< synindex > supported_syn_ids_
Definition secondary_event.h:167
size_t size() override
size of event in units of unsigned int
Definition secondary_event.h:270
void reset_supported_syn_ids() override
Resets the vector of supported syn ids to those originally registered via ModelsModule or user define...
Definition secondary_event.h:216
static size_t coeff_length_
Definition secondary_event.h:168
void set_coeffarray(std::vector< DataType > &ca)
Definition secondary_event.h:224
union nest::DataSecondaryEvent::CoeffarrayEnd coeffarray_end_
union nest::DataSecondaryEvent::CoeffarrayBegin coeffarray_begin_
static void set_coeff_length(const size_t coeff_length)
Definition secondary_event_impl.h:50
DataType get_coeffvalue(std::vector< unsigned int >::iterator &pos)
Definition secondary_event.h:397
const std::vector< unsignedint >::iterator & end()
Definition secondary_event.h:286
void add_syn_id(const synindex synid) override
This function adds the ids of connection models that use this event type.
Definition secondary_event_impl.h:33
std::vector< unsignedint >::iterator & operator>>(std::vector< unsigned int >::iterator &pos) override
The following operator is used to write the information of the DataSecondaryEvent into the secondary_...
Definition secondary_event.h:258
std::vector< unsignedint >::iterator & operator<<(std::vector< unsigned int >::iterator &pos) override
The following operator is used to read the information of the DataSecondaryEvent from the buffer in E...
Definition secondary_event.h:236
const std::vector< unsignedint >::iterator & begin()
Definition secondary_event.h:280
const std::set< synindex > & get_supported_syn_ids() const override
Definition secondary_event.h:203
Event for rate model connections with delay.
Definition secondary_event.h:331
void operator()() override
Deliver the event to receiver.
Definition event.cpp:143
DelayedRateConnectionEvent * clone() const override
Definition secondary_event.h:423
DelayedRateConnectionEvent()
Definition secondary_event.h:334
Event for diffusion connections (rate model connections for the siegert_neuron).
Definition secondary_event.h:348
DiffusionConnectionEvent * clone() const override
Definition secondary_event.h:429
DiffusionConnectionEvent()
Definition secondary_event.h:356
void set_diffusion_factor(double t) override
Set diffusion_factor of the event (see DiffusionConnectionEvent).
Definition secondary_event.h:364
double get_diffusion_factor() const
Definition secondary_event.h:441
void set_drift_factor(double t) override
Set drift_factor of the event (see DiffusionConnectionEvent).
Definition secondary_event.h:370
double diffusion_factor_
Definition secondary_event.h:353
double drift_factor_
Definition secondary_event.h:351
void operator()() override
Deliver the event to receiver.
Definition event.cpp:149
double get_drift_factor() const
Definition secondary_event.h:435
Encapsulate information sent between nodes.
Definition event.h:103
Event for gap-junction information.
Definition secondary_event.h:299
GapJunctionEvent()
Definition secondary_event.h:302
GapJunctionEvent * clone() const override
Definition secondary_event.h:411
void operator()() override
Deliver the event to receiver.
Definition event.cpp:131
Event for rate model connections without delay.
Definition secondary_event.h:315
InstantaneousRateConnectionEvent()
Definition secondary_event.h:318
void operator()() override
Deliver the event to receiver.
Definition event.cpp:137
InstantaneousRateConnectionEvent * clone() const override
Definition secondary_event.h:417
Event for learning signal connections.
Definition secondary_event.h:384
LearningSignalConnectionEvent()
Definition secondary_event.h:387
void operator()() override
Deliver the event to receiver.
Definition event.cpp:155
LearningSignalConnectionEvent * clone() const override
Definition secondary_event.h:447
Event for slow inward current (SIC) connections between astrocytes and neurons.
Definition secondary_event.h:458
SICEvent()
Definition secondary_event.h:461
void operator()()
Deliver the event to receiver.
Definition event.cpp:161
SICEvent * clone() const
Definition secondary_event.h:470
Base class of secondary events.
Definition secondary_event.h:50
SecondaryEvent * clone() const override=0
virtual size_t size()=0
size of event in units of unsigned int
virtual const std::set< synindex > & get_supported_syn_ids() const =0
virtual void reset_supported_syn_ids()=0
virtual void add_syn_id(const synindex synid)=0
virtual std::vector< unsignedint >::iterator & operator>>(std::vector< unsigned int >::iterator &pos)=0
virtual std::vector< unsignedint >::iterator & operator<<(std::vector< unsigned int >::iterator &pos)=0
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
size_t number_of_uints_covered()
This template function returns the number of uints covered by a variable of type T.
Definition secondary_event.h:75
void write_to_comm_buffer(T d, std::vector< unsigned int >::iterator &pos)
This template function writes data of type T to a given position of a std::vector< unsigned int >.
Definition secondary_event.h:97
void read_from_comm_buffer(T &d, std::vector< unsigned int >::iterator &pos)
This template function reads data of type T from a given position of a std::vector< unsigned int >.
Definition secondary_event.h:124
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:115
Definition secondary_event.h:171
std::vector< unsignedint >::iterator as_uint
Definition secondary_event.h:172
CoeffarrayBegin()
Definition secondary_event.h:175
std::vector< DataType >::iterator as_DataType
Definition secondary_event.h:173
Definition secondary_event.h:180
CoeffarrayEnd()
Definition secondary_event.h:184
std::vector< DataType >::iterator as_DataType
Definition secondary_event.h:182
std::vector< unsignedint >::iterator as_uint
Definition secondary_event.h:181