Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[measurement] GetChannelDataTypeInformation / SetChannelDataTypeInformation #1349

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/meas_cutter/src/measurement_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ MeasurementExporter::~MeasurementExporter()
void MeasurementExporter::createChannel(const std::string& channel_name, const eCALMeasCutterUtils::ChannelInfo& channel_info)
{
_current_channel_name = channel_name;
eCAL::experimental::measurement::base::DataTypeInformation data_type_info;
if (channel_info.format == eCALMeasCutterUtils::SerializationFormat::PROTOBUF)
{
_writer->SetChannelType(channel_name, "proto:" + channel_info.type);
data_type_info.encoding = "proto";
}
else
{
_writer->SetChannelType(channel_name, channel_info.type);
data_type_info.encoding = "";
}
_writer->SetChannelDescription(channel_name, channel_info.description);
data_type_info.name = channel_info.type;
data_type_info.descriptor = channel_info.description;
_writer->SetChannelDataTypeInformation(channel_name, data_type_info);
}

void MeasurementExporter::setData(eCALMeasCutterUtils::Timestamp timestamp, const eCALMeasCutterUtils::MetaData& meta_data, const std::string& payload)
Expand Down
13 changes: 6 additions & 7 deletions app/meas_cutter/src/measurement_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ void MeasurementImporter::openChannel(const std::string& channel_name)
_current_opened_channel_data._timestamps.clear();
_current_opened_channel_data._timestamp_entry_info_map.clear();

if (isProtoChannel(_reader->GetChannelType(channel_name)))
auto channel_information = _reader->GetChannelDataTypeInformation(channel_name);
if (isProtoChannel(channel_information))
{
_current_opened_channel_data._channel_info.format = eCALMeasCutterUtils::SerializationFormat::PROTOBUF;
_current_opened_channel_data._channel_info.type = _reader->GetChannelType(channel_name).substr(6); // remove "proto:" from type string
}
else
{
_current_opened_channel_data._channel_info.format = eCALMeasCutterUtils::SerializationFormat::UNKNOWN;
_current_opened_channel_data._channel_info.type = _reader->GetChannelType(channel_name);
}
_current_opened_channel_data._channel_info.description = _reader->GetChannelDescription(channel_name);
_current_opened_channel_data._channel_info.type = channel_information.name;
_current_opened_channel_data._channel_info.description = channel_information.descriptor;
_current_opened_channel_data._channel_info.name = channel_name;

eCAL::experimental::measurement::base::EntryInfoSet entry_info_set;
Expand Down Expand Up @@ -177,10 +177,9 @@ bool MeasurementImporter::isEcalMeasFile(const std::string& path)
return false;
}

