Project

General

Profile

Wiki » History » Version 35

Kyle Knoepfel, 04/27/2015 02:18 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 28 Walter E Brown
* [[Release Notes]] (Separate page)
20 12 Walter E Brown
21 14 Walter E Brown
22 5 Walter E Brown
h2. Library overview
23 1 Walter E Brown
24 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.)
25 1 Walter E Brown
26 14 Walter E Brown
The following types are provided, each declared in the @fhicl@ namespace:
27 14 Walter E Brown
28 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");
29 4 Walter E Brown
* @ParameterSetID@, uniquely identifying a specific value of a @ParameterSet@ instance;
30 7 Walter E Brown
* @ParameterSetRegistry@, automatically registering each @ParameterSet@ instance (or sub-instance) with its corresponding @ParameterSetID@;
31 7 Walter E Brown
* @intermediate_table@, serving as an internal ("raw" or "working") representation of a FHiCL document;
32 4 Walter E Brown
* @extended_value@, representing a FHiCL value within an @intermediate_table@;
33 1 Walter E Brown
* @value_tag@, classifying an @extended_value@ instance; and
34 1 Walter E Brown
* @exception@, describing a circumstance from which the library can't recover.
35 16 Walter E Brown
36 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.
37 1 Walter E Brown
38 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.)
39 1 Walter E Brown
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 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_%.
50 19 Walter E Brown
** The C++ standard @bool@ type corresponds to FHiCL's notion of a _boolean value_.
51 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_.
52 20 Walter E Brown
** The C++ @std::complex<>@ types correspond to FHiCL's notion of a _complex value_.
53 21 Walter E Brown
** The C++ @std::string@ type corresponds to FHiCL's notion of a _string value_.
54 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".
55 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@.
56 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.
57 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.)
58 1 Walter E Brown
59 26 Walter E Brown
h3. Relationship to ParameterSetID
60 1 Walter E Brown
61 1 Walter E Brown
* A @ParameterSetID@ is automatically generated from (and thus corresponds to) the value of a @ParameterSet@ object.
62 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@.
63 18 Walter E Brown
64 26 Walter E Brown
h3. Immutability
65 18 Walter E Brown
66 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.
67 10 Walter E Brown
68 10 Walter E Brown
h3. Compiler-generated functions
69 10 Walter E Brown
70 10 Walter E Brown
* A default-constructed @ParameterSet@ object is  _empty_; that is, it consists of no key-value pairs.
71 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.
72 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.
73 10 Walter E Brown
74 10 Walter E Brown
h3. Observers
75 1 Walter E Brown
76 31 Christopher Green
Note that all @key@ arguments to observers must be names: it is an error to specify a nested (dot-delimited) key.
77 31 Christopher Green
78 1 Walter E Brown
* A call of the form @ps.is_empty()@ returns @true@ if @ps@ is empty, and returns @false@ otherwise.
79 1 Walter E Brown
* A call of the form @ps.id()@ returns the @ParameterSetID@ value corresponding to the current value of @ps@.
80 31 Christopher Green
* A call of the form @ps.to_string()@ returns a @std::string@ representation of the current value of @ps@.
81 35 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>@.
82 35 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 name was defined or overridden.
83 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@.
84 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.
85 31 Christopher Green
* @ps.has_key(key)@  returns @true@ if @ps@ contains a pair with a matching name as key, @false@ otherwise.
86 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).
87 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.
88 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@).
89 1 Walter E Brown
90 1 Walter E Brown
h3. Retrievers
91 1 Walter E Brown
92 31 Christopher Green
Keys specified as arguments to retrievers may be nested (dot-delimited).
93 31 Christopher Green
94 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. 
95 20 Walter E Brown
** Either call will throw an exception if:
96 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
97 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@.
98 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
99 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@.
100 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.
101 20 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
102 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@.
103 20 Walter E Brown
** Either call will return the supplied @default_value@ (which must be of type @T@) if:
104 20 Walter E Brown
*** @ps@ contains no pair with a matching key, or 
105 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@.
106 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:
107 20 Walter E Brown
** If the supplied key is an empty string, throw an exception.
108 20 Walter E Brown
** If @ps@ contains no pair with a matching key, return @false@.
109 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.
110 1 Walter E Brown
** Otherwise, set the supplied @result@ (which must be an lvalue expression) to the corresponding value and return @true@.
111 22 Walter E Brown
** The first form is used when the type @T@ is corresponds to a FHiCL value.
112 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@.
113 22 Walter E Brown
114 1 Walter E Brown
h3. Inserters
115 1 Walter E Brown
116 31 Christopher Green
Note that all @key@ arguments to inserters must be names: it is an error to specify a nested (dot-delimited) key.
117 31 Christopher Green
118 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.
119 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
120 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
121 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@.
122 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.
123 31 Christopher Green
** If @ps@ already contains a pair with the given name, a @cant_insert@ exception is thrown.
124 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
125 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.
126 1 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
127 1 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
128 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.
129 24 Walter E Brown
** If @ps@ already contains a pair with the given name, that pair's value component is replaced.
130 24 Walter E Brown
** Otherwise, a new pair is constructed and inserted into @ps@.
131 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.
132 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.
133 31 Christopher Green
** Otherwise, a new pair is constructed and inserted into @ps@.
134 10 Walter E Brown
135 11 Walter E Brown
h3. Deleters
136 21 Walter E Brown
137 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).
138 10 Walter E Brown
139 10 Walter E Brown
h3. Comparators
140 14 Walter E Brown
141 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.
142 10 Walter E Brown
143 10 Walter E Brown
h3. Interface technical summary
144 10 Walter E Brown
145 30 Christopher Green
See source:fhiclcpp/ParameterSet.h.
146 10 Walter E Brown
147 1 Walter E Brown
</code></pre>