Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
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
16using namespace pandora;
17
18namespace lar_content
19{
20
21std::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
Header file for the file helper class.
Header file for the xml helper class.
static std::string FindFileInPath(const std::string &unqualifiedFileName, const std::string &environmentVariable, const std::string &delimiter=":")
Find the fully-qualified file name by searching through a list of delimiter-separated paths in a name...
StatusCodeException class.
static void TokenizeString(const std::string &inputString, StringVector &tokens, const std::string &delimiter=" ")
Tokenize a string.
Definition XmlHelper.cc:122
std::vector< std::string > StringVector