LArFileHelper.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArHelpers/LArFileHelper.cc
3  *
4  * @brief Implementation of the file helper class.
5  *
6  * $Log: $
7  */
8 
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
42  << ", delimiter " << delimiter << std::endl;
43  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
44 }
45 
46 } // namespace lar_content
std::string string
Definition: nybbler.cc:12
std::string getenv(std::string const &name)
Definition: getenv.cc:15
Header file for the file helper class.
std::vector< string > StringVector
Definition: fcldump.cxx:29
QTextStream & endl(QTextStream &s)