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
00008
00009
00010
00011
00012
00013
00014
00015 cwdPath_.reset(new cet::search_path(".:."));
00016
00017
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 {
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 {}