Complete: 3

Purpose of edm::FileInPath

The class edm::FileInPath exists to provide a reasonably flexible mechanism, to be used in configuration files, by which filenames can be specified.

The ability to search for a file both "locally" (in a developer's working area) and in "the official place" (determined by the CMSSW release with which one is working) was required.

Also required was the ability to track the location of origin of the file that matched the request.

edm::FileInPath provides the mechanism to find the file, and to return the name of the file that has been found. The edm::FileInPath class does not deal with opening files.

The search mechanism

from CMSSW_0_3_0_pre5

The search mechanism used by edm::FileInPath uses the environment variable:

  • CMSSW_SEARCH_PATH, which defines the directories under which files may be found.

This environment variable works as the "$PATH" environment variable, in the sense that it is a list of locations separated by the character ":" (colon). The system will look in the various locations in the order they are provided until a match is found.

The default value of CMSSW_SEARCH_PATH is:

To add a location:


Configuration File Syntax

A new element has been added to the configuration language to allow the use of edm::FileInPath objects as parameters in ParameterSet objects.

In the same place that one can introduce any basic parameter (e.g. int32), one can use FileInPath as a parameter type. The parameter must be initialized by a quoted string:

  FileInPath fip = "x/y/whatever.xml"

File name resolution

When the configuration file containing such a declaration is parsed, the search for the file file =x/y/whatever.xml* is performed, as directed by the value of CMSSW_SEARCH_PATH (see above). For each "node" in the search path (up to the maximum of two), the resolution of the file name is as follows:

  1. The string supplied as the value of the FileInPath parameter is used as a relative path, under the "base" directory.

  1. If a file is found, the search stops. The filename is remembered for later use, as is whether the file was found "locally" (under the same scram area) or not.

  1. If a symbolic link is found, an exception is thrown. This is done so that history tracking of names isn't misleading. Otherwise, what appears to be a local file could really have come from the release.
  2. If a directory is found, an exception is thrown.
  3. If nothing is found, the next element in the CMSSW_SEARCH_PATH is considered.

If the search path is exhausted, and no file is found, an exception is thrown.

Using the edm::FileInPath object.

The following code extracts a parameter of type edm::FileInPath from a ParameterSet object (given the name used above).

  // assume we are given ParameterSet ps
  edm::FileInPath fp = ps.getParameter<edm::FileInPath>("fip");

The most useful member function of edm::FileInPath are:

  bool FileInPath::isLocal() const;
  std::string FileInPath::fullPath() const;

isLocal() returns true if the file was located under the current working area, and false otherwise. (Note that if the file was not found, the configuration parsing system would already have thrown an exception).

fullPath() returns a std::string. To pass this filename to the constructor of fstream or TFile for the purpose of open the file, use the method std::string::c_str().

Review Status

Reviewer/Editor and Date (copy from screen) Comments
Main.paterno - 01 Jan 2006 page contributor sometime in 2006
JennyWilliams - 31 Jan 2007 editing to include in SWGuide

Responsible: paterno
Last reviewed by: Reviewer

Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r9 - 2008-08-27 - CharlesRiedel

    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback