Apollo 10.0
自动驾驶开放平台
util.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
20#include "cyber/common/file.h"
21
22namespace apollo {
23namespace perception {
24
27
28std::string GetCommonConfigFile(const std::string &config_file) {
29 std::string actual_config_path = "";
30 std::string relative_config_path = config_file;
31 if (!apollo::cyber::common::PathIsAbsolute(config_file)) {
32 // If config_file is relative, then prepend "modules/" to it.
33 relative_config_path = "modules/perception/data/conf/" + config_file;
34 }
36 relative_config_path, "APOLLO_CONF_PATH", &actual_config_path)) {
37 AERROR << "Failed to get config path of " << config_file << " please check "
38 << "if config exists or `APOLLO_CONF_PATH` environment variable has "
39 << "been set correctly.";
40 }
41 return actual_config_path;
42}
43
44std::string GetModelPath(const std::string &model_name) {
45 std::string model_path = "";
47 model_name, "APOLLO_MODEL_PATH", &model_path)) {
48 AERROR << "Failed to get model path of " << model_name << " please check "
49 << "if model has been installed or `APOLLO_MODEL_PATH` environment "
50 << "variable has been set correctly.";
51 }
52 return model_path;
53}
54
55std::string GetModelFile(const std::string &model_name,
56 const std::string &file_name) {
57 std::string model_path = GetModelPath(model_name);
58 if (model_path.empty()) {
59 return "";
60 }
61 return model_path + "/" + file_name;
62}
63
64std::string GetConfigPath(const std::string &config_path) {
65 std::string actual_config_path = "";
66 std::string relative_config_path = config_path;
67 if (!apollo::cyber::common::PathIsAbsolute(config_path)) {
68 // If config_path is relative, then prepend "modules/" to it.
69 relative_config_path = "modules/" + config_path;
70 }
72 relative_config_path, "APOLLO_CONF_PATH", &actual_config_path)) {
73 AERROR << "Failed to get config path of " << config_path << " please check "
74 << "if config exists or `APOLLO_CONF_PATH` environment variable has "
75 << "been set correctly.";
76 }
77 return actual_config_path;
78}
79
80std::string GetConfigFile(const std::string &config_path,
81 const std::string &config_file) {
82 std::string absolute_config_path = GetConfigPath(config_path);
83 std::string file_path =
84 cyber::common::GetAbsolutePath(absolute_config_path, config_file);
85 return file_path;
86}
87
88} // namespace perception
89} // namespace apollo
#define AERROR
Definition log.h:44
bool GetFilePathWithEnv(const std::string &path, const std::string &env_var, std::string *file_path)
get file path, judgement priority:
Definition file.cc:436
std::string GetAbsolutePath(const std::string &prefix, const std::string &relative_path)
Get absolute path by concatenating prefix and relative_path.
Definition file.cc:179
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
Definition environment.h:29
bool PathIsAbsolute(const std::string &path)
Definition file.cc:200
std::string GetConfigPath(const std::string &config_path)
Get the config path
Definition util.cc:64
std::string GetCommonConfigFile(const std::string &config_file)
Get the perception common config path
Definition util.cc:28
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
Definition util.cc:55
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
Definition util.cc:44
class register implement
Definition arena_queue.h:37