Project

General

Profile

Wiki » History » Version 39

Kyle Knoepfel, 08/17/2015 02:01 PM

1 1 Walter E Brown
h1. Wiki
2 1 Walter E Brown
3 14 Walter E Brown
4 1 Walter E Brown
h2. Contents
5 2 Walter E Brown
6 14 Walter E Brown
* [[Wiki#Library overview|Library overview]]
7 14 Walter E Brown
* [[Wiki#The ParameterSet interface|The ParameterSet interface]]
8 26 Walter E Brown
** [[Wiki#Names, keys, and values|Names, keys, and values]]
9 26 Walter E Brown
** [[Wiki#Relationship to ParameterSetID|Relationship to ParameterSetID]]
10 26 Walter E Brown
** [[Wiki#Immutability|Immutability]]
11 26 Walter E Brown
** [[Wiki#Compiler-generated functions|Compiler-generated functions]]
12 26 Walter E Brown
** [[Wiki#Observers|Observers]]
13 26 Walter E Brown
** [[Wiki#Retrievers|Retrievers]]
14 26 Walter E Brown
** [[Wiki#Inserters|Inserters]]
15 26 Walter E Brown
** [[Wiki#Deleters|Deleters]]
16 26 Walter E Brown
** [[Wiki#Comparators|Comparators]]
17 26 Walter E Brown
** [[Wiki#Interface technical summary|Interface technical summary]]
18 1 Walter E Brown
* [[ParameterSet Creation]] (Separate page)
19 39 Kyle Knoepfel
* [[Configuration validation and fhiclcpp types]] (Separate page)
20 28 Walter E Brown
* [[Release Notes]] (Separate page)
21 12 Walter E Brown
22 14 Walter E Brown
23 5 Walter E Brown
h2. Library overview
24 1 Walter E Brown
25 14 Walter E Brown
The @fhiclcpp@ library provides types and functions that constitute a _binding_ of the FHiCL specification to C++.  (See https://cdcvs.fnal.gov/redmine/attachments/5348/quick_start.pdf for an introduction to FHiCL nomenclature and concepts.)
26 1 Walter E Brown
27 14 Walter E Brown
The following types are provided, each declared in the @fhicl@ namespace:
28 14 Walter E Brown
29 14 Walter E Brown
* @ParameterSet@, corresponding to a user-specified _configuration_ (a "collection of named values accessible to a user’s program while it is running");
30 4 Walter E Brown
* @ParameterSetID@, uniquely identifying a specific value of a @ParameterSet@ instance;
31 7 Walter E Brown
* @ParameterSetRegistry@, automatically registering each @ParameterSet@ instance (or sub-instance) with its corresponding @ParameterSetID@;
32 7 Walter E Brown
* @intermediate_table@, serving as an internal ("raw" or "working") representation of a FHiCL document;
33 4 Walter E Brown
* @extended_value@, representing a FHiCL value within an @intermediate_table@;
34 1 Walter E Brown
* @value_tag@, classifying an @extended_value@ instance; and
35 1 Walter E Brown
* @exception@, describing a circumstance from which the library can't recover.
36 16 Walter E Brown
37 1 Walter E Brown
In addition, the library provides public member functions and (also in the @fhicl@ namespace) free functions to construct, observe, and transform values of these types.
38 1 Walter E Brown
39 27 Walter E Brown
The next section details the interface of the @ParameterSet@ type, likely of greatest interest to most users of this library.  (A separate [[ParameterSet Creation|page]] describes those remaining types and functions that are typically used only while initially producing @ParameterSet@ instances by combining information obtained from a @fhicl@ document with additional information from such sources as a command line and application-specific defaults.)
40 1 Walter E Brown
41 21 Walter E Brown
42 1 Walter E Brown
h2.  The ParameterSet interface
43 1 Walter E Brown
44 26 Walter E Brown
h3. Names, keys, and values
45 21 Walter E Brown
46 26 Walter E Brown
* In the descriptions below, parameters and arguments denoted @name@ are always of type of type @std::string@; each corresponds to FHiCL's notion of a _name_.
47 26 Walter E Brown
* In the descriptions below, parameters and arguments denoted @key@ are always of type of type @std::string@; each also corresponds to FHiCL's notion of a _name_, but when one @ParameterSet@ is nested within another @ParameterSet@, a key may employ the FHiCL _member notation_.
48 20 Walter E Brown
* Each @ParameterSet@ object consists of some number of  keys, each associated with a value of some C++ type.  Such an association is termed a _key-value pair_.  When the key is a simple name, the association is equivalently termed a _name-value pair_.
49 19 Walter E Brown
* A value can be retrieved from a @ParameterSet@ by presenting its corresponding key.  Similarly, a value can be inserted into a @ParameterSet@ by presenting both the value and its desired corresponding key.  
50 31 Christopher Green
* A @ParameterSet@ contains values of C++ types closely corresponding to FHiCL values.  We refer to the C++ types in the following list as %(FHiCL_types) _FHiCL types_%.
51 19 Walter E Brown
** The C++ standard @bool@ type corresponds to FHiCL's notion of a _boolean value_.
52 19 Walter E Brown
** The C++ standard signed and unsigned integer types, as well as the C++ standard floating-point types, correspond to FHiCL's notion of a _numeric value_.
53 20 Walter E Brown
** The C++ @std::complex<>@ types correspond to FHiCL's notion of a _complex value_.
54 21 Walter E Brown
** The C++ @std::string@ type corresponds to FHiCL's notion of a _string value_.
55 34 Kyle Knoepfel
** The C++ @std::array@, @std::pair@, @std::tuple@ and @std::vector@ types correspond to FHiCL's notion of a _sequence value_.  Heterogenous sequences are supported as of version:"3.05.00".
56 1 Walter E Brown
** The @fhicl::ParameterSet@ type corresponds to FHiCL's notion of a _table value_. Note that a processed FHiCL _document_ also yields a @ParameterSet@.
57 32 Christopher Green
* The above-defined [[Wiki#FHiCL_type|FHiCL types]] fit into three %(#FHiCL_categories) _FHiCL categories_%: _table_, _sequence_ or _atom_. A @nil@ value is an atom by definition.
58 1 Walter E Brown
* As an extension to the functionality required of a FHiCL binding, a @ParameterSet@ can contain values of arbitrary user-defined C++ types. The library processes such values via user-supplied functions that convert to the user-defined type.  (In practice, this has been a rarely-used @fhiclcpp@ library feature.)
59 1 Walter E Brown
60 26 Walter E Brown
h3. Relationship to ParameterSetID
61 1 Walter E Brown
62 1 Walter E Brown
* A @ParameterSetID@ is automatically generated from (and thus corresponds to) the value of a @ParameterSet@ object.
63 17 Walter E Brown
* If the value of a @ParameterSet@ object @ps@ is modified in any way (whether by inserting, deleting, or updating any key-value pair), a new @ParameterSetID@ value is generated to correspond to the updated value of @ps@.
64 18 Walter E Brown
65 26 Walter E Brown
h3. Immutability
66 18 Walter E Brown
67 18 Walter E Brown
In practice, most @ParameterSet@ objects, once constructed, are treated as immutable. While such practice is not required, it is preferable because of the relationship of a @ParameterSet@ to a @ParameterSetID@, described above.
68 10 Walter E Brown
69 10 Walter E Brown
h3. Compiler-generated functions
70 10 Walter E Brown
71 10 Walter E Brown
* A default-constructed @ParameterSet@ object is  _empty_; that is, it consists of no key-value pairs.
72 10 Walter E Brown
* A copy-constructed @ParameterSet@ object has the same key-value pairs as did the @ParameterSet@ object from which it was copied.
73 10 Walter E Brown
* A newly assigned-to @ParameterSet@ object has the same key-value pairs as did the @ParameterSet@ object from which it was copied.
74 10 Walter E Brown
75 10 Walter E Brown
h3. Observers
76 1 Walter E Brown
77 31 Christopher Green
Note that all @key@ arguments to observers must be names: it is an error to specify a nested (dot-delimited) key.
78 31 Christopher Green
79 1 Walter E Brown
* A call of the form @ps.is_empty()@ returns @true@ if @ps@ is empty, and returns @false@ otherwise.
80 1 Walter E Brown
* A call of the form @ps.id()@ returns the @ParameterSetID@ value corresponding to the current value of @ps@.
81 31 Christopher Green
* A call of the form @ps.to_string()@ returns a @std::string@ representation of the current value of @ps@.
82 38 Kyle Knoepfel
* A call of the form @ps.to_compact_string()@ returns a compact @std::string@ representation of the current value of @ps@, including the collapsing of non-trivial nested parameter sets to @@id::<hash>@.
83 37 Kyle Knoepfel
* A call of the form @ps.to_indented_string(unsigned initial_indent_level = 0, bool annotate = true)@ returns an expanded and easier-to-read @std::string@ representation of the current value of @ps@, annotated with the filename and line number where the key was defined or overridden.  Annotation supported as of version:"3.05.00".
84 1 Walter E Brown
* A call of the form @ps.get_keys()@ returns, as a @std::vector<std::string>@, a list of all names in @ps@.
85 1 Walter E Brown
* A call of the form @ps.get_pset_keys()@ returns, as a @std::vector<std::string>@, a list of all names in @ps@ whose corresponding values are of @ParameterSet@ type.
86 37 Kyle Knoepfel
* A call of the form @ps.get_src_info(key)@ returns a @std::string@ with the filename and line number (delimited by @':'@) corresponding to where the key was defined or overridden.  Supported as of version:"3.05.00".
87 31 Christopher Green
* @ps.has_key(key)@  returns @true@ if @ps@ contains a pair with a matching name as key, @false@ otherwise.
88 31 Christopher Green
* @ps.is_key_to_atom(key)@ returns @true@ if @ps@ contains a pair with a matching name as key, and a value which is an atom (@nil@ is an atom by definition).
89 31 Christopher Green
* @ps.is_key_to_sequence(key)@ returns @true@ if @ps@ contains a pair with a matching name as key, and a value which is a sequence.
90 31 Christopher Green
* @ps.is_key_to_table(key)@ returns @true@ if @ps@ contains a pair with a matching name as key, and a value which is a table (nested @ParameterSet@).
91 1 Walter E Brown
92 1 Walter E Brown
h3. Retrievers
93 1 Walter E Brown
94 31 Christopher Green
Keys specified as arguments to retrievers may be nested (dot-delimited).
95 31 Christopher Green
96 20 Walter E Brown
* A call of the form @ps.get<T>(key)@ (or of the variant form @ps.get<T>(key, convert)@) will return the value of type @T@ associated with the key. 
97 20 Walter E Brown
** Either call will throw an exception if:
98 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
99 20 Walter E Brown
*** @ps@ does contain a pair with a matching key, but the corresponding value can't be returned as a value of type @T@.
100 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
101 20 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
102 20 Walter E Brown
* A call of the form @ps.get(key,default_value)@ (or of the variant form @ps.get<T>(key, default_value, convert)@) will return the value of type @T@ associated with the key.
103 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
104 20 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
105 20 Walter E Brown
** Either call will return the supplied @default_value@ (which must be of type @T@) if:
106 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
107 20 Walter E Brown
*** @ps@ does contain a pair with a matching key, but the corresponding value can't be returned as a value of type @T@.
108 20 Walter E Brown
* A call of the form @get_if_present(key, result)@ (or of the variant form @get_if_present(key, result, convert)@) has the following behavior:
109 20 Walter E Brown
** If the supplied key is an empty string, throw an exception.
110 20 Walter E Brown
** If @ps@ contains no pair with a matching key, return @false@.
111 1 Walter E Brown
** If @ps@ does contain a pair with a matching key, but the corresponding value isn't of type @T@, throw an exception.
112 1 Walter E Brown
** Otherwise, set the supplied @result@ (which must be an lvalue expression) to the corresponding value and return @true@.
113 22 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
114 22 Walter E Brown
** The variant form is used when @T@ is an arbitrary user-defined type. The @convert@ argument is a user-provided function that converts a given FHiCL value to a value of type @T@.
115 22 Walter E Brown
116 1 Walter E Brown
h3. Inserters
117 1 Walter E Brown
118 31 Christopher Green
Note that all @key@ arguments to inserters must be names: it is an error to specify a nested (dot-delimited) key.
119 31 Christopher Green
120 22 Walter E Brown
* A call of the form @ps.put(name, value)@ will insert into @ps@ a name-value pair composed of the given name and the given value.
121 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
122 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
123 31 Christopher Green
** The type of the supplied value must either be a [[Wiki#FHiCL_type|FHiCL type]], or the user must define a function @encode(X const & x)@ in the same namespace as @X@ which returns the result of calling @fhicl::encode()@ on one of the aforementioned types. As a fallback, a @boost::lexical_cast()@ will be attempted to decode @x@.
124 24 Walter E Brown
* A call of the form @ps.put(name)@ will insert into @ps@ a name-value pair composed of the given name and the library's equivalent of a FHiCL @nil@ value.
125 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
126 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
127 31 Christopher Green
* A call of the form @ps.put_or_replace(name, value)@ will insert into @ps@ a name-value pair composed of the given name and the given value.
128 1 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
129 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
130 31 Christopher Green
* A call of the form @ps.put(name)@ will insert into @ps@ a name-value pair composed of the given name and the library's equivalent of a FHiCL @nil@ value.
131 24 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
132 24 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
133 31 Christopher Green
* A call of the form @ps.put_or_replace_compatible(name, value)@ will insert into @ps@ a name-value pair composed of the given name and the given value.
134 31 Christopher Green
** If @ps@ already contains a pair with the given name, that pair's value component is replaced if and only if it is of a compatible [[Wiki#FHiCL_categories|FHiCL category]]. A @nil@ value is compatible with all classifications. If the replacement value is not compatible with the existing value, a @cant_insert@ exception is thrown.
135 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
136 10 Walter E Brown
137 11 Walter E Brown
h3. Deleters
138 21 Walter E Brown
139 10 Walter E Brown
A call of the form @ps.erase(name)@ will attempt to remove from @ps@ the name-value pair with matching name and will return @true@ if successful and @false@ otherwise (_i.e._, if @ps@ contains no pair with the specified name).
140 10 Walter E Brown
141 10 Walter E Brown
h3. Comparators
142 14 Walter E Brown
143 10 Walter E Brown
Two @ParameterSet@ objects may be compared for equality or inequality via the corresponding conventional operator notations.  The objects are considered equal if and only if their respective @ParameterSetID@ values are equal.
144 10 Walter E Brown
145 10 Walter E Brown
h3. Interface technical summary
146 10 Walter E Brown
147 30 Christopher Green
See source:fhiclcpp/ParameterSet.h.
148 10 Walter E Brown
149 1 Walter E Brown
</code></pre>