AnimatLab  2
Test
CsNeuronDataColumn.cpp
1 
7 #include "StdAfx.h"
8 
9 #include "CsSynapseGroup.h"
10 #include "CsNeuronGroup.h"
11 #include "CsSpikeGeneratorGroup.h"
12 #include "CsNeuralModule.h"
13 #include "CsNeuronDataColumn.h"
14 
15 namespace AnimatCarlSim
16 {
17 
25 {
26  m_bAddDataAtEnd = false;
27  m_lpNeuron = NULL;
28  m_iNeuronID = -1;
29 }
30 
38 {
39 }
40 
41 void CsNeuronDataColumn::NeuronID(const std::string &strValue)
42 {
43  if(!Std_IsNumeric(strValue))
44  THROW_PARAM_ERROR(Cs_Err_lInvalidNeuralIndex, Cs_Err_strInvalidNeuralIndex, "NeuronID is not an integer", strValue);
45 
46  m_strNeuronID = strValue;
47 
48  if(m_lpNeuron)
49  {
50  int iId = atoi(strValue.c_str());
51 
52  if(iId < 0 || iId >= m_lpNeuron->NeuronCount())
53  THROW_PARAM_ERROR(Cs_Err_lInvalidNeuralIndex, Cs_Err_strInvalidNeuralIndex, "NeuronID is out of range", strValue);
54 
55  if(Std_CheckString(m_strDataType) == "SPIKE" && m_iNeuronID >= 0)
56  m_lpNeuron->DecrementCollectSpikeDataForNeuron(m_iNeuronID);
57 
58  m_iNeuronID = iId;
59 
60  if(Std_CheckString(m_strDataType) == "SPIKE" && m_iNeuronID >= 0)
61  m_lpNeuron->IncrementCollectSpikeDataForNeuron(m_iNeuronID);
62  }
63 }
64 
65 unsigned int CsNeuronDataColumn::NeuronID() {return 0;}
66 
67 void CsNeuronDataColumn::DataType(std::string strType)
68 {
69  std::string strOldDataType = Std_CheckString(m_strDataType);
70 
71  DataColumn::DataType(strType);
72 
73  std::string strData = Std_CheckString(strType);
74 
75  m_bAddDataAtEnd = false;
76  if(strData == "SPIKE")
77  m_bAddDataAtEnd = true;
78 
79  std::string strNewDataType = Std_CheckString(m_strDataType);
80 
81  if(strOldDataType == "SPIKE" && strNewDataType != "SPIKE" && m_iNeuronID >= 0)
82  m_lpNeuron->DecrementCollectSpikeDataForNeuron(m_iNeuronID);
83  else if(strNewDataType == "SPIKE" && strOldDataType != "SPIKE" && m_iNeuronID >= 0)
84  m_lpNeuron->IncrementCollectSpikeDataForNeuron(m_iNeuronID);
85 }
86 
87 #pragma region DataAccesMethods
88 
89 bool CsNeuronDataColumn::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
90 {
91  std::string strType = Std_CheckString(strDataType);
92 
93  if(DataColumn::SetData(strDataType, strValue, false))
94  return true;
95 
96  if(strType == "SUBDATA")
97  {
98  NeuronID(strValue);
99  return true;
100  }
101 
102  //If it was not one of those above then we have a problem.
103  if(bThrowError)
104  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
105 
106  return false;
107 }
108 
109 void CsNeuronDataColumn::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
110 {
111  DataColumn::QueryProperties(aryProperties);
112 
113  aryProperties.Add(new TypeProperty("SubData", AnimatPropertyType::String, AnimatPropertyDirection::Set));
114 }
115 
116 #pragma endregion
117 
119 {
120  DataColumn::Initialize();
121 
122  //Lets check this target and data type to see if it should be updated at the end or not.
123  if(m_lpTarget)
124  {
125  m_lpNeuron = dynamic_cast<CsNeuronGroup *>(m_lpTarget);
126 
127  if(!m_lpNeuron)
128  THROW_PARAM_ERROR(Al_Err_lConvertingClassToType, Al_Err_strConvertingClassToType, "Neuron: ", m_lpTarget->ID());
129 
130  if(m_strNeuronID.length() > 0)
131  NeuronID(m_strNeuronID);
132  }
133 }
134 
135 void CsNeuronDataColumn::Deactivate()
136 {
137  //Only try to set the data if this chart has been set to collect its
138  //data at the end of the run.
140  FillInDeactivateData();
141 }
142 
143 void CsNeuronDataColumn::FillInDeactivateData()
144 {
145  if(m_bAddDataAtEnd && m_lpNeuron && m_lpChart && m_iNeuronID >= 0)
146  {
147  float fltTimeBase = m_lpChart->ChartTimeBase();
148  long lColumnCount = m_lpChart->ColumnCount();
149  long lRowCount = m_lpChart->RowCount();
150 
151  if(fltTimeBase > 0)
152  {
153  std::pair<std::multimap<int, unsigned long>::iterator, std::multimap<int, unsigned long>::iterator> arySpikeTimes = m_lpNeuron->SpikeTimes()->equal_range(m_iNeuronID);
154 
155  for (std::multimap<int, unsigned long>::iterator it = arySpikeTimes.first; it != arySpikeTimes.second; ++it)
156  {
157  int iTime = (int) (*it).second;
158  float fltTime = iTime*CARLSIM_STEP_INCREMENT;
159 
160  int iRow = (int) ((fltTime/fltTimeBase)+0.5);
161 
162  if( (m_iColumnIndex>=0) && (m_iColumnIndex<lColumnCount) && (iRow>=0) && (iRow<lRowCount))
163  m_lpChart->SetData(m_iColumnIndex, iRow, 1.0);
164  }
165  }
166  }
167 }
168 
169 void CsNeuronDataColumn::Load(CStdXml &oXml)
170 {
171  DataColumn::Load(oXml);
172 
173  oXml.IntoElem();
174 
175  if(oXml.FindChildElement("SubData", false))
176  NeuronID(oXml.GetChildString("SubData"));
177 
178  oXml.OutOfElem();
179 }
180 
181 } //AnimatSim
Contains the classes for a firing rate neural model.
Definition: CsAdapter.cpp:14
Declares the CsNeuronGroup class.
bool Std_IsNumeric(std::string strVal)
Tests if this string is a number.
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
virtual long RowCount()
Gets the row count.
Definition: DataChart.cpp:376
virtual void SetData(int iColumn, int iRow, float fltVal)
Sets a data element to the data buffer.
Definition: DataChart.cpp:842
virtual float ChartTimeBase()
Gets the Time base used by this data chart.
Definition: DataChart.cpp:279
CsNeuronDataColumn()
Default constructor.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual std::string DataType()
Gets the data type of the variable we are collecting. This is the value passed into GetDataPointer...
Definition: DataColumn.cpp:96
DataChart * m_lpChart
Pointer to the parent DataChart.
Definition: DataColumn.h:34
Declares the synapse class.
Firing Rate Neuron model.
Definition: CsNeuronGroup.h:28
virtual bool SetStartEndTime()
Gets whether a start/end time is set for this chart.
Definition: DataChart.cpp:136
AnimatBase * m_lpTarget
Pointer to the target object that contains the data variable we will be collecting.
Definition: DataColumn.h:37
virtual long ColumnCount()
Gets the column count.
Definition: DataChart.cpp:366
virtual void Initialize()
Initializes this object.
std::string m_strDataType
The Data type of the variable we will be collecting. This is passed into the GetDataPointer method of...
Definition: DataColumn.h:31
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the data column class.
virtual ~CsNeuronDataColumn()
Destructor.