Skip to content

Commit

Permalink
Support loading .hdf5 files directly in the player (Fixes #179)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianReimold committed Feb 18, 2021
1 parent b66bd23 commit 545af8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/play/play_core/include/ecal_play.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ class EcalPlay
std::vector<EcalPlayScenario> scenarios_; /**< The scenarios loaded from the current measurement. Empty, if no measurement is loaded or no description file has been found*/

std::unique_ptr<PlayThread> play_thread_; /**< The "actual" eCAL Player that runs in it's own thread and executes commands from outside */
std::string measurement_path_; /**< The path that was loaded. It may point to a file or a directory (depending on if the user loaded a measurement file or a mesaurement directory */
std::string measurement_path_; /**< The path that was loaded. It may point to a file or a directory (depending on whether the user loaded a measurement file or a measurement directory) */

/**
* @brief Loads a text file from the given file as measurement description
Expand Down
27 changes: 24 additions & 3 deletions app/play/play_core/src/ecal_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ bool EcalPlay::LoadMeasurement(const std::string& path)

std::shared_ptr<eCAL::eh5::HDF5Meas> measurement(std::make_shared<eCAL::eh5::HDF5Meas>());

std::string meas_dir;
std::string meas_dir; // The directory of the measurement
std::string path_to_load; // The actual path we load the measurement from. May be a directory or a .hdf5 file
bool is_hdf5_file = false; // Whether the given path pointed to an hdf5 file

// Check if the user opened a .ecalmeas file or a directory
// Check if the user opened a file or a directory
auto file_status = EcalUtils::Filesystem::FileStatus(path, EcalUtils::Filesystem::OsStyle::Current);
if (!file_status.IsOk())
{
Expand All @@ -72,6 +74,23 @@ bool EcalPlay::LoadMeasurement(const std::string& path)
{
if (file_status.GetType() == EcalUtils::Filesystem::Type::RegularFile)
{
// The user opened a file! Let's check if it is an HDF5 file or an .ecalmeas file!
std::string filename = EcalUtils::Filesystem::FileName(path, EcalUtils::Filesystem::OsStyle::Current);
size_t dot_pos = filename.find_last_of('.');
if (dot_pos != std::string::npos)
{
std::string file_extension = filename.substr(dot_pos);
std::transform(file_extension.begin(), file_extension.end(), file_extension.begin(),
[](char c) -> char
{
return std::tolower(static_cast<int>(c));
});
if (file_extension == ".hdf5")
{
is_hdf5_file = true;
}
}

// Although the path points to a file, our filesystem API will strip out the last componentent (i.e. the filename) when appending a "/.."
meas_dir = EcalUtils::Filesystem::CleanPath(path + "/..", EcalUtils::Filesystem::OsStyle::Current);
}
Expand All @@ -81,8 +100,10 @@ bool EcalPlay::LoadMeasurement(const std::string& path)
}
}

path_to_load = (is_hdf5_file ? path : meas_dir);

// Load the measurement
if (measurement->Open(meas_dir) && measurement->IsOk())
if (measurement->Open(path_to_load) && measurement->IsOk())
{
EcalPlayLogger::Instance()->info("Measurement dir: " + meas_dir);
play_thread_->SetMeasurement(measurement, meas_dir);
Expand Down

0 comments on commit 545af8b

Please sign in to comment.