Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
test
test_tagrules.cxx
Go to the documentation of this file.
1
/* Test TagRules
2
3
This has some built-in testing data but can also be used to test
4
from the command line.
5
6
test_tagrules file.jsonnet tag1 tag2 ...
7
8
The file (can be JSON also) must follow schema:
9
[array
10
{category1:
11
match1a: tagset1a
12
match1b: tagset1b
13
},
14
{category2:
15
match2: tagset2
16
},
17
]
18
19
*/
20
21
#include "
WireCellUtil/TagRules.h
"
22
#include "
WireCellUtil/Persist.h
"
23
24
#include <iostream>
25
26
using namespace
std
;
27
using namespace
WireCell
;
28
29
int
main
(
int
argc
,
char
*
argv
[])
30
{
31
std::string
jtext = R
"(
32
[
33
{
34
frame: {
35
tagXY: ["tagX%d"%n, "tagY%d"%n],
36
"is-tagged\\d": "was-tagged",
37
["is-tagged%d"%n]: "was-tagged%d"%n,
38
},
39
// Output traces are tagged based on a map from an
40
// input to one or more output tags.
41
trace: {
42
intagA: "outtagA%d"%n,
43
intagB: ["outtagB%d"%n, "outtagBB%d"%n],
44
}
45
} for n in std.range(0,5)
46
]
47
)";
48
49
tagrules::tagset_t
tags;
50
Configuration
cfg
;
51
if
(argc == 2) {
52
cfg =
Persist::load
(argv[1]);
// .jsonnet or .json file assumed
53
}
54
else
{
55
cfg =
Persist::loads
(jtext);
56
}
57
if
(argc > 2) {
58
for
(
int
ind=2; ind<
argc
; ++ind) {
59
tags.insert(argv[ind]);
60
}
61
}
62
else
{
63
tags.insert(
"tagXY"
);
64
tags.insert(
"tagXY"
);
// intenional duplicate
65
tags.insert(
"intagA"
);
66
tags.insert(
"dontmatchme"
);
// a tag that shouldn't be matched
67
tags.insert(
"is-tagged2"
);
68
}
69
70
int
iport = 0;
71
for
(
auto
jport : cfg) {
72
for
(
auto
cat : jport.getMemberNames()) {
73
auto
jrules = jport[cat];
74
auto
rs = convert<tagrules::ruleset_t>(jrules);
75
auto
newtags =
tagrules::transform
(tags, rs);
76
std::cout <<
"port:"
<<iport<<
", categ:\""
<<cat<<
"\": have tags:["
;
77
string
comma=
""
;
78
for
(
auto
t
: tags) {
79
std::cout << comma <<
t
;
80
comma =
", "
;
81
}
82
std::cout <<
"], got tags: ["
;
83
comma=
""
;
84
for
(
auto
t
: newtags) {
85
std::cout << comma <<
t
;
86
comma =
", "
;
87
}
88
std::cout <<
"], with rules:"
<<
std::endl
;
89
std::cout << jrules <<
std::endl
;
90
}
91
++iport;
92
std::cout <<
std::endl
;
93
}
94
return
0;
95
}
96
TagRules.h
WireCell::tagrules::tagset_t
std::unordered_set< tag_t > tagset_t
Definition:
TagRules.h:48
update_metadata.loads
loads
Definition:
update_metadata.py:26
generate_CCQE_events.t
t
Definition:
generate_CCQE_events.py:68
string
std::string string
Definition:
nybbler.cc:12
main
int main(int argc, char *argv[])
Definition:
test_tagrules.cxx:29
std
STL namespace.
dbjson.cfg
cfg
Definition:
dbjson.py:29
freeze_graph.argv
argv
Definition:
freeze_graph.py:218
WireCell::tagrules::transform
tagset_t transform(const tagset_t &ts, const ruleset_t &rs, bool all_rules=true)
Definition:
TagRules.cxx:43
WireCell
Definition:
Main.h:22
Persist.h
WireCell::Configuration
Json::Value Configuration
Definition:
Configuration.h:50
test_gen_rays_pdsp.argc
argc
Definition:
test_gen_rays_pdsp.py:6
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
wirecell.gen.depos.load
def load(filename, jpath="depos")
Definition:
depos.py:34
Generated by
1.8.11