@@ -66,9 +66,7 @@ class Hdf5Recorder : public Recorder {
6666
6767 // TODO: No parameters needed (AllVertices &vertices)
6868 // / Writes simulation results to an output destination.
69- virtual void saveSimData (const AllVertices &neurons) override
70- {
71- }
69+ virtual void saveSimData (const AllVertices &neurons) override ;
7270
7371 // / Prints out all parameters to logging file.
7472 // / Registered to OperationManager as Operation::printParameters
@@ -93,6 +91,10 @@ class Hdf5Recorder : public Recorder {
9391 {
9492 }
9593
94+ virtual void initDataSet ()
95+ {
96+ }
97+
9698 struct singleVariableInfo {
9799 // / the name of each variable
98100 string variableName_;
@@ -127,31 +129,49 @@ class Hdf5Recorder : public Recorder {
127129 if (dataType_ == typeid (uint64_t ).name ()) {
128130 hdf5Datatype_ = PredType::NATIVE_UINT64;
129131 } else if (dataType_ == typeid (bool ).name ()) {
130- hdf5Datatype_ = PredType::NATIVE_UINT8 ;
132+ hdf5Datatype_ = PredType::NATIVE_INT ;
131133 } else if (dataType_ == typeid (int ).name ()) {
132134 hdf5Datatype_ = PredType::NATIVE_INT;
133- } else if (dataType_ == typeid (float ).name ()) {
135+ } else if (dataType_ == typeid (BGFLOAT ).name ()) {
134136 hdf5Datatype_ = PredType::NATIVE_FLOAT;
135- } else if (dataType_ == typeid (double ).name ()) {
136- hdf5Datatype_ = PredType::NATIVE_DOUBLE;
137137 } else {
138- // string errorMsg = "Not supported type for type: " + dataType_;
139138 throw runtime_error (" Unsupported data type" );
140139 }
141140 }
142141
143- // Creates a dynamic dataset in the HDF5 file
144- void createDynamicDataset (H5File *resultOut_ )
142+ // Method to capture and write data to the HDF5 dataset
143+ void captureData ( )
145144 {
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;
145+ // Ensure the dataset exists and data can be written
146+ if (variableLocation_.getNumElements () > 0 ) {
147+ // Prepare the data buffer based on the HDF5 data type
148+ if (hdf5Datatype_ == PredType::NATIVE_FLOAT) {
149+ vector<BGFLOAT> dataBuffer (variableLocation_.getNumElements ());
150+ for (int i = 0 ; i < variableLocation_.getNumElements (); ++i) {
151+ dataBuffer[i] = get<BGFLOAT>(variableLocation_.getElement (i));
152+ }
153+ // Write the data to the dataset
154+ hdf5DataSet_.write (dataBuffer.data (), hdf5Datatype_);
155+
156+ } else if (hdf5Datatype_ == PredType::NATIVE_INT) {
157+ vector<int > dataBuffer (variableLocation_.getNumElements ());
158+ for (int i = 0 ; i < variableLocation_.getNumElements (); ++i) {
159+ dataBuffer[i] = get<int >(variableLocation_.getElement (i));
160+ }
161+ hdf5DataSet_.write (dataBuffer.data (), hdf5Datatype_);
162+
163+ } else if (hdf5Datatype_ == PredType::NATIVE_UINT64) {
164+ vector<uint64_t > dataBuffer (variableLocation_.getNumElements ());
165+ for (int i = 0 ; i < variableLocation_.getNumElements (); ++i) {
166+ dataBuffer[i] = get<uint64_t >(variableLocation_.getElement (i));
167+ }
168+ hdf5DataSet_.write (dataBuffer.data (), hdf5Datatype_);
169+
170+ } else {
171+ // Throw an error if the data type is unsupported
172+ throw runtime_error (" Unsupported data type" );
173+ }
174+ }
155175 }
156176 };
157177
@@ -170,8 +190,6 @@ class Hdf5Recorder : public Recorder {
170190 }
171191
172192private:
173- virtual void initDataSet ();
174-
175193 // / Populates Starter neuron matrix based with boolean values based on starterMap state
176194 // /@param[in] matrix starter neuron matrix
177195 // /@param starterMap Bool vector to reference neuron matrix location from.
@@ -182,7 +200,7 @@ class Hdf5Recorder : public Recorder {
182200
183201 // Member variables for HDF5 datasets
184202 H5File *resultOut_;
185- DataSet dataSetXloc_;
203+ /* DataSet dataSetXloc_;
186204 DataSet dataSetYloc_;
187205 DataSet dataSetNeuronTypes_;
188206 DataSet dataSetNeuronThresh_;
@@ -204,7 +222,7 @@ class Hdf5Recorder : public Recorder {
204222 const H5std_string nameSimulationEndTime = "simulationEndTime";
205223 const H5std_string nameSpikesProbedNeurons = "spikesProbedNeurons";
206224 const H5std_string nameAttrPNUnit = "attrPNUint";
207- const H5std_string nameProbedNeurons = " probedNeurons" ;
225+ const H5std_string nameProbedNeurons = "probedNeurons";*/
208226
209227 // Keep track of where we are in incrementally writing spikes
210228 vector<hsize_t > offsetSpikesProbedNeurons_;
0 commit comments