LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
LArFileHelper.cc
Go to the documentation of this file.
1 
9 #include "Helpers/XmlHelper.h"
10 
12 
13 #include <cstdlib>
14 #include <sys/stat.h>
15 
16 using namespace pandora;
17 
18 namespace lar_content
19 {
20 
21 std::string LArFileHelper::FindFileInPath(const std::string &unqualifiedFileName, const std::string &environmentVariable, const std::string &delimiter)
22 {
23  StringVector filePaths;
24  const char *const pFilePathList(std::getenv(environmentVariable.c_str()));
25 
26  if (pFilePathList)
27  XmlHelper::TokenizeString(pFilePathList, filePaths, delimiter);
28 
29  // Always test unqualified file name too
30  filePaths.push_back("");
31 
32  for (const std::string &filePath : filePaths)
33  {
34  const std::string qualifiedFileNameAttempt(filePath + "/" + unqualifiedFileName);
35  struct stat fileInfo;
36 
37  if (0 == stat(qualifiedFileNameAttempt.c_str(), &fileInfo))
38  return qualifiedFileNameAttempt;
39  }
40 
41  std::cout << "Unable to find file " << unqualifiedFileName << " in any path specified by environment variable " << environmentVariable << ", delimiter " << delimiter << std::endl;
42  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
43 }
44 
45 } // namespace lar_content
Header file for the file helper class.