Skip to content

Commit

Permalink
Update Channel.hpp/cpp to avoid shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Sep 19, 2024
1 parent 5c37c40 commit 2071445
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 68 deletions.
35 changes: 10 additions & 25 deletions src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,17 @@ Channel::Channel(const std::string name,
const float bitVolts,
const std::array<float, 3> position,
const std::string comments)
: name(name)
, groupName(groupName)
, groupIndex(groupIndex)
, localIndex(localIndex)
, globalIndex(globalIndex)
, position(position)
, conversion(conversion)
, samplingRate(samplingRate)
, bitVolts(bitVolts)
, comments(comments)
: m_name(name)
, m_groupName(groupName)
, m_groupIndex(groupIndex)
, m_localIndex(localIndex)
, m_globalIndex(globalIndex)
, m_position(position)
, m_conversion(conversion)
, m_samplingRate(samplingRate)
, m_bitVolts(bitVolts)
, m_comments(comments)
{
}

Channel::~Channel() {}

float Channel::getConversion() const
{
return bitVolts / conversion;
}

float Channel::getSamplingRate() const
{
return samplingRate;
}

float Channel::getBitVolts() const
{
return bitVolts;
}
178 changes: 150 additions & 28 deletions src/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,194 @@ class Channel
~Channel();

/**
* @brief Copy constructor
*/
Channel(const Channel& other) = default;

/**
* @brief Move constructor
*/
Channel(Channel&& other) = default;

/**
* @brief Assignment operator
*/
Channel& operator=(const Channel& other) = default;

/**
* @brief Move assignment operator
*/
Channel& operator=(Channel&& other) = default;

/**
* @brief Getter for conversion factor
* @return The conversion value.
*/
float getConversion() const;
inline float getConversion() const { return m_bitVolts / m_conversion; }

/**
* @brief Getter for samplingRate
* @return The samplingRate value.
/**
* @brief Getter for sampling rate of the channel.
* @return The sampling rate value.
*/
float getSamplingRate() const;
inline float getSamplingRate() const { return m_samplingRate; }

/**
* @brief Getter for bitVolts
/**
* @brief Getter for bitVolts floating point value of microvolts per bit
* @return The bitVolts value.
*/
float getBitVolts() const;
inline float getBitVolts() const { return m_bitVolts; }

/**
* @brief Name of the channel.
/**
* @brief Get the name of the array group the channel belongs to.
* @return The groupName value.
*/
std::string name;
inline std::string getGroupName() const { return m_groupName; }

/**
* @brief Name of the array group the channel belongs to.
/**
* @brief Get the name of the channel
* @return The name value.
*/
inline std::string getName() const { return m_name; }

/**
* @brief Get the array group index the channel belongs to
* @return The groupIndex value.
*/
inline SizeType getGroupIndex() const { return m_groupIndex; }

/**
* @brief Get the index of the channel within the recording array.
* @return The localIndex value.
*/
inline SizeType getLocalIndex() const { return m_localIndex; }

/**
* @brief Get the index of the channel across the recording system.
* @return The globalIndex value.
*/
inline SizeType getGlobalIndex() const { return m_globalIndex; }

/**
* @brief Get the coordinates of channel (x, y, z) within the recording array.
* @return The position value.
*/
inline const std::array<float, 3>& getPosition() const { return m_position; }

/**
* @brief Get comments about the channel
* @return The comments value.
*/
inline std::string getComments() const { return m_comments; }

/**
* @brief Set comments about the channel.
* @param comments The comments to set.
*/
inline void setComments(const std::string& comments) { m_comments = comments; }

/**
* @brief Set coordinates of channel (x, y, z) within the recording array.
* @param position The position to set.
*/
inline void setPosition(const std::array<float, 3>& position) { m_position = position; }

/**
* @brief Set index of channel across the recording system.
* @param globalIndex The globalIndex to set.
*/
inline void setGlobalIndex(const SizeType globalIndex) { m_globalIndex = globalIndex; }

