Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed May 23, 2024
1 parent 86efbfe commit 680ea8c
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 57 deletions.
7 changes: 5 additions & 2 deletions src/BaseIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BaseDataType BaseDataType::DSTR = BaseDataType(T_STR, DEFAULT_STR_SIZE);
// BaseIO

BaseIO::BaseIO()
: readyToOpen(true)
: readyToOpen(true)
, opened(false)
{
}
Expand Down Expand Up @@ -78,7 +78,10 @@ Status BaseIO::createDataAttributes(const std::string& path,
Status BaseIO::createTimestampsAttributes(const std::string& path)
{
int interval = 1;
createAttribute(BaseDataType::I32, static_cast<const void*>(&interval), path + "/timestamps", "interval");
createAttribute(BaseDataType::I32,
static_cast<const void*>(&interval),
path + "/timestamps",
"interval");
createAttribute("seconds", path + "/timestamps", "unit");

return Status::Success;
Expand Down
3 changes: 2 additions & 1 deletion src/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Channel
int globalIndex,
float conversion = 1e6f, // uV to V
float samplingRate = 30000.f,
float bitVolts = 0.000002f, // least significant bit needed to convert 16-bit int to volts
float bitVolts = 0.000002f, // least significant bit needed to
// convert 16-bit int to volts
std::vector<float> position = {0.f, 0.f, 0.f})
: name(name)
, groupName(groupName)
Expand Down
16 changes: 9 additions & 7 deletions src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include "boost/date_time/c_local_time_adjustor.hpp"

#include "BaseIO.hpp"
#include "boost/date_time/c_local_time_adjustor.hpp"
#include "hdf5/HDF5IO.hpp"

namespace AQNWB
Expand Down Expand Up @@ -58,11 +58,13 @@ inline std::string getCurrentTime()
* @brief Factory method to create an IO object.
* @return A pointer to a BaseIO object
*/
inline std::unique_ptr<BaseIO> createIO(const std::string& type, const std::string& filename) {
if (type == "HDF5") {
return std::make_unique<HDF5::HDF5IO>(filename);
} else {
throw std::invalid_argument("Invalid IO type");
}
inline std::unique_ptr<BaseIO> createIO(const std::string& type,
const std::string& filename)
{
if (type == "HDF5") {
return std::make_unique<HDF5::HDF5IO>(filename);
} else {
throw std::invalid_argument("Invalid IO type");
}
}
} // namespace AQNWB
2 changes: 1 addition & 1 deletion src/hdf5/HDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,4 @@ Status HDF5RecordingData::writeDataRow(const SizeType& xDataSize,
}

return Status::Success;
};
}
9 changes: 5 additions & 4 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ Status NWBFile::startRecording(std::vector<Types::ChannelGroup> recordingArrays)

timeseriesData.push_back(std::move(electricalSeries));

// Add electrode information to electrode table (does not write to datasets yet)
// Add electrode information to electrode table (does not write to datasets
// yet)
elecTable.addElectrodes(channelGroup);
}

Expand All @@ -191,9 +192,9 @@ Status NWBFile::startRecording(std::vector<Types::ChannelGroup> recordingArrays)
void NWBFile::stopRecording() {}

Status NWBFile::writeTimeseriesTimestamps(int datasetInd,
int numSamples,
BaseDataType type,
const void* data)
int numSamples,
BaseDataType type,
const void* data)
{
if (!timeseriesData[datasetInd])
return Status::Failure;
Expand Down
10 changes: 4 additions & 6 deletions src/nwb/NWBFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class NWBFile
* @brief Starts a recording.
* @return Status The status of the recording operation.
*/
Status startRecording(
std::vector<Types::ChannelGroup>
recordingArrays);
Status startRecording(std::vector<Types::ChannelGroup> recordingArrays);

/**
* @brief Closes the relevant datasets.
Expand All @@ -72,9 +70,9 @@ class NWBFile
* @param data The data to write.
*/
Status writeTimeseriesTimestamps(int datasetInd,
int numSamples,
BaseDataType type,
const void* data);
int numSamples,
BaseDataType type,
const void* data);

