17 #ifndef NVTRACKERPARAMS_HPP_
18 #define NVTRACKERPARAMS_HPP_
27 namespace NvTrackerFilesystem = std::filesystem;
29 #include <experimental/filesystem>
31 #include <yaml-cpp/yaml.h>
32 #include "modules/utility/debug_common.hpp"
45 virtual void read(
const YAML::Node& fn) = 0;
57 if (filePath.empty() || configFilePath.empty())
63 std::filesystem::path requestedPath(filePath);
64 if (requestedPath.is_absolute()) {
65 return requestedPath.string();
67 return (std::filesystem::absolute(std::filesystem::path(configFilePath)).parent_path() /
68 requestedPath).string();
70 char resolved[PATH_MAX + 1];
72 if (filePath[0] ==
'/')
74 if (realpath(filePath.c_str(), resolved) !=
nullptr)
76 return std::string(resolved);
85 char absCfg[PATH_MAX + 1];
86 if (realpath(configFilePath.c_str(), absCfg) ==
nullptr)
91 std::string cfgDir(absCfg);
92 const size_t last = cfgDir.find_last_of(
'/');
93 if (last != std::string::npos)
95 cfgDir.resize(last + 1);
102 const std::string combined = cfgDir + filePath;
103 if (realpath(combined.c_str(), resolved) !=
nullptr)
105 return std::string(resolved);
121 static const YAML::Node
getConfigRoot(
const std::string &configFilePath,
const bool printMessage =
false)
124 if(configFilePath.size() == 0)
128 std::cout <<
"[NvTrackerParams::getConfigRoot()] !!![WARNING] Empty config file path is provided. Will go ahead with default values" << std::endl;
133 std::filesystem::exists(configFilePath)
135 std::experimental::filesystem::exists(configFilePath)
141 std::cout <<
"[NvTrackerParams::getConfigRoot()] !!![WARNING] File doesn't exist. Will go ahead with default values" << std::endl;
148 YAML::Node configFn = YAML::LoadFile(configFilePath);
150 if(configFn.size() > 0)
158 std::cout <<
"[NvTrackerParams::getConfigRoot()] !!![WARNING] Can't open config file (" << configFilePath <<
"). Will go ahead with default values" << std::endl;
162 catch (std::exception& e)
167 std::string(
"[NvTrackerParams::getConfigRoot()] !!![WARNING] Invalid low-level config file caused an exception, but will go ahead with the default config values" ).c_str()
187 if (name.size() <= 5)
191 else if (name.substr(0, 5) !=
"model")
197 for (
uint ind = 5; ind < name.size(); ind++)
199 if (!std::isdigit(name.at(ind)) )
214 return "model" + std::to_string(index);
218 #endif // NVTRACKERPARAMS_HPP_