Project

General

Profile

Wiki » History » Version 44

Kyle Knoepfel, 11/17/2015 10:44 AM

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 40 Kyle Knoepfel
* [[Helper applications]]
21 28 Walter E Brown
* [[Release Notes]] (Separate page)
22 12 Walter E Brown
23 5 Walter E Brown
h2. Library overview
24 1 Walter E Brown
25 42 Kyle Knoepfel
The @fhiclcpp@ library provides types and functions that constitute a _binding_ of the FHiCL specification to C++.  The current version of @fhicl-cpp@ corresponds to FHiCL 3 (see fhicl:document:"FHiCL 3 Quick Start Guide").
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 1 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 21 Walter E Brown
41 1 Walter E Brown
h2.  The ParameterSet interface
42 1 Walter E Brown
43 26 Walter E Brown
h3. Names, keys, and values
44 21 Walter E Brown
45 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_.
46 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_.
47 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_.
48 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.  
49 41 Kyle Knoepfel
* A @ParameterSet@ contains values of C++ types closely corresponding to FHiCL values as described in the below table.  We define a _FHiCL type_ as any C++ type for which a conversion from the corresponding FHiCL value to that type is supported.
50 41 Kyle Knoepfel
51 41 Kyle Knoepfel
table{margin-left:4em}.
52 41 Kyle Knoepfel
|{background:#fba}. *FHiCL type (C++ type)*|{background:#fba}. *FHiCL value*|{background:#fba}. *FHiCL category*|
53 41 Kyle Knoepfel
|@bool@| boolean |/4. atom |
54 41 Kyle Knoepfel
|(un)signed integer types &
55 41 Kyle Knoepfel
 floating-point types | numeric|
56 41 Kyle Knoepfel
|@std::string@| string |
57 41 Kyle Knoepfel
|@std::complex@| complex |
58 41 Kyle Knoepfel
|@std::array@|/4. sequence |/4. sequence |
59 41 Kyle Knoepfel
|@std::pair@|
60 41 Kyle Knoepfel
|@std::tuple@|
61 41 Kyle Knoepfel
|@std::array@|
62 41 Kyle Knoepfel
|@fhicl::ParameterSet@| table | table |
63 41 Kyle Knoepfel
64 41 Kyle Knoepfel
* Note that a processed FHiCL _document_ also yields a @ParameterSet@.
65 41 Kyle Knoepfel
* A @nil@ value is an atom by definition.
66 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.)
67 1 Walter E Brown
68 26 Walter E Brown
h3. Relationship to ParameterSetID
69 1 Walter E Brown
70 1 Walter E Brown
* A @ParameterSetID@ is automatically generated from (and thus corresponds to) the value of a @ParameterSet@ object.
71 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@.
72 18 Walter E Brown
73 26 Walter E Brown
h3. Immutability
74 18 Walter E Brown
75 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.
76 10 Walter E Brown
77 10 Walter E Brown
h3. Compiler-generated functions
78 10 Walter E Brown
79 10 Walter E Brown
* A default-constructed @ParameterSet@ object is  _empty_; that is, it consists of no key-value pairs.
80 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.
81 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.
82 10 Walter E Brown
83 10 Walter E Brown
h3. Observers
84 1 Walter E Brown
85 43 Kyle Knoepfel
* A call of the form *@ps.is_empty()@* returns @true@ if @ps@ is empty, and returns @false@ otherwise.
86 43 Kyle Knoepfel
* A call of the form *@ps.id()@* returns the @ParameterSetID@ value corresponding to the current value of @ps@.
87 43 Kyle Knoepfel
* A call of the form *@ps.to_string()@* returns a @std::string@ representation of the current value of @ps@.
88 43 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>@.
89 43 Kyle Knoepfel
* String-rendered representations of the parameter set can be obtain by any of the calls:
90 43 Kyle Knoepfel
## *@ps.to_indented_string()@* returns an expanded and easier-to-read @std::string@ representation of the current value of @ps@.
91 43 Kyle Knoepfel
## *@ps.to_indented_string(initial_indent_level)@* -- same as 1, but with an optional indent level (@unsigned int@) to increase the left-side margin.
92 43 Kyle Knoepfel
## *@ps.to_indented_string(initial_indent_level, annotate)@* -- same as 2 but additionally annotated (when @annotate == true@) with the filename and line number where the key was defined or overridden.  
93 43 Kyle Knoepfel
## *@ps.to_indented_string(initial_indent_level, print_mode)@* -- same as 3, but allows additional printing formats (as defined in source:fhiclcpp/detail/print_mode.h).
94 43 Kyle Knoepfel
* A call of the form *@ps.get_names()@* returns, as a @std::vector<std::string>@, a list of all names in @ps@.
95 1 Walter E Brown
* A call of the form *@ps.get_pset_names()@* returns, as a @std::vector<std::string>@, a list of all names in @ps@ whose corresponding values are of @ParameterSet@ type.
96 1 Walter E Brown
* 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.
97 44 Kyle Knoepfel
* *@ps.has_key(key)@*  returns @true@ if @ps@ contains a pair with a matching name as key (nested keys allowed), @false@ otherwise.
98 44 Kyle Knoepfel
* *@ps.is_key_to_atom(key)@* returns @true@ if @ps@ contains a pair with a matching name as key (no dot notation allowed), and a value which is an atom (@@nil@ is an atom by definition).
99 44 Kyle Knoepfel
* *@ps.is_key_to_sequence(key)@* returns @true@ if @ps@ contains a pair with a matching name as key (no dot notation allowed), and a value which is a sequence.
100 44 Kyle Knoepfel
* *@ps.is_key_to_table(key)@* returns @true@ if @ps@ contains a pair with a matching name as key (no dot notation allowed), and a value which is a table (nested @ParameterSet@).
101 1 Walter E Brown
102 1 Walter E Brown
h3. Retrievers
103 1 Walter E Brown
104 31 Christopher Green
Keys specified as arguments to retrievers may be nested (dot-delimited).
105 31 Christopher Green
106 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. 
107 20 Walter E Brown
** Either call will throw an exception if:
108 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
109 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@.
110 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
111 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@.
112 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.
113 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
114 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@.
115 20 Walter E Brown
** Either call will return the supplied @default_value@ (which must be of type @T@) if:
116 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
117 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@.
118 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:
119 20 Walter E Brown
** If the supplied key is an empty string, throw an exception.
120 20 Walter E Brown
** If @ps@ contains no pair with a matching key, return @false@.
121 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.
122 1 Walter E Brown
** Otherwise, set the supplied @result@ (which must be an lvalue expression) to the corresponding value and return @true@.
123 22 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
124 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@.
125 22 Walter E Brown
126 1 Walter E Brown
h3. Inserters
127 1 Walter E Brown
128 31 Christopher Green
Note that all @key@ arguments to inserters must be names: it is an error to specify a nested (dot-delimited) key.
129 31 Christopher Green
130 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.
131 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
132 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
133 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@.
134 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.
135 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
136 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
137 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.
138 1 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
139 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
140 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.
141 24 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
142 24 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
143 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.
144 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.
145 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
146 10 Walter E Brown
147 11 Walter E Brown
h3. Deleters
148 21 Walter E Brown
149 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).
150 10 Walter E Brown
151 10 Walter E Brown
h3. Comparators
152 14 Walter E Brown
153 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.
154 10 Walter E Brown
155 10 Walter E Brown
h3. Interface technical summary
156 10 Walter E Brown
157 30 Christopher Green
See source:fhiclcpp/ParameterSet.h.
158 10 Walter E Brown
159 1 Walter E Brown
</code></pre>