Belle II Software  release-08-01-10
FileSystem Class Reference

Utility functions related to filename validation and filesystem access. More...

#include <FileSystem.h>

Classes

class  Lock
 Helper class for locking a file. More...
 
class  TemporaryFile
 Helper file to create a temporary file and ensure deletion if object goes out of scope. More...
 

Static Public Member Functions

static std::string findFile (const std::string &path, bool silent=false)
 Search for given file or directory in local or central release directory, and return absolute path if found. More...
 
static std::string findFile (const std::string &path, const std::string &dataType, bool silent=false)
 Search for given file or directory in the directory given by the environment variable BELLE2_<DATATYPE>_DATA_DIR or local/central release directory and return absolute path if found. More...
 
static bool fileExists (const std::string &filename)
 Check if the file with given filename exists.
 
static bool fileDirExists (const std::string &filename)
 Check if the dir containing the filename exists.
 
static bool isFile (const std::string &filename)
 Check if filename points to an existing file.
 
static bool isDir (const std::string &filename)
 Check if filename points to an existing directory.
 
static bool isSymLink (const std::string &filename)
 Check if filename points to an existing symbolic link.
 
static std::string calculateMD5 (const std::string &filename)
 Calculate the MD5 checksum of a given file.
 
static std::string calculateAdler32 (const std::string &filename)
 Calculate the Adler-32 checksum of a given file.
 
static bool loadLibrary (std::string library, bool fullname=true)
 Load a shared library. More...
 

Private Member Functions

 FileSystem ()=delete
 no instances.
 

Static Private Member Functions

static std::string findFile (const std::string &path, const std::vector< std::string > &dirs, bool silent)
 Search for given file or directory in list of directories or working directory.
 

Detailed Description

Utility functions related to filename validation and filesystem access.

Definition at line 20 of file FileSystem.h.

Member Function Documentation

◆ findFile() [1/2]

std::string findFile ( const std::string &  path,
bool  silent = false 
)
static

Search for given file or directory in local or central release directory, and return absolute path if found.

If the file isn't found in either of these, absolute paths and paths relative to the current working directory are also accepted.

It is recommended to replace any relative paths you have with the return value of this function during initialization.

Parameters
pathpath to file/directory, assuming it's installed locally (e.g. /data/geometry/Belle2.xml). Leading slash is not strictly required.
silentIf true, no error message is printed when file could not be found.
Returns
absolute path to file in local directory, if it exists, otherwise abs. path to file in central release directory, or empty string if file wasn't found.

Definition at line 148 of file FileSystem.cc.

149 {
150  std::vector<std::string> dirs;
151  if (getenv("BELLE2_LOCAL_DIR")) {
152  dirs.emplace_back(getenv("BELLE2_LOCAL_DIR"));
153  }
154  if (getenv("BELLE2_RELEASE_DIR")) {
155  dirs.emplace_back(getenv("BELLE2_RELEASE_DIR"));
156  }
157  return findFile(path, dirs, silent);
158 }
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148

◆ findFile() [2/2]

std::string findFile ( const std::string &  path,
const std::string &  dataType,
bool  silent = false 
)
static

Search for given file or directory in the directory given by the environment variable BELLE2_<DATATYPE>_DATA_DIR or local/central release directory and return absolute path if found.

If the file isn't found in either of these, absolute paths and paths relative to the current working directory are also accepted.

It is recommended to replace any relative paths you have with the return value of this function during initialization.

Parameters
pathpath to file/directory, assuming it's installed locally (e.g. /data/geometry/Belle2.xml). Leading slash is not strictly required.
dataTypetype of data, like "examples" or "validation".
silentIf true, no error message is printed when file could not be found.
Returns
absolute path to file in local directory, if it exists, otherwise abs. path to file in central release directory, or empty string if file wasn't found.

Definition at line 160 of file FileSystem.cc.

◆ loadLibrary()

bool loadLibrary ( std::string  library,
bool  fullname = true 
)
static

Load a shared library.

Symbols are resolved only when used, slightly reducing loading time (RTLD_LAZY, see dlopen(3))

Parameters
libraryName of the library
fullnameIf false, the Library name is interpreted as short name like given to the compiler with -l. It will be expanded to lib<library>.so

Definition at line 63 of file FileSystem.cc.


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