-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdunedaq-appfwk-schema.html
900 lines (810 loc) · 36 KB
/
dunedaq-appfwk-schema.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2020-09-30 Wed 15:23 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>DAQ Object Schema</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Brett Viren" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.equation-container {
display: table;
text-align: center;
width: 100%;
}
.equation {
vertical-align: middle;
}
.equation-label {
display: table-cell;
text-align: right;
vertical-align: middle;
}
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/styles/readtheorg/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/styles/readtheorg/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/styles/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://fniessen.github.io/org-html-themes/styles/readtheorg/js/readtheorg.js"></script>
<style> #content{max-width:1800px;}</style>
<style> p{max-width:800px;}</style>
<style> li{max-width:800px;}</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2020 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">DAQ Object Schema</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orgaceaba5">Introduction</a></li>
<li><a href="#orgf4fd163">Prepare</a></li>
<li><a href="#orgde0952f">Jsonnet</a></li>
<li><a href="#orgfb1b029">Schema definition structure</a></li>
<li><a href="#org5b05d2a">Schema Preamble</a></li>
<li><a href="#orga6c40b4">Schema body</a></li>
<li><a href="#orgd5e1cda">Finishing the schema</a></li>
<li><a href="#org211a2d9">Compiled result</a></li>
<li><a href="#orgacd896a">Code generating</a></li>
<li><a href="#org913db63">Object generating</a></li>
<li><a href="#org440bdea">Validating</a></li>
<li><a href="#org1523552">Running</a></li>
</ul>
</div>
</div>
<div id="outline-container-orgaceaba5" class="outline-2">
<h2 id="orgaceaba5">Introduction</h2>
<div class="outline-text-2" id="text-orgaceaba5">
<p>
In the DAQ we will have various entities (applications, services, etc)
which must share data objects. We describe the structure of these
objects with a (meta) data structure called a "schema". Schema is
like a "contract" honored by all that share objects which are derived
from or validated by a schema. From this schema we may also generate
C++ structures, object serialization methods, structure documentation,
actual object instances and other artifacts.
</p>
<p>
Implementation of <code>appfwk::DAQModules</code> generally require some
configuration. The configuration comes from the end user or run
control and is an object that is governed by schema. This document
gives a brief "howto" showing how to provide the needed schema.
</p>
<div class="warning">
<p>
Some details are a work in progress. Expect some evolution.
</p>
</div>
<p>
We now walk through how to write our own schema for a <code>DAQModule</code>.
</p>
</div>
</div>
<div id="outline-container-orgf4fd163" class="outline-2">
<h2 id="orgf4fd163">Prepare</h2>
<div class="outline-text-2" id="text-orgf4fd163">
<p>
For now we place our schema files in a <code>schema/</code> directory of the same
source package that holds our <code>DAQModule</code> implementation. For example,
in a package called <code>mypackage</code> with a module called <code>MyModule</code>
abbreviated as <code>mm</code> we might make:
</p>
<pre class="example">
$ cd mypackage/
$ mkdir schema
$ emacs schema/mypackage-mm-schema.jsonnet
</pre>
<div class="note">
<p>
The exact file name is not critical. The example shows the current
convention.
</p>
</div>
<p>
The rest of this document will make use of the real
<code>FakeDataConsumerDAQModule</code> provided in <code>appfwk/test</code>.
</p>
</div>
</div>
<div id="outline-container-orgde0952f" class="outline-2">
<h2 id="orgde0952f">Jsonnet</h2>
<div class="outline-text-2" id="text-orgde0952f">
<p>
Jsonnet language is like "JSON plus functions". It is a "pure
functional" language and is focused on making it easy to create
expressive data structures. Jsonnet is "small" language and to write
schema files one only needs to understand a fraction which will be
described below. The Jsonnet <a href="https://jsonnet.org/learning/tutorial.html">tutorial</a> and <a href="https://jsonnet.org/ref/stdlib.html">standard library</a>
documentation are very good resources for learning more.
</p>
<p>
Compiling a Jsonnet "program" thus results in a data structure and
typically output in JSON format. We may use the <code>jsonnet</code> or <code>moo</code> (or
other) command line programs to "compile" or otherwise consume the
Jsonnet code.
</p>
</div>
</div>
<div id="outline-container-orgfb1b029" class="outline-2">
<h2 id="orgfb1b029">Schema definition structure</h2>
<div class="outline-text-2" id="text-orgfb1b029">
<p>
Ultimately, our schema is defined as an <b>array of objects</b> where each
object describes a <b>type</b> and a type is an instance of a <b>schema class</b>.
We have a fixed set of schema classes to choose from. They include:
<code>number</code>, <code>string</code>, <code>record</code>, <code>sequence</code> and others. A full list is given in
the <a href="https://brettviren.github.io/moo/oschema.html#outline-container-concepts">moo object schema</a> page. One particular type may <b>refer</b> to other
types. For example, a <code>record</code> is composed of <code>fields</code> each of which
references their type. Although we end up with an <b>array of types</b>, in
order to easily reference, we will first make an intermediate <b>object
of types</b>.
</p>
</div>
</div>
<div id="outline-container-org5b05d2a" class="outline-2">
<h2 id="org5b05d2a">Schema Preamble</h2>
<div class="outline-text-2" id="text-org5b05d2a">
<p>
We start out by importing helper code from <code>moo</code>:
</p>
<div class="org-src-container">
<pre class="src src-jsonnet"><span style="color: #b4fa70;">local</span> moo = <span style="color: #b4fa70;">import</span> <span style="color: #e9b96e;">"moo.jsonnet"</span>;
</pre>
</div>
<p>
Then we define the base "path" and make a "schema factory" object
rooted on that path:
</p>
<div class="org-src-container">
<pre class="src src-jsonnet"><span style="color: #b4fa70;">local</span> ns = <span style="color: #e9b96e;">"dunedaq.appfwk.fdc"</span>;
<span style="color: #b4fa70;">local</span> s = moo.oschema.schema(ns);
</pre>
</div>
<div class="note">
<p>
These variables are <code>local</code> meaning they will not be directly accessible
by other Jsonnet files that may use this file. But they can be simply
referenced elsewhere in the file.
</p>
</div>
<p>
The <code>ns</code> variable holds a "base path" for our schema types. As may be
guessed, this maps to a C++ <code>namespace</code> when the schema is used to
generate C++ code. A "path" is also used in the Jsonnet to refer to a
type that may be defined elsewhere. Every type will carry its path in
a <code>.path</code> attribute.
</p>
</div>
</div>
<div id="outline-container-orga6c40b4" class="outline-2">
<h2 id="orga6c40b4">Schema body</h2>
<div class="outline-text-2" id="text-orga6c40b4">
<p>
We now get to the main body of the schema definition
</p>
<div class="org-src-container">
<pre class="src src-jsonnet"><span style="color: #b4fa70;">local</span> fdc = {
size: s.number(<span style="color: #e9b96e;">"Size"</span>, <span style="color: #e9b96e;">"u8"</span>,
doc=<span style="color: #e9b96e;">"A count of very many things"</span>),
count : s.number(<span style="color: #e9b96e;">"Count"</span>, <span style="color: #e9b96e;">"i4"</span>,
doc=<span style="color: #e9b96e;">"A count of not too many things"</span>),
conf: s.record(<span style="color: #e9b96e;">"Conf"</span>, [
s.field(<span style="color: #e9b96e;">"nIntsPerVector"</span>, <span style="color: #b4fa70;">self</span>.size, 10,
doc=<span style="color: #e9b96e;">"Number of numbers"</span>),
s.field(<span style="color: #e9b96e;">"starting_int"</span>, <span style="color: #b4fa70;">self</span>.count, -4,
doc=<span style="color: #e9b96e;">"Number to start with"</span>),
s.field(<span style="color: #e9b96e;">"ending_int"</span>, <span style="color: #b4fa70;">self</span>.count, 14,
doc=<span style="color: #e9b96e;">"Number to end with"</span>),
s.field(<span style="color: #e9b96e;">"queue_timeout_ms"</span>, <span style="color: #b4fa70;">self</span>.count, 100,
doc=<span style="color: #e9b96e;">"Milliseconds to wait on queue before timing out"</span>),
], doc=<span style="color: #e9b96e;">"Fake Data Consumer DAQ Module Configuration"</span>),
};
</pre>
</div>
<p>
This temporary <code>fdc</code> object holds three types. When referred to by the
local attribute keys they are:
</p>
<dl class="org-dl">
<dt><code>size</code></dt><dd>a <code>number</code> of Numpy-style dtype <code>"u8"</code></dd>
<dt><code>count</code></dt><dd>another <code>number</code> of dtype <code>"i4"</code></dd>
<dt><code>conf</code></dt><dd>a <code>record</code> with various fields, each with a type</dd>
</dl>
<p>
A few things to note about the types:
</p>
<ul class="org-ul">
<li>a type has a name given as the first argument to its construction function</li>
<li>a type may have a <code>doc</code> which is a short description ("docstring").</li>
</ul>
<p>
The type held in the <code>conf</code> key is a <code>record</code> named <code>Conf</code> (fully qualified,
<code>dunedaq.appfwk.fdc.Conf</code>). A <code>record</code> holds an array of fields. Each
<code>field</code> itself has a type which is specified as a reference by naming an
attribute key, eg <code>self.count</code>. Fields may also be given a <code>doc</code>.
</p>
</div>
</div>
<div id="outline-container-orgd5e1cda" class="outline-2">
<h2 id="orgd5e1cda">Finishing the schema</h2>
<div class="outline-text-2" id="text-orgd5e1cda">
<p>
We now come to the last line in our Jsonnet program which prepares our
final <b>array of types</b>. It is:
</p>
<div class="org-src-container">
<pre class="src src-jsonnet">moo.oschema.sort_select(fdc, ns)
</pre>
</div>
<p>
The <code>fdc</code> is our temporary working object and the <code>ns</code> is again the "base
path" defined at the top of the file. The <code>sort_select()</code> function will:
</p>
<ul class="org-ul">
<li>perform a <a href="https://en.wikipedia.org/wiki/Topological_sorting">topological sort</a> on the graph formed by the types and any
type references they hold</li>
<li>return the sorted list with any types that reside outside the "base
path" removed.</li>
</ul>
</div>
</div>
<div id="outline-container-org211a2d9" class="outline-2">
<h2 id="org211a2d9">Compiled result</h2>
<div class="outline-text-2" id="text-org211a2d9">
<p>
Normally we will leave the schema in this Jsonnet form as <code>moo</code> can read
it directly. It is sometimes instructive to see the result of
"compiling" the Jsonnet program to JSON. It is also important to do
this frequently while developing the schema to assure there are no
syntax or other errors. Here is one command to run and its full JSON
output:
</p>
<div class="org-src-container">
<pre class="src src-shell">moo compile appfwk-fdc-schema.jsonnet
</pre>
</div>
<div class="org-src-container">
<pre class="src src-json">[
{
<span style="color: #b4fa70;">"deps"</span>: [],
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"A count of very many things"</span>,
<span style="color: #b4fa70;">"dtype"</span>: <span style="color: #e9b96e;">"u8"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"Size"</span>,
<span style="color: #b4fa70;">"path"</span>: [
<span style="color: #e9b96e;">"dunedaq"</span>,
<span style="color: #e9b96e;">"appfwk"</span>,
<span style="color: #e9b96e;">"fdc"</span>
],
<span style="color: #b4fa70;">"schema"</span>: <span style="color: #e9b96e;">"number"</span>
},
{
<span style="color: #b4fa70;">"deps"</span>: [],
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"A count of not too many things"</span>,
<span style="color: #b4fa70;">"dtype"</span>: <span style="color: #e9b96e;">"i4"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"Count"</span>,
<span style="color: #b4fa70;">"path"</span>: [
<span style="color: #e9b96e;">"dunedaq"</span>,
<span style="color: #e9b96e;">"appfwk"</span>,
<span style="color: #e9b96e;">"fdc"</span>
],
<span style="color: #b4fa70;">"schema"</span>: <span style="color: #e9b96e;">"number"</span>
},
{
<span style="color: #b4fa70;">"deps"</span>: [
<span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Size"</span>,
<span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>,
<span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>,
<span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>
],
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"Fake Data Consumer DAQ Module Configuration"</span>,
<span style="color: #b4fa70;">"fields"</span>: [
{
<span style="color: #b4fa70;">"default"</span>: <span style="color: #e9b2e3;">10</span>,
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"Number of numbers"</span>,
<span style="color: #b4fa70;">"item"</span>: <span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Size"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"nIntsPerVector"</span>
},
{
<span style="color: #b4fa70;">"default"</span>: -<span style="color: #e9b2e3;">4</span>,
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"Number to start with"</span>,
<span style="color: #b4fa70;">"item"</span>: <span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"starting_int"</span>
},
{
<span style="color: #b4fa70;">"default"</span>: <span style="color: #e9b2e3;">14</span>,
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"Number to end with"</span>,
<span style="color: #b4fa70;">"item"</span>: <span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"ending_int"</span>
},
{
<span style="color: #b4fa70;">"default"</span>: <span style="color: #e9b2e3;">100</span>,
<span style="color: #b4fa70;">"doc"</span>: <span style="color: #e9b96e;">"Milliseconds to wait on queue before timing out"</span>,
<span style="color: #b4fa70;">"item"</span>: <span style="color: #e9b96e;">"dunedaq.appfwk.fdc.Count"</span>,
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"queue_timeout_ms"</span>
}
],
<span style="color: #b4fa70;">"name"</span>: <span style="color: #e9b96e;">"Conf"</span>,
<span style="color: #b4fa70;">"path"</span>: [
<span style="color: #e9b96e;">"dunedaq"</span>,
<span style="color: #e9b96e;">"appfwk"</span>,
<span style="color: #e9b96e;">"fdc"</span>
],
<span style="color: #b4fa70;">"schema"</span>: <span style="color: #e9b96e;">"record"</span>
}
]
</pre>
</div>
<div class="warning">
<p>
Never edit this JSON file nor any other generated files. Besides
being painful to edit JSON compared to Jsonnet, it is the Jsonnet that
is definitive. It is used in other contexts so editing the JSON will
break the contract that the schema represents. In other words: if you
edit the JSON you'll likely crash the DAQ!
</p>
</div>
</div>
</div>
<div id="outline-container-orgacd896a" class="outline-2">
<h2 id="orgacd896a">Code generating</h2>
<div class="outline-text-2" id="text-orgacd896a">
<p>
One primary purpose of schema is to generate code. This is done by
using <code>moo</code> to apply the schema data structure to a <i>template</i> file. The
template file is essentially a code file (eg, a C++ header file) with
additional markup in a meta language (<code>moo</code> uses Jinja2).
</p>
<p>
Currently, for each schema we generate two code files.
</p>
<dl class="org-dl">
<dt>struct</dt><dd>a C++ header file with C++ <code>struct</code> and <code>using</code> type aliases for each type in our schema.</dd>
<dt>nljs</dt><dd>short for <code>nlohmann::json</code> and a C++ header file holding <code>to_json()</code> and <code>from_json()</code> function definitions that allow serialization of the types defined in <b>struct</b>.</dd>
</dl>
<div class="warning">
<p>
Running the code generator will be integrated into our CMake build.
Until that support is ready we will generate code somewhat manually
with the help of a little <code>schema/generate.sh</code> script that will be
customized to each package and using the one provided by <code>appfwk</code> as a
starting point.
</p>
<p>
Also until we integrate the codegen with CMake we will actually commit
the generated headers to the source repository so that builds will be
successful. Normally, one should <b>not</b> commit generated files to code
repositories and we will cease doing this when CMake integration is
ready.
</p>
<p>
Although it is easy to run <code>generate</code>, the developer <b>must</b> remember to
re-run it each time any change to a schema is made in order that the
generated files are updated. The rest of this section describes the
<code>generate.sh</code> used in <code>appfwk</code>.
</p>
</div>
<p>
An example of a <code>moo</code> command line for code generation is:
</p>
<pre class="example">
moo -g /lang:ocpp.jsonnet \ # 1
-M /home/bv/dev/moo/examples/oschema \ # 2
-T /home/bv/dev/moo/examples/oschema \ # 3
-M /home/bv/dev/dune-daq/sv/appfwk/schema \ # 4
-A path=dunedaq.appfwk.fdc \ # 5
-A ctxpath=dunedaq \ # 6
-A os=appfwk-fdc-schema.jsonnet \ # 7
render omodel.jsonnet ostructs.hpp.j2 \ # 8
\ # 9
> /home/bv/dev/dune-daq/sv/appfwk/test/appfwk/fdc/Structs.hpp
</pre>
<p>
Some implementation details are exposed in this example and the
develop need not attempt to understand everything but for completeness
the command line is explained.
</p>
<ol class="org-ol">
<li>we "graft" on some supporting utility Jsonnet function provided by
<code>moo</code> at a location in the "model" (see note below)</li>
<li>set a path in which to find models (Jsonnet files)</li>
<li>set a path in which to find templates (Jinja files)</li>
<li>find our schema files</li>
<li>Set a "top-level argument" (TLA) <code>path</code> which names the a "base path"</li>
<li>Set a TLA which names a "context path"</li>
<li>Set a TLA to provide our schema</li>
<li>The <code>render</code> command applies the model (first file) to the template (second file)</li>
<li>The output of this is then redirected by <code>generate.sh</code> to a header file.</li>
</ol>
<div class="note">
<p>
A "model" is an overall data structure in a form expected by the
template. We use a model called <code>omodel.jsonnet</code> which defines a
Jsonnet top-level function which expects to receive our schema data
structure as a top-level argument (TLA). Thus the model's function
"glues" our schema data structure into the structure that is actually
required by the template.
</p>
</div>
</div>
</div>
<div id="outline-container-org913db63" class="outline-2">
<h2 id="org913db63">Object generating</h2>
<div class="outline-text-2" id="text-org913db63">
<p>
The codegen schema described above satisfies the "consumer" end of a
contract. We must also satisfy a "producer" end when we create actual
command objects. That is, we must be able to produce a data structure
such when fed through the processing inside <code>appfwk</code> the right bits pop
out to our <code>DAQModule</code> configuration handling method.
</p>
<div class="warning">
<p>
How we best do this is still in development. Eventually we will have
a "configuration editor" application. What follows is just one way to
do things with Jsonnet. A Python-centric approach is also under
development.
</p>
</div>
<p>
The main <code>appfwk</code> program <code>daq_application</code> accepts a <b>command sequence</b>
which is simply a number of <b>command objects</b> consumed in some serial
fashion. Many interfaces for consuming command objects exist and are
in development (file based, HTTP/REST server based).
</p>
<p>
Each command object is composed of an ID (<code>init</code>, <code>conf</code>, etc) and a
payload. The structure of the payoad depends on the command ID. In
some commands (notably <code>conf</code>) a portion of the payload is "addressed"
to be delivered to an instance of our <code>DAQModule</code> and the structure of
this portion is governed by the schema we wrote above.
</p>
<p>
To help make correct command objects, we may use a set of Jsonnet
functions. These reflect the structure of schema. We'll focus on a
job called "fdpc" which combines two <code>DAQModule</code> instances: one of the
<code>FakeDataProducerDAQModule</code> implementation and one of
<code>FakeDataConsumerDAQModule</code>.
</p>
<p>
Here, we build our command sequence as a JSON Array (a JSON Stream is
also possible). Let's walk through the Jsonnet defining the sequence.
</p>
<p>
First the preamble
</p>
<div class="org-src-container">
<pre class="src src-jsonnet"><span style="color: #b4fa70;">local</span> moo = <span style="color: #b4fa70;">import</span> <span style="color: #e9b96e;">"moo.jsonnet"</span>;
<span style="color: #b4fa70;">local</span> cmd = <span style="color: #b4fa70;">import</span> <span style="color: #e9b96e;">"appfwk-cmd-make.jsonnet"</span>;
<span style="color: #b4fa70;">local</span> fdp = <span style="color: #b4fa70;">import</span> <span style="color: #e9b96e;">"appfwk-fdp-make.jsonnet"</span>;
<span style="color: #b4fa70;">local</span> fdc = <span style="color: #b4fa70;">import</span> <span style="color: #e9b96e;">"appfwk-fdc-make.jsonnet"</span>;
<span style="color: #b4fa70;">local</span> qname = <span style="color: #e9b96e;">"hose"</span>; <span style="color: #73d216;">// the name of the single queue in this job</span>
</pre>
</div>
<p>
The <code>*-make.jsonnet</code> modules provide functions which reflect the schema.
The <code>cmd</code> schema governs the internals of <code>appfwk</code> while <code>fdp</code> and <code>fdc</code> cover
their associated <code>DAQModule</code> implementations. The <code>qname</code> is a name of an
<code>appfwk</code> Queue that is needed in a few places.
</p>
<p>
What follows is an array (<code>[...]</code>), each element is a command object
which we will take in turn.
</p>
<div class="org-src-container">
<pre class="src src-jsonnet">cmd.init([cmd.qspec(<span style="color: #e9b96e;">"hose"</span>, <span style="color: #e9b96e;">"StdDeQueue"</span>, 10)],
[cmd.mspec(<span style="color: #e9b96e;">"fdp"</span>, <span style="color: #e9b96e;">"FakeDataProducerDAQModule"</span>,
cmd.qinfo(fdp.queue, qname, cmd.qdir.output)),
cmd.mspec(<span style="color: #e9b96e;">"fdc"</span>, <span style="color: #e9b96e;">"FakeDataConsumerDAQModule"</span>,
cmd.qinfo(fdc.queue, qname, cmd.qdir.input))]),
</pre>
</div>
<p>
The <code>cmd.init()</code> function takes two arguments, a list of "queue specs"
and a list of "module specs". Instances of each speck type can be
also constructed with a corresponding function. The use of these
functions can catch some mistakes early.
</p>
<p>
A <code>qspec()</code> function returns an object defining an <code>appfwk</code> queue, giving
it a name, a "kind" and a capacity. A <code>mspec()</code> returns an object
holding information needed to instantiate and initialize a <code>DAQModule</code>
instance. A name and "kind" are given as well as one or a list of
"queue info" as returned by the <code>qinfo()</code> function. Queue info is
standardized information needed to locate a module's queue. The, eg,
<code>fdc.queue</code> gives a "label" which is also hard-wired into the module's
C++. The module can then associate this known label with the <code>qname</code>
(<code>"hose"</code> in this case). Finally a queue info is tagged as being for an
"input" or an "output" queue.
</p>
<div class="warning">
<p>
The module developer must write C++ code to make use of this queue
info. <code>appfwk</code> provides some helper functions. Most expected handling
of this information in the module C++ is expected to be very general
and may itself be provided as generated code in the future.
</p>
</div>
<p>
We next continue to defining the <code>conf</code> command object.
</p>
<div class="org-src-container">
<pre class="src src-jsonnet">cmd.conf([cmd.mcmd(<span style="color: #e9b96e;">"fdp"</span>, fdp.conf(10,-4,14)),
cmd.mcmd(<span style="color: #e9b96e;">"fdc"</span>, fdc.conf(10,-4,14))]),
</pre>
</div>
<p>
The <code>cmd.mcmd()</code> wraps is arguments in the correct structure expected by
<code>appfwk</code> for the portion of a <code>conf</code> command payload meant for each
module. The main information is provided by the module-specific <code>make</code>
helpers, eg <code>fdc.conf()</code>. Let's look a that function:
</p>
<div class="org-src-container">
<pre class="src src-jsonnet"><span style="color: #73d216;">// Make a conf object for FDC</span>
conf(nper, beg, end, toms=100) :: {
nIntsPerVector: nper, starting_int: beg, ending_int: end,
queue_timeout_ms: toms,
},
</pre>
</div>
<p>
You may compare this construction schema function to what is defined
in the corresponding codegen schema shows above to see it matches.
</p>
<div class="note">
<p>
This construction schema function was hand-written. Means to
automatically define it based on codegen schema is a work in progress.
</p>
</div>
</div>
</div>
<div id="outline-container-org440bdea" class="outline-2">
<h2 id="org440bdea">Validating</h2>
<div class="outline-text-2" id="text-org440bdea">
<p>
Due to the nature of the <code>appfwk</code> code, the codegen schema must have
type-free breaks in the overall command object schema. Thus, using
that same schema to validate a command object will be weak (any data
will fit the "<code>any</code>" types). A more explicit <b>validation schema</b> is made
as an extension to the codegen schema.
</p>
<div class="warning">
<p>
This is still a work in progress.
</p>
</div>
</div>
</div>
<div id="outline-container-org1523552" class="outline-2">
<h2 id="org1523552">Running</h2>
<div class="outline-text-2" id="text-org1523552">
<p>
Finally, we may run something:
</p>
<pre class="example">
$ moo compile appfwk/schema/fdpc-job.jsonnet > fdpc-job.json
$ daq_application --commandFacility file://fdpc-job.json
</pre>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Brett Viren</p>
<p class="date">Created: 2020-09-30 Wed 15:23</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>