Skip to content

Commit

Permalink
convert stopRecording to pauseRecording
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Aug 6, 2024
1 parent 30b404c commit 75c31a9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/BaseIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class BaseIO
* @brief Stops the recording process.
* @return The status of the operation.
*/
virtual Status pauseRecording() = 0;

/**
* @brief Returns true if the file is in a mode where objects can
* be added or deleted. Note, this does not apply to the modification
Expand Down
8 changes: 5 additions & 3 deletions src/hdf5/HDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,18 @@ Status HDF5IO::createStringDataSet(const std::string& path,

Status HDF5IO::startRecording()
{
modifyObjects = false;
if (H5Fstart_swmr_write(this->file->getId()) < 0) {
return Status::Failure;
}
return Status::Success;
}

Status HDF5IO::stopRecording()
Status HDF5IO::pauseRecording()
{
modifyObjects = true;
file->close();
file.reset();
opened = false;
open(false);
return Status::Success;
}

Expand Down
5 changes: 3 additions & 2 deletions src/hdf5/HDF5IO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ class HDF5IO : public BaseIO
Status startRecording() override;

/**
* @brief Stops the recording process.
* @return The status of the stop recording operation.
* @brief Pause the recording process.
* @return The status of the pause recording operation.
*/
Status pauseRecording() override;

/**
* @brief Checks whether the file is in a mode where objects
Expand Down
5 changes: 2 additions & 3 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Status NWBFile::initialize()

Status NWBFile::finalize()
{
io->stopRecording();
recordingContainers.reset();
return io->close();
}
Expand Down Expand Up @@ -145,9 +144,9 @@ Status NWBFile::startRecording()
return io->startRecording();
}

void NWBFile::stopRecording()
void NWBFile::pauseRecording()
{
io->stopRecording();
io->pauseRecording();
}

void NWBFile::cacheSpecifications(const std::string& specPath,
Expand Down
7 changes: 4 additions & 3 deletions src/nwb/NWBFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class NWBFile
* @brief Create ElectricalSeries objects to record data into.
* Created objects are stored in recordingContainers.
* Note, this function will fail if the file is in a mode where
* new objects cannot be added.
* new objects cannot be added, which can be checked via
* nwbfile.io->canModifyObjects()
* @param recordingArrays vector of ChannelVector indicating the electrodes to
* record from. A separate ElectricalSeries will be
* created for each ChannelVector.
Expand All @@ -74,9 +75,9 @@ class NWBFile
Status startRecording();

/**
* @brief Closes the relevant datasets.
* @brief Pauses the recording but allows the file to remain open.
*/
void stopRecording();
void pauseRecording();

/**
* @brief Indicates the NWB schema version.
Expand Down
46 changes: 44 additions & 2 deletions tests/testNWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ TEST_CASE("createElectricalSeries", "[nwb]")
std::vector<Types::ChannelVector> mockArrays = getMockChannelArrays(1, 2);
Status resultCreate =
nwbfile.createElectricalSeries(mockArrays, BaseDataType::F32);
REQUIRE(resultCreate == Status::Success);

// start recording
Status resultStart = nwbfile.startRecording();
REQUIRE(resultStart == Status::Success);

// write timeseries data
std::vector<float> mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
Expand All @@ -51,8 +53,6 @@ TEST_CASE("createElectricalSeries", "[nwb]")
dataShape, positionOffset, mockData.data(), mockTimestamps.data());

nwbfile.finalize();

REQUIRE(resultCreate == Status::Success);
}

TEST_CASE("setCanModifyObjectsMode", "[nwb]")
Expand All @@ -78,6 +78,48 @@ TEST_CASE("setCanModifyObjectsMode", "[nwb]")
nwbfile.createElectricalSeries(mockArrays, BaseDataType::F32);
REQUIRE(resultCreatePostStart == Status::Failure);

// stop recording
nwbfile.finalize();
}


TEST_CASE("pauseRecording", "[nwb]")
{
std::string filename = getTestFilePath("testPauseRecording.nwb");

// initialize nwbfile object and create base structure
NWB::NWBFile nwbfile(generateUuid(),
std::make_unique<HDF5::HDF5IO>(filename));
nwbfile.initialize();

// create Electrical Series
std::vector<Types::ChannelVector> mockArrays = getMockChannelArrays(1, 2);
Status resultCreate =
nwbfile.createElectricalSeries(mockArrays, BaseDataType::F32);
REQUIRE(resultCreate == Status::Success);

// start recording
Status resultStart = nwbfile.startRecording();
REQUIRE(resultStart == Status::Success);

// write timeseries data
std::vector<float> mockData = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
std::vector<double> mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5};
std::vector<SizeType> positionOffset = {0, 0};
std::vector<SizeType> dataShape = {mockData.size(), 0};

NWB::TimeSeries* ts0 = nwbfile.getTimeSeries(0);
ts0->writeData(
dataShape, positionOffset, mockData.data(), mockTimestamps.data());
NWB::TimeSeries* ts1 = nwbfile.getTimeSeries(1);
ts1->writeData(
dataShape, positionOffset, mockData.data(), mockTimestamps.data());

// pause recording and check recording containers still exist
nwbfile.pauseRecording();
NWB::TimeSeries* ts0AfterPause = nwbfile.getTimeSeries(0);
REQUIRE(ts0AfterPause != nullptr);

// stop recording
nwbfile.finalize();
}

0 comments on commit 75c31a9

Please sign in to comment.