Skip to content

Commit

Permalink
Measurement Reader provides DatatypeInfo instead of separate Type & D…
Browse files Browse the repository at this point in the history
…escriptor Infos.
  • Loading branch information
KerstinKeller committed Oct 26, 2023
1 parent df8efee commit c8dae59
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 43 deletions.
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::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::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.compare("proto") == 0);
}

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::measurement::base::DataTypeInformation& channel_info);
std::unique_ptr<eCAL::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, eCAL::SDataTypeInformation info_)
: publisher_(topic_name, info_)
, message_counter_(0)
{}
};
Expand Down
51 changes: 34 additions & 17 deletions contrib/ecalhdf5/include/ecalhdf5/eh5_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ namespace eCAL
namespace eh5
{

// To be removed soon-ish!
std::pair<std::string, std::string> SplitCombinedTopicType(const std::string& combined_topic_type_)
{
auto pos = combined_topic_type_.find(':');
if (pos == std::string::npos)
{
std::string encoding;
std::string type{ combined_topic_type_ };
return std::make_pair(encoding, type);
}
else
{
std::string encoding = combined_topic_type_.substr(0, pos);
std::string type = combined_topic_type_.substr(pos + 1);
return std::make_pair(encoding, type);
}
}

/**
* @brief Hdf5 based Reader Implementation
**/
Expand Down Expand Up @@ -111,23 +129,22 @@ namespace eCAL
**/
bool HasChannel(const std::string& channel_name) const override { return measurement.HasChannel(channel_name); }

/**
* @brief Get the channel description for the given channel
*
* @param channel_name channel name
*
* @return channel description
**/
std::string GetChannelDescription(const std::string& channel_name) const override { return measurement.GetChannelDescription(channel_name); }

/**
* @brief Gets the channel type of the given channel
*
* @param channel_name channel name
*
* @return channel type
**/
std::string GetChannelType(const std::string& channel_name) const override { return measurement.GetChannelType(channel_name); }
/**
* @brief Get data type information of the given channel
*
* @param channel_name channel name
*
* @return channel type
**/
measurement::base::DataTypeInformation GetChannelDataTypeInformation(const std::string& channel_name) {
measurement::base::DataTypeInformation info;
auto type = measurement.GetChannelType(channel_name);
auto split_types = SplitCombinedTopicType(type);
info.encoding = split_types.first;
info.name = split_types.second;
info.descriptor = measurement.GetChannelDescription(channel_name);
return info;
}

/**
* @brief Gets minimum timestamp for specified channel
Expand Down
13 changes: 2 additions & 11 deletions contrib/measurement/base/include/ecal/measurement/base/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,13 @@ namespace eCAL
virtual bool HasChannel(const std::string& channel_name) const = 0;

/**
* @brief Get the channel description for the given channel
*
* @param channel_name channel name
*
* @return channel description
**/
virtual std::string GetChannelDescription(const std::string& channel_name) const = 0;

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

/**
* @brief Gets minimum timestamp for specified channel
Expand Down
23 changes: 23 additions & 0 deletions contrib/measurement/base/include/ecal/measurement/base/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ namespace eCAL
{
namespace base
{
/**
* @brief Optional compile time information associated with a given topic
* (necessary for reflection / runtime type checking)
**/
struct DataTypeInformation
{
std::string name; //!< name of the datatype
std::string encoding; //!< encoding of the datatype (e.g. protobuf, flatbuffers, capnproto)
std::string descriptor; //!< descriptor information of the datatype (necessary for reflection)

//!< @cond
bool operator==(const DataTypeInformation& other) const
{
return name == other.name && encoding == other.encoding && descriptor == other.descriptor;
}

bool operator!=(const DataTypeInformation& other) const
{
return !(*this == other);
}
//!< @endcond
};

/**
* @brief Info struct for a single measurement entry
**/
Expand Down

0 comments on commit c8dae59

Please sign in to comment.