Project

General

Profile

Fhiclcpp types in detail » History » Version 51

Kyle Knoepfel, 12/16/2015 10:25 AM

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 1 Kyle Knoepfel
h2(#tuple). %{color:blue}@Tuple<T...>@%
232 46 Kyle Knoepfel
233 46 Kyle Knoepfel
h3. Allowed constructors
234 46 Kyle Knoepfel
235 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._
236 48 Kyle Knoepfel
237 46 Kyle Knoepfel
<pre><code class="cpp">
238 46 Kyle Knoepfel
explicit Tuple(Name&&);
239 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&);
240 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, std::function<bool()> maybeUse);
241 46 Kyle Knoepfel
242 46 Kyle Knoepfel
// c'tors supporting default values
243 46 Kyle Knoepfel
explicit Tuple(Name&&, dtype const& t);
244 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, dtype const& t);
245 46 Kyle Knoepfel
explicit Tuple(Name&&, Comment&&, std::function<bool()> maybeUse, dtype const& t);
246 46 Kyle Knoepfel
</code></pre>
247 46 Kyle Knoepfel
248 46 Kyle Knoepfel
h3. Examples
249 1 Kyle Knoepfel
250 1 Kyle Knoepfel
<pre><code class="cpp">
251 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple") };
252 18 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple") };
253 44 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), std::tuple<string,bool>{"explicit?", true} };
254 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), {"compact?", true } };
255 44 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple"), std::tuple<string,bool>{ "Particle physics is neat.", true } };
256 1 Kyle Knoepfel
Tuple<string,bool> tuple { Name("tuple"), Comment("A tuple"), { "This is false", false } };
257 1 Kyle Knoepfel
</code></pre>
258 1 Kyle Knoepfel
259 1 Kyle Knoepfel
----
260 1 Kyle Knoepfel
261 35 Kyle Knoepfel
h1(#return). Standard parameters - return types
262 35 Kyle Knoepfel
263 38 Kyle Knoepfel
_[ In what follows, @array@, @string@, @tuple@, and @vector@ should each be prefaced with the appropriate namespace resolution: '@std::@'. ]_
264 37 Kyle Knoepfel
265 1 Kyle Knoepfel
|{background:#fba}. *@fhiclcpp@ parameter*|{background:#fba}. *Function call*|{background:#fba}. *Return type*|
266 1 Kyle Knoepfel
|\3{background:#ddd}. _Simple @fhiclcpp@ parameters_|
267 37 Kyle Knoepfel
|@Atom<string> label@; |@label()@| @string const&@|
268 37 Kyle Knoepfel
|/2.@Sequence<int> counts@; | @counts()@ | @vector<int>@|
269 35 Kyle Knoepfel
|@counts(1)@ | @int@ |
270 37 Kyle Knoepfel
|/2.@Sequence<double, 3u> point@;| @point()@ | @array<double, 3u>@|
271 1 Kyle Knoepfel
|@point(0)@ | @double@ |
272 37 Kyle Knoepfel
|/3.@Tuple<string, double> assoc;@|@assoc()@| @tuple<string, double>@|
273 37 Kyle Knoepfel
|@assoc.get<0>()@|@string@|
274 35 Kyle Knoepfel
|@assoc.get<double>()@|@double@|
275 35 Kyle Knoepfel
|@Table<Config> config;@|@config()@|@Config const&@|
276 35 Kyle Knoepfel
|\3{background:#ddd}. _Nested @fhiclcpp@ parameters_|
277 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int> > datasets;@ | @datasets()@ | @vector< vector<int> >@ |
278 37 Kyle Knoepfel
| @datasets(17)@ | @vector<int>@ |
279 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int>, 2u > twoDatasets;@ | @twoDatasets()@ | @array< vector<int>, 2u >@ |
280 37 Kyle Knoepfel
|@twoDatasets(1)@ | @vector<int>@ |
281 37 Kyle Knoepfel
|/2.@Sequence< Sequence<int, 2u> > intPairs;@ | @intPairs()@ | @vector< array<int, 2u> >@ |
282 37 Kyle Knoepfel
|@intPairs(42)@ | @array<int, 2u>@|
283 37 Kyle Knoepfel
|/2.@Sequence< Tuple<string, int, bool> > triplets;@ | @triplets()@ | @vector< tuple<string, int, bool> >@ |
284 37 Kyle Knoepfel
|@triplets(3)@ | @tuple<string, int, bool>@ |
285 37 Kyle Knoepfel
|/2.@Sequence< Table<Config> > manyConfigTables;@ | @manyConfigTables()@ | @vector< Config >@ |
286 35 Kyle Knoepfel
|@manyConfigTables(6)@ | @Config const&@ |
287 37 Kyle Knoepfel
|/3.@Tuple< string, Table<Config> > configAssoc;@ | @configAssoc()@ | @tuple< string, Config >@ |
288 37 Kyle Knoepfel
|@configAssoc.get<0>()@ | @string@ |
289 35 Kyle Knoepfel
|@configAssoc.get<1>()@ | @Config@ |
290 37 Kyle Knoepfel
|/3.@Tuple< Tuple<string,bool>, Sequence<int> > awkward;@ | @awkward()@ | @tuple< tuple<string, bool>, vector<int> >@ |
291 37 Kyle Knoepfel
|@awkward.get<0>()@|@tuple<string,bool>@|
292 37 Kyle Knoepfel
|@awkward.get<1>()@|@vector<int>@|
293 1 Kyle Knoepfel
294 36 Kyle Knoepfel
h1(#opt_arg). @Optional@ parameters - argument types
295 1 Kyle Knoepfel
296 38 Kyle Knoepfel
The usage pattern for @Optional@ @fhiclcpp@ parameters is:
297 38 Kyle Knoepfel
298 38 Kyle Knoepfel
<pre><code class="cpp">
299 38 Kyle Knoepfel
OptionalAtom<string> message { Name("message") };
300 38 Kyle Knoepfel
301 38 Kyle Knoepfel
string filled_msg; // passed argument
302 38 Kyle Knoepfel
303 38 Kyle Knoepfel
if ( message(filled_msg) ) {
304 38 Kyle Knoepfel
   // use 'filled_msg'
305 38 Kyle Knoepfel
}
306 38 Kyle Knoepfel
</code></pre>
307 38 Kyle Knoepfel
308 38 Kyle Knoepfel
The following table gives the required passed-argument types for a given @Optional@ parameter.
309 38 Kyle Knoepfel
310 38 Kyle Knoepfel
_[ In what follows, @array@, @string@, @tuple@, and @vector@ should each be prefaced with the appropriate namespace resolution: '@std::@'. ]_
311 38 Kyle Knoepfel
312 1 Kyle Knoepfel
|{background:#fba}. *@fhiclcpp@ parameter*|{background:#fba}. *Passed argument*|{background:#fba}. *Function call*|
313 1 Kyle Knoepfel
|\3{background:#ddd}. _Simple @fhiclcpp@ parameters_|
314 38 Kyle Knoepfel
|@OptionalAtom<string> label@; |@string l;@| @bool exists = label(l);@|
315 38 Kyle Knoepfel
|@OptionalSequence<int> counts@; | @vector<int> v;@|@bool exists = counts(v);@ |
316 38 Kyle Knoepfel
|@OptionalSequence<double, 3u> point@;| @array<double, 3u> p;@| @bool exists = point(p);@ |
317 38 Kyle Knoepfel
|@OptionalTuple<string, double> assoc;@|@tuple<string, double> t;@| @bool exists = assoc(t);@|
318 36 Kyle Knoepfel
|@OptionalTable<Config> config;@|@Config c;@|@bool exists = config(c);@|
319 14 Kyle Knoepfel
|\3{background:#ddd}. _Nested @fhiclcpp@ parameters_|
320 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int> > datasets;@ |  @vector< vector<int> > sets;@ |@bool exists = datasets(sets);@ |
321 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int>, 2u > twoDatasets;@ |  @array< vector<int>, 2u >@ sets; |@bool exists = twoDatasets(sets);@ |
322 38 Kyle Knoepfel
|@OptionalSequence< Sequence<int, 2u> > intPairs;@ | @vector< array<int, 2u> >@ prs; |@bool exists = intPairs(prs);@ |
323 38 Kyle Knoepfel
|@OptionalSequence< Tuple<string, int, bool> > triplets;@ |  @vector< tuple<string, int, bool> > trps;@ |@bool exists = triplets(trps);@ |
324 38 Kyle Knoepfel
|@OptionalSequence< Table<Config> > manyConfigTables;@ | @vector< Config > tbls;@ |@bool exists = manyConfigTables(tbls);@ |
325 38 Kyle Knoepfel
|@OptionalTuple< string, Table<Config> > configAssoc;@ | @tuple< string, Config > assoc;@ |@bool exists = configAssoc(assoc);@ |
326 38 Kyle Knoepfel
|@OptionalTuple< Tuple<string,bool>, Sequence<int> > awkward;@ | @tuple< tuple<string, bool>, vector<int> > wow;@ |@bool exists = awkward(wow);@ |
327 38 Kyle Knoepfel
328 21 Kyle Knoepfel
329 21 Kyle Knoepfel
----
330 21 Kyle Knoepfel
331 21 Kyle Knoepfel
h1(#table_func). Additional functions for @Table<T>@
332 21 Kyle Knoepfel
333 21 Kyle Knoepfel
The @Table@ template offers a few extra functions that the user can call: 
334 21 Kyle Knoepfel
335 21 Kyle Knoepfel
<pre><code class="cpp">
336 21 Kyle Knoepfel
fhicl::ParameterSet const& get_PSet() const;
337 21 Kyle Knoepfel
338 21 Kyle Knoepfel
void print_allowed_configuration(std::ostream& os,
339 21 Kyle Knoepfel
                                 std::string const& tab = std::string(3,' ') ) const;
340 21 Kyle Knoepfel
341 21 Kyle Knoepfel
// Expert-level functions
342 21 Kyle Knoepfel
void validate_ParameterSet(fhicl::ParameterSet const& pset,
343 21 Kyle Knoepfel
                           std::set<std::string> const& keysToIgnore = {} );
344 21 Kyle Knoepfel
345 21 Kyle Knoepfel
</code></pre>
346 24 Kyle Knoepfel
347 1 Kyle Knoepfel
h3(#get_pset). @get_PSet@
348 28 Kyle Knoepfel
349 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.
350 21 Kyle Knoepfel
351 21 Kyle Knoepfel
h3(#print). @print_allowed_configuration@
352 1 Kyle Knoepfel
353 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.
354 24 Kyle Knoepfel
355 21 Kyle Knoepfel
----
356 25 Kyle Knoepfel
357 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.]_%
358 17 Kyle Knoepfel
359 14 Kyle Knoepfel
h3(#validate). @validate_ParameterSet@ (expert)
360 14 Kyle Knoepfel
361 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@.
362 14 Kyle Knoepfel
363 30 Kyle Knoepfel
Should the validation step fail, an exception is thrown of type @fhicl::detail::validationException@.  This behavior is not currently configurable.
364 14 Kyle Knoepfel
365 14 Kyle Knoepfel
----
366 30 Kyle Knoepfel
367 14 Kyle Knoepfel
h1(#common_acc). Common parameter accessors
368 14 Kyle Knoepfel
369 14 Kyle Knoepfel
Each of the @fhiclcpp@ types has the following accessors:
370 14 Kyle Knoepfel
<pre><code class="cpp">
371 14 Kyle Knoepfel
std::string key()            const;
372 14 Kyle Knoepfel
std::string name()           const;
373 14 Kyle Knoepfel
std::string comment()        const;
374 14 Kyle Knoepfel
bool        has_default()    const;
375 14 Kyle Knoepfel
bool        is_optional()    const;
376 45 Kyle Knoepfel
bool        is_conditional() const;
377 14 Kyle Knoepfel
par_type    parameter_type() const;
378 45 Kyle Knoepfel
bool        should_use()     const;
379 14 Kyle Knoepfel
</code></pre>
380 14 Kyle Knoepfel
381 17 Kyle Knoepfel
To call these functions, the difference in syntax is crucial:
382 14 Kyle Knoepfel
383 14 Kyle Knoepfel
<pre><code class="cpp">
384 14 Kyle Knoepfel
Atom<int> val { Name("val") };
385 14 Kyle Knoepfel
386 14 Kyle Knoepfel
auto key1 = val.key();   //   correct
387 14 Kyle Knoepfel
auto key2 = val().key(); // ! compile-time ERROR - 'val()' is an int, which has no accessor called 'key()' 
388 14 Kyle Knoepfel
</code></pre>
389 31 Kyle Knoepfel
390 1 Kyle Knoepfel
h2. @key()@
391 30 Kyle Knoepfel
392 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:
393 30 Kyle Knoepfel
<pre><code class="ruby">
394 1 Kyle Knoepfel
pset: {
395 30 Kyle Knoepfel
  list: [ { particle: electron },
396 30 Kyle Knoepfel
          { particle: muon } ]
397 17 Kyle Knoepfel
}
398 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@.
399 14 Kyle Knoepfel
400 14 Kyle Knoepfel
h2. @name()@
401 17 Kyle Knoepfel
402 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]@.
403 1 Kyle Knoepfel
404 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.
405 30 Kyle Knoepfel
406 30 Kyle Knoepfel
h2. @comment()@
407 30 Kyle Knoepfel
408 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.
409 1 Kyle Knoepfel
410 1 Kyle Knoepfel
h2. @has_default()@
411 1 Kyle Knoepfel
412 1 Kyle Knoepfel
Returns @true@ or @false@ depending on whether the user supplied a default value for the parameter.
413 14 Kyle Knoepfel
414 30 Kyle Knoepfel
h2. @is_optional()@
415 1 Kyle Knoepfel
416 45 Kyle Knoepfel
Returns @true@ if the parameter is an @Optional*@ @fhiclcpp@ type; @false@ otherwise.
417 1 Kyle Knoepfel
418 45 Kyle Knoepfel
h2. @is_conditional()@
419 45 Kyle Knoepfel
420 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.
421 45 Kyle Knoepfel
422 30 Kyle Knoepfel
h2. @parameter_type()@
423 30 Kyle Knoepfel
424 14 Kyle Knoepfel
Returns an enumeration value based on the parameter type:
425 14 Kyle Knoepfel
426 14 Kyle Knoepfel
<pre><code class="cpp">
427 1 Kyle Knoepfel
enum class par_type {
428 1 Kyle Knoepfel
  ATOM,        // (Optional)Atom<T>
429 1 Kyle Knoepfel
  TABLE,       // (Optional)Table<T>
430 1 Kyle Knoepfel
  SEQ_VECTOR,  // (Optional)Sequence<T>
431 1 Kyle Knoepfel
  SEQ_ARRAY,   // (Optional)Sequence<T,std::size_t>
432 1 Kyle Knoepfel
  TUPLE,       // (Optional)Tuple<T...>
433 1 Kyle Knoepfel
  NTYPES       // Signifies invalid parameter 
434 1 Kyle Knoepfel
};
435 1 Kyle Knoepfel
</code></pre>
436 45 Kyle Knoepfel
437 45 Kyle Knoepfel
h2. @should_use()@
438 45 Kyle Knoepfel
439 45 Kyle Knoepfel
Returns @true@ unless a user-provided configuration predicate returns @false@.