/**
* @brief Write a row of timeseries data to the NWB file.
Expand Down
22 changes: 10 additions & 12 deletions src/nwb/NWBRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ Status NWBRecording::openFiles(const std::string& rootFolder,
rootFolder + baseName + std::to_string(experimentNumber) + ".nwb";

// initialize nwbfile object and create base structure
nwbfile = std::make_unique<NWB::NWBFile>(
generateUuid(),
createIO(IOType, filename));
nwbfile = std::make_unique<NWB::NWBFile>(generateUuid(),
createIO(IOType, filename));
nwbfile->initialize();

// start the new recording
return nwbfile->startRecording(
recordingArrays);
return nwbfile->startRecording(recordingArrays);
}

void NWBRecording::closeFiles()
Expand All @@ -62,12 +60,12 @@ void NWBRecording::writeTimeseriesData(int timeseriesInd,
[multFactor](float value) { return value * multFactor; });

// convert float to int16
std::transform(scaledBuffer.get(),
scaledBuffer.get() + numSamples,
intBuffer.get(),
[](float value) {
return static_cast<int16_t>(std::clamp(value, -32768.0f, 32767.0f));
});
std::transform(
scaledBuffer.get(),
scaledBuffer.get() + numSamples,
intBuffer.get(),
[](float value)
{ return static_cast<int16_t>(std::clamp(value, -32768.0f, 32767.0f)); });

// write intBuffer data to dataset
nwbfile->writeTimeseriesData(timeseriesInd,
Expand All @@ -79,4 +77,4 @@ void NWBRecording::writeTimeseriesData(int timeseriesInd,
nwbfile->writeTimeseriesTimestamps(
timeseriesInd, numSamples, BaseDataType::F64, timestampBuffer);
}
}
}
2 changes: 1 addition & 1 deletion src/nwb/file/ElectrodeTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ElectrodeTable::addElectrodes(std::vector<Channel> channels)
groupNames.push_back(ch.groupName);
electrodeNumbers.push_back(ch.globalIndex);
locationNames.push_back("unknown");
}
}
}

void ElectrodeTable::finalize()
Expand Down
2 changes: 1 addition & 1 deletion src/nwb/hdmf/table/DynamicTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ std::string DynamicTable::getDescription() const
const std::vector<std::string>& DynamicTable::getColNames()
{
return colNames;
}
}
3 changes: 1 addition & 2 deletions src/nwb/hdmf/table/DynamicTableRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace AQNWB::NWB
/**
* @brief An n-dimensional dataset representing a column of a DynamicTable.
*/
class DynamicTableRegion
: public VectorData
class DynamicTableRegion : public VectorData
{
public:
/**
Expand Down
8 changes: 4 additions & 4 deletions tests/testHDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ TEST_CASE("writeGroup", "[hdf5io]")
hdf5io.close();
}

SECTION("try initializing group that already exists")
SECTION("try initializing group that already exists")
{
// TODO
}

SECTION("try initializing group without parent group")
SECTION("try initializing group without parent group")
{
// TODO
}
}

TEST_CASE("writeDataset", "[hdf5io]")
{
SECTION("create dataset and write data row")
SECTION("create dataset and write data row")
{
// TODO
}

SECTION("create dataset and write data block")
SECTION("create dataset and write data block")
{
// TODO
}
Expand Down
6 changes: 4 additions & 2 deletions tests/testNWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ TEST_CASE("startRecording", "[nwb]")
std::vector<float> mockData = {1.0, 2.0, 3.0, 4.0, 5.0};
std::vector<float> mockTimestamps = {0.1, 0.2, 0.3, 0.4, 0.5};
nwbfile.writeTimeseriesData(0, 0, 5, BaseDataType::F32, mockData.data());
nwbfile.writeTimeseriesTimestamps(0, 5, BaseDataType::F32, mockTimestamps.data());
nwbfile.writeTimeseriesTimestamps(
0, 5, BaseDataType::F32, mockTimestamps.data());
nwbfile.writeTimeseriesData(1, 0, 5, BaseDataType::F32, mockData.data());
nwbfile.writeTimeseriesTimestamps(1, 5, BaseDataType::F32, mockTimestamps.data());
nwbfile.writeTimeseriesTimestamps(
1, 5, BaseDataType::F32, mockTimestamps.data());

nwbfile.finalize();

Expand Down
18 changes: 9 additions & 9 deletions tests/testNWBRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ TEST_CASE("writeContinuousData", "[recording]")
for (const auto& channel : channelGroup) {
// copy data into buffer
std::copy(mockData[channel.globalIndex].begin() + samplesRecorded,
mockData[channel.globalIndex].begin() + samplesRecorded + numSamples / 10,
mockData[channel.globalIndex].begin() + samplesRecorded
+ numSamples / 10,
dataBuffer.begin());
std::copy(mockTimestamps.begin() + samplesRecorded,
mockTimestamps.begin() + samplesRecorded + numSamples / 10,
Expand All @@ -60,7 +61,6 @@ TEST_CASE("writeContinuousData", "[recording]")
dataBuffer.data(),
timestampsBuffer.data(),
dataBuffer.size());

}
}
// check if recording is done
Expand All @@ -71,18 +71,18 @@ TEST_CASE("writeContinuousData", "[recording]")
}
}

SECTION("check contents of data and timestamps", "[recording]")
SECTION("check contents of data and timestamps", "[recording]")
{
// TODO
// TODO
}

SECTION("test if more samples than buffer size", "[recording]")
SECTION("test if more samples than buffer size", "[recording]")
{
// TODO
// TODO
}

SECTION("add a new recording number to the same file", "[recording]")
SECTION("add a new recording number to the same file", "[recording]")
{
// TODO
// TODO
}
}
}
9 changes: 4 additions & 5 deletions tests/testUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ inline std::vector<Types::ChannelGroup> getMockChannelArrays()
Channel ch1 = Channel("ch1", "array1", 1, 1);
Channel ch2 = Channel("ch2", "array2", 0, 2);
Channel ch3 = Channel("ch3", "array2", 1, 3);
std::vector<Types::ChannelGroup> arrays = {
Types::ChannelGroup {ch0, ch1},
Types::ChannelGroup {ch2, ch3}};
std::vector<Types::ChannelGroup> arrays = {Types::ChannelGroup {ch0, ch1},
Types::ChannelGroup {ch2, ch3}};
return arrays;
}

Expand All @@ -50,7 +49,7 @@ inline std::vector<std::vector<float>> getMockData(int numChannels = 4,

std::random_device rd;
std::mt19937 rng(rd()); // random number generator
std::uniform_real_distribution<> dis(-1.0, 1.0); //range of floats
std::uniform_real_distribution<> dis(-1.0, 1.0); // range of floats

for (auto& channelData : mockData) {
for (auto& data : channelData) {
Expand All @@ -73,4 +72,4 @@ inline std::vector<double> getMockTimestamps(int numSamples = 1000,
}

return mockTimestamps;
}
}

0 comments on commit 680ea8c

Please sign in to comment.