EventSelector_t.cpp
Go to the documentation of this file.
5 
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
10 using namespace art;
11 using namespace fhicl;
12 using namespace std;
13 
14 constexpr size_t numBits = 5;
15 constexpr int numPatterns = 11;
16 constexpr int numMasks = 9;
17 
18 typedef bool Answers[numPatterns][numMasks];
19 typedef std::vector<std::string> Strings;
20 typedef std::vector<Strings> VStrings;
21 typedef std::vector<bool> Bools;
22 typedef std::vector<Bools> VBools;
23 
24 std::ostream&
25 operator<<(std::ostream& ost, const Strings& s)
26 {
27  for (auto const& str : s) {
28  ost << str << " ";
29  }
30  return ost;
31 }
32 
33 std::ostream&
34 operator<<(std::ostream& ost, const Bools& b)
35 {
36  for (unsigned int i = 0; i < b.size(); ++i) {
37  ost << b[i] << " ";
38  }
39  return ost;
40 }
41 
42 void
43 testone(const Strings& paths,
44  const Strings& pattern,
45  const Bools& mask,
46  bool answer,
47  int jmask)
48 {
49  EventSelector selector{pattern};
50 
51  int number_of_trigger_paths = 0;
52  std::vector<unsigned char> bitArray;
53 
54  HLTGlobalStatus bm(mask.size());
59  for (unsigned int b = 0; b < mask.size(); ++b) {
60  bm.at(b) = (mask[b] ? pass : fail);
61 
62  // There is an alternate version of the function acceptEvent
63  // that takes an array of characters as an argument instead
64  // of a TriggerResults object. These next few lines build
65  // that array so we can test that also.
66  if ((number_of_trigger_paths % 4) == 0)
67  bitArray.push_back(0);
68  int byteIndex = number_of_trigger_paths / 4;
69  int subIndex = number_of_trigger_paths % 4;
70  bitArray[byteIndex] |= (mask[b] ? art::hlt::Pass : art::hlt::Fail)
71  << (subIndex * 2);
72  ++number_of_trigger_paths;
73  }
74 
75  if (jmask == 8 && mask.size() > 4) {
76  bm.at(0) = ready;
77  bm.at(4) = ex;
78  bitArray[0] = (bitArray[0] & 0xfc) | art::hlt::Ready;
79  bitArray[1] = (bitArray[1] & 0xfc) | art::hlt::Exception;
80  }
81 
82  ParameterSet trigger_pset;
83  trigger_pset.put<Strings>("trigger_paths", paths);
84  ParameterSetRegistry::put(trigger_pset);
85 
86  TriggerResults const results_id{bm, trigger_pset.id()};
87  bool const result = selector.acceptEvent(ScheduleID::first(), results_id);
88  if (result != answer) {
89  std::cerr << "failed to compare pattern with mask using pset ID: "
90  << "correct=" << answer << " "
91  << "results=" << std::boolalpha << result << '\n'
92  << "pattern=" << pattern << "\n"
93  << "mask=" << mask << "\n"
94  << "jmask = " << jmask << "\n";
95  abort();
96  }
97 }
98 
99 void
100 testall(const Strings& paths,
101  const VStrings& patterns,
102  const VBools& masks,
103  const Answers& answers)
104 {
105  for (unsigned int i = 0; i < patterns.size(); ++i) {
106  for (unsigned int j = 0; j < masks.size(); ++j) {
107  testone(paths, patterns[i], masks[j], answers[i][j], j);
108  }
109  }
110 }
111 
112 int
114 {
115  Strings const paths{"a1", "a2", "a3", "a4", "a5"};
116  assert(size(paths) == numBits);
117 
118  VStrings patterns(numPatterns);
119  patterns[0] = {"a1", "a2"};
120  patterns[1] = {"!a1", "!a2"};
121  patterns[2] = {"a1", "!a2"};
122  patterns[3] = {"*"};
123  patterns[4] = {"!*"};
124  patterns[5] = {"*", "!*"};
125  patterns[6] = {"*", "!a2"};
126  patterns[7] = {"!*", "a2"};
127  patterns[8] = {"a1", "a2", "a5"};
128  patterns[9] = {"a3", "a4"};
129  patterns[10] = {"!a5"};
130 
131  VBools testmasks(numMasks);
132  testmasks[0] = {true, false, true, false, true};
133  testmasks[1] = {false, true, true, false, true};
134  testmasks[2] = {true, true, true, false, true};
135  testmasks[3] = {false, false, true, false, true};
136  testmasks[4] = {false, false, false, false, false};
137  testmasks[5] = {true, true, true, true, true};
138  testmasks[6] = {true, true, true, true, false};
139  testmasks[7] = {false, false, false, false, true};
140  testmasks[8] = {false,
141  false,
142  false,
143  false,
144  false}; // Not sure why this duplicates [4] above
145 
146  Answers ans = {
147  {true, true, true, false, false, true, true, false, false},
148  {true, true, false, true, true, false, false, true, true},
149  {true, false, true, true, true, true, true, true, true},
150  {true, true, true, true, false, true, true, true, false}, // last column
151  // changed due to
152  // treatment of
153  // excp
154  {false, false, false, false, true, false, false, false, false},
155  {true, true, true, true, true, true, true, true, false}, // last column
156  // changed due to
157  // treatment of
158  // excp
159  {true, true, true, true, true, true, true, true, true},
160  {false, true, true, false, true, true, true, false, false},
161  {true, true, true, true, false, true, true, true, false}, // last column
162  // changed due to
163  // treatment of
164  // excp
165  {true, true, true, true, false, true, true, false, false},
166  {false, false, false, false, true, false, true, false, false} // last column
167  // changed due
168  // to
169  // treatment
170  // of excp
171  };
172 
173  Strings bit_qualified_paths;
174  size_t i = 0;
175  for (auto const& name : paths) {
176  bit_qualified_paths.push_back(to_string(i) + ':' + name);
177  }
178 
179  // We are ready to run some tests
180  testall(bit_qualified_paths, patterns, testmasks, ans);
181  return 0;
182 }
static QCString name
Definition: declinfo.cpp:673
static QCString result
constexpr size_t numBits
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
STL namespace.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
std::vector< Bools > VBools
HLTPathStatus const pass
HLTPathStatus const fail
ParameterSetID id() const
constexpr int numMasks
std::vector< Strings > VStrings
int main()
std::string pattern
Definition: regex_t.cc:35
std::vector< bool > Bools
void testone(const Strings &paths, const Strings &pattern, const Bools &mask, bool answer, int jmask)
void testall(const Strings &paths, const VStrings &patterns, const VBools &masks, const Answers &answers)
static bool * b
Definition: config.cpp:1043
std::vector< std::string > Strings
constexpr int numPatterns
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
std::vector< std::vector< bool > > Answers
static QCString * s
Definition: config.cpp:1042
void put(std::string const &key)
static QCString str