/**
* @brief Set index of channel within the recording array.
* @param localIndex The localIndex to set.
*/
std::string groupName;
inline void setLocalIndex(const SizeType localIndex) { m_localIndex = localIndex; }

/**
* @brief Set index of array group the channel belongs to.
* @param groupIndex The groupIndex to set.
*/
inline void setGroupIndex(const SizeType groupIndex) { m_groupIndex = groupIndex; }

/**
* @brief Set name of the channel.
* @param name The name to set.
*/
inline void setName(const std::string& name) { m_name = name; }

/**
* @brief Set name of the array group the channel belongs to.
* @param groupName The groupName to set.
*/
inline void setGroupName(const std::string& groupName) { m_groupName = groupName; }

/**
* @brief Set conversion factor.
* @param conversion The conversion to set.
*/
inline void setConversion(const float conversion) { m_conversion = conversion; }

/**
* @brief Set sampling rate of the channel.
* @param samplingRate The samplingRate to set.
*/
inline void setSamplingRate(const float samplingRate) { m_samplingRate = samplingRate; }

/**
* @brief Set floating point value of microvolts per bit
* @param bitVolts The bitVolts to set.
*/
inline void setBitVolts(const float bitVolts) { m_bitVolts = bitVolts; }

private:
/**
* @brief Index of array group the channel belongs to.
* @brief Comments about the channel.
*/
std::string m_comments;

/**
* @brief Coordinates of channel (x, y, z) within the recording array.
*/
std::array<float, 3> m_position;

/**
* @brief Index of channel across the recording system.
*/
SizeType groupIndex;
SizeType m_globalIndex;

/**
* @brief Index of channel within the recording array.
*/
SizeType localIndex;
SizeType m_localIndex;

/**
* @brief Index of channel across the recording system.
* @brief Index of array group the channel belongs to.
*/
SizeType globalIndex;
SizeType m_groupIndex;

/**
* @brief Coordinates of channel (x, y, z) within the recording array.
* @brief Name of the channel.
*/
std::array<float, 3> position;
std::string m_name;

/**
* @brief Comments about the channel.
* @brief Name of the array group the channel belongs to.
*/
std::string comments;
std::string m_groupName;

private:
/**
* @brief Conversion factor.
*/
float conversion;
float m_conversion;

/**
* @brief Sampling rate of the channel.
*/
float samplingRate;
float m_samplingRate;

/**
* @brief floating point value of microvolts per bit
*/
float bitVolts;
float m_bitVolts;
};
} // namespace AQNWB
} // namespace AQNWB
4 changes: 2 additions & 2 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Status NWBFile::createElectricalSeries(
const std::string& recordingName = recordingNames[i];

// Setup electrodes and devices
std::string groupName = channelVector[0].groupName;
std::string groupName = channelVector[0].getGroupName();
std::string devicePath = "/general/devices/" + groupName;
std::string electrodePath = "/general/extracellular_ephys/" + groupName;
std::string electricalSeriesPath = acquisitionPath + "/" + recordingName;
Expand Down Expand Up @@ -208,7 +208,7 @@ Status NWBFile::createSpikeEventSeries(
const std::string& recordingName = recordingNames[i];

// Setup electrodes and devices
std::string groupName = channelVector[0].groupName;
std::string groupName = channelVector[0].getGroupName();
std::string devicePath = "/general/devices/" + groupName;
std::string electrodePath = "/general/extracellular_ephys/" + groupName;
std::string spikeEventSeriesPath = acquisitionPath + "/" + recordingName;
Expand Down
4 changes: 2 additions & 2 deletions src/nwb/RecordingContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Status RecordingContainers::writeTimeseriesData(
return Status::Failure;

// write data and timestamps to datasets
if (channel.localIndex == 0) {
if (channel.getLocalIndex() == 0) {
// write with timestamps if it's the first channel
return ts->writeData(dataShape, positionOffset, data, timestamps);
} else {
Expand All @@ -62,7 +62,7 @@ Status RecordingContainers::writeElectricalSeriesData(
if (es == nullptr)
return Status::Failure;

es->writeChannel(channel.localIndex, numSamples, data, timestamps);
es->writeChannel(channel.getLocalIndex(), numSamples, data, timestamps);
}

Status RecordingContainers::writeSpikeEventData(const SizeType& containerInd,
Expand Down
4 changes: 2 additions & 2 deletions src/nwb/ecephys/ElectricalSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ElectricalSeries::ElectricalSeries(const std::string& path,
dataType,
"volts", // default unit for Electrical Series
description,
channelVector[0].comments,
channelVector[0].getComments(),
dsetSize,
chunkSize,
channelVector[0].getConversion(),
Expand All @@ -45,7 +45,7 @@ void ElectricalSeries::initialize()
std::vector<int> electrodeInds(channelVector.size());
std::vector<float> channelConversions(channelVector.size());
for (size_t i = 0; i < channelVector.size(); ++i) {
electrodeInds[i] = channelVector[i].globalIndex;
electrodeInds[i] = channelVector[i].getGlobalIndex();
channelConversions[i] = channelVector[i].getConversion();
}
samplesRecorded = SizeArray(channelVector.size(), 0);
Expand Down
6 changes: 3 additions & 3 deletions src/nwb/file/ElectrodeTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void ElectrodeTable::addElectrodes(std::vector<Channel> channels)
{
// create datasets
for (const auto& ch : channels) {
groupReferences.push_back(groupPathBase + ch.groupName);
groupNames.push_back(ch.groupName);
electrodeNumbers.push_back(ch.globalIndex);
groupReferences.push_back(groupPathBase + ch.getGroupName());
groupNames.push_back(ch.getGroupName());
electrodeNumbers.push_back(ch.getGlobalIndex());
locationNames.push_back("unknown");
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/examples/testWorkflowExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ TEST_CASE("workflowExamples")
const auto& channelVector = mockRecordingArrays[i];
for (const auto& channel : channelVector) {
// copy data into buffer
std::copy(mockData[channel.globalIndex].begin() + samplesRecorded,
mockData[channel.globalIndex].begin() + samplesRecorded
std::copy(mockData[channel.getGlobalIndex()].begin() + samplesRecorded,
mockData[channel.getGlobalIndex()].begin() + samplesRecorded
+ bufferSize,
dataBuffer.begin());
std::copy(mockTimestamps.begin() + samplesRecorded,
Expand All @@ -80,7 +80,7 @@ TEST_CASE("workflowExamples")

// write timeseries data
std::vector<SizeType> positionOffset = {samplesRecorded,
channel.localIndex};
channel.getLocalIndex()};
std::vector<SizeType> dataShape = {dataBuffer.size(), 1};
std::unique_ptr<int16_t[]> intBuffer = transformToInt16(
dataBuffer.size(), channel.getBitVolts(), dataBuffer.data());
Expand Down
6 changes: 3 additions & 3 deletions tests/testRecordingWorkflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ TEST_CASE("writeContinuousData", "[recording]")
const auto& channelVector = mockRecordingArrays[i];
for (const auto& channel : channelVector) {
// copy data into buffer
std::copy(mockData[channel.globalIndex].begin() + samplesRecorded,
mockData[channel.globalIndex].begin() + samplesRecorded
std::copy(mockData[channel.getGlobalIndex()].begin() + samplesRecorded,
mockData[channel.getGlobalIndex()].begin() + samplesRecorded
+ bufferSize,
dataBuffer.begin());
std::copy(mockTimestamps.begin() + samplesRecorded,
Expand All @@ -75,7 +75,7 @@ TEST_CASE("writeContinuousData", "[recording]")

// write timeseries data
std::vector<SizeType> positionOffset = {samplesRecorded,
channel.localIndex};
channel.getLocalIndex()};
std::vector<SizeType> dataShape = {dataBuffer.size(), 1};

recordingContainers->writeTimeseriesData(i,
Expand Down

0 comments on commit 2071445

Please sign in to comment.