bool MeasurementImporter::isProtoChannel(const std::string& channel_type)
bool MeasurementImporter::isProtoChannel(const eCAL::experimental::measurement::base::DataTypeInformation& channel_info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'isProtoChannel' can be made static [readability-convert-member-functions-to-static]

app/meas_cutter/src/measurement_importer.h:54:

-   bool                                 isProtoChannel(const eCAL::experimental::measurement::base::DataTypeInformation& channel_info);
+   static bool                                 isProtoChannel(const eCAL::experimental::measurement::base::DataTypeInformation& channel_info);

{
std::string space = channel_type.substr(0, channel_type.find_first_of(':'));
return (space.compare("proto") == 0);
return (channel_info.encoding == "proto");
}

std::string MeasurementImporter::getLoadedPath()
Expand Down
2 changes: 1 addition & 1 deletion app/meas_cutter/src/measurement_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MeasurementImporter

private:
bool isEcalMeasFile(const std::string& path);
bool isProtoChannel(const std::string& channel_type);
bool isProtoChannel(const eCAL::experimental::measurement::base::DataTypeInformation& channel_info);
std::unique_ptr<eCAL::experimental::measurement::base::Reader> _reader;
eCALMeasCutterUtils::ChannelData _current_opened_channel_data;
std::string _loaded_path;
Expand Down
14 changes: 9 additions & 5 deletions app/play/play_core/src/measurement_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ void MeasurementContainer::CreatePublishers(const std::map<std::string, std::str
// Create new publishers
for (const auto& channel_mapping : publisher_map)
{
auto topic_type = hdf5_meas_->GetChannelType(channel_mapping.first);
auto topic_description = hdf5_meas_->GetChannelDescription(channel_mapping.first);

publisher_map_.emplace(channel_mapping.first, PublisherInfo(channel_mapping.second, topic_type, topic_description));
auto topic_info = hdf5_meas_->GetChannelDataTypeInformation(channel_mapping.first);
eCAL::SDataTypeInformation data_type_info;
data_type_info.name = topic_info.name;
data_type_info.encoding = topic_info.encoding;
data_type_info.descriptor = topic_info.descriptor;
publisher_map_.emplace(channel_mapping.first, PublisherInfo(channel_mapping.second, data_type_info));
}

// Assign publishers to entries
Expand Down Expand Up @@ -307,7 +309,9 @@ double MeasurementContainer::GetMaxTimestampOfChannel(const std::string& channel

std::string MeasurementContainer::GetChannelType(const std::string& channel_name) const
{
return hdf5_meas_->GetChannelType(channel_name);
// This function needs to also return the proper datatypes information! To clean up.
auto datatype_information = hdf5_meas_->GetChannelDataTypeInformation(channel_name);
return eCAL::Util::CombinedTopicEncodingAndType(datatype_information.encoding, datatype_information.name);
}

size_t MeasurementContainer::GetChannelCumulativeEstimatedSize(const std::string& channel_name) const
Expand Down
4 changes: 2 additions & 2 deletions app/play/play_core/src/measurement_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class MeasurementContainer
eCAL::CPublisher publisher_;
long long message_counter_;

PublisherInfo(const std::string& topic_name, const std::string& topic_type = "", const std::string& topic_description = "")
: publisher_(topic_name, topic_type, topic_description)
PublisherInfo(const std::string& topic_name, const eCAL::SDataTypeInformation& info_)
: publisher_(topic_name, info_)
, message_counter_(0)
{}
};
Expand Down
44 changes: 38 additions & 6 deletions app/rec/rec_client_core/include/rec_client_core/topic_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,56 @@
#include <string>
#include <set>
#include <map>
#include <ecal/ecal_types.h>

namespace eCAL
{
namespace rec
{
struct TopicInfo
{
TopicInfo(const std::string& type, const std::string& description)
: type_(type), description_(description), description_quality_(0)
TopicInfo(const eCAL::SDataTypeInformation& tinfo)
: tinfo_(tinfo)
{}

TopicInfo(const std::string& type, const std::string& encoding, const std::string& description)
: tinfo_{ type, encoding, description }
{}

TopicInfo()
: description_quality_(0)
{}

std::string type_;
std::string description_;
eCAL::SDataTypeInformation tinfo_;

// This should be removed once internally SDatatypeInformation is saved alongside with the publisher ID..
std::string GetLegacyType() const
{
if (tinfo_.encoding.empty())
{
return tinfo_.name;
}
else
{
return tinfo_.encoding + ":" + tinfo_.name;
}
}

void SetLegacyType(const std::string& combined_topic_type_)
{
auto pos = combined_topic_type_.find(':');
if (pos == std::string::npos)
{
tinfo_.encoding = "";
tinfo_.name = combined_topic_type_;
}
else
{
tinfo_.encoding = combined_topic_type_.substr(0, pos);
tinfo_.name = combined_topic_type_.substr(pos + 1);
}
}

int description_quality_;
int description_quality_ = 0;

std::map<std::string, std::set<std::string>> publishers_;
};
Expand Down
4 changes: 2 additions & 2 deletions app/rec/rec_client_core/src/job/hdf5_writer_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ namespace eCAL

for (const auto& topic : topic_info_map_to_set)
{
hdf5_writer_->SetChannelType(topic.first, topic.second.type_);
hdf5_writer_->SetChannelDescription(topic.first, topic.second.description_);
eCAL::experimental::measurement::base::DataTypeInformation const topic_info{ topic.second.tinfo_.name, topic.second.tinfo_.encoding, topic.second.tinfo_.descriptor };
hdf5_writer_->SetChannelDataTypeInformation(topic.first, topic_info);
}
}
else if (frame)
Expand Down
12 changes: 6 additions & 6 deletions app/rec/rec_client_core/src/monitoring_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace eCAL
if (topic_info_map_it == topic_info_map_.end())
{
// Create a new topic entry
topic_info_map_.emplace(topic.tname(), eCAL::rec::TopicInfo("", ""));
topic_info_map_.emplace(topic.tname(), eCAL::rec::TopicInfo("", "", ""));
topic_info_map_it = topic_info_map_.find(topic.tname());
}

Expand Down Expand Up @@ -166,18 +166,18 @@ namespace eCAL
if ((channel_descriptor_entry_it != channel_descriptor_map.end())
&& (channel_descriptor_entry_it->second.first >= topic_info_map_entry.second.description_quality_))
{
topic_info_map_entry.second.type_ = channel_descriptor_entry_it->second.second.first;
topic_info_map_entry.second.description_ = channel_descriptor_entry_it->second.second.second;
topic_info_map_entry.second.SetLegacyType(channel_descriptor_entry_it->second.second.first);
topic_info_map_entry.second.tinfo_.descriptor = channel_descriptor_entry_it->second.second.second;
topic_info_map_entry.second.description_quality_ = channel_descriptor_entry_it->second.first;
}

if (!topic_info_map_entry.second.type_.empty())
if (!topic_info_map_entry.second.GetLegacyType().empty())
{
auto type_descriptor_entry_it = type_descriptor_map.find(topic_info_map_entry.second.type_);
auto type_descriptor_entry_it = type_descriptor_map.find(topic_info_map_entry.second.GetLegacyType());
if ((type_descriptor_entry_it != type_descriptor_map.end())
&& (type_descriptor_entry_it->second.first >= topic_info_map_entry.second.description_quality_))
{
topic_info_map_entry.second.description_ = type_descriptor_entry_it->second.second;
topic_info_map_entry.second.tinfo_.descriptor = type_descriptor_entry_it->second.second;
topic_info_map_entry.second.description_quality_ = type_descriptor_entry_it->second.first;
}
}
Expand Down
23 changes: 23 additions & 0 deletions contrib/ecalhdf5/include/ecalhdf5/eh5_meas.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ namespace eCAL
*
* @return channel description
**/
[[deprecated("Please use GetChannelDataTypeInformation instead")]]
std::string GetChannelDescription(const std::string& channel_name) const;

/**
Expand All @@ -195,6 +196,7 @@ namespace eCAL
* @param channel_name channel name
* @param description description of the channel
**/
[[deprecated("Please use SetChannelDataTypeInformation instead")]]
void SetChannelDescription(const std::string& channel_name, const std::string& description);

/**
Expand All @@ -204,6 +206,7 @@ namespace eCAL
*
* @return channel type
**/
[[deprecated("Please use GetChannelDataTypeInformation instead")]]
std::string GetChannelType(const std::string& channel_name) const;

/**
Expand All @@ -212,8 +215,28 @@ namespace eCAL
* @param channel_name channel name
* @param type type of the channel
**/
[[deprecated("Please use SetChannelDataTypeInformation instead")]]
void SetChannelType(const std::string& channel_name, const std::string& type);

/**
* @brief Get data type information of the given channel
*
* @param channel_name channel name
*
* @return channel type
**/
DataTypeInformation GetChannelDataTypeInformation(const std::string& channel_name) const;

/**
* @brief Set data type information of the given channel
*
* @param channel_name channel name
* @param info datatype info of the channel
*
* @return channel type
**/
void SetChannelDataTypeInformation(const std::string& channel_name, const DataTypeInformation& info);

/**
* @brief Gets minimum timestamp for specified channel
*
Expand Down
2 changes: 2 additions & 0 deletions contrib/ecalhdf5/include/ecalhdf5/eh5_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace eCAL
using eAccessType = eCAL::experimental::measurement::base::AccessType;
using eCAL::experimental::measurement::base::RDONLY;
using eCAL::experimental::measurement::base::CREATE;

using eCAL::experimental::measurement::base::DataTypeInformation;
//!< @endcond
} // namespace eh5
} // namespace eCAL
41 changes: 27 additions & 14 deletions contrib/ecalhdf5/src/eh5_meas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,41 +233,54 @@ bool eCAL::eh5::HDF5Meas::HasChannel(const std::string& channel_name) const
return ret_val;
}

// deprecated
std::string eCAL::eh5::HDF5Meas::GetChannelDescription(const std::string& channel_name) const
{
std::string ret_val;
if (hdf_meas_impl_)
{
ret_val = hdf_meas_impl_->GetChannelDescription(GetEscapedTopicname(channel_name));
}

return ret_val;
auto datatype_info = GetChannelDataTypeInformation(channel_name);
return datatype_info.descriptor;
}

// deprecated
void eCAL::eh5::HDF5Meas::SetChannelDescription(const std::string& channel_name, const std::string& description)
{
if (hdf_meas_impl_)
{
hdf_meas_impl_->SetChannelDescription(GetEscapedTopicname(channel_name), description);
}
auto current_info = GetChannelDataTypeInformation(channel_name);
current_info.descriptor = description;
SetChannelDataTypeInformation(channel_name, current_info);
}

// deprecated
std::string eCAL::eh5::HDF5Meas::GetChannelType(const std::string& channel_name) const
{
std::string ret_val;
auto datatype_info = GetChannelDataTypeInformation(channel_name);
std::tie(ret_val, std::ignore) = FromInfo(datatype_info);
return ret_val;
}

// deprecated
void eCAL::eh5::HDF5Meas::SetChannelType(const std::string& channel_name, const std::string& type)
{
auto current_info = GetChannelDataTypeInformation(channel_name);
auto new_info = CreateInfo(type, current_info.descriptor);
SetChannelDataTypeInformation(channel_name, new_info);
}

eCAL::eh5::DataTypeInformation eCAL::eh5::HDF5Meas::GetChannelDataTypeInformation(const std::string& channel_name) const
{
eCAL::eh5::DataTypeInformation ret_val;
if (hdf_meas_impl_)
{
ret_val = hdf_meas_impl_->GetChannelType(GetEscapedTopicname(channel_name));
ret_val = hdf_meas_impl_->GetChannelDataTypeInformation(GetEscapedTopicname(channel_name));
}

return ret_val;
}

void eCAL::eh5::HDF5Meas::SetChannelType(const std::string& channel_name, const std::string& type)
void eCAL::eh5::HDF5Meas::SetChannelDataTypeInformation(const std::string& channel_name, const eCAL::eh5::DataTypeInformation& info)
{
if (hdf_meas_impl_)
{
hdf_meas_impl_->SetChannelType(GetEscapedTopicname(channel_name), type);
hdf_meas_impl_->SetChannelDataTypeInformation(GetEscapedTopicname(channel_name), info);
}
}

Expand Down
Loading
Loading