-
Notifications
You must be signed in to change notification settings - Fork 294
Exclude topics #105
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
Exclude topics #105
Changes from 2 commits
fccafd0
c7a885a
ec055cb
255102d
9202737
65ed49e
9bb8d9d
f521e92
f7297a0
9880bf2
ce5cad4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| #include <chrono> | ||
| #include <string> | ||
| #include <vector> | ||
| #include <set> | ||
danieldube marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #include "rosbag2_transport/rosbag2_transport.hpp" | ||
| #include "rosbag2_transport/record_options.hpp" | ||
|
|
@@ -102,18 +103,21 @@ rosbag2_transport_play(PyObject * Py_UNUSED(self), PyObject * args, PyObject * k | |
| "storage_id", | ||
| "node_prefix", | ||
| "read_ahead_queue_size", | ||
| "exclude_topics", | ||
| nullptr | ||
| }; | ||
|
|
||
| char * uri; | ||
| char * storage_id; | ||
| char * node_prefix; | ||
| PyObject * exclude_topics = nullptr; | ||
| size_t read_ahead_queue_size; | ||
| if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|k", const_cast<char **>(kwlist), | ||
| if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss|kO", const_cast<char **>(kwlist), | ||
| &uri, | ||
| &storage_id, | ||
| &node_prefix, | ||
| &read_ahead_queue_size)) | ||
| &read_ahead_queue_size, | ||
| &exclude_topics)) | ||
| { | ||
| return nullptr; | ||
| } | ||
|
|
@@ -124,6 +128,32 @@ rosbag2_transport_play(PyObject * Py_UNUSED(self), PyObject * args, PyObject * k | |
| play_options.node_prefix = std::string(node_prefix); | ||
| play_options.read_ahead_queue_size = read_ahead_queue_size; | ||
|
|
||
| std::set<std::string> exclude_topics_list; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the command that the topic names could be filtered for uniqueness on the python side, I believe it makes sense to parse the topics as a vector and reuse the code for converting the PyObject to a vector from the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored the PyObject parser code into a generic parse_python_list() function. |
||
| if (exclude_topics) { | ||
| PyObject * topic_exclude_iterator = PyObject_GetIter(exclude_topics); | ||
| if (topic_exclude_iterator != nullptr) { | ||
| PyObject * topic; | ||
| while ((topic = PyIter_Next(topic_exclude_iterator))) { | ||
| exclude_topics_list.insert(PyUnicode_AsUTF8(topic)); | ||
|
|
||
| Py_DECREF(topic); | ||
| } | ||
| Py_DECREF(topic_exclude_iterator); | ||
| } | ||
|
|
||
| if (exclude_topics_list.empty() == false) { | ||
| auto topic_filter_function = [exclude_topics_list](const std::string& topic) | ||
| { | ||
| auto entry = exclude_topics_list.find(topic); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this block just be replaced by
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would argue, that the current implementation is more readable and therefore more expressive than putting everything into one line. However, if you like to change this, I'll do it.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought to believe that it's easier for the compiler to inline and optimize this as there is no if and thus no branch prediction and stuff might happen. But it's solely premature optimization thinking :) |
||
| if (entry == exclude_topics_list.end()) | ||
| return false; | ||
| return true; | ||
| }; | ||
|
|
||
| play_options.topic_filter = topic_filter_function; | ||
| } | ||
| } | ||
|
|
||
| rosbag2_transport::Rosbag2Transport transport; | ||
| transport.init(); | ||
| transport.play(storage_options, play_options); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for unique topic names can be done in python. I guess that's a bit easier and avoids the need of a
std::set.Something like
exclude_topics = list(set(args.exclude_topics))Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me a set would be the natural choice of container. I guess at this point it doesn't make a difference, but the idea is to have a O(log n) complexity for excluding topic names.
Using a set on python side, wouldn't guarantee, that the API isn't misused from Python side in the future. Using a sorted vector and binary search for the topic lookup bloats the code. @Karsten1987, are you sure you want to have a std::vector instead of a std::set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not completely certain that I follow correctly. The idea to filter out duplicates in Python is really just a convenience thing because it's a one-liner in Python. That allows us further to pass in a vector with unique topic names in C++.
I am not so much concerned about a misuse from Python side as the current c++ file relies on receiving PyObjects.