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