00001
00008 #include "artdaq-core/Utilities/SimpleLookupPolicy.h"
00009 #include "cetlib/filesystem.h"
00010
00011 artdaq::SimpleLookupPolicy::
00012 SimpleLookupPolicy(std::string const &paths, ArgType argType)
00013 {
00014
00015
00016
00017
00018
00019
00020
00021
00022 cwdPath_.reset(new cet::search_path(".:."));
00023
00024
00025 if (paths.empty()) {
00026 fallbackPaths_.reset(new cet::search_path(".:."));
00027 return;
00028 }
00029
00030 if (argType == PATH_STRING) {
00031 std::string workString(paths);
00032 if (workString.find(':') == std::string::npos) {
00033 workString.append(":");
00034 workString.append(paths);
00035 }
00036 fallbackPaths_.reset(new cet::search_path(workString));
00037 }
00038
00039 else {
00040 fallbackPaths_.reset(new cet::search_path(paths));
00041 }
00042 }
00043
00044 std::string artdaq::SimpleLookupPolicy::operator() (std::string const &filename)
00045 {
00046 if (cet::is_absolute_filepath(filename)) {
00047 return filename;
00048 }
00049
00050 try {
00051 return cwdPath_->find_file(filename);
00052 }
00053 catch (...) {}
00054
00055 return fallbackPaths_->find_file(filename);
00056 }
00057
00058 artdaq::SimpleLookupPolicy::~SimpleLookupPolicy() noexcept
00059 {
00060 }