Skip to content

Commit

Permalink
Use empty default for sessionStartTime and timestampReferenceTime
Browse files Browse the repository at this point in the history
  • Loading branch information
oruebel committed Jan 27, 2025
1 parent 350dc1e commit c7767f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 34 deletions.
30 changes: 15 additions & 15 deletions src/nwb/NWBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ NWBFile::NWBFile(const std::string& path, std::shared_ptr<IO::BaseIO> io)

NWBFile::~NWBFile() {}

Status NWBFile::initialize(const std::string& identifierText,
const std::string& description,
const std::string& dataCollection)
{
std::string time = getCurrentTime();
return this->initialize(
identifierText, description, dataCollection, time, time);
}

Status NWBFile::initialize(const std::string& identifierText,
const std::string& description,
const std::string& dataCollection,
Expand All @@ -65,15 +56,24 @@ Status NWBFile::initialize(const std::string& identifierText,
if (!m_io->isOpen()) {
return Status::Failure;
}
if (!isISO8601Date(sessionStartTime)) {
std::string currentTime = getCurrentTime();
// use the current time if sessionStartTime is empty
std::string useSessionStartTime =
(!sessionStartTime.empty()) ? sessionStartTime : currentTime;
// use the current time if timestampsReferenceTime is empty
std::string useTimestampsReferenceTime = (!timestampsReferenceTime.empty())
? timestampsReferenceTime
: currentTime;
// check that sessionStartTime and timestampsReferenceTime are ISO8601
if (!isISO8601Date(useSessionStartTime)) {
std::cerr << "NWBFile::initialize sessionStartTime not in ISO8601 format: "
<< sessionStartTime << std::endl;
<< useSessionStartTime << std::endl;
return Status::Failure;
}
if (!isISO8601Date(timestampsReferenceTime)) {
if (!isISO8601Date(useTimestampsReferenceTime)) {
std::cerr
<< "NWBFile::initialize timestampsReferenceTime not in ISO8601 format: "
<< timestampsReferenceTime << std::endl;
<< useTimestampsReferenceTime << std::endl;
return Status::Failure;
}

Expand All @@ -83,8 +83,8 @@ Status NWBFile::initialize(const std::string& identifierText,
return createFileStructure(identifierText,
description,
dataCollection,
sessionStartTime,
timestampsReferenceTime);
useSessionStartTime,
useTimestampsReferenceTime);
} else {
return Status::Success; // File is already initialized
}
Expand Down
25 changes: 6 additions & 19 deletions src/nwb/NWBFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ class NWBFile : public Container
*/
~NWBFile();

/**
* @brief Initializes the NWB file by setting up the file structure.
*
* If the file is already initialized then no action will be performed.
*
* @param identifierText The identifier text for the NWBFile.
* @param description A description of the NWBFile session.
* @param dataCollection Information about the data collection methods.
*/
Status initialize(const std::string& identifierText,
const std::string& description = "a recording session",
const std::string& dataCollection = "");

/**
* @brief Initializes the NWB file by setting up the file structure.
*
Expand All @@ -81,15 +68,15 @@ class NWBFile : public Container
* @param description A description of the NWBFile session.
* @param dataCollection Information about the data collection methods.
* @param sessionStartTime ISO formatted time string with the session start
* time
* time. If empty (default), then the getCurrentTime() will be used.
* @param timestampsReferenceTime ISO formatted time string with the timestamp
* reference time
* reference time. If empty (default), then the getCurrentTime() will be used.
*/
Status initialize(const std::string& identifierText,
const std::string& description,
const std::string& dataCollection,
const std::string& sessionStartTime,
const std::string& timestampsReferenceTime);
const std::string& description = "a recording session",
const std::string& dataCollection = "",
const std::string& sessionStartTime = "",
const std::string& timestampsReferenceTime = "");

/**
* @brief Check if the NWB file is initialized.
Expand Down

0 comments on commit c7767f4

Please sign in to comment.