Skip to content

Commit

Permalink
add check for device or electrode group existing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Sep 10, 2024
1 parent ddde29a commit 905547b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ Status NWBFile::createElectricalSeries(
std::string groupName = channelVector[0].groupName;
std::string devicePath = "/general/devices/" + groupName;
std::string electrodePath = "/general/extracellular_ephys/" + groupName;
std::string electricalSeriesPath = acquisitionPath + groupName;
std::string electricalSeriesPath = acquisitionPath + "/" + groupName;

Device device = Device(devicePath, io, "description", "unknown");
device.initialize();
// Check if device exists for groupName, create device and electrode group if not
if (!io->objectExists(devicePath)){
Device device = Device(devicePath, io, "description", "unknown");
device.initialize();

ElectrodeGroup elecGroup =
ElectrodeGroup elecGroup =
ElectrodeGroup(electrodePath, io, "description", "unknown", device);
elecGroup.initialize();
elecGroup.initialize();
}

// Setup electrical series datasets
auto electricalSeries = std::make_unique<ElectricalSeries>(
Expand Down Expand Up @@ -186,14 +189,17 @@ Status NWBFile::createSpikeEventSeries(
std::string groupName = channelVector[0].groupName;
std::string devicePath = "/general/devices/" + groupName;
std::string electrodePath = "/general/extracellular_ephys/" + groupName;
std::string spikeEventSeriesPath = acquisitionPath + groupName;
std::string spikeEventSeriesPath = acquisitionPath + "/" + groupName;

Device device = Device(devicePath, io, "description", "unknown");
device.initialize();
// Check if device exists for groupName, create device and electrode group if not
if (!io->objectExists(devicePath)){
Device device = Device(devicePath, io, "description", "unknown");
device.initialize();

ElectrodeGroup elecGroup =
ElectrodeGroup elecGroup =
ElectrodeGroup(electrodePath, io, "description", "unknown", device);
elecGroup.initialize();
elecGroup.initialize();
}

// Setup Spike Event Series datasets
SizeArray dsetSize;
Expand All @@ -219,7 +225,7 @@ Status NWBFile::createSpikeEventSeries(
containerIndexes.push_back(recordingContainers->containers.size() - 1);
}

if (electrodeTableCreated) {
if (!electrodeTableCreated) {
// Add electrode information to table (does not write to datasets yet)
for (const auto& channelVector : recordingArrays) {
elecTable->addElectrodes(channelVector);
Expand All @@ -239,7 +245,7 @@ void NWBFile::cacheSpecifications(
const std::array<std::pair<std::string_view, std::string_view>, N>&
specVariables)
{
io->createGroup("/specifications/" + specPath + "/");
io->createGroup("/specifications/" + specPath);
io->createGroup("/specifications/" + specPath + "/" + versionNumber);

for (const auto& [name, content] : specVariables) {
Expand Down

0 comments on commit 905547b

Please sign in to comment.