Skip to content

Commit

Permalink
add example to track container index
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Sep 3, 2024
1 parent d1bcc72 commit 1a67791
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ using namespace AQNWB::NWB;

constexpr SizeType CHUNK_XSIZE = 2048;

std::vector<SizeType> NWBFile::emptyContainerIndexes = {};

// NWBFile

NWBFile::NWBFile(const std::string& idText, std::shared_ptr<BaseIO> io)
Expand Down Expand Up @@ -93,7 +95,8 @@ Status NWBFile::createFileStructure()
Status NWBFile::createElectricalSeries(
std::vector<Types::ChannelVector> recordingArrays,
const BaseDataType& dataType,
RecordingContainers* recordingContainers)
RecordingContainers* recordingContainers,
std::vector<SizeType>& containerIndexes)
{
if (!io->canModifyObjects()) {
return Status::Failure;
Expand Down Expand Up @@ -132,7 +135,8 @@ Status NWBFile::createElectricalSeries(
SizeArray {0, channelVector.size()},
SizeArray {CHUNK_XSIZE, 0});
electricalSeries->initialize();
recordingContainers->addData(std::move(electricalSeries));
recordingContainers->addContainer(std::move(electricalSeries));
containerIndexes.push_back(recordingContainers->containers.size() - 1);

// Add electrode information to electrode table (does not write to datasets
// yet)
Expand Down
6 changes: 5 additions & 1 deletion src/nwb/NWBFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ class NWBFile
* record from. A separate ElectricalSeries will be
* created for each ChannelVector.
* @param recordingContainers The container to store the created TimeSeries.
* @param containerIndexes The indexes of the containers added to
* recordingContainers
* @param dataType The data type of the elements in the data block.
* @return Status The status of the object creation operation.
*/
Status createElectricalSeries(
std::vector<Types::ChannelVector> recordingArrays,
const BaseDataType& dataType = BaseDataType::I16,
RecordingContainers* recordingContainers = nullptr);
RecordingContainers* recordingContainers = nullptr,
std::vector<SizeType>& containerIndexes = emptyContainerIndexes);

protected:
/**
Expand Down Expand Up @@ -120,6 +123,7 @@ class NWBFile

const std::string identifierText;
std::shared_ptr<BaseIO> io;
static std::vector<SizeType> emptyContainerIndexes;
};

} // namespace AQNWB::NWB
11 changes: 7 additions & 4 deletions tests/examples/testWorkflowExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ TEST_CASE("workflowExamples")
// [example_workflow_nwbfile_snippet]

// [example_workflow_datasets_snippet]
nwbfile->createElectricalSeries(
mockRecordingArrays, BaseDataType::I16, recordingContainers.get());
std::vector<SizeType> containerIndexes;
nwbfile->createElectricalSeries(mockRecordingArrays,
BaseDataType::I16,
recordingContainers.get(),
containerIndexes);
// [example_workflow_datasets_snippet]

// [example_workflow_start_snippet]
Expand All @@ -60,7 +63,7 @@ TEST_CASE("workflowExamples")
bool isRecording = true;
while (isRecording) {
// write data to the file for each channel
for (SizeType i = 0; i < mockRecordingArrays.size(); ++i) {
for (SizeType i = 0; i < containerIndexes.size(); ++i) {
const auto& channelVector = mockRecordingArrays[i];
for (const auto& channel : channelVector) {
// copy data into buffer
Expand All @@ -80,7 +83,7 @@ TEST_CASE("workflowExamples")
dataBuffer.size(), channel.getBitVolts(), dataBuffer.data());

// [example_workflow_write_snippet]
recordingContainers->writeTimeseriesData(i,
recordingContainers->writeTimeseriesData(containerIndexes[i],
channel,
dataShape,
positionOffset,
Expand Down

0 comments on commit 1a67791

Please sign in to comment.