Project

General

Profile

Fhiclcpp types in detail » History » Version 52

Kyle Knoepfel, 09/09/2016 01:51 PM

1 1 Kyle Knoepfel
h1. @fhiclcpp@ types in detail
2 1 Kyle Knoepfel
3 34 Kyle Knoepfel
{{toc}}
4 1 Kyle Knoepfel
5 9 Kyle Knoepfel
----
6 9 Kyle Knoepfel
7 17 Kyle Knoepfel
h1(#ctors). Parameter constructors
8 1 Kyle Knoepfel
9 50 Kyle Knoepfel
h2(#ctors_rules). %{color:blue}General comments%
10 1 Kyle Knoepfel
11 50 Kyle Knoepfel
* The @Name@ argument is required for each of the @fhiclcpp@ types.
12 39 Kyle Knoepfel
* Neither the @Table<T>@ parameter nor any of the @Optional*@ parameters support a default value.
13 50 Kyle Knoepfel
* None of the examples below include a use of the conditional configuration facility (i.e. @std::function<bool()> maybeUse@).  An explanation of how users can take advantage of the facility is given [[Conditional_configuration|here]].
14 51 Kyle Knoepfel
* The @Name&&@ and @Comment&&@ references are explained [[System_details#Name-and-Comment|here]].  The double-ampersand is a way of (almost unconditionally) requiring users to provide a temporary object by specifying (e.g.) @Name("some_name")@ for each parameter.
15 50 Kyle Knoepfel
* In addition to @Optional*@ parameters not supporting default values, they also cannot be used as template arguments to *any* @fhiclcpp@ types:
16 39 Kyle Knoepfel
<pre><code class="cpp">
17 39 Kyle Knoepfel
Sequence< OptionalSequence<int> >     e1 { ... };  // error
18 39 Kyle Knoepfel
Sequence< OptionalSequence<int,2u> >  e2 { ... };  // error
19 39 Kyle Knoepfel
Sequence< OptionalTuple<int,double> > e3 { ... };  // error
20 40 Kyle Knoepfel
OptionalSequence< Sequence<int> >     ok { ... };  // ok
21 39 Kyle Knoepfel
</code></pre>
22 39 Kyle Knoepfel
23 18 Kyle Knoepfel
h2(#atom). %{color:blue}@Atom<T>@%
24 7 Kyle Knoepfel
25 46 Kyle Knoepfel
h3. Allowed constructors
26 46 Kyle Knoepfel
27 1 Kyle Knoepfel
<pre><code class="cpp">
28 46 Kyle Knoepfel
explicit Atom(Name&&);
29 46 Kyle Knoepfel
explicit Atom(Name&&, Comment&&);
30 46 Kyle Knoepfel
explicit Atom(Name&&, Comment&&, std::function<bool()> maybeUse);
31 46 Kyle Knoepfel
32 46 Kyle Knoepfel
// c'tors supporting default values
33 46 Kyle Knoepfel
explicit Atom(Name&&, T const& t);
34 46 Kyle Knoepfel
explicit Atom(Name&&, Comment&&, T const& t);
35 46 Kyle Knoepfel
explicit Atom(Name&&, Comment&&, std::function<bool()> maybeUse, T const& t);
36 46 Kyle Knoepfel
</code></pre>
37 46 Kyle Knoepfel
38 46 Kyle Knoepfel
h3. Examples
39 46 Kyle Knoepfel
40 46 Kyle Knoepfel
<pre><code class="cpp">
41 1 Kyle Knoepfel
Atom<int> var { Name("var") };
42 1 Kyle Knoepfel
Atom<int> var { Name("var"), 9 };
43 7 Kyle Knoepfel
Atom<int> var { Name("var"), Comment("A parameter description") };
44 1 Kyle Knoepfel
Atom<int> var { Name("var"), Comment("A parameter description"), 9 };
45 1 Kyle Knoepfel
</code></pre>
46 33 Kyle Knoepfel
47 39 Kyle Knoepfel
48 33 Kyle Knoepfel
h2(#opt_atom). %{color:blue}@OptionalAtom<T>@%
49 33 Kyle Knoepfel
50 46 Kyle Knoepfel
h3. Allowed constructors
51 46 Kyle Knoepfel
52 33 Kyle Knoepfel
<pre><code class="cpp">
53 46 Kyle Knoepfel
explicit OptionalAtom(Name&&);
54 46 Kyle Knoepfel
explicit OptionalAtom(Name&&, Comment&&);
55 46 Kyle Knoepfel
explicit OptionalAtom(Name&&, Comment&&, std::function<bool()> maybeUse);
56 46 Kyle Knoepfel
</code></pre>
57 46 Kyle Knoepfel
58 46 Kyle Knoepfel
h3. Examples
59 46 Kyle Knoepfel
60 46 Kyle Knoepfel
<pre><code class="cpp">
61 33 Kyle Knoepfel
OptionalAtom<int> var { Name("var") };
62 33 Kyle Knoepfel
OptionalAtom<int> var { Name("var"), Comment("A parameter description") };
63 33 Kyle Knoepfel
</code></pre>
64 33 Kyle Knoepfel
65 33 Kyle Knoepfel
h2(#opt_vector). %{color:blue}@OptionalSequence<T>@%
66 1 Kyle Knoepfel
67 39 Kyle Knoepfel
This class template is used for unbounded sequences.
68 33 Kyle Knoepfel
69 46 Kyle Knoepfel
h3. Allowed constructors
70 46 Kyle Knoepfel
71 33 Kyle Knoepfel
<pre><code class="cpp">
72 46 Kyle Knoepfel
explicit OptionalSequence(Name&&);
73 46 Kyle Knoepfel
explicit OptionalSequence(Name&&, Comment&&);
74 46 Kyle Knoepfel
explicit OptionalSequence(Name&&, Comment&&, std::function<bool()> maybeUse);
75 46 Kyle Knoepfel
</code></pre>
76 46 Kyle Knoepfel
77 46 Kyle Knoepfel
h3. Examples
78 46 Kyle Knoepfel
79 46 Kyle Knoepfel
<pre><code class="cpp">
80 33 Kyle Knoepfel
OptionalSequence<int> seq { Name("seq") };
81 33 Kyle Knoepfel
OptionalSequence<int> seq { Name("seq"), Comment("A sequence") };
82 33 Kyle Knoepfel
</code></pre>
83 33 Kyle Knoepfel
84 33 Kyle Knoepfel
h2(#opt_array). %{color:blue}@OptionalSequence<T,std::size_t>@%
85 33 Kyle Knoepfel
86 33 Kyle Knoepfel
This class template is used for sequences of a specific length, known at compile time.
87 33 Kyle Knoepfel
88 46 Kyle Knoepfel
h3. Allowed constructors
89 46 Kyle Knoepfel
90 33 Kyle Knoepfel
<pre><code class="cpp">
91 46 Kyle Knoepfel
explicit OptionalSequence(Name&&);
92 46 Kyle Knoepfel
explicit OptionalSequence(Name&&, Comment&&);
93 46 Kyle Knoepfel
explicit OptionalSequence(Name&&, Comment&&, std::function<bool()> maybeUse);
94 46 Kyle Knoepfel
</code></pre>
95 46 Kyle Knoepfel
96 46 Kyle Knoepfel
h3. Examples
97 46 Kyle Knoepfel
98 46 Kyle Knoepfel
<pre><code class="cpp">
99 33 Kyle Knoepfel
OptionalSequence<int,3u> seq { Name("seq") };
100 33 Kyle Knoepfel
OptionalSequence<int,3u> seq { Name("seq"), Comment("A sequence") };
101 33 Kyle Knoepfel
</code></pre>
102 33 Kyle Knoepfel
103 33 Kyle Knoepfel
h2(#opt_table). %{color:blue}@OptionalTable<T>@%
104 33 Kyle Knoepfel
105 46 Kyle Knoepfel
h3. Allowed constructors
106 46 Kyle Knoepfel
107 33 Kyle Knoepfel
<pre><code class="cpp">
108 46 Kyle Knoepfel
explicit OptionalTable(Name&&);
109 46 Kyle Knoepfel
explicit OptionalTable(Name&&, Comment&&);
110 46 Kyle Knoepfel
explicit OptionalTable(Name&&, Comment&&, std::function<bool()> maybeUse);
111 46 Kyle Knoepfel
</code></pre>
112 46 Kyle Knoepfel
113 46 Kyle Knoepfel
h3. Examples
114 46 Kyle Knoepfel
115 46 Kyle Knoepfel
<pre><code class="cpp">
116 33 Kyle Knoepfel
OptionalTable<T> config { Name("config") };
117 33 Kyle Knoepfel
OptionalTable<T> config { Name("config"), Comment("This describes the table") };
118 33 Kyle Knoepfel
</code></pre>
119 33 Kyle Knoepfel
120 33 Kyle Knoepfel
h2(#opt_tuple). %{color:blue}@OptionalTuple<T...>@%
121 33 Kyle Knoepfel
122 46 Kyle Knoepfel
h3. Allowed constructors
123 46 Kyle Knoepfel
124 33 Kyle Knoepfel
<pre><code class="cpp">
125 46 Kyle Knoepfel
explicit OptionalTuple(Name&&);
126 46 Kyle Knoepfel
explicit OptionalTuple(Name&&, Comment&&);
127 46 Kyle Knoepfel
explicit OptionalTuple(Name&&, Comment&&, std::function<bool()> maybeUse);
128 46 Kyle Knoepfel
</code></pre>
129 46 Kyle Knoepfel
130 46 Kyle Knoepfel
h3. Examples
131 46 Kyle Knoepfel
132 46 Kyle Knoepfel
<pre><code class="cpp">
133 33 Kyle Knoepfel
OptionalTuple<string,bool> tuple { Name("tuple") };
134 33 Kyle Knoepfel
OptionalTuple<string,bool> tuple { Name("tuple"), Comment("A tuple") };
135 33 Kyle Knoepfel
</code></pre>
136 18 Kyle Knoepfel
137 1 Kyle Knoepfel
h2(#vector). %{color:blue}@Sequence<T>@%
138 1 Kyle Knoepfel
139 46 Kyle Knoepfel
This class template is used for unbounded sequences.  See the caveat below regarding narrowing conversions.
140 1 Kyle Knoepfel
141 46 Kyle Knoepfel
h3. Allowed constructors
142 46 Kyle Knoepfel
143 1 Kyle Knoepfel
<pre><code class="cpp">
144 46 Kyle Knoepfel
explicit Sequence(Name&&);
145 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&);
146 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, std::function<bool()> maybeUse);
147 46 Kyle Knoepfel
148 46 Kyle Knoepfel
// c'tors supporting default values
149 46 Kyle Knoepfel
explicit Sequence(Name&&, std::vector<T> const& t);
150 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, std::vector<T> const& t);
151 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, std::function<bool()> maybeUse, std::vector<T> const& t);
152 46 Kyle Knoepfel
</code></pre>
153 46 Kyle Knoepfel
154 46 Kyle Knoepfel
h3. Examples
155 46 Kyle Knoepfel
156 46 Kyle Knoepfel
<pre><code class="cpp">
157 7 Kyle Knoepfel
Sequence<int> seq { Name("seq") };
158 1 Kyle Knoepfel
Sequence<int> seq { Name("seq"), Comment("A sequence") };
159 42 Kyle Knoepfel
Sequence<int> seq { Name("seq"), std::vector<int>{ 4, 5, 6, 7 } };
160 1 Kyle Knoepfel
Sequence<int> seq { Name("seq"), { 4, 5, 6, 7 } };
161 42 Kyle Knoepfel
Sequence<int> seq { Name("seq"), Comment("A sequence"), std::vector<int>{ 4, 5, 6, 7 } };
162 1 Kyle Knoepfel
Sequence<int> seq { Name("seq"), Comment("A sequence"), { 4, 5, 6, 7 } };
163 1 Kyle Knoepfel
</code></pre>
164 1 Kyle Knoepfel
165 1 Kyle Knoepfel
h3(#narrowing). Precaution regarding narrowing conversions and @std::initializer_list@ objects
166 1 Kyle Knoepfel
167 18 Kyle Knoepfel
The following configuration will trigger a compilation warning:
168 19 Kyle Knoepfel
169 19 Kyle Knoepfel
<pre><code class="cpp">
170 42 Kyle Knoepfel
Sequence<int> seq1 { Name("seq1"), std::vector<int>{ 1, 2.4e-4 } };
171 19 Kyle Knoepfel
Sequence<int> seq2 { Name("seq2"), { 1, 2.4e-4 } };
172 19 Kyle Knoepfel
</code></pre>
173 19 Kyle Knoepfel
174 19 Kyle Knoepfel
that looks similar to this:
175 19 Kyle Knoepfel
176 18 Kyle Knoepfel
<pre>
177 18 Kyle Knoepfel
warning: narrowing conversion of ‘2.4000000000000001e-4’ from ‘double’ to ‘int’ inside { } [-Wnarrowing]
178 18 Kyle Knoepfel
</pre>
179 1 Kyle Knoepfel
180 42 Kyle Knoepfel
For build systems that convert compile-time warnings to errors, this will result in a build failure.  The warning results from the nature of an @std::initializer_list@ object (also referred to as a brace-enclosed initializer), signified by @'{1, 2.4e-4}'@, which is used to initialize the sequence objects.  For @std::initializer_list@ objects, narrowing conversions are not allowed--that is, converting a @double@ to an @int@ is an example of narrowing that results in loss of information.  This is the most likely example of where you may find a narrowing conversion.
181 1 Kyle Knoepfel
182 1 Kyle Knoepfel
h2(#array). %{color:blue}@Sequence<T,std::size_t>@%
183 1 Kyle Knoepfel
184 1 Kyle Knoepfel
This class template is used for sequences of a specific length, known at compile time.
185 1 Kyle Knoepfel
186 46 Kyle Knoepfel
h3. Allowed constructors
187 46 Kyle Knoepfel
188 47 Kyle Knoepfel
_The @dtype@ is a type alias that allows users to specify as a default argument either an @std::array<T,N>@ object or a brace-enclosed @std::initializer_list<T>@ object.  It is preferred that users provide an @std::array@ object as a default value since the size of the supplied array is checked against the expected size at compile time._
189 47 Kyle Knoepfel
190 1 Kyle Knoepfel
<pre><code class="cpp">
191 46 Kyle Knoepfel
explicit Sequence(Name&&);
192 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&);
193 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, std::function<bool()> maybeUse);
194 46 Kyle Knoepfel
195 46 Kyle Knoepfel
// c'tors supporting default values
196 46 Kyle Knoepfel
explicit Sequence(Name&&, dtype const& t);
197 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, dtype const& t);
198 46 Kyle Knoepfel
explicit Sequence(Name&&, Comment&&, std::function<bool()> maybeUse, dtype const& t);
199 46 Kyle Knoepfel
</code></pre>
200 46 Kyle Knoepfel
201 46 Kyle Knoepfel
h3. Examples
202 46 Kyle Knoepfel
203 46 Kyle Knoepfel
<pre><code class="cpp">
204 1 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq") };
205 18 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq"), Comment("A sequence") };
206 43 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq"), std::array<int,3u>{ 4, 5, 6 } };
207 18 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq"), { 4, 5, 6 } };
208 43 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq"), Comment("A sequence"), std::array<int,3u>{ 4, 5, 6 } };
209 1 Kyle Knoepfel
Sequence<int,3u> seq { Name("seq"), Comment("A sequence"), { 4, 5, 6 } };
210 1 Kyle Knoepfel
</code></pre>
211 1 Kyle Knoepfel
212 1 Kyle Knoepfel
The warning regarding narrowing conversions [[Fhiclcpp_types_in_detail#narrowing|above]] applies for bounded sequences as well.
213 1 Kyle Knoepfel
214 33 Kyle Knoepfel
h2(#table). %{color:blue}@Table<T>@%
215 1 Kyle Knoepfel
216 46 Kyle Knoepfel
h3. Allowed constructors
217 46 Kyle Knoepfel
218 1 Kyle Knoepfel
<pre><code class="cpp">
219 46 Kyle Knoepfel
explicit Table(Name&&);
220 46 Kyle Knoepfel
explicit Table(Name&&, Comment&&);
221 46 Kyle Knoepfel
explicit Table(Name&&, Comment&&, std::function<bool()> maybeUse);
222 46 Kyle Knoepfel
</code></pre>
223 46 Kyle Knoepfel
224 46 Kyle Knoepfel
h3. Examples
225 46 Kyle Knoepfel
226 46 Kyle Knoepfel
<pre><code class="cpp">
227 33 Kyle Knoepfel
Table<T> config { Name("config") };
228 33 Kyle Knoepfel
Table<T> config { Name("config"), Comment("This describes the table") };
229 33 Kyle Knoepfel
</code></pre>
230 33 Kyle Knoepfel
231 52 Kyle Knoepfel
h2(#table). %{color:blue}@Table<T, KeysToIgnore>@%
232 52 Kyle Knoepfel
233 52 Kyle Knoepfel
This version of the @Table@ template is used whenever there are specific keys (and nested keys) that are intended to be ignored during the validation step.
234 52 Kyle Knoepfel
235 52 Kyle Knoepfel
h3. Constructor
236 52 Kyle Knoepfel
237 52 Kyle Knoepfel
<pre><code class="cpp">
238 52 Kyle Knoepfel
Table(ParameterSet const&);
239 52 Kyle Knoepfel
</code></pre>
240 52 Kyle Knoepfel
241 52 Kyle Knoepfel
h3. Example
242 52 Kyle Knoepfel
243 52 Kyle Knoepfel
<pre><code class="cpp">
244 52 Kyle Knoepfel
struct KeysToIgnore {
245 52 Kyle Knoepfel
  std::set<std::string> operator()()
246 52 Kyle Knoepfel
  {
247 52 Kyle Knoepfel
    return {"otherTable", "otherAtom", "nested.sequence"};
248 52 Kyle Knoepfel
  }
249 52 Kyle Knoepfel
};
250 52 Kyle Knoepfel
251 52 Kyle Knoepfel
auto const& pset = get_ParameterSet_from_somewhere();
252 52 Kyle Knoepfel
Table<T, KeysToIgnore> config {pset};
253 52 Kyle Knoepfel
</code></pre>
254 52 Kyle Knoepfel
255 52 Kyle Knoepfel
Notice that the @KeysToIgnore@ type must contain an @operator()@ function that returns an @std::set<std::string>@ object containing the list of keys that should be ignored during the validation step.  The validation skips any keys that match any of the strings specified by the @operator()@ function are skipped.  If the ignorable key is a table, all of the table's contents are ignored as well.
256 52 Kyle Knoepfel
257 1 Kyle Knoepfel
h2(#tuple). %{color:blue}@Tuple<T...>@%
258 46 Kyle Knoepfel
259 46 Kyle Knoepfel
h3. Allowed constructors
260 46 Kyle Knoepfel
261 49 Kyle Knoepfel
_The @dtype@ is a type alias that allows users to specify as a default argument either an @std::tuple<T...>@ object or a brace-enclosed initializer, which, in this case, is *not* an @std::initializer_list@ object._
262 48 Kyle Knoepfel
263 46 Kyle Knoepfel
<pre><code class="cpp">
264 46 Kyle Knoepfel
explicit Tuple(Name&&);
265 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&);
266 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, std::function<bool()> maybeUse);
267 46 Kyle Knoepfel
268 46 Kyle Knoepfel
// c'tors supporting default values
269 46 Kyle Knoepfel
explicit Tuple(Name&&, dtype const& t);
270 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, dtype const& t);
271 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, std::function<bool()> maybeUse, dtype const& t);
272 46 Kyle Knoepfel
</code></pre>
273 46 Kyle Knoepfel
274 46 Kyle Knoepfel
h3. Examples
275 1 Kyle Knoepfel
276 1 Kyle Knoepfel
<pre><code class="cpp">
277 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple") };
278 18 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple") };
279 44 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), std::tuple<string,bool>{"explicit?", true} };
280 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), {"compact?", true } };
281 44 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple"), std::tuple<string,bool>{ "Particle physics is neat.", true } };
282 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple"), { "This is false", false } };
283 1 Kyle Knoepfel
</code></pre>
284 1 Kyle Knoepfel
285 1 Kyle Knoepfel
----
286 1 Kyle Knoepfel
287 35 Kyle Knoepfel
h1(#return). Standard parameters - return types
288 35 Kyle Knoepfel
289 38 Kyle Knoepfel
_[ In what follows, @array@, @string@, @tuple@, and @vector@ should each be prefaced with the appropriate namespace resolution: '@std::@'. ]_
290 37 Kyle Knoepfel
291 1 Kyle Knoepfel
|{background:#fba}. *@fhiclcpp@ parameter*|{background:#fba}. *Function call*|{background:#fba}. *Return type*|
292 1 Kyle Knoepfel
|\3{background:#ddd}. _Simple @fhiclcpp@ parameters_|
293 37 Kyle Knoepfel
|@Atom<string> label@; |@label()@| @string const&@|
294 37 Kyle Knoepfel
|/2.@Sequence<int> counts@; | @counts()@ | @vector<int>@|
295 35 Kyle Knoepfel
|@counts(1)@ | @int@ |
296 37 Kyle Knoepfel
|/2.@Sequence<double, 3u> point@;| @point()@ | @array<double, 3u>@|
297 1 Kyle Knoepfel
|@point(0)@ | @double@ |
298 37 Kyle Knoepfel
|/3.@Tuple<string, double> assoc;@|@assoc()@| @tuple<string, double>@|
299 37 Kyle Knoepfel
|@assoc.get<0>()@|@string@|
300 35 Kyle Knoepfel
|@assoc.get<double>()@|@double@|
301 35 Kyle Knoepfel
|@Table<Config> config;@|@config()@|@Config const&@|
302 35 Kyle Knoepfel
|\3{background:#ddd}. _Nested @fhiclcpp@ parameters_|
303 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int> > datasets;@ | @datasets()@ | @vector< vector<int> >@ |
304 37 Kyle Knoepfel
| @datasets(17)@ | @vector<int>@ |
305 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int>, 2u > twoDatasets;@ | @twoDatasets()@ | @array< vector<int>, 2u >@ |
306 37 Kyle Knoepfel
|@twoDatasets(1)@ | @vector<int>@ |
307 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int, 2u> > intPairs;@ | @intPairs()@ | @vector< array<int, 2u> >@ |
308 37 Kyle Knoepfel
|@intPairs(42)@ | @array<int, 2u>@|
309 37 Kyle Knoepfel
|/2.@Sequence< Tuple<string, int, bool> > triplets;@ | @triplets()@ | @vector< tuple<string, int, bool> >@ |
310 37 Kyle Knoepfel
|@triplets(3)@ | @tuple<string, int, bool>@ |
311 37 Kyle Knoepfel
|/2.@Sequence< Table<Config> > manyConfigTables;@ | @manyConfigTables()@ | @vector< Config >@ |
312 35 Kyle Knoepfel
|@manyConfigTables(6)@ | @Config const&@ |
313 37 Kyle Knoepfel
|/3.@Tuple< string, Table<Config> > configAssoc;@ | @configAssoc()@ | @tuple< string, Config >@ |
314 37 Kyle Knoepfel
|@configAssoc.get<0>()@ | @string@ |
315 35 Kyle Knoepfel
|@configAssoc.get<1>()@ | @Config@ |
316 37 Kyle Knoepfel
|/3.@Tuple< Tuple<string,bool>, Sequence<int> > awkward;@ | @awkward()@ | @tuple< tuple<string, bool>, vector<int> >@ |
317 37 Kyle Knoepfel
|@awkward.get<0>()@|@tuple<string,bool>@|
318 37 Kyle Knoepfel
|@awkward.get<1>()@|@vector<int>@|
319 1 Kyle Knoepfel
320 36 Kyle Knoepfel
h1(#opt_arg). @Optional@ parameters - argument types
321 1 Kyle Knoepfel
322 38 Kyle Knoepfel
The usage pattern for @Optional@ @fhiclcpp@ parameters is:
323 38 Kyle Knoepfel
324 38 Kyle Knoepfel
<pre><code class="cpp">
325 38 Kyle Knoepfel
OptionalAtom<string> message { Name("message") };
326 38 Kyle Knoepfel
327 38 Kyle Knoepfel
string filled_msg; // passed argument
328 38 Kyle Knoepfel
329 38 Kyle Knoepfel
if ( message(filled_msg) ) {
330 38 Kyle Knoepfel
   // use 'filled_msg'
331 38 Kyle Knoepfel
}
332 38 Kyle Knoepfel
</code></pre>
333 38 Kyle Knoepfel
334 38 Kyle Knoepfel
The following table gives the required passed-argument types for a given @Optional@ parameter.
335 38 Kyle Knoepfel
336 38 Kyle Knoepfel
_[ In what follows, @array@, @string@, @tuple@, and @vector@ should each be prefaced with the appropriate namespace resolution: '@std::@'. ]_
337 38 Kyle Knoepfel
338 1 Kyle Knoepfel
|{background:#fba}. *@fhiclcpp@ parameter*|{background:#fba}. *Passed argument*|{background:#fba}. *Function call*|
339 1 Kyle Knoepfel
|\3{background:#ddd}. _Simple @fhiclcpp@ parameters_|
340 38 Kyle Knoepfel
|@OptionalAtom<string> label@; |@string l;@| @bool exists = label(l);@|
341 38 Kyle Knoepfel
|@OptionalSequence<int> counts@; | @vector<int> v;@|@bool exists = counts(v);@ |
342 38 Kyle Knoepfel
|@OptionalSequence<double, 3u> point@;| @array<double, 3u> p;@| @bool exists = point(p);@ |
343 38 Kyle Knoepfel
|@OptionalTuple<string, double> assoc;@|@tuple<string, double> t;@| @bool exists = assoc(t);@|
344 36 Kyle Knoepfel
|@OptionalTable<Config> config;@|@Config c;@|@bool exists = config(c);@|
345 14 Kyle Knoepfel
|\3{background:#ddd}. _Nested @fhiclcpp@ parameters_|
346 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int> > datasets;@ |  @vector< vector<int> > sets;@ |@bool exists = datasets(sets);@ |
347 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int>, 2u > twoDatasets;@ |  @array< vector<int>, 2u >@ sets; |@bool exists = twoDatasets(sets);@ |
348 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int, 2u> > intPairs;@ | @vector< array<int, 2u> >@ prs; |@bool exists = intPairs(prs);@ |
349 38 Kyle Knoepfel
|@OptionalSequence< Tuple<string, int, bool> > triplets;@ |  @vector< tuple<string, int, bool> > trps;@ |@bool exists = triplets(trps);@ |
350 38 Kyle Knoepfel
|@OptionalSequence< Table<Config> > manyConfigTables;@ | @vector< Config > tbls;@ |@bool exists = manyConfigTables(tbls);@ |
351 38 Kyle Knoepfel
|@OptionalTuple< string, Table<Config> > configAssoc;@ | @tuple< string, Config > assoc;@ |@bool exists = configAssoc(assoc);@ |
352 38 Kyle Knoepfel
|@OptionalTuple< Tuple<string,bool>, Sequence<int> > awkward;@ | @tuple< tuple<string, bool>, vector<int> > wow;@ |@bool exists = awkward(wow);@ |
353 38 Kyle Knoepfel
354 21 Kyle Knoepfel
355 21 Kyle Knoepfel
----
356 21 Kyle Knoepfel
357 21 Kyle Knoepfel
h1(#table_func). Additional functions for @Table<T>@
358 21 Kyle Knoepfel
359 21 Kyle Knoepfel
The @Table@ template offers a few extra functions that the user can call: 
360 21 Kyle Knoepfel
361 21 Kyle Knoepfel
<pre><code class="cpp">
362 21 Kyle Knoepfel
fhicl::ParameterSet const& get_PSet() const;
363 21 Kyle Knoepfel
364 21 Kyle Knoepfel
void print_allowed_configuration(std::ostream& os,
365 21 Kyle Knoepfel
                                 std::string const& tab = std::string(3,' ') ) const;
366 21 Kyle Knoepfel
367 21 Kyle Knoepfel
// Expert-level functions
368 21 Kyle Knoepfel
void validate_ParameterSet(fhicl::ParameterSet const& pset,
369 21 Kyle Knoepfel
                           std::set<std::string> const& keysToIgnore = {} );
370 21 Kyle Knoepfel
371 21 Kyle Knoepfel
</code></pre>
372 24 Kyle Knoepfel
373 1 Kyle Knoepfel
h3(#get_pset). @get_PSet@
374 28 Kyle Knoepfel
375 24 Kyle Knoepfel
A call to this function returns a @const@ reference to the @ParameterSet@ object that was used to fill the values of the individual @Table@ members.  This is helpful for users who need to interact with the @ParameterSet@ object itself.
376 21 Kyle Knoepfel
377 21 Kyle Knoepfel
h3(#print). @print_allowed_configuration@
378 1 Kyle Knoepfel
379 21 Kyle Knoepfel
For any @Table<Config>@ object, @print_allowed_configuration@ will fill a user-supplied @std::ostream@ object with the allowed configuration as defined by the @Config@ struct.  The optional second argument specifies the number of spaces per indentation.  The default is 3 spaces but is, of course, user-configurable.
380 24 Kyle Knoepfel
381 21 Kyle Knoepfel
----
382 25 Kyle Knoepfel
383 25 Kyle Knoepfel
%{color:red} _[ *N.B.* The following function should not normally be invoked by users. It is meant to be called only in contexts outside of @art@.  Please consult artists@fnal.gov for guidance.]_%
384 17 Kyle Knoepfel
385 14 Kyle Knoepfel
h3(#validate). @validate_ParameterSet@ (expert)
386 14 Kyle Knoepfel
387 14 Kyle Knoepfel
This function is intended for experts who need to validate the @pset@ object themselves.  The @keysToIgnore@ variable represents a set of keys for which the validation step will ignore.  The validation function will ignore any nested keys as well--i.e. if a user specifies an ignorable key as @table1@, the (e.g.) @table1.someAtom@ key would be ignored in addition to just the @table1@ name.  An indexed parameter (e.g.) @seq[1]@ is considered a nested parameter of its parent @seq@.  Providing or not providing the ignorable key in a configuration will lead to no error upon validation of the @ParameterSet@.
388 14 Kyle Knoepfel
389 30 Kyle Knoepfel
Should the validation step fail, an exception is thrown of type @fhicl::detail::validationException@.  This behavior is not currently configurable.
390 14 Kyle Knoepfel
391 14 Kyle Knoepfel
----
392 30 Kyle Knoepfel
393 14 Kyle Knoepfel
h1(#common_acc). Common parameter accessors
394 14 Kyle Knoepfel
395 14 Kyle Knoepfel
Each of the @fhiclcpp@ types has the following accessors:
396 14 Kyle Knoepfel
<pre><code class="cpp">
397 14 Kyle Knoepfel
std::string key()            const;
398 14 Kyle Knoepfel
std::string name()           const;
399 14 Kyle Knoepfel
std::string comment()        const;
400 14 Kyle Knoepfel
bool        has_default()    const;
401 14 Kyle Knoepfel
bool        is_optional()    const;
402 45 Kyle Knoepfel
bool        is_conditional() const;
403 14 Kyle Knoepfel
par_type    parameter_type() const;
404 45 Kyle Knoepfel
bool        should_use()     const;
405 14 Kyle Knoepfel
</code></pre>
406 14 Kyle Knoepfel
407 17 Kyle Knoepfel
To call these functions, the difference in syntax is crucial:
408 14 Kyle Knoepfel
409 14 Kyle Knoepfel
<pre><code class="cpp">
410 14 Kyle Knoepfel
Atom<int> val { Name("val") };
411 14 Kyle Knoepfel
412 14 Kyle Knoepfel
auto key1 = val.key();   //   correct
413 14 Kyle Knoepfel
auto key2 = val().key(); // ! compile-time ERROR - 'val()' is an int, which has no accessor called 'key()' 
414 14 Kyle Knoepfel
</code></pre>
415 31 Kyle Knoepfel
416 1 Kyle Knoepfel
h2. @key()@
417 30 Kyle Knoepfel
418 14 Kyle Knoepfel
A call to @key()@ returns the _full_ key, including all enclosing tables.  For example, consider a module that is designed to allow the following configuration:
419 30 Kyle Knoepfel
<pre><code class="ruby">
420 1 Kyle Knoepfel
pset: {
421 30 Kyle Knoepfel
  list: [ { particle: electron },
422 30 Kyle Knoepfel
          { particle: muon } ]
423 17 Kyle Knoepfel
}
424 14 Kyle Knoepfel
</code></pre>For a suitably declared set of @fhiclcpp@ parameters, the returned key corresponding to "muon" would be @pset.list[1].particle@.
425 14 Kyle Knoepfel
426 14 Kyle Knoepfel
h2. @name()@
427 17 Kyle Knoepfel
428 14 Kyle Knoepfel
The name is the most-nested name in the key.  For the above "muon" parameter, a key of @pset.list[1].particle@ has a corresponding name of @particle@.  If the parameter in question were @pset.list[1]@, the name would be[1] @list[1]@.
429 1 Kyle Knoepfel
430 1 Kyle Knoepfel
fn1. Technically, this is inaccurate -- sequence elements do not have names.  However, for the sake of parameter identification, a sequence element has a name whose value is the sequence name with the appropriate sequence element index/indices appended.
431 30 Kyle Knoepfel
432 30 Kyle Knoepfel
h2. @comment()@
433 30 Kyle Knoepfel
434 30 Kyle Knoepfel
Returns the comment supplied as the string literal in (e.g.) @Comment("Here is the comment")@.  If no @Comment@ argument is provided in the @fhiclcpp@ parameter constructor, a call to this function returns an empty string.
435 1 Kyle Knoepfel
436 1 Kyle Knoepfel
h2. @has_default()@
437 1 Kyle Knoepfel
438 1 Kyle Knoepfel
Returns @true@ or @false@ depending on whether the user supplied a default value for the parameter.
439 14 Kyle Knoepfel
440 30 Kyle Knoepfel
h2. @is_optional()@
441 1 Kyle Knoepfel
442 45 Kyle Knoepfel
Returns @true@ if the parameter is an @Optional*@ @fhiclcpp@ type; @false@ otherwise.
443 1 Kyle Knoepfel
444 45 Kyle Knoepfel
h2. @is_conditional()@
445 45 Kyle Knoepfel
446 45 Kyle Knoepfel
Returns @true@ if a configuration predicate (either through @fhicl::use_if@, @fhicl::use_unless@, or some supplied lambda function) has been provided by the user; @false@ otherwise.
447 45 Kyle Knoepfel
448 30 Kyle Knoepfel
h2. @parameter_type()@
449 30 Kyle Knoepfel
450 14 Kyle Knoepfel
Returns an enumeration value based on the parameter type:
451 14 Kyle Knoepfel
452 14 Kyle Knoepfel
<pre><code class="cpp">
453 1 Kyle Knoepfel
enum class par_type {
454 1 Kyle Knoepfel
  ATOM,        // (Optional)Atom<T>
455 1 Kyle Knoepfel
  TABLE,       // (Optional)Table<T>
456 1 Kyle Knoepfel
  SEQ_VECTOR,  // (Optional)Sequence<T>
457 1 Kyle Knoepfel
  SEQ_ARRAY,   // (Optional)Sequence<T,std::size_t>
458 1 Kyle Knoepfel
  TUPLE,       // (Optional)Tuple<T...>
459 1 Kyle Knoepfel
  NTYPES       // Signifies invalid parameter 
460 1 Kyle Knoepfel
};
461 1 Kyle Knoepfel
</code></pre>
462 45 Kyle Knoepfel
463 45 Kyle Knoepfel
h2. @should_use()@
464 45 Kyle Knoepfel
465 45 Kyle Knoepfel
Returns @true@ unless a user-provided configuration predicate returns @false@.