Functions
test_tagrules.cxx File Reference
#include "WireCellUtil/TagRules.h"
#include "WireCellUtil/Persist.h"
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 29 of file test_tagrules.cxx.

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;
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 }
std::unordered_set< tag_t > tagset_t
Definition: TagRules.h:48
std::string string
Definition: nybbler.cc:12
cfg
Definition: dbjson.py:29
tagset_t transform(const tagset_t &ts, const ruleset_t &rs, bool all_rules=true)
Definition: TagRules.cxx:43
Json::Value Configuration
Definition: Configuration.h:50
QTextStream & endl(QTextStream &s)
def load(filename, jpath="depos")
Definition: depos.py:34