$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_06_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include <memory> 00002 00003 #include "artdaq-core/Utilities/SimpleLookupPolicy.hh" 00004 #include "cetlib/filesystem.h" 00005 00006 artdaq::SimpleLookupPolicy:: 00007 SimpleLookupPolicy(std::string const& paths, ArgType argType) 00008 { 00009 // the cetlib search_path constructor expects either the name of 00010 // an environmental variable that contains the search path *or* a 00011 // colon-delimited list of paths. So, a constructor argument of 00012 // a single path string is doomed to fail because it gets interpreted 00013 // as an env var. So, in this class, we will always pass either 00014 // an env var name or a list of paths. If/when a single path is 00015 // specified, we'll simply duplicate it so that search_path will 00016 // do the right thing. 00017 cwdPath_ = std::make_unique<cet::search_path>(".:."); 00018 00019 // if no fallback path was specified, simply use the current directory 00020 if (paths.empty()) 00021 { 00022 fallbackPaths_ = std::make_unique<cet::search_path>(".:."); 00023 return; 00024 } 00025 00026 if (argType == ArgType::PATH_STRING) 00027 { 00028 auto workString(paths); 00029 if (workString.find(':') == std::string::npos) 00030 { 00031 workString.append(":"); 00032 workString.append(paths); 00033 } 00034 fallbackPaths_ = std::make_unique<cet::search_path>(workString); 00035 } 00036 00037 else 00038 { // argType == ENV_VAR 00039 fallbackPaths_ = std::make_unique<cet::search_path>(paths); 00040 } 00041 } 00042 00043 std::string artdaq::SimpleLookupPolicy::operator()(std::string const& filename) 00044 { 00045 if (cet::is_absolute_filepath(filename)) 00046 { 00047 return filename; 00048 } 00049 00050 try 00051 { 00052 return cwdPath_->find_file(filename); 00053 } 00054 catch (...) 00055 {} 00056 00057 return fallbackPaths_->find_file(filename); 00058 } 00059 00060 artdaq::SimpleLookupPolicy::~SimpleLookupPolicy() noexcept = default;