LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar_content::LArFileHelper Class Reference

LArFileHelper class. More...

#include "LArFileHelper.h"

Static Public Member Functions

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 named environment variable. The fully-qualified file name will be provided for the first instance of the file name encountered. More...
 

Detailed Description

LArFileHelper class.

Definition at line 19 of file LArFileHelper.h.

Member Function Documentation

std::string lar_content::LArFileHelper::FindFileInPath ( const std::string &  unqualifiedFileName,
const std::string &  environmentVariable,
const std::string &  delimiter = ":" 
)
static

Find the fully-qualified file name by searching through a list of delimiter-separated paths in a named environment variable. The fully-qualified file name will be provided for the first instance of the file name encountered.

Parameters
unqualifiedFileNamethe unqualified file name
environmentVariablethe name of the environment variable specifying a list of delimiter-separated paths
delimiterthe specified delimiter
Returns
the fully-qualified name if found, else a StatusCode exception will be raised

Definition at line 21 of file LArFileHelper.cc.

Referenced by lar_content::MvaPfoCharacterisationAlgorithm< T >::ReadSettings(), lar_content::MvaVertexSelectionAlgorithm< T >::ReadSettings(), lar_content::NeutrinoIdTool< T >::ReadSettings(), lar_content::MasterAlgorithm::ReadSettings(), and lar_content::BdtBeamParticleIdTool::ReadSettings().

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 }

The documentation for this class was generated from the following files: