diff --git a/modules/prediction/BUILD b/modules/prediction/BUILD index d7dd95fac5ff0830e76900d2472f4279c8b2bce1..992596079d4f37bc5af1094f3c1062f7751aab26 100644 --- a/modules/prediction/BUILD +++ b/modules/prediction/BUILD @@ -30,6 +30,7 @@ cc_library( "//modules/prediction/predictor:predictor_manager", "//modules/prediction/proto:prediction_conf_proto", "//modules/prediction/proto:prediction_proto", + "//modules/prediction/util:data_extraction", "//framework:cybertron", ], ) diff --git a/modules/prediction/prediction_component.cc b/modules/prediction/prediction_component.cc index 2739be7958a0c83aee551408c77ee9dad1086273..3a7a2342a272284b3eeb491fe74c83a65ff07d3c 100644 --- a/modules/prediction/prediction_component.cc +++ b/modules/prediction/prediction_component.cc @@ -40,6 +40,7 @@ #include "modules/prediction/evaluator/evaluator_manager.h" #include "modules/prediction/predictor/predictor_manager.h" #include "modules/prediction/proto/prediction_obstacle.pb.h" +#include "modules/prediction/util/data_extraction.h" namespace apollo { namespace prediction { @@ -61,28 +62,6 @@ std::string PredictionComponent::Name() const { return FLAGS_prediction_module_name; } -void GetDataFiles(const boost::filesystem::path& p, - std::vector* bag_files) { - CHECK(bag_files); - if (!boost::filesystem::exists(p)) { - return; - } - if (boost::filesystem::is_regular_file(p)) { - const auto ext = p.extension(); - if (ext == ".bag" || ext == ".BAG") { - AINFO << "Found bag file: " << p.c_str(); - bag_files->push_back(p.c_str()); - } - return; - } - if (boost::filesystem::is_directory(p)) { - for (auto& entry : boost::make_iterator_range( - boost::filesystem::directory_iterator(p), {})) { - GetDataFiles(entry.path(), bag_files); - } - } -} - void PredictionComponent::ProcessRosbag(const std::string& filename) { const std::vector topics{FLAGS_perception_obstacle_topic, FLAGS_localization_topic}; diff --git a/modules/prediction/util/BUILD b/modules/prediction/util/BUILD new file mode 100644 index 0000000000000000000000000000000000000000..4f035ada08ceaefac4e91fb1acd0a4a0c19a409e --- /dev/null +++ b/modules/prediction/util/BUILD @@ -0,0 +1,16 @@ +load("//tools:cpplint.bzl", "cpplint") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "data_extraction", + srcs = ["data_extraction.cc"], + hdrs = [ + "data_extraction.h", + ], + deps = [ + "//modules/common", + "//modules/common:log", + "//framework:cybertron", + ], +) diff --git a/modules/prediction/util/data_extraction.cc b/modules/prediction/util/data_extraction.cc new file mode 100644 index 0000000000000000000000000000000000000000..dcf84e4e7e6b592de0e0872dca18de670a7e7d32 --- /dev/null +++ b/modules/prediction/util/data_extraction.cc @@ -0,0 +1,47 @@ +/****************************************************************************** + * Copyright 2018 The Apollo Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#include "modules/prediction/util/data_extraction.h" + +#include "modules/common/log.h" + +namespace apollo { +namespace prediction { + +void GetDataFiles(const boost::filesystem::path& p, + std::vector* bag_files) { + CHECK(bag_files); + if (!boost::filesystem::exists(p)) { + return; + } + if (boost::filesystem::is_regular_file(p)) { + const auto ext = p.extension(); + if (ext == ".bag" || ext == ".BAG") { + AINFO << "Found bag file: " << p.c_str(); + bag_files->push_back(p.c_str()); + } + return; + } + if (boost::filesystem::is_directory(p)) { + for (auto& entry : boost::make_iterator_range( + boost::filesystem::directory_iterator(p), {})) { + GetDataFiles(entry.path(), bag_files); + } + } +} + +} // namespace prediction +} // namespace apollo diff --git a/modules/prediction/util/data_extraction.h b/modules/prediction/util/data_extraction.h new file mode 100644 index 0000000000000000000000000000000000000000..79dc1ffe2c68b478b48eed8471a149d49e0aa2a6 --- /dev/null +++ b/modules/prediction/util/data_extraction.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * Copyright 2018 The Apollo Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#ifndef MODULES_PREDICTION_UTIL_DATA_EXTRACTION_H_ +#define MODULES_PREDICTION_UTIL_DATA_EXTRACTION_H_ + +#include + +#include "boost/filesystem.hpp" +#include "boost/range/iterator_range.hpp" + +namespace apollo { +namespace prediction { + +void GetDataFiles(const boost::filesystem::path& p, + std::vector* bag_files); + +} // namespace prediction +} // namespace apollo + +#endif /* MODULES_PREDICTION_UTIL_DATA_EXTRACTION_H_ */