Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
src
TagRules.cxx
Go to the documentation of this file.
1
#include "
WireCellUtil/TagRules.h
"
2
3
/* nb:
4
typedef std::string tag_t;
5
typedef std::string match_t;
6
typedef std::unordered_set<tag_t> tagset_t;
7
typedef std::pair<std::regex, tagset_t> rule_t;
8
typedef std::vector<rule_t> ruleset_t;
9
*/
10
11
#include <regex>
12
13
using namespace
WireCell
;
14
15
16
tagrules::tagset_t
tagrules::match
(
const
tag_t
&
tag
,
const
rule_t
& rule)
17
{
18
if
(std::regex_match(tag, rule.first)) {
19
return
rule.second;
20
}
21
return
tagset_t
{};
22
}
23
24
bool
tagrules::match
(
const
tagrules::tag_t
&
tag
,
const
tagrules::ruleset_t
& rs,
25
tagrules::tagset_t
& ret,
bool
all
)
26
{
27
bool
found
=
false
;
28
for
(
const
auto
& rule : rs) {
29
auto
ts =
tagrules::match
(tag, rule);
30
if
(ts.empty()) {
31
continue
;
32
}
33
ret.insert(ts.begin(), ts.end());
34
if
(all) {
35
found =
true
;
36
continue
;
37
}
38
return
true
;
39
}
40
return
found
;
41
}
42
43
tagrules::tagset_t
tagrules::transform
(
const
tagrules::tagset_t
& ts,
const
tagrules::ruleset_t
& rs,
bool
all
)
44
{
45
tagrules::tagset_t
ret;
46
for
(
auto
tag
: ts) {
47
tagrules::tagset_t
one;
48
if
(
match
(
tag
, rs, one, all)) {
49
ret.insert(one.begin(), one.end());
50
}
51
}
52
return
ret;
53
}
54
55
56
57
58
59
60
61
void
tagrules::Context::configure
(
const
Configuration
& jcfg)
62
{
63
if
(jcfg.empty() or !jcfg.isArray()) {
64
return
;
65
}
66
67
const
int
nrss = jcfg.size();
68
69
// Note: JSON is in name-major order, C++ index-major.
70
for
(
int
ind=0; ind<nrss; ++ind) {
71
auto
jone = jcfg[ind];
72
for
(
auto
name
: jone.getMemberNames()) {
73
auto
& rsv =
m_rulesets
[
name
];
// eg, "frame" or "trace"
74
rsv.resize(nrss);
75
rsv[ind] = convert<tagrules::ruleset_t>(jone[
name
]);
76
}
77
}
78
}
79
80
tagrules::tagset_t
tagrules::Context::transform
(
size_t
ind,
const
std::string
&
name
,
81
const
tagrules::tag_t
&
tag
)
82
{
83
const
auto
& rsv =
m_rulesets
[
name
];
84
if
(rsv.empty() or ind >= rsv.size()) {
85
return
tagrules::tagset_t
{};
86
}
87
const
auto
& rs = rsv[ind];
88
tagrules::tagset_t
ts;
89
ts.insert(tag);
90
return
tagrules::transform
(ts, rs);
91
}
name
static QCString name
Definition:
declinfo.cpp:673
WireCell::tagrules::rule_t
std::pair< std::regex, tagset_t > rule_t
Definition:
TagRules.h:49
TagRules.h
WireCell::tagrules::tagset_t
std::unordered_set< tag_t > tagset_t
Definition:
TagRules.h:48
string
std::string string
Definition:
nybbler.cc:12
tag
Definition:
ProxyBaseTest_module.cc:152
WireCell::tagrules::match
tagset_t match(const tag_t &tag, const rule_t &rs)
Definition:
TagRules.cxx:16
WireCell::tagrules::transform
tagset_t transform(const tagset_t &ts, const ruleset_t &rs, bool all_rules=true)
Definition:
TagRules.cxx:43
WireCell::tagrules::ruleset_t
std::vector< rule_t > ruleset_t
Definition:
TagRules.h:50
WireCell::tagrules::Context::m_rulesets
std::unordered_map< std::string, std::vector< ruleset_t > > m_rulesets
Definition:
TagRules.h:71
WireCell
Definition:
Main.h:22
all
static QInternalList< QTextCodec > * all
Definition:
qtextcodec.cpp:63
WireCell::tagrules::Context::transform
tagset_t transform(size_t ind, const std::string &name, const tag_t &tag)
Definition:
TagRules.cxx:80
WireCell::Configuration
Json::Value Configuration
Definition:
Configuration.h:50
ValidateOpDetReco.found
bool found
Definition:
ValidateOpDetReco.py:354
WireCell::tagrules::Context::configure
void configure(const Configuration &cfg)
Definition:
TagRules.cxx:61
WireCell::tagrules::tag_t
std::string tag_t
Definition:
TagRules.h:46
Generated by
1.8.11