LSSTApplications  19.0.0-14-gb0260a2+d60062ef16,20.0.0+1540ce6389,20.0.0+7c6b12c2f9,20.0.0+ae956f52c5,20.0.0+be870186d9,20.0.0+e2e26847c2,20.0.0-1-g10df615+7683e4f082,20.0.0-1-g253301a+7c6b12c2f9,20.0.0-1-g2b7511a+46a6078777,20.0.0-1-g3dda6ea+606b36f8c0,20.0.0-1-g4d801e7+901ee84527,20.0.0-1-g5b95a8c+a5fa15ec54,20.0.0-1-gb058bd0+46a6078777,20.0.0-1-gb88604f+acecce4127,20.0.0-1-gc96f8cb+61a4a056b1,20.0.0-1-gedffbd8+4f0e391d5e,20.0.0-10-g0891cd99+aadc987f3e,20.0.0-10-g9a20bd332+576ca7b471,20.0.0-17-gcdbda88+ed0d4927ab,20.0.0-2-g4dae9ad+61a4a056b1,20.0.0-2-g61b8584+85c46248f3,20.0.0-2-gb780d76+f45b7d88f4,20.0.0-2-gf072044+7c6b12c2f9,20.0.0-21-g9bbb7f7+61a4a056b1,20.0.0-22-gc512666+9eba1c4719,20.0.0-23-g8900aa8+68630f7098,20.0.0-3-g1653f94+85c46248f3,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g750bffe+e05f822de9,20.0.0-3-gbd60e8c+ff10c6d78d,20.0.0-32-g15a0e07c+ff1c9f120b,20.0.0-4-g97dc21a+68630f7098,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-6-g9a5b7a1+2c4171520d,20.0.0-61-g4de25fb+e4dd172200,20.0.0-7-gcda7bf1+85e953d7e4,w.2020.43
LSSTDataManagementBasePackage

Introduction

A policy is a set of named parameters that can be used to configure the internal data and behavior of an object within an application. An important feature Policy objects is that the parameters can be loaded in from a file. Thus, it allows applications fine-grained control of objects even if much of the configuration parameters they provide are normally set to defaults and otherwise do not change.

Obtaining Data from a Policy Object

The Policy interface allows an application to pull out parameter values by name. Typically, the application "knows" the names it needs from a Policy to configure itself–that is, these names and the use of their values are hard-coded into the application. The application simply calls one of the "get" methods to retrieve a typed value for the parameter.
(Nevertheless, if necessary, the parameter names contained in a policy can be retrieved via the Policy::names() member function.

Policy parameters values are restricted to a limited set of types to ensure simple, well-defined ASCII text serialization format. These types are In particular, a Policy parameter can be one of:

  • integer (int not long)
  • double
  • string
  • boolean (bool)
  • Policy
  • PolicyFile, a reference to file containing additional Policy data
  • arrays of any of the above

As implied by the inclusion of Policy as a value type, a Policy can be
hierarchical (like a PropertySet). Values deep within the hierarchy can be retrieved via a hiearchical name. Such a name is made up of name fields delimited by dots (.) where each name field represents a level of the hierarchy. The first field represents the top level of the hierarchy. If a given name does not resolve to value, a NameNotFound exception is thrown. If one expects a different value type for a name than what is actually stored, (e.g. one calls getInt(name) for a parameter that is actually a string), a TypeError exception is thrown.

A hierarchical Policy allows an application to configure a whole hierarchy of objects, even if the object classes (and their associated policy parameters) were developed by different people. In particular, if an application that is configuring one of the objects it uses, it can either pull out the relevent values directly by their hierarchical names, or if that object supports configuration from a Policy, it can pull all of the values for the object by retrieving a Policy (via getPolicy(name)) and passing it to the object.

It is important to note that parameter names relative the Policy that contains them. For example, suppose you have a parameter accessible via the name "foo.bar.zub". This implies that the name "foo.bar" will resolve to a Policy object. You can retrieve the "zub" parameter from that "sub-Policy" object by asking for "zub".

Loading Policy Data from a File

One can read Policy data via the constructors that take a file name in some form as an input argument; however the prefered manner is via one of the createPolicy() functions. The latter is able to intelligently differentiate between simple Policy file and a Dictionary file.

In general, the format of the file is detected automatically (via the PolicyFile and SupportedFormats). By default, the formats supported are those currently built into this package:

Other formats can be plugged in via the SupportedFormats class.

Dictionaries

When a class uses a Policy to configure itself, there is an implicit expectation as to the data available from the policy and the names with which they can be retrieved; that is, the class expects the file to follow a particular schema. A Dictionary provides a way to document the schema of a Policy file. A Dictionary itself is a Policy (and thus can be written in any Policy file format) with a particular schema. When a Dictionary fully documents a Policy schema, the Dictionary can be used to validate a particular Policy instance–i.e. test that it actually complies with the schema. A Dictionary can also provide default values for Policy parameters.

For explanation of the Dictionary schema and how to encode it using the PAF format, see The Dictionary Schema.

Default Policy Data

When an object using a Policy fails to find a parameter it was expecting, it is a little inelegant to provide a default hard-coded in the object's implementation, by design. Instead it is recommended that defaults be loaded from another Policy. The intended way to do this is to load defaults via a DefaultPolicyFile (which can located a policy file from any EUPS-setup installation directory) and to merge them into to the primary Policy instance via the Policy::mergeDefaults() function.