@@ -85,16 +85,76 @@ class Hdf5Recorder : public Recorder {
8585 * @param variableType Type of the recorded variable.
8686 */
8787 virtual void registerVariable (const string &varName, RecordableBase &recordVar,
88- UpdatedType variableType) override
89- {
90- }
88+ UpdatedType variableType) override ;
9189
9290 // / Register a vector of instance of a class derived from RecordableBase.
9391 virtual void registerVariable (const string &varName, vector<RecordableBase *> &recordVars,
9492 UpdatedType variableType) override
9593 {
9694 }
9795
96+ struct singleVariableInfo {
97+ // / the name of each variable
98+ string variableName_;
99+
100+ // / the basic data type in the Recorded variable
101+ string dataType_;
102+
103+ // / the data type in Hdf5 file
104+ DataType hdf5Datatype_;
105+
106+ // / the data set for Hdf5 file
107+ DataSet hdf5DataSet_;
108+
109+ // / the variable type: updated frequency
110+ UpdatedType variableType_;
111+
112+ // / a reference to a RecordableBase variable
113+ // / As the simulator runs, the values in the RecordableBase object will be updated
114+ RecordableBase &variableLocation_;
115+
116+ // Constructor accepting the variable name, the address of recorded variable, the updated type
117+ singleVariableInfo (const string &name, RecordableBase &location, UpdatedType variableType) :
118+ variableLocation_ (location), variableName_(name), variableType_(variableType)
119+ {
120+ dataType_ = location.getDataType ();
121+ convertType ();
122+ }
123+
124+ // Converts the data type of the variable to HDF5 data type
125+ void convertType ()
126+ {
127+ if (dataType_ == typeid (uint64_t ).name ()) {
128+ hdf5Datatype_ = PredType::NATIVE_UINT64;
129+ } else if (dataType_ == typeid (bool ).name ()) {
130+ hdf5Datatype_ = PredType::NATIVE_UINT8;
131+ } else if (dataType_ == typeid (int ).name ()) {
132+ hdf5Datatype_ = PredType::NATIVE_INT;
133+ } else if (dataType_ == typeid (float ).name ()) {
134+ hdf5Datatype_ = PredType::NATIVE_FLOAT;
135+ } else if (dataType_ == typeid (double ).name ()) {
136+ hdf5Datatype_ = PredType::NATIVE_DOUBLE;
137+ } else {
138+ // string errorMsg = "Not supported type for type: " + dataType_;
139+ throw runtime_error (" Unsupported data type" );
140+ }
141+ }
142+
143+ // Creates a dynamic dataset in the HDF5 file
144+ void createDynamicDataset (H5File *resultOut_)
145+ {
146+ // Create dataspace with initial size and unlimited max size
147+ hsize_t dims[1 ] = {static_cast <hsize_t >(variableLocation_.getNumElements ())};
148+ hsize_t maxDims[1 ] = {H5S_UNLIMITED};
149+ DataSpace dataspace (1 , dims, maxDims);
150+
151+ // Create dataset
152+ hdf5DataSet_ = resultOut_->createDataSet (variableName_, hdf5Datatype_, dataspace);
153+
154+ std::cout << " Created dataset: " << variableName_ << std::endl;
155+ }
156+ };
157+
98158 // /@{
99159 /* * These methods are intended only for unit tests */
100160 // / constructor only for unit test
@@ -103,6 +163,12 @@ class Hdf5Recorder : public Recorder {
103163 resultFileName_ = fileName;
104164 }
105165
166+ // Accessor method to retrieve variableTable_
167+ const vector<singleVariableInfo> &getVariableTable () const
168+ {
169+ return variableTable_;
170+ }
171+
106172private:
107173 virtual void initDataSet ();
108174
@@ -147,6 +213,8 @@ class Hdf5Recorder : public Recorder {
147213 // track spikes count of probed neurons
148214 vector<vector<uint64_t >> spikesProbedNeurons_;
149215
216+ // / List of registered variables for recording
217+ vector<singleVariableInfo> variableTable_;
150218 // Other member functions...
151219};
152220
0 commit comments