artdaq_core  v1_07_01
 All Classes Namespaces Functions
SimpleLookupPolicy.cc
1 
8 #include "artdaq-core/Utilities/SimpleLookupPolicy.h"
9 #include "cetlib/filesystem.h"
10 
12 SimpleLookupPolicy(std::string const &paths, ArgType argType)
13 {
14  // the cetlib search_path constructor expects either the name of
15  // an environmental variable that contains the search path *or* a
16  // colon-delimited list of paths. So, a constructor argument of
17  // a single path string is doomed to fail because it gets interpreted
18  // as an env var. So, in this class, we will always pass either
19  // an env var name or a list of paths. If/when a single path is
20  // specified, we'll simply duplicate it so that search_path will
21  // do the right thing.
22  cwdPath_.reset(new cet::search_path(".:."));
23 
24  // if no fallback path was specified, simply use the current directory
25  if (paths.empty()) {
26  fallbackPaths_.reset(new cet::search_path(".:."));
27  return;
28  }
29 
30  if (argType == PATH_STRING) {
31  std::string workString(paths);
32  if (workString.find(':') == std::string::npos) {
33  workString.append(":");
34  workString.append(paths);
35  }
36  fallbackPaths_.reset(new cet::search_path(workString));
37  }
38 
39  else { // argType == ENV_VAR
40  fallbackPaths_.reset(new cet::search_path(paths));
41  }
42 }
43 
44 std::string artdaq::SimpleLookupPolicy::operator() (std::string const &filename)
45 {
46  if (cet::is_absolute_filepath(filename)) {
47  return filename;
48  }
49 
50  try {
51  return cwdPath_->find_file(filename);
52  }
53  catch (...) {}
54 
55  return fallbackPaths_->find_file(filename);
56 }
57 
58 artdaq::SimpleLookupPolicy::~SimpleLookupPolicy() noexcept
59 {
60 }
SimpleLookupPolicy(std::string const &paths, ArgType argType=ENV_VAR)