NEST  2.6.0,not_revisioned_source_dir@0
event.h
Go to the documentation of this file.
1 /*
2  * 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 EVENT_H
24 #define EVENT_H
25 
26 #include <cassert>
27 
28 #include "nest.h"
29 #include "nest_time.h"
30 #include "lockptr.h"
31 #include "exceptions.h"
32 #include "name.h"
33 
34 namespace nest{
35 
36  class Node;
37 
73  class Event {
74 
75  public:
76 
77  Event();
78 
79  virtual
80  ~Event(){}
81 
85  virtual
86  Event* clone() const=0;
87 
94  virtual
95  void operator()() = 0;
96 
100  void set_receiver(Node &);
101 
105  Node & get_receiver() const;
106 
110  Node & get_sender() const;
111 
115  void set_sender(Node &);
116 
120  index get_sender_gid() const;
121 
125  void set_sender_gid(index);
126 
135  Time const& get_stamp() const;
136 
144  void set_delay(delay);
145 
151  delay get_delay() const;
152 
153  delay get_max_delay() const;
154 
166  long_t get_rel_delivery_steps(const Time& t) const;
167 
175  port get_port() const;
176 
183  rport get_rport() const;
184 
193  void set_port(port p);
194 
203  void set_rport(rport p);
204 
212  double_t get_offset() const;
213 
222  void set_offset(double_t t);
223 
227  weight get_weight() const;
228 
232  void set_weight(weight t);
233 
239  bool is_valid() const;
240 
246  void set_stamp(Time const &);
247 
248  protected:
250  /*
251  * The original formulation used references to Nodes as
252  * members, however, in order to avoid the reference of reference
253  * problem, we store sender and receiver as pointers and use
254  * references in the interface.
255  * Thus, we can still ensure that the pointers are never NULL.
256  */
259 
260 
261 
271 
282 
290 
297 
305  double offset_;
306 
311  };
312 
313 
314  // Built-in event types
315 
320  class SpikeEvent: public Event
321  {
322  public:
323  SpikeEvent();
324  void operator()();
325  SpikeEvent* clone() const;
326 
327  void set_multiplicity(int_t);
328  int_t get_multiplicity() const;
329 
330  protected:
332  };
333 
334  inline
336  : multiplicity_(1)
337  {}
338 
339  inline
341  {
342  return new SpikeEvent(*this);
343  }
344 
345  inline
347  {
348  multiplicity_=multiplicity;
349  }
350 
351  inline
353  {
354  return multiplicity_;
355  }
356 
357 
374  class DSSpikeEvent : public SpikeEvent
375  {
376  public:
377  void operator()();
378  };
379 
387  class RateEvent: public Event
388  {
390  public:
391  void operator()();
392  RateEvent* clone() const;
393 
394  void set_rate(double_t);
395  double_t get_rate() const;
396  };
397 
398  inline
400  {
401  return new RateEvent(*this);
402  }
403 
404  inline
406  {
407  r_=r;
408  }
409 
410  inline
412  {
413  return r_;
414  }
415 
420  class CurrentEvent: public Event
421  {
423  public:
424  void operator()();
425  CurrentEvent* clone() const;
426 
427  void set_current(double_t);
428  double_t get_current() const;
429  };
430 
431  inline
433  {
434  return new CurrentEvent(*this);
435  }
436 
437  inline
439  {
440  c_ = c;
441  }
442 
443  inline
445  {
446  return c_;
447  }
448 
466  {
467  public:
468  void operator()();
469  };
470 
486  class DataLoggingRequest : public Event
487  {
488  public:
491 
493  DataLoggingRequest(const Time&, const std::vector<Name>&);
494 
495  DataLoggingRequest* clone() const;
496 
497  void operator()();
498 
500  const Time& get_recording_interval() const;
501 
503  const std::vector<Name>& record_from() const;
504 
505  private:
506 
509 
514  std::vector<Name> const * const record_from_;
515  };
516 
517  inline
519  : Event(),
520  recording_interval_(Time::neg_inf()),
521  record_from_(0)
522  {}
523 
524  inline
526  const std::vector<Name>& recs)
527  : Event(),
528  recording_interval_(rec_int),
529  record_from_(&recs)
530  {}
531 
532  inline
534  {
535  return new DataLoggingRequest(*this);
536  }
537 
538  inline
540  {
541  // During simulation, events are created without recording interval
542  // information. On these, get_recording_interval() must not be called.
544 
545  return recording_interval_;
546  }
547 
548  inline
549  const std::vector<Name>& DataLoggingRequest::record_from() const
550  {
551  // During simulation, events are created without recordables
552  // information. On these, record_from() must not be called.
553  assert(record_from_ != 0);
554 
555  return *record_from_;
556  }
557 
563  class DataLoggingReply : public Event
564  {
565  public:
567  typedef std::vector<double_t> DataItem;
568 
576  struct Item {
577  Item(size_t n) : data(n, std::numeric_limits<double_t>::max()),
578  timestamp(Time::neg_inf()) {}
581  };
582 
584  typedef std::vector<Item> Container;
585 
587  DataLoggingReply(const Container&);
588 
589  void operator()();
590 
592  const Container& get_info() const { return info_; }
593 
594  private:
597 
599  DataLoggingReply* clone() const { assert(false); return 0; }
600 
602  const Container& info_;
603  };
604 
605  inline
607  : Event(),
608  info_(d)
609  {}
610 
616  class ConductanceEvent: public Event
617  {
619  public:
620  void operator()();
621  ConductanceEvent* clone() const;
622 
624  double_t get_conductance() const;
625  };
626 
627  inline
629  {
630  return new ConductanceEvent(*this);
631  }
632 
633  inline
635  {
636  g_=g;
637  }
638 
639  inline
641  {
642  return g_;
643  }
644 
645 
661  template<typename D>
662  class DataEvent: public Event
663  {
665 
666  public:
667  void set_pointer(D &data);
668  lockPTR<D> get_pointer() const;
669  };
670 
671  template<typename D>
672  inline
674  {
675  data_ = data;
676  }
677 
678  template<typename D>
679  inline
681  {
682  return data_;
683  }
684 
685  class DoubleDataEvent: public DataEvent<double>
686  {
687  public:
688  void operator()();
689  DoubleDataEvent* clone() const;
690  };
691 
692  inline
694  {
695  return new DoubleDataEvent(*this);
696  }
697 
698  //*************************************************************
699  // Inline implementations.
700 
701  inline
702  bool Event::is_valid() const
703  {
704  return ( (sender_ != NULL) && (receiver_ != NULL) && (d_ > 0));
705  }
706 
707  inline
709  {
710  receiver_= &r;
711  }
712 
713  inline
715  {
716  sender_= &s;
717  }
718 
719  inline
721  {
722  sender_gid_ = gid;
723  }
724 
725  inline
726  Node & Event::get_receiver(void) const
727  {
728  return *receiver_;
729  }
730 
731  inline
732  Node & Event::get_sender(void) const
733  {
734  return *sender_;
735  }
736 
737  inline
739  {
740  assert(sender_gid_ > 0);
741  return sender_gid_;
742  }
743 
744  inline
746  {
747  return w_;
748  }
749 
750  inline
752  {
753  w_=w;
754  }
755 
756  inline
757  Time const & Event::get_stamp() const
758  {
759  return stamp_;
760  }
761 
762  inline
763  void Event::set_stamp(Time const & s)
764  {
765  stamp_ = s;
766  }
767 
768  inline
770  {
771  return d_;
772  }
773 
774  inline
776  {
777  return stamp_.get_steps() + d_ - 1 - t.get_steps();
778  }
779 
780  inline
782  {
783  d_=d;
784  }
785 
786  inline
788  {
789  return offset_;
790  }
791 
792  inline
794  {
795  offset_=t;
796  }
797 
798  inline
800  {
801  return p_;
802  }
803 
804  inline
806  {
807  return rp_;
808  }
809 
810  inline
812  {
813  p_=p;
814  }
815 
816  inline
818  {
819  rp_=rp;
820  }
821 }
822 
823 #endif //EVENT_H
std::vector< double_t > DataItem
Data type data at single recording time.
Definition: event.h:567
void operator()()
Deliver the event to receiver.
Definition: event.cpp:101
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
void set_rport(rport p)
Set the receiver port number (r-port).
Definition: event.h:817
double_t weight
Weight of a connection.
Definition: nest.h:170
int int_t
Integer number with at least 16 bit.
Definition: nest.h:95
void set_receiver(Node &)
Change pointer to receiving Node.
Definition: event.h:708
const Name g("g")
Conductance.
Definition: nest_names.h:144
double_t r_
Definition: event.h:389
RateEvent * clone() const
Virtual copy constructor.
Definition: event.h:399
double_t get_rate() const
Definition: event.h:411
Node & get_receiver() const
Return reference to receiving Node.
Definition: event.h:726
void operator()()
Deliver the event to receiver.
Definition: event.cpp:65
Time timestamp
Definition: event.h:580
Time recording_interval_
Interval between two recordings, first is step 1.
Definition: event.h:508
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
"Callback request event" for use in Device.
Definition: event.h:374
ConductanceEvent * clone() const
Virtual copy constructor.
Definition: event.h:628
void set_conductance(double_t)
Definition: event.h:634
DataLoggingRequest * clone() const
Virtual copy constructor.
Definition: event.h:533
Node * receiver_
Pointer to receiver or NULL.
Definition: event.h:258
void set_sender(Node &)
Change pointer to sending Node.
Definition: event.h:714
lockPTR< D > data_
Definition: event.h:664
Encapsulates information which is sent between Nodes.
Definition: event.h:73
Event for transmitting arbitrary data.
Definition: event.h:662
delay get_steps() const
Definition: nest_time.h:395
SpikeEvent()
Definition: event.h:335
DoubleDataEvent * clone() const
Virtual copy constructor.
Definition: event.h:693
port get_port() const
Return the sender port number of the event.
Definition: event.h:799
void set_weight(weight t)
Set weight of the event.
Definition: event.h:751
double_t c_
Definition: event.h:422
void set_sender_gid(index)
Change GID of sending Node.
Definition: event.h:720
rport rp_
Receiver port number (r-port).
Definition: event.h:281
Event for electrical currents.
Definition: event.h:420
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
Node & get_sender() const
Return reference to sending Node.
Definition: event.h:732
double_t g_
Definition: event.h:618
const std::vector< Name > & record_from() const
Access to vector of recordables.
Definition: event.h:549
Time stamp_
Time stamp.
Definition: event.h:296
assert(pNet!=0)
void operator()()
Deliver the event to receiver.
Definition: event.cpp:107
void operator()()
Deliver the event to receiver.
Definition: event.cpp:95
SpikeEvent * clone() const
Virtual copy constructor.
Definition: event.h:340
void operator()()
Deliver the event to receiver.
Definition: event.cpp:71
void operator()()
Deliver the event to receiver.
Definition: event.cpp:89
double_t get_offset() const
Return the creation time offset of the Event.
Definition: event.h:787
void set_offset(double_t t)
Set the creation time of the Event.
Definition: event.h:793
const Name std("std")
Miscellaneous parameters.
Definition: nest_names.h:265
index sender_gid_
GID of sender or -1.
Definition: event.h:249
const Name w("w")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:343
index get_sender_gid() const
Return GID of sending Node.
Definition: event.h:738
Provide logged data through request transmitting reference.
Definition: event.h:563
int_t get_multiplicity() const
Definition: event.h:352
Definition: nest_time.h:130
long_t get_rel_delivery_steps(const Time &t) const
Relative spike delivery time in steps.
Definition: event.h:775
void set_delay(delay)
Set the transmission delay of the event.
Definition: event.h:781
int_t multiplicity_
Definition: event.h:331
weight w_
Weight of the connection.
Definition: event.h:310
bool is_valid() const
Check integrity of the event.
Definition: event.h:702
void set_current(double_t)
Definition: event.h:438
void operator()()
Deliver the event to receiver.
Definition: event.cpp:83
void set_port(port p)
Set the port number.
Definition: event.h:811
void operator()()
Deliver the event to receiver.
Definition: event.cpp:113
Time const & get_stamp() const
Return time stamp of the event.
Definition: event.h:757
const Time & get_recording_interval() const
Access to stored time interval.
Definition: event.h:539
const Container & info_
data to be transmitted, with time stamps
Definition: event.h:602
DataLoggingReply * clone() const
Prohibit cloning.
Definition: event.h:599
void set_multiplicity(int_t)
Definition: event.h:346
std::vector< Name > const *const record_from_
Names of properties to record from.
Definition: event.h:514
weight get_weight() const
Return the weight.
Definition: event.h:745
void set_rate(double_t)
Definition: event.h:405
delay get_max_delay() const
Definition: event.cpp:55
void operator()()
Deliver the event to receiver.
Definition: event.cpp:77
Event for firing rate information.
Definition: event.h:387
lockPTR< D > get_pointer() const
Definition: event.h:680
Data item with pertaining time stamp.
Definition: event.h:576
double_t get_conductance() const
Definition: event.h:640
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
virtual Event * clone() const =0
Virtual copy constructor.
double double_t
Double precision floating point numbers.
Definition: nest.h:93
virtual void operator()()=0
Deliver the event to receiver.
CurrentEvent * clone() const
Virtual copy constructor.
Definition: event.h:432
Request data to be logged/logged data to be sent.
Definition: event.h:486
bool is_finite() const
Definition: nest_time.h:329
const Name max("max")
Definition: topology_names.h:75
rport get_rport() const
Return the receiver port number of the event.
Definition: event.h:805
DataLoggingReply(const Container &)
Construct with reference to data and time stamps to transmit.
Definition: event.h:606
const Container & get_info() const
Access referenced data.
Definition: event.h:592
Definition: event.h:685
Node * sender_
Pointer to sender or NULL.
Definition: event.h:257
Item(size_t n)
Definition: event.h:577
port p_
Sender port number.
Definition: event.h:270
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
long_t delay
Delay of a connection.
Definition: nest.h:178
void set_stamp(Time const &)
Set the time stamp of the event.
Definition: event.h:763
DataLoggingRequest()
Create empty request for use during simulation.
Definition: event.h:518
Default types used by the NEST kernel.
DataItem data
Definition: event.h:579
Event for spike information.
Definition: event.h:320
This template is the standard safe-pointer implementation of SYNOD.
Definition: lockptr.h:84
Base class for all NEST network objects.
Definition: node.h:96
void set_pointer(D &data)
Definition: event.h:673
std::vector< Item > Container
Container for entries.
Definition: event.h:584
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
const Name c("c")
Specific to Izhikevich 2003.
Definition: nest_names.h:62
delay d_
Transmission delay.
Definition: event.h:289
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
double offset_
Offset for precise spike times.
Definition: event.h:305
virtual ~Event()
Definition: event.h:80
double_t get_current() const
Definition: event.h:444
Event()
Definition: event.cpp:40
"Callback request event" for use in Device.
Definition: event.h:465
Event for electrical conductances.
Definition: event.h:616
delay get_delay() const
Return transmission delay of the event.
Definition: event.h:769