All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
Header file for the file helper class.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
BEGIN_PROLOG could also